:root {
  color-scheme: light;
  --surface:        #fcfcfb;
  --plane:          #f9f9f7;
  --ink:            #0b0b0b;
  --ink-2:          #52514e;
  --ink-muted:      #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --hover:          rgba(11, 11, 11, 0.04);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --success-text: #006300;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5;
  --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface: #1a1a19; --plane: #0d0d0d;
    --ink: #ffffff; --ink-2: #c3c2b7; --ink-muted: #898781;
    --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.05);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --success-text: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a19; --plane: #0d0d0d;
  --ink: #ffffff; --ink-2: #c3c2b7; --ink-muted: #898781;
  --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.05);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --success-text: #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--plane);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

/* ---- layout ---------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }
.meta-line { color: var(--ink-muted); font-size: 12px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 49px; z-index: 19;
}
.filters .group { display: flex; align-items: center; gap: 4px; }
.filters label { color: var(--ink-muted); font-size: 12px; }

.tabs {
  display: flex; gap: 2px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 94px; z-index: 18; overflow-x: auto;
}
.tab {
  padding: 9px 14px; border: 0; background: none; cursor: pointer;
  color: var(--ink-2); font: inherit; font-size: 13px;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--s1); font-weight: 600; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

/* ---- controls -------------------------------------------------------- */
select, input, button {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 8px;
}
select, input { max-width: 240px; }
input[type="date"] { padding: 4px 6px; }
button { cursor: pointer; }
button:hover { background: var(--hover); }
button.primary { background: var(--s1); border-color: var(--s1); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { border-color: transparent; color: var(--ink-2); }
.chips { display: flex; gap: 4px; }
.chip {
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); font-size: 12px; cursor: pointer;
}
.chip.active { background: var(--s1); border-color: var(--s1); color: #fff; }

/* ---- cards ----------------------------------------------------------- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 14px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}
.card h2 {
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  margin: 0 0 10px; text-transform: uppercase; letter-spacing: 0.04em;
}
.card .head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card .head h2 { margin: 0; flex: 1; }

.kpi .label {
  font-size: 11px; color: var(--ink-muted); text-transform: uppercase;
  letter-spacing: 0.04em; margin-bottom: 4px;
}
.kpi .value { font-size: 25px; font-weight: 600; letter-spacing: -0.02em; }
.kpi .sub { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
.kpi .value.good { color: var(--success-text); }
.kpi .value.critical { color: var(--critical); }

.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }
.chart-box.short { height: 220px; }

/* ---- tables ---------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--grid); }
th {
  color: var(--ink-muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--hover); }
tr.clickable { cursor: pointer; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; }
.trunc { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.pill {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; border: 1px solid var(--border); color: var(--ink-2);
}
.pill.err { color: var(--critical); border-color: var(--critical); }
a { color: var(--s1); }

.empty { color: var(--ink-muted); padding: 18px 0; text-align: center; }
.note { color: var(--ink-muted); font-size: 12px; margin-top: 8px; }

/* ---- modal ----------------------------------------------------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 24px;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 12px; border: 1px solid var(--border);
  max-width: 900px; width: 100%; max-height: 85vh; overflow: auto; padding: 18px 20px;
}
.modal h3 { margin: 0 0 12px; font-size: 15px; }
.modal pre {
  white-space: pre-wrap; word-break: break-word; background: var(--plane);
  padding: 10px; border-radius: 8px; font-size: 12px; max-height: 320px; overflow: auto;
  border: 1px solid var(--border);
}
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--ink-muted); }
.kv dd { margin: 0; word-break: break-all; }

.toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  display: none; max-width: 380px;
}
.toast.show { display: block; }

.loading { opacity: 0.45; transition: opacity 0.15s; }

/* ---- chat ------------------------------------------------------------ */
.chat-layout {
  display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 14px;
  height: calc(100vh - 190px); min-height: 520px;
}
.chat-layout.with-files { grid-template-columns: 260px minmax(0, 1fr) 280px; }

.chat-sidebar { display: flex; flex-direction: column; overflow: hidden; padding: 12px; }
.chat-list { overflow-y: auto; margin: -4px; padding: 4px; }
.chat-item {
  padding: 8px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
  border: 1px solid transparent;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--hover); border-color: var(--border); }
