/* nedemtra design system — tokeny, svetlý/tmavý/auto, mobile-first. */

:root {
  /* farby — svetlý režim */
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #efede8;
  --border: #e0ddd5;
  --text: #1c1b18;
  --text-2: #6b675e;
  --acc: #0b7a6b;        /* nedemtra teal */
  --acc-strong: #086355;
  --acc-soft: #e3f2ef;
  --danger: #b3372e;
  --danger-soft: #f9e8e6;
  --warn: #9a6b00;
  --warn-soft: #f7efdc;
  --ok: #2e7d43;
  --ok-soft: #e5f2e8;

  /* grafy — série validované CVD validátorom (svetlý povrch) */
  --chart-1: #008f70;
  --chart-2: #eb6834;
  --chart-grid: #e7e5de;
  --chart-axis: #c8c5bc;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 3px rgba(28,27,24,.08), 0 4px 16px rgba(28,27,24,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --chart-1: #25a58e;
  --chart-2: #d95926;
  --chart-grid: #2e2c27;
  --chart-axis: #45423b;
  --bg: #141311;
  --surface: #1e1d1a;
  --surface-2: #262420;
  --border: #35332d;
  --text: #ece9e2;
  --text-2: #a09b8f;
  --acc: #2fbfa9;
  --acc-strong: #4fd6c1;
  --acc-soft: #12312c;
  --danger: #e06055;
  --danger-soft: #3a1f1c;
  --warn: #d9a441;
  --warn-soft: #332a17;
  --ok: #66bb7a;
  --ok-soft: #1c2f21;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --chart-1: #25a58e;
    --chart-2: #d95926;
    --chart-grid: #2e2c27;
    --chart-axis: #45423b;
    --bg: #141311; --surface: #1e1d1a; --surface-2: #262420; --border: #35332d;
    --text: #ece9e2; --text-2: #a09b8f;
    --acc: #2fbfa9; --acc-strong: #4fd6c1; --acc-soft: #12312c;
    --danger: #e06055; --danger-soft: #3a1f1c;
    --warn: #d9a441; --warn-soft: #332a17;
    --ok: #66bb7a; --ok-soft: #1c2f21;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- layout ---------- */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; letter-spacing: -.02em; font-size: 18px; color: var(--text); text-decoration: none; }
.brand b { color: var(--acc); }
.topbar .spacer { flex: 1; }

.main { flex: 1; width: 100%; max-width: 900px; margin: 0 auto; padding: 16px; }
.main.wide { max-width: 1200px; }

/* spodná navigácia (mobil) / horná (desktop cez topbar) */
.nav {
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  position: sticky; bottom: 0; z-index: 20;
  padding: 4px 0 max(4px, env(safe-area-inset-bottom));
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); text-decoration: none; font-size: 11px; min-width: 56px;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.active { color: var(--acc); }
.nav a:active { background: var(--surface-2); }

@media (min-width: 800px) {
  .nav { position: sticky; top: 49px; bottom: auto; border-top: none; border-bottom: 1px solid var(--border);
         justify-content: center; gap: 8px; }
  .nav a { flex-direction: row; font-size: 14px; gap: 7px; padding: 8px 14px; }
  .nav a svg { width: 18px; height: 18px; }
}

/* ---------- komponenty ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 17px; }
.card h3 { margin: 14px 0 6px; font-size: 14px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 600; font-family: var(--font);
  cursor: pointer; text-decoration: none; transition: background .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #fff; }
.btn.primary:hover { background: var(--acc-strong); border-color: var(--acc-strong); }
[data-theme="dark"] .btn.primary, [data-theme="auto"] .btn.primary { color: #10201d; }
@media (prefers-color-scheme: light) { [data-theme="auto"] .btn.primary { color: #fff; } }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }

input, select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 16px; font-family: var(--font);
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--acc); outline-offset: 1px; border-color: var(--acc);
}
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 12px 0 4px; }
textarea { resize: vertical; min-height: 80px; }

.field-err { color: var(--danger); font-size: 14px; margin-top: 8px; }
.hint { color: var(--text-2); font-size: 13px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.badge.acc { background: var(--acc-soft); color: var(--acc); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- chat ---------- */
.chat-log { flex: 1; overflow-y: auto; padding: 8px 2px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg { max-width: 85%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--acc); color: #fff; border-bottom-right-radius: 4px; }
[data-theme="dark"] .msg.user { color: #10201d; }
.msg.system { align-self: center; background: var(--warn-soft); color: var(--warn); font-size: 13px; border-radius: 8px; }
.msg .time { display: block; font-size: 11px; opacity: .6; margin-top: 3px; text-align: right; }

/* robot: bez bubliny — čistý „dokumentový" tok ako v Claude Code */
.msg.robot {
  align-self: stretch; max-width: none; padding: 0 2px; border-radius: 0;
  background: transparent; white-space: normal;
}
.msg.robot .mhead {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 3px;
}
.msg.robot .mhead .star { color: var(--acc); font-size: 13px; }
.msg.robot .mhead .mtime { font-weight: 400; font-size: 11px; opacity: .7; }
.msg.robot .mbody { max-width: 70ch; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin: 0; }
.msg pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.msg code { font-family: var(--mono); font-size: .9em; }
.msg ul, .msg ol { margin: 4px 0; padding-left: 20px; }

/* oddeľovač dní */
.day-sep { display: flex; align-items: center; gap: 10px; margin: 6px 0; color: var(--text-2); font-size: 12px; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; border-top: 1px solid var(--border); }

/* prílohy */
.file-img { padding: 4px; max-width: 260px; text-decoration: none; }
.file-img img { display: block; max-width: 100%; min-width: 48px; min-height: 48px; border-radius: 11px; background: var(--surface-2); object-fit: cover; }
.file-img .time { padding: 2px 6px 4px; }
.file-chip { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 200px; }
.file-chip .fico svg { width: 26px; height: 26px; display: block; opacity: .9; }
.file-chip .fmeta { display: flex; flex-direction: column; min-width: 0; }
.file-chip .fname { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.file-chip .fsize { font-size: 11px; opacity: .75; }
.file-chip .time { margin-left: auto; align-self: flex-end; }
.chat-pane.dropping { outline: 2px dashed var(--acc); outline-offset: -6px; border-radius: var(--radius); }

/* „robot na tom pracuje" — riadok nad vstupom */
.working-note {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 4px 2px; font-size: 13px; color: var(--text-2); min-height: 28px;
}
.working-note[hidden] { display: none; }
.working-note .wstar { color: var(--acc); animation: star-spin 1.6s linear infinite; display: inline-block; }
.working-note .wtext { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; animation: shimmer-fade 1.4s ease-in-out infinite; }
@keyframes star-spin { to { transform: rotate(180deg); } }
@keyframes shimmer-fade { 50% { opacity: .45; } }

/* composer */
.composer {
  display: flex; align-items: flex-end; gap: 4px;
  border: 1px solid var(--border); border-radius: 18px; background: var(--surface);
  padding: 6px; margin-top: 4px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--acc); outline: 1px solid var(--acc); }
.composer textarea {
  flex: 1; border: none; background: transparent; box-shadow: none; resize: none;
  min-height: 34px; max-height: 160px; padding: 6px 4px;
}
.composer textarea:focus { outline: none; border: none; }
.composer .btn.icon { border: none; background: transparent; color: var(--text-2); }
.composer .btn.icon:hover { color: var(--acc); background: var(--surface-2); }
.composer .btn.send { background: var(--acc); color: #fff; border-radius: 12px; }
.composer .btn.send:hover { background: var(--acc-strong); }
[data-theme="dark"] .composer .btn.send { color: #10201d; }

.jump-down {
  position: absolute; right: 14px; bottom: 96px; z-index: 5;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 16px; cursor: pointer; box-shadow: var(--shadow);
}
.empty-star { font-size: 34px; color: var(--acc); margin-bottom: 6px; }

/* ---------- vlákna + live aktivita + stav robota ---------- */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap; max-width: 45vw; overflow: hidden;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.status-pill.working { background: var(--acc-soft); color: var(--acc); }
.status-pill.working .dot { background: var(--acc); animation: pulse 1.2s ease-in-out infinite; }
.status-pill.stopped { background: var(--danger-soft); color: var(--danger); }
.status-pill.stopped .dot { background: var(--danger); }
.status-pill .detail { font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 799px) { .status-pill .detail { display: none; } }
@keyframes pulse { 50% { opacity: .35; } }

.btn.icon { padding: 8px; }
.btn.icon svg { width: 18px; height: 18px; display: block; }

.chat-wrap { display: flex; gap: 14px; height: calc(100dvh - 180px); min-height: 320px; }
@media (min-width: 800px) { .chat-wrap { height: calc(100dvh - 220px); } }
.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.chat-head .thread-title { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.threads-panel {
  width: 260px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.threads-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.threads-head h2 { margin: 0; font-size: 15px; }
.thread-new { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.thread-new .btn { padding: 8px 12px; font-size: 13px; }
.thread-list { flex: 1; overflow-y: auto; }
.thread-item { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; }
.thread-item:hover { background: var(--surface-2); }
.thread-item.active { background: var(--acc-soft); }
.thread-item .row1 { display: flex; align-items: center; gap: 6px; }
.thread-item .tname { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-item .ttime { font-size: 11px; color: var(--text-2); flex-shrink: 0; }
.thread-item .tsnip { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--acc); flex-shrink: 0; }
.unread-dot.work { animation: pulse 1.2s ease-in-out infinite; }

@media (max-width: 799px) {
  .threads-panel {
    position: fixed; inset: 49px 0 auto 0; bottom: 0; z-index: 30; width: min(320px, 85vw);
    border-radius: 0; border-left: none; border-top: none; border-bottom: none;
    transform: translateX(-100%); transition: transform .18s ease-out; box-shadow: var(--shadow);
  }
  .threads-panel.open { transform: translateX(0); }
}
@media (min-width: 800px) { .threads-toggle { display: none; } }

details.act-group {
  align-self: stretch; max-width: none;
  border-left: 2px solid var(--border); padding: 2px 0 2px 12px;
  font-size: 12.5px; color: var(--text-2);
}
details.act-group summary { cursor: pointer; font-weight: 600; padding: 2px 0; list-style: none; display: flex; align-items: center; gap: 7px; user-select: none; }
details.act-group summary::-webkit-details-marker { display: none; }
details.act-group summary::before { content: '›'; transition: transform .12s; color: var(--text-2); }
details.act-group[open] summary::before { transform: rotate(90deg); }
details.act-group.live { border-left-color: var(--acc); }
details.act-group.live summary::after {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--acc);
  animation: pulse 1.2s ease-in-out infinite;
}
.act { padding: 2px 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; display: flex; gap: 8px; align-items: baseline; }
.act .ico { color: var(--acc); flex-shrink: 0; width: 12px; text-align: center; }
.act.note { font-family: var(--font); font-style: italic; font-size: 12.5px; }

/* ---------- stop ---------- */
.stopbar {
  background: var(--danger); color: #fff; text-align: center;
  padding: 8px 12px; font-weight: 700; font-size: 14px;
}
.stop-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch .track {
  position: absolute; inset: 0; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border); transition: background .15s;
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow); transition: transform .15s;
}
.switch input:checked ~ .track { background: var(--danger); border-color: var(--danger); }
.switch input:checked ~ .thumb { transform: translateX(22px); }
.switch input:focus-visible ~ .track { outline: 2px solid var(--acc); outline-offset: 1px; }

/* ---------- zoznamy / tabuľky ---------- */
.list-item {
  display: block; padding: 12px 14px; border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none; cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.list-item .row1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.list-item .row2 { display: flex; justify-content: space-between; color: var(--text-2); font-size: 13px; margin-top: 2px; gap: 8px; }
.card.flush { padding: 0; overflow: hidden; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar select, .toolbar input { width: auto; flex: 1; min-width: 120px; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 100%; max-width: 380px; }
.login-box .brand { font-size: 26px; display: block; text-align: center; margin-bottom: 18px; }
.qr-box { display: flex; justify-content: center; margin: 12px 0; background: #fff; border-radius: var(--radius-sm); padding: 12px; }
.secret-code { font-family: var(--mono); font-size: 14px; text-align: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px; user-select: all; overflow-wrap: anywhere; }

/* ---------- drobnosti ---------- */
.muted { color: var(--text-2); }
.right { text-align: right; }
.mt { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); z-index: 100;
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
.empty { text-align: center; color: var(--text-2); padding: 32px 16px; }

/* ---------- dashboard ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 40px; font-weight: 650; line-height: 1.15; letter-spacing: -.01em; }
.tile .sub { font-size: 12px; color: var(--text-2); }
.chart-wrap { position: relative; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--text); color: var(--bg); font-size: 12px; font-weight: 600;
  padding: 4px 9px; border-radius: 6px; white-space: nowrap;
  transform: translate(-50%, -130%); display: none;
}
details.tbl summary { cursor: pointer; color: var(--text-2); font-size: 13px; margin-top: 8px; }

/* ---------- call flow ---------- */
.outcome-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 800px) { .outcome-grid { grid-template-columns: repeat(3, 1fr); } }
.outcome-grid .btn { padding: 12px 8px; font-size: 14px; }
.outcome-grid .btn.selected { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); }
.script-box { white-space: pre-wrap; font-size: 15px; line-height: 1.6; }
.script-box p { margin: 0 0 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.kv dd a { color: var(--acc); }
.spin { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--acc); border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
