* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: oklch(97.3% 0.005 262);
  --surface: oklch(99.2% 0.002 262);
  --surface-2: oklch(96% 0.006 262);
  --ink: oklch(24% 0.02 262);
  --ink-2: oklch(46% 0.018 262);
  --ink-3: oklch(64% 0.014 262);
  --line: oklch(90.5% 0.008 262);
  --line-strong: oklch(84% 0.012 262);
  --accent: oklch(46% 0.125 266);
  --accent-hover: oklch(41% 0.13 266);
  --accent-soft: oklch(94.5% 0.022 266);
  --accent-soft-line: oklch(88% 0.04 266);
  --on-accent: oklch(98.5% 0.005 266);
  --ok: oklch(55% 0.11 160);
  --ok-soft: oklch(94.5% 0.035 160);
  --warn: oklch(58% 0.12 65);
  --warn-soft: oklch(95% 0.04 85);
  --danger: oklch(54% 0.16 25);
  --danger-soft: oklch(95.5% 0.025 25);
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-1: 0 1px 2px oklch(30% 0.02 262 / 0.05);
  --shadow-2: 0 2px 10px oklch(30% 0.02 262 / 0.07);
  --shadow-3: 0 8px 32px oklch(30% 0.03 262 / 0.13);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html { direction: rtl; }