.chat-item .t { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .m { font-size: 11px; color: var(--ink-muted); margin-top: 2px; }

.chat-main { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.chat-head .spacer { flex: 1; }
.chat-head label { color: var(--ink-muted); font-size: 12px; margin-right: 4px; }
.usage-badge { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; }
.msg { margin-bottom: 16px; max-width: 860px; }
.msg.user { margin-left: auto; }
.msg .bubble {
  padding: 10px 13px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--plane); white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble { background: var(--s1); border-color: var(--s1); color: #fff; }
.msg.error .bubble { border-color: var(--critical); color: var(--critical); }
.msg .meta {
  font-size: 11px; color: var(--ink-muted); margin-top: 4px;
  display: flex; gap: 10px; flex-wrap: wrap; font-variant-numeric: tabular-nums;
}
.msg.user .meta { justify-content: flex-end; }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3 { font-size: 14px; margin: 10px 0 4px; }
.msg .bubble code {
  font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  background: var(--hover); padding: 1px 4px; border-radius: 4px;
}
.msg .bubble pre {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; overflow-x: auto; margin: 8px 0;
}
.msg .bubble pre code { background: none; padding: 0; }
.msg .bubble table { margin: 8px 0; font-size: 12px; }

.tool-line {
  font-size: 12px; color: var(--ink-muted); margin: 4px 0 4px 2px;
  font-family: ui-monospace, Consolas, monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-line .dot { background: var(--s3); }

.chat-input {
  display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border);
}
.chat-input textarea {
  flex: 1; max-width: none; resize: vertical; font: inherit; font-size: 13px;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  background: var(--surface); color: var(--ink);
}
.chat-hints {
  display: flex; gap: 6px; flex-wrap: wrap; padding: 0 14px 12px;
}
.chat-hints button {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; color: var(--ink-2);
}
.chat-files { overflow-y: auto; padding: 12px; }
.file-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px;
  border-bottom: 1px solid var(--grid); font-size: 12px;
}
.file-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .size { color: var(--ink-muted); }

.typing::after {
  content: "▍"; animation: blink 1s steps(2) infinite; color: var(--ink-muted);
}
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 900px) {
  .chat-layout, .chat-layout.with-files { grid-template-columns: 1fr; height: auto; }
}

.file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--s1); text-decoration: none;
}
.file-chip:hover { background: var(--hover); }
.file-chip .size { color: var(--ink-muted); }

/* ---- prihlasenie CLI ------------------------------------------------- */
.auth-badge {
  font-size: 12px; color: var(--ink-2); margin-left: 6px;
  border-radius: 999px; padding: 3px 10px 3px 8px; white-space: nowrap;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
.auth-badge::before, .dot {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-muted); margin-right: 6px; vertical-align: 1px;
}
.auth-badge.on::before, .dot.on { background: var(--good); }
.auth-badge.off::before, .dot.off { background: var(--critical); }
.auth-badge.off { color: var(--critical); border-color: var(--critical); }

.auth-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 14px; font-size: 13px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--critical) 8%, var(--surface));
}

.modal .login-clis { margin-bottom: 12px; flex-wrap: wrap; }
.login-status { font-size: 13px; margin-bottom: 12px; }
.login-status.on strong { color: var(--success-text); }
.login-methods { display: grid; gap: 6px; margin-bottom: 12px; }
.login-method {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 13px;
}
.login-method.active { border-color: var(--s1); background: var(--hover); }
.login-method input { margin-top: 3px; }
.login-body { border-top: 1px solid var(--border); padding-top: 12px; font-size: 13px; }
.login-steps { margin: 0 0 12px; padding-left: 20px; line-height: 1.7; }
.login-steps code, .login-method code {
  font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  background: var(--hover); padding: 1px 4px; border-radius: 4px;
}
.login-row { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.login-link { font-weight: 600; }
.device-code {
  font-family: ui-monospace, Consolas, monospace; font-size: 18px; font-weight: 700;
  letter-spacing: 2px; padding: 2px 8px; border-radius: 6px; background: var(--hover);
  user-select: all;
}
.login-ok { color: var(--success-text); margin-top: 10px; }
.login-error { color: var(--critical); margin-top: 10px; }
#loginResult { margin-top: 12px; }
/* kluc skryty bez type=password - inak Chrome vnuti ulozene hesla a meno do filtrov */
input.secret { -webkit-text-security: disc; }

/* secret field: one input with a show/hide icon (password, setup token, API key) */
.pw-field { position: relative; display: flex; flex: 1; min-width: 0; }
.pw-field input { width: 100%; max-width: none; box-sizing: border-box; padding-right: 34px; }
.pw-toggle {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; padding: 4px 6px; line-height: 0; color: var(--ink-2);
}
.pw-toggle:hover { background: transparent; color: var(--ink); }
.pw-toggle svg { width: 16px; height: 16px; }
.pw-toggle .pw-hide, .pw-field.shown .pw-toggle .pw-show { display: none; }
.pw-field.shown .pw-toggle .pw-hide { display: inline; }

/* account dialogs (password change) */
.account-form { display: flex; flex-direction: column; gap: 10px; min-width: 300px; }
.account-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.account-form input { max-width: none; }

/* chats of other users: listed, readable, not writable */
.chat-filter { margin: 0 0 8px; }
.chat-item.foreign .t { color: var(--ink-2); }

/* admin dashboard (tab Ucty) */
.cli-badges { display: inline-flex; gap: 8px; white-space: nowrap; font-size: 12px; }
.cli-badge { display: inline-flex; align-items: center; }
.account-actions { display: flex; flex-direction: column; gap: 6px; min-width: 280px; }
.account-form label.inline { flex-direction: row; align-items: center; gap: 6px; }
.password-once { font-size: 16px; user-select: all; }
