:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #eceae4;
  --text: #1d1e21;
  --muted: #6b6d73;
  --border: #dddad2;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --user: #2f5fd0;
  --user-text: #ffffff;
  --danger: #c83a2e;
  --ok: #24875a;
  --warn-bg: #fff6e0;
  --warn-border: #e8c46a;
  --code-bg: #f0eee8;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171a;
    --surface: #212226;
    --surface-2: #2b2d32;
    --text: #ececee;
    --muted: #9a9ca3;
    --border: #34363c;
    --accent: #6d95f5;
    --accent-text: #0e1220;
    --user: #3d64c4;
    --user-text: #ffffff;
    --danger: #ef6b5f;
    --ok: #4cc28a;
    --warn-bg: #2f2817;
    --warn-border: #7d6528;
    --code-bg: #1a1b1e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16171a; --surface: #212226; --surface-2: #2b2d32; --text: #ececee; --muted: #9a9ca3;
  --border: #34363c; --accent: #6d95f5; --accent-text: #0e1220; --user: #3d64c4; --user-text: #fff;
  --danger: #ef6b5f; --ok: #4cc28a; --warn-bg: #2f2817; --warn-border: #7d6528; --code-bg: #1a1b1e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 22px; height: 22px; fill: currentColor; }

/* logowanie */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px; display: grid; gap: 10px;
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.login-card label { font-size: 14px; color: var(--muted); }
.login-card input {
  font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.logo {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 4px;
  background: var(--accent) url("/static/icon-192.png") center/cover;
}
.primary {
  border: 0; border-radius: 10px; padding: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.error { color: var(--danger); min-height: 1.5em; margin: 0; font-size: 14px; }

/* aplikacja */
.app {
  height: 100%; height: 100dvh; display: flex; flex-direction: column;
  max-width: 820px; margin: 0 auto;
}
.bar {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; border-bottom: 1px solid var(--border);
}
.title { display: flex; align-items: center; gap: 10px; }
.title h1 { font-size: 18px; margin: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); }
.menu {
  position: absolute; right: 12px; top: calc(100% - 4px); z-index: 10; min-width: 260px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px;
  box-shadow: 0 8px 28px rgb(0 0 0 / .14); display: grid;
}
.menu button, .menu .toggle {
  text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 8px; font-size: 15px;
  display: flex; align-items: center; gap: 10px;
}
.menu button:hover, .menu .toggle:hover { background: var(--surface-2); }

.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 320px; }
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }

.msg { max-width: 88%; padding: 10px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.assistant p { margin: 0 0 .6em; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: .2em 0 .6em; padding-left: 1.3em; }
.msg.assistant a { color: var(--accent); }
.msg code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.msg pre {
  font-family: var(--mono); font-size: 13px; background: var(--code-bg); padding: 10px 12px;
  border-radius: 8px; overflow-x: auto; margin: .4em 0 .6em; white-space: pre;
}
.msg pre code { background: none; padding: 0; }
.status { align-self: flex-start; font-size: 13px; color: var(--muted); font-family: var(--mono); padding: 0 4px; overflow-wrap: anywhere; }
.divider { align-self: stretch; text-align: center; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

.approval {
  align-self: stretch; background: var(--warn-bg); border: 1px solid var(--warn-border);
  border-radius: var(--radius); padding: 12px 14px;
}
.approval h3 { margin: 0 0 6px; font-size: 15px; }
.approval pre {
  font-family: var(--mono); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere;
  margin: 0 0 10px; max-height: 280px; overflow-y: auto;
}
.approval .actions { display: flex; gap: 8px; }
.approval .actions button { flex: 1; padding: 10px; border-radius: 10px; border: 0; font-weight: 600; }
.approve { background: var(--ok); color: #fff; }
.reject { background: var(--surface-2); }
.approval.done .actions { display: none; }
.approval .result { font-size: 14px; font-weight: 600; }

.working { padding: 4px 16px; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px); border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; min-width: 0; resize: none; font: inherit; padding: 11px 14px; max-height: 160px;
  border-radius: 22px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.composer textarea:focus, .login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.mic, .send, .tool {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center; position: relative;
}
.mic, .tool { background: var(--surface-2); }

/* zdjęcia: podgląd przed wysłaniem i w rozmowie */
.attachments { display: flex; gap: 8px; padding: 10px 12px 0; overflow-x: auto; border-top: 1px solid var(--border); }
.attachments:not([hidden]) + .composer { border-top: 0; }
.thumb { position: relative; flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.loading img { opacity: .45; }
.thumb button {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%;
  background: rgb(0 0 0 / .6); color: #fff; font-size: 15px; line-height: 1; display: grid; place-items: center;
}
.msg.user .photo { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 6px; cursor: zoom-in; }
.msg.user .photo:last-child { margin-bottom: 0; }
.mic.recording { background: var(--danger); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
.mic.busy { opacity: .6; }
.rec-time {
  position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--danger); font-variant-numeric: tabular-nums;
}
.send { background: var(--accent); color: var(--accent-text); }
.send:disabled { opacity: .4; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgb(200 58 46 / .18); } }
