:root {
  --stone: #e6e7e3;
  --paper: #f8f8f6;
  --paper-2: #f1f1ee;
  --line: #cfd1cb;
  --line-soft: #e0e1dc;
  --ink: #1c2129;
  --ink-2: #4b515a;
  --ink-3: #7a808a;
  --navy: #2e4868;
  --navy-soft: #dfe6ef;
  --marker: #f3e37a;
  --marker-strong: #e9d24a;
  --tag: #fbf3c4;
  --error: #9b3b3b;
  --white: #ffffff;
  --top-bg: #1c2129; --top-fg: #f8f8f6; --top-muted: #aeb4bd; --top-line: #4b515a; --top-hover: #2a313b;
  --sel-bg: #ffffff;
  --sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  --display: var(--serif);
  --radius: 4px;
}

/* Vzhled Noc: tmavá čítárna, jantar místo bílé. Jediný režim. */
:root[data-theme="noc"] {
  --stone: #0f1216; --paper: #181c22; --paper-2: #1f242c; --line: #333a45; --line-soft: #272d36;
  --ink: #e8e4d9; --ink-2: #b7b2a5; --ink-3: #7f7b71;
  --navy: #e9b44c; --navy-soft: #3a3020; --marker: #6b5615; --marker-strong: #b8892c; --tag: #3a3020;
  --white: #12161b; --sel-bg: #232931;
  --top-bg: #0b0e12; --top-fg: #e8e4d9; --top-muted: #7f7b71; --top-line: #333a45; --top-hover: #1c2128;
  --sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif; --serif: "Source Serif 4", Georgia, serif; --display: "Source Serif 4", Georgia, serif;
  --radius: 4px;
}
:root[data-theme="noc"] mark { color: #fff3c4; }
:root[data-theme="noc"] .chip.active { background: var(--navy); border-color: var(--navy); color: #14110a; }
:root[data-theme="noc"] .chip.active .n { color: #4a3d1c; }
:root[data-theme="noc"] .btn-primary { background: var(--navy); border-color: var(--navy); color: #14110a; }
:root[data-theme="noc"] .btn-primary:hover { background: #d4a03f; }
:root[data-theme="noc"] .item.selected { background: var(--sel-bg); border-left-color: var(--navy); }
:root[data-theme="noc"] .thread .t.cur { background: var(--navy); border-color: var(--navy); color: #14110a; }
:root[data-theme="noc"] .idtag, :root[data-theme="noc"] .cite, :root[data-theme="noc"] .cite-demo, :root[data-theme="noc"] .inatt { background: var(--tag); border-color: var(--marker-strong); color: #f3d98a; }
:root[data-theme="noc"] .scope-interni { background: #22303f; color: #9fbce0; border-color: #33475e; }
:root[data-theme="noc"] .scope-protistrana { background: #3d2618; color: #f0b48c; border-color: #5a3a26; }
:root[data-theme="noc"] .scope-treti { background: #2a2d31; color: #b7b2a5; border-color: #3d4147; }
:root[data-theme="noc"] .msg.user { background: var(--paper-2); border-left: 3px solid var(--navy); }
:root[data-theme="noc"] .side-tabs button.active, :root[data-theme="noc"] .mobile-tabs button.active { border-bottom-color: var(--navy); box-shadow: inset 0 3px 0 var(--navy); }
:root[data-theme="noc"] .top-link { border-color: var(--top-line); }
:root[data-theme="noc"] .quote.att { border-left-color: var(--marker-strong); }
:root[data-theme="noc"] .people-table tbody tr:hover td { background: var(--navy-soft); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--sans); font-size: 14px; line-height: 1.45;
  color: var(--ink); background: var(--stone);
  display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
kbd { font: 12px var(--sans); background: var(--paper); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; }
mark { background: var(--marker); color: inherit; padding: 0 1px; border-radius: 2px; }
.hint { color: var(--ink-3); }

.top {
  height: 44px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; background: var(--top-bg); color: var(--top-fg);
}
.brand { font-weight: 600; letter-spacing: .01em; }
.brand-sub { font-weight: 400; color: var(--top-muted); margin-left: 10px; }
.top-nav { margin-left: auto; margin-right: 18px; display: flex; gap: 8px; align-items: center; }
a.top-link { text-decoration: none; font-size: 14px; }
.acc-block a { color: var(--navy); }
.top-link { background: none; border: 1px solid var(--top-line); color: var(--top-fg); border-radius: var(--radius); padding: 4px 12px; cursor: pointer; }
.top-link:hover { background: var(--top-hover); }
.people { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.people-head { padding: 20px 32px 10px; }
.people-head h1 { font: 500 20px/1.3 var(--display); margin: 0 0 10px; }
.people-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.people-tools input { flex: 1; min-width: 180px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); }
.people-tools select { padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); }
.people-head .hint { margin: 0; font-size: 12.5px; }
.people-table-wrap { flex: 1; overflow: auto; padding: 0 32px 40px; }
.people-table { border-collapse: collapse; width: 100%; font-size: 13px; background: var(--white); }
.people-table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--ink-2); padding: 8px 10px; border-bottom: 2px solid var(--line); position: sticky; top: 0; background: var(--paper-2); }
.people-table td { padding: 7px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.people-table tbody tr { cursor: pointer; }
.people-table tbody tr:hover td { background: var(--navy-soft); }
.people-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.people-table th.num, .people-table td.num { width: 64px; }
.people-table .pname { font-weight: 500; }
.people-table .pmail { font-size: 11.5px; color: var(--ink-3); }
.people-table .range { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 12px; }
.status { font-size: 12.5px; color: var(--top-muted); display: flex; align-items: center; gap: 8px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--top-muted); display: inline-block; }
.status .dot.on { background: var(--marker-strong); }

.cols { flex: 1; min-height: 0; display: grid; grid-template-columns: 360px minmax(0, 1fr) 400px; gap: 1px; background: var(--line); }
.col { min-height: 0; display: flex; flex-direction: column; background: var(--paper); }

/* seznam */
.search-box { position: relative; padding: 12px 12px 8px; }
#q { width: 100%; padding: 9px 32px 9px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); outline: none; }
#q:focus { border-color: var(--navy); box-shadow: 0 0 0 3px var(--navy-soft); }
#q-clear { position: absolute; right: 18px; top: 18px; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--ink-3); padding: 2px 6px; border-radius: var(--radius); font-size: 16px; line-height: 1; }
.icon-btn:hover { color: var(--ink); background: var(--paper-2); }
.filters { padding: 0 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--white); border-radius: 999px; padding: 3px 10px; cursor: pointer;
  font-size: 12.5px; color: var(--ink-2);
}
.chip .n { color: var(--ink-3); margin-left: 4px; }
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip.active .n { color: var(--top-muted); }
.scope { display: inline-block; font-size: 11px; border-radius: 3px; padding: 0 6px; line-height: 1.6; border: 1px solid transparent; vertical-align: baseline; }
.scope-interni { background: #e8ecf2; color: #2e4868; border-color: #c9d3e0; }
.scope-protistrana { background: #f7e3d6; color: #7a3b18; border-color: #e6c3ae; }
.scope-treti { background: #ebebe6; color: #5a5f66; border-color: #d3d4cd; }
.chip-interni.active { background: #2e4868; border-color: #2e4868; }
.chip-protistrana.active { background: #7a3b18; border-color: #7a3b18; }
.chip-treti.active { background: #5a5f66; border-color: #5a5f66; }
.thread .t.t-protistrana { border-left: 3px solid #c4693a; }
.thread .t.t-interni { border-left: 3px solid #2e4868; }
.filter-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.filter-row select { flex: 1; min-width: 0; padding: 5px 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); }
.own-toggle { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.list-head { padding: 6px 14px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); background: var(--paper-2); min-height: 27px; }
.list { flex: 1; overflow-y: auto; outline: none; }
.item { padding: 10px 14px 10px 12px; border-bottom: 1px solid var(--line-soft); cursor: pointer; border-left: 3px solid transparent; }
.item:hover { background: var(--paper-2); }
.item.selected { background: var(--sel-bg); border-left-color: var(--navy); }
.item .meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-3); }
.item .meta .date { font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .from { font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .subject { margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .snippet { margin-top: 3px; font-size: 12.5px; color: var(--ink-2); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .attach { color: var(--ink-3); }
.item .boxes { color: var(--ink-3); }
.list-more { padding: 12px; text-align: center; color: var(--ink-3); font-size: 12.5px; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--ink-3); }

/* čtečka */
.col-read { background: var(--paper-2); }
.reader-empty { margin: auto; text-align: center; color: var(--ink-2); padding: 20px; }
.reader { flex: 1; overflow-y: auto; padding: 22px 32px 60px; }
.reader-inner { max-width: 78ch; }
.mail-head { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 14px; }
.mail-head h1 { font: 500 20px/1.3 var(--display); margin: 0 0 10px; }
.mail-head .row { display: grid; grid-template-columns: 74px 1fr; gap: 2px 10px; font-size: 13px; }
.mail-head .row dt { color: var(--ink-3); }
.mail-head .row dd { margin: 0; }
.mail-head .idtag { float: right; font-size: 12px; background: var(--tag); border: 1px solid var(--marker-strong); border-radius: 3px; padding: 1px 7px; color: var(--ink-2); }
.attach-list { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.attach-list span { color: var(--ink-2); }
.attach-list span::before, .attach-list a::before { content: "📎 "; font-size: 11px; }
.attach-list a { color: var(--navy); text-decoration: none; border-bottom: 1px solid var(--navy-soft); }
.attach-list a:hover { border-bottom-color: var(--navy); }
.attach-list small { color: var(--ink-3); }
.inatt { font-size: 11px; background: var(--tag); border: 1px solid var(--marker-strong); border-radius: 3px; padding: 0 5px; color: var(--ink-2); }
.quote.att { border-left-color: var(--marker-strong); }
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-grid a { display: block; width: 120px; text-decoration: none; color: var(--ink-3); font-size: 11px; }
.photo-grid img { width: 120px; height: 90px; object-fit: cover; border-radius: 3px; border: 1px solid var(--line); background: var(--white); display: block; }
.photo-grid a:hover img { border-color: var(--navy); }
.photo-grid span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.thread { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 0; }
.thread .t { font-size: 12px; padding: 2px 8px; border-radius: 3px; border: 1px solid var(--line); background: var(--white); cursor: pointer; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.thread .t.cur { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.save-sel, .toast { background: var(--top-bg); color: var(--top-fg); }
.thread-label { font-size: 12px; color: var(--ink-3); margin-top: 10px; }
.own { font: 15px/1.6 var(--serif); white-space: pre-wrap; word-wrap: break-word; }
.own.empty { color: var(--ink-3); font-style: italic; }
.quote { margin-top: 14px; border-left: 3px solid var(--line); padding-left: 12px; }
.quote > summary { cursor: pointer; font-size: 13px; color: var(--ink-2); list-style: none; padding: 4px 0; }
.quote > summary::before { content: "▸ "; color: var(--ink-3); }
.quote[open] > summary::before { content: "▾ "; }
.quote > summary .qsub { color: var(--ink-3); }
.quote .own { font-size: 14px; color: var(--ink-2); margin-top: 6px; }
.reader .src { margin-top: 30px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 8px; }

/* chat a záložky */
.side-tabs { display: flex; border-bottom: 1px solid var(--line-soft); }
.side-tabs button { flex: 1; padding: 9px 0 7px; border: 0; background: none; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; }
.side-tabs button.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--marker-strong); }
.side-tabs #notes-count { color: var(--ink-3); font-weight: 400; }
.notes-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.notes-head { padding: 10px 12px; display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; }
.notes-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.note { border: 1px solid var(--line); border-left: 3px solid var(--marker-strong); border-radius: var(--radius); background: var(--white); padding: 8px 10px; font-size: 13.5px; line-height: 1.5; }
.note .note-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--ink-3); margin-bottom: 4px; }
.note .note-meta .actions { display: flex; gap: 8px; }
.note .note-meta button { background: none; border: 0; color: var(--ink-3); cursor: pointer; padding: 0; font-size: 11.5px; }
.note .note-meta button:hover { color: var(--ink); text-decoration: underline; }
.note p { margin: 0 0 6px; }
.note ul, .note ol { margin: 0 0 6px; padding-left: 18px; }
.note blockquote { margin: 4px 0 6px; padding-left: 8px; border-left: 3px solid var(--line); color: var(--ink-2); font-family: var(--serif); }
.note table { border-collapse: collapse; font-size: 12px; display: block; overflow-x: auto; }
.note th, .note td { border: 1px solid var(--line); padding: 2px 5px; }
.account-view { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 14px 20px; }
.acc-block { padding: 14px 0; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; }
.acc-block h2 { font: 600 14px/1.3 var(--sans); margin: 0 0 8px; }
.acc-block p { margin: 6px 0; }
.acc-block .row { display: flex; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.acc-block .row input { flex: 1; min-width: 120px; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); color: var(--ink); }
.acc-block code { font-size: 12.5px; background: var(--paper-2); padding: 1px 5px; border-radius: 3px; }
.acc-block .ok { color: var(--marker-strong); font-weight: 600; }
.acc-block .alt { margin-top: 8px; }
.acc-block .alt summary { cursor: pointer; color: var(--ink-3); font-size: 12.5px; }
.devcode { font-size: 18px; letter-spacing: .08em; padding: 3px 10px; }
.msg-line { font-size: 12.5px; color: var(--ink-2); min-height: 16px; margin-top: 4px; }
.msg-line.err { color: #e08585; }
.users-table { border-collapse: collapse; width: 100%; font-size: 12.5px; margin: 8px 0; }
.users-table td { padding: 4px 6px; border-bottom: 1px solid var(--line-soft); }
.users-table button { background: none; border: 0; color: var(--ink-3); cursor: pointer; font-size: 12px; padding: 0 4px; }
.users-table button:hover { color: var(--ink); text-decoration: underline; }
.notes-empty { color: var(--ink-3); text-align: center; padding: 30px 10px; }
.msg-actions { margin-top: -6px; font-size: 12px; }
.msg-actions button { background: none; border: 0; color: var(--ink-3); cursor: pointer; padding: 0; font-size: 12px; }
.msg-actions button:hover { color: var(--ink); text-decoration: underline; }
.save-sel { position: fixed; z-index: 50; background: var(--ink); color: var(--paper); border: 0; border-radius: var(--radius); padding: 6px 10px; font-size: 12.5px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.save-sel:hover { background: var(--top-hover); }
.toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: var(--radius); font-size: 13px; z-index: 60; }

.chat-head { display: grid; grid-template-columns: 1fr auto; gap: 8px 6px; padding: 12px 12px 10px; border-bottom: 1px solid var(--line-soft); align-items: center; }
.backend-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-3); min-width: 0; }
.backend-label select { flex: 1; min-width: 0; }
.chat-head select { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); }
.chat-head #chat-backend { max-width: 220px; }
.chat-head #chat-backend:disabled { opacity: .6; }
.btn { border: 1px solid var(--line); background: var(--white); border-radius: var(--radius); padding: 6px 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--paper-2); }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { background: var(--top-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 14px; }
.chat-intro { color: var(--ink-2); font-size: 13.5px; }
.chat-intro p { margin: 0 0 8px; }
.cite-demo, .cite {
  display: inline-block; font-size: 12px; background: var(--tag); border: 1px solid var(--marker-strong); border-radius: 3px;
  padding: 0 6px; color: var(--ink); cursor: pointer; line-height: 1.5; vertical-align: baseline; text-decoration: none;
}
.cite:hover { background: var(--marker); }
.msg { max-width: 100%; }
.msg.user { align-self: flex-end; background: var(--navy-soft); border-radius: 10px 10px 2px 10px; padding: 8px 12px; max-width: 90%; white-space: pre-wrap; }
.msg.assistant { font-size: 14px; line-height: 1.55; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 8px; padding-left: 20px; }
.msg.assistant li { margin: 2px 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { font-size: 14px; margin: 10px 0 4px; }
.msg.assistant code { font-size: 12.5px; background: var(--paper-2); padding: 0 3px; border-radius: 3px; }
.msg.assistant blockquote { margin: 4px 0 8px; padding-left: 10px; border-left: 3px solid var(--line); color: var(--ink-2); font-family: var(--serif); }
.msg.assistant table { border-collapse: collapse; font-size: 12.5px; margin: 4px 0 10px; display: block; overflow-x: auto; max-width: 100%; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--line); padding: 3px 6px; text-align: left; vertical-align: top; }
.msg.assistant th { background: var(--paper-2); font-weight: 600; }
.msg.error { color: var(--error); font-size: 13px; white-space: pre-wrap; }
.tools { font-size: 12px; color: var(--ink-3); margin: -8px 0 0; display: flex; flex-direction: column; gap: 2px; }
.tools div::before { content: "› "; }
.thinking { color: var(--ink-3); font-size: 12.5px; }
.thinking::after { content: ""; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.chat-form { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--line-soft); align-items: flex-end; }
#chat-input { flex: 1; resize: none; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); outline: none; max-height: 200px; }
#chat-input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px var(--navy-soft); }

.mobile-tabs { display: none; }
@media (max-width: 980px) {
  .cols { grid-template-columns: 1fr; }
  .col { display: none; }
  .col.show { display: flex; }
  .mobile-tabs { display: flex; flex: none; border-top: 1px solid var(--line); background: var(--paper); }
  .mobile-tabs button { flex: 1; padding: 10px; border: 0; background: none; color: var(--ink-2); }
  .mobile-tabs button.active { color: var(--ink); font-weight: 600; box-shadow: inset 0 3px 0 var(--marker-strong); }
  .reader { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { .thinking::after { animation: none; content: "…"; } }
