:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1d2126;
  --muted: #646b73;
  --line: #e2e0da;
  --accent: #1f5c4a;
  --accent-ink: #ffffff;
  --accent-soft: #e5efe9;
  --user: #eef1f4;
  --warn: #8a5a00;
  --danger: #a3271f;
  --code: #f1efe9;
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181b;
    --panel: #1c2024;
    --ink: #e6e8ea;
    --muted: #9aa2aa;
    --line: #2c3238;
    --accent: #5fb393;
    --accent-ink: #0d1a15;
    --accent-soft: #1f3129;
    --user: #242a30;
    --warn: #e0b45c;
    --danger: #ff8a80;
    --code: #252a2f;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}
button { font: inherit; cursor: pointer; }

/* Chat: stran se nikoli ne premika kot celota (prepreči »potegni za osvežitev«
   in elastično poskakovanje na iOS); premika se samo seznam sporočil. */
html:has(body.chat) { overscroll-behavior: none; overflow: hidden; height: 100%; }
body.chat {
  overscroll-behavior: none; overflow: hidden; height: 100%;
  position: fixed; inset: 0; width: 100%;
}
.thread, .convs { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
button:disabled { cursor: default; opacity: .55; }

/* --- prijava --- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent);
  color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.brand h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: .1px; }
.login p.sub { color: var(--muted); margin: 0 0 22px; font-size: 13.5px; }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font: inherit;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer textarea:focus { outline: none; }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.login button {
  margin-top: 20px; width: 100%; padding: 10px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.err { color: var(--danger); font-size: 13.5px; min-height: 20px; margin-top: 10px; }
.login .note { color: var(--muted); font-size: 12.5px; line-height: 1.45; margin: 6px 0 0; }

/* --- aplikacija --- */
.app { display: grid; grid-template-columns: 270px 1fr; height: 100%; }
.side {
  border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 16px; border-bottom: 1px solid var(--line); }
.new-btn {
  width: 100%; margin-top: 14px; padding: 9px; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.convs { flex: 1; overflow-y: auto; padding: 8px; }
.conv {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  border: 0; background: transparent; color: var(--ink); padding: 8px 10px; border-radius: 7px;
  font-size: 13.5px;
}
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv:hover { background: var(--user); }
.conv.active { background: var(--accent-soft); }
.conv .del { visibility: hidden; color: var(--muted); border: 0; background: none; padding: 0 2px; }
.conv:hover .del { visibility: visible; }
.side-foot {
  border-top: 1px solid var(--line); padding: 12px 16px; font-size: 12.5px; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.side-foot button { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 0; }

.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* noga */
.credit { padding: 0 16px 10px; font-size: 11px; color: var(--muted); opacity: .75; }
.login-wrap { grid-template-rows: 1fr auto; }
.credit-login { text-align: center; padding: 14px 0 4px; align-self: end; }
@media (max-width: 760px) { .credit { padding-bottom: calc(10px + env(safe-area-inset-bottom)); } }

/* povratna informacija */
.side-fb { padding: 10px 16px 0; border-top: 1px solid var(--line); }
.fb-btn {
  width: 100%; padding: 8px 10px; border-radius: 8px; font-size: 13.5px; text-align: left;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.fb-btn:hover { border-color: var(--accent); }
.topbar-actions { display: inline-flex; gap: 6px; }
.modal[hidden], .toast[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .4);
  display: grid; place-items: center; padding: 16px;
}
.modal-box {
  width: 100%; max-width: 480px; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px; padding: 22px;
  max-height: calc(100dvh - 32px); overflow-y: auto;
}
.modal-box h2 { margin: 0 0 4px; font-size: 17px; }
.modal-sub { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; }
.modal-box label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.modal-box select, .modal-box textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
}
.modal-box textarea { resize: vertical; min-height: 110px; }
.modal-box select:focus, .modal-box textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.modal-box .chk { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13.5px; margin-top: 12px; }
.modal-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.btn-pri, .btn-sec { padding: 9px 16px; border-radius: 8px; font-weight: 600; }
.btn-pri { border: 0; background: var(--accent); color: var(--accent-ink); }
.btn-sec { border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
}
@media (max-width: 760px) {
  .modal-box select, .modal-box textarea { font-size: 16px; }
}
.topbar {
  display: none; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 7px; padding: 5px 10px; }
.thread { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.thread-inner { max-width: 820px; margin: 0 auto; }
.empty { color: var(--muted); padding: 40px 4px; }
.empty h2 { color: var(--ink); font-size: 20px; font-weight: 600; margin: 0 0 6px; }
.empty .docs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.empty .docs span {
  font-family: var(--mono); font-size: 12px; border: 1px solid var(--line);
  background: var(--panel); border-radius: 5px; padding: 2px 7px;
}
.msg { margin: 0 0 20px; }
.msg.user .bubble {
  background: var(--user); border-radius: var(--radius); padding: 10px 14px;
  white-space: pre-wrap; margin-left: auto; max-width: 85%; width: fit-content;
}
.msg.assistant .bubble { padding: 2px 2px; }
.bubble p { margin: 0 0 .7em; }
.bubble ul, .bubble ol { margin: 0 0 .7em; padding-left: 1.3em; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15.5px; margin: 1em 0 .4em; }
.bubble code { font-family: var(--mono); font-size: 13px; background: var(--code); padding: 1px 5px; border-radius: 4px; }
.bubble pre { background: var(--code); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: 0 0 .8em; display: block; overflow-x: auto; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
.bubble th { background: var(--user); }
.bubble blockquote { margin: 0 0 .7em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.status {
  display: inline-flex; align-items: center; gap: 10px; color: var(--muted);
  font-size: 14px; padding: 4px 0;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.status-label { transition: opacity .2s; }
.status-time { font-family: var(--mono); font-size: 12px; opacity: .8; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .status-dot { animation: none; } }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg-tools { display: flex; gap: 6px; margin-top: 4px; }
.msg-tools button {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 6px; font-size: 12.5px; padding: 2px 9px;
}
.msg-tools button.on { color: var(--accent); border-color: var(--accent); }
.msg.error .bubble { color: var(--danger); }

.composer-wrap { padding: 8px 16px 16px; }
.composer {
  max-width: 820px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px;
}
.composer textarea {
  flex: 1; border: 0; resize: none; background: transparent; color: var(--ink);
  font: inherit; padding: 6px 8px; max-height: 220px; border-radius: 6px;
}
.composer button {
  border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  padding: 8px 14px; font-weight: 600;
}
.hint { max-width: 820px; margin: 6px auto 0; font-size: 12px; color: var(--muted); }

.errbox {
  position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 99;
  background: #fff3f2; color: #8a1c14; border: 1px solid #e8b4af; border-radius: 8px;
  padding: 10px 12px; font: 12px/1.4 ui-monospace, Menlo, monospace; white-space: pre-wrap;
  max-height: 40vh; overflow: auto;
}
/* Stolpca sta določena izrecno, da dodatni elementi ne morejo premakniti postavitve. */
.side { grid-column: 1; grid-row: 1; }
.main { grid-column: 2; grid-row: 1; }
.scrim { display: none; position: fixed; }
.icon-btn {
  min-width: 40px; height: 40px; display: inline-grid; place-items: center;
  font-size: 18px; line-height: 1;
}

/* --- telefon in ozki zasloni --- */
@media (max-width: 760px) {
  body { font-size: 16px; -webkit-text-size-adjust: 100%; }
  body.chat { height: 100dvh; }
  .app { grid-template-columns: 1fr; height: 100dvh; }
  .main { grid-column: 1; }

  /* stranski meni kot predal */
  .side {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
    width: min(320px, 86vw);
    transform: translateX(-102%); transition: transform .22s ease;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
    visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s;
  }
  .app.menu .side {
    transform: none; visibility: visible; transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .18);
  }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .38);
    opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  .app.menu .scrim { opacity: 1; pointer-events: auto; }

  .conv { padding: 12px 10px; font-size: 15px; }
  .conv .del { visibility: visible; font-size: 20px; padding: 0 6px; }
  .side-foot { padding: 14px 16px; }
  .side-foot button { padding: 6px 0; }

  /* zgornja vrstica */
  .topbar {
    display: flex; justify-content: space-between; padding: 6px 8px;
    padding-top: calc(6px + env(safe-area-inset-top));
    position: sticky; top: 0; z-index: 5;
  }
  .topbar-title { font-size: 15px; font-weight: 600; }

  /* pogovor */
  .thread { padding: 14px 12px 4px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .empty { padding: 20px 2px; }
  .empty h2 { font-size: 19px; }
  .msg { margin-bottom: 18px; }
  .msg.user .bubble { max-width: 92%; }
  .bubble { overflow-wrap: anywhere; }
  .bubble table { font-size: 13px; }
  .bubble th, .bubble td { padding: 5px 7px; }
  .msg-tools { flex-wrap: wrap; }
  .msg-tools button { padding: 6px 12px; font-size: 13.5px; }

  /* vnosno polje */
  .composer-wrap {
    padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--line);
  }
  .composer { border-radius: 14px; padding: 6px; }
  .composer textarea { font-size: 16px; max-height: 35dvh; }  /* 16px prepreči povečavo na iOS */
  .composer button { min-height: 40px; padding: 8px 14px; }
  .hint { display: none; }

  /* prijava */
  .login { padding: 22px; border-radius: 12px; }
  .login input { font-size: 16px; padding: 12px; }
  .login button { padding: 12px; }
}

@media (max-width: 380px) {
  .topbar-title { font-size: 14px; }
  .composer button { padding: 8px 10px; }
}

@media (hover: none) {
  .conv:hover { background: transparent; }
  .conv.active { background: var(--accent-soft); }
}