body {
  font-family: 'Heebo', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Top bar ─────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.brand .mark svg { display: block; }
.brand .logo { font-size: 17.5px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.brand .logo b { color: var(--accent); font-weight: 700; }
.badge-callsai {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 3px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--ink-3); font-size: 13px; }

.container { max-width: 1080px; margin: 0 auto; padding: 30px 28px 72px; }

h1 { font-size: 23px; font-weight: 700; letter-spacing: -0.015em; margin-bottom: 4px; }
h2 { font-size: 16.5px; font-weight: 600; margin: 34px 0 14px; letter-spacing: -0.01em; }
.sub { color: var(--ink-2); margin-bottom: 26px; font-size: 14.5px; }

/* ── Tabs ─────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.tab {
  background: none; border: none; cursor: pointer; font-family: inherit;
  font-size: 14.5px; font-weight: 500; color: var(--ink-2);
  padding: 11px 20px 13px; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color 160ms var(--ease);
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab:hover:not(.active) { color: var(--ink); }

/* ── Buttons ─────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; cursor: pointer; font-family: inherit;
  font-size: 14px; font-weight: 500; line-height: 1;
  padding: 10px 18px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--on-accent);
  box-shadow: var(--shadow-1);
  transition: background 160ms var(--ease), border-color 160ms var(--ease),
              color 160ms var(--ease), box-shadow 160ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn.ghost { background: transparent; color: var(--ink-2); box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); box-shadow: none; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.big { font-size: 15.5px; padding: 14px 26px; border-radius: var(--radius-sm); }
.btn:disabled { opacity: 0.45; cursor: default; pointer-events: none; }

/* ── Cards ─────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-1);
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }

.agent-card { display: flex; flex-direction: column; gap: 4px; padding: 18px 20px; transition: box-shadow 180ms var(--ease), border-color 180ms var(--ease); }
.agent-card:hover { box-shadow: var(--shadow-2); border-color: var(--line-strong); }
.agent-card .icon { font-size: 24px; margin-bottom: 6px; }
.agent-card .name { font-weight: 600; font-size: 15.5px; letter-spacing: -0.01em; }
.agent-card .meta { color: var(--ink-3); font-size: 12.5px; line-height: 1.7; }
.agent-card .actions { display: flex; gap: 6px; margin-top: 14px; }
.agent-card .actions .btn { padding: 8px 14px; font-size: 13px; }

.new-card {
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px;
  border: 1.5px dashed var(--line-strong); background: transparent; color: var(--ink-3);
  cursor: pointer; min-height: 158px; border-radius: var(--radius);
  font-family: inherit; font-size: 14px; font-weight: 500;
  transition: border-color 160ms var(--ease), color 160ms var(--ease), background 160ms var(--ease);
}
.new-card:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.new-card .plus { font-size: 26px; font-weight: 300; }

/* ── Forms ─────────────────────────────── */
input, textarea, select {
  width: 100%; font-family: inherit; font-size: 14.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 10px 13px; outline: none;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
input:hover, textarea:hover, select:hover { border-color: var(--ink-3); }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, textarea:disabled, select:disabled { background: var(--surface-2); color: var(--ink-3); }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin: 16px 0 6px; }
textarea { resize: vertical; min-height: 84px; line-height: 1.6; }
::placeholder { color: var(--ink-3); }

/* ── Modals ─────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; background: oklch(22% 0.02 262 / 0.42);
  display: none; align-items: flex-start; justify-content: center; z-index: 50;
  padding: 48px 16px; overflow-y: auto;
}
.modal-back.open { display: flex; animation: fadeIn 180ms var(--ease); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: 16px; width: 560px; max-width: 100%;
  padding: 28px; box-shadow: var(--shadow-3); border: 1px solid var(--line);
  animation: modalIn 220ms var(--ease);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.modal h3 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 4px; }
.modal .hint { color: var(--ink-2); font-size: 13px; margin-bottom: 10px; line-height: 1.6; }
.modal .foot { display: flex; justify-content: flex-start; gap: 10px; margin-top: 26px; }

.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.tpl {
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 14px 15px; cursor: pointer;
  background: var(--surface);
  transition: border-color 140ms var(--ease), background 140ms var(--ease);
}
.tpl:hover { border-color: var(--ink-3); }
.tpl.sel { border-color: var(--accent); background: var(--accent-soft); }
.tpl .t { font-weight: 600; margin-bottom: 3px; font-size: 14.5px; }
.tpl .d { font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }

/* ── Tables ─────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: right; color: var(--ink-3); font-size: 11.5px; font-weight: 600;
  text-transform: none; letter-spacing: 0.02em;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; transition: background 120ms var(--ease); }
tr.clickable:hover { background: var(--surface-2); }

/* ── Misc ─────────────────────────────── */
.banner {
  background: var(--warn-soft); border: 1px solid oklch(87% 0.06 85); color: oklch(38% 0.08 65);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 24px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 14px;
}

.pill {
  font-size: 11.5px; font-weight: 500; padding: 2px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.err { color: var(--danger); font-size: 13.5px; margin-top: 10px; min-height: 18px; }
.muted { color: var(--ink-3); font-size: 12.5px; }

.footer-note { text-align: center; color: var(--ink-3); font-size: 12px; margin-top: 56px; }

/* ── Login ─────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1100px 500px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.login-card { width: 404px; max-width: 100%; text-align: center; padding: 44px 38px 38px; box-shadow: var(--shadow-2); }
.login-card .mark {
  width: 52px; height: 52px; border-radius: 15px; background: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; margin-bottom: 18px;
}
.login-card .big-logo { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; }
.login-card .big-logo b { color: var(--accent); }
.login-card .tag { color: var(--ink-2); font-size: 14px; margin-bottom: 20px; }
.login-card input { text-align: right; margin-top: 10px; padding: 12px 14px; }
.login-card .btn { width: 100%; margin-top: 20px; }

/* ── Talk screen ─────────────────────────────── */
.talk-wrap { max-width: 720px; margin: 0 auto; padding: 26px 24px; display: flex; flex-direction: column; height: calc(100vh - 58px); }
.talk-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.talk-head .who { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }

.transcript { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px 2px; }
.bubble {
  max-width: 78%; padding: 10px 15px; border-radius: 14px;
  line-height: 1.6; font-size: 14.5px;
  animation: bubbleIn 200ms var(--ease);
}
@keyframes bubbleIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bubble.user { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-right-radius: 5px; }
.bubble.agent { align-self: flex-end; background: var(--accent-soft); border: 1px solid var(--accent-soft-line); border-bottom-left-radius: 5px; }
.bubble .tag { display: block; font-size: 10.5px; font-weight: 600; color: var(--ink-3); margin-bottom: 3px; letter-spacing: 0.02em; }
.bubble.seekable { cursor: pointer; transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease); }
.bubble.seekable:hover { border-color: var(--accent); }
.bubble.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.bubble.current .tag { color: var(--accent); }

.talk-controls { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 18px 0 8px; border-top: 1px solid var(--line); }
.mic-btn {
  width: 78px; height: 78px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font-size: 28px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-2);
  transition: background 180ms var(--ease), transform 140ms var(--ease), box-shadow 180ms var(--ease);
}
.mic-btn:hover { background: var(--accent-hover); transform: scale(1.04); }
.mic-btn:active { transform: scale(0.98); }
.mic-btn.live { background: var(--danger); animation: pulse 1.8s var(--ease) infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 oklch(54% 0.16 25 / 0.30); }
  70% { box-shadow: 0 0 0 20px oklch(54% 0.16 25 / 0); }
  100% { box-shadow: 0 0 0 0 oklch(54% 0.16 25 / 0); }
}
.talk-status { color: var(--ink-2); font-size: 13.5px; min-height: 20px; }
.usage-bar { display: flex; gap: 20px; color: var(--ink-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.usage-bar b { font-weight: 600; color: var(--ink-2); }

.summary-card {
  background: var(--accent-soft); border: 1px solid var(--accent-soft-line);
  border-radius: var(--radius); padding: 18px; margin-top: 12px; font-size: 14px;
}

/* ── Summary rendering ─────────────────────────────── */
.sum-wrap { display: flex; flex-direction: column; gap: 9px; margin-top: 6px; }
.sum-lead { font-size: 14.5px; line-height: 1.65; padding-bottom: 11px; border-bottom: 1px solid var(--accent-soft-line); }
.sum-row { display: flex; gap: 14px; align-items: baseline; }
.sum-label { min-width: 148px; color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.sum-val { font-size: 14px; flex: 1; line-height: 1.55; }
.sum-bool { font-weight: 600; font-size: 12.5px; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.sum-bool.good { background: var(--ok-soft); color: var(--ok); }
.sum-bool.bad { background: var(--danger-soft); color: var(--danger); }
.sum-bool.off { background: var(--surface-2); color: var(--ink-3); }
.sum-score { font-weight: 600; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.sum-score.good { background: var(--ok-soft); color: var(--ok); }
.sum-score.mid { background: var(--warn-soft); color: var(--warn); }
.sum-score.bad { background: var(--danger-soft); color: var(--danger); }
.sum-chip {
  display: inline-block; background: var(--surface); border: 1px solid var(--accent-soft-line);
  border-radius: 999px; padding: 2px 11px; font-size: 12.5px; margin: 2px 0;
}
.sum-json-toggle {
  background: none; border: none; color: var(--ink-3); font-size: 11.5px;
  cursor: pointer; font-family: inherit; padding: 6px 0 2px;
}
.sum-json-toggle:hover { color: var(--accent); }
.sum-json {
  direction: ltr; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px; font-family: Consolas, monospace;
  font-size: 11.5px; white-space: pre-wrap; max-height: 220px; overflow-y: auto;
}

/* Viewers see the same screens without the controls that would fail server-side. */
body.readonly .new-card,
body.readonly .agent-card .btn.danger,
body.readonly .agent-card .btn.secondary,
body.readonly #btnUpload { display: none; }
