/* Sunaoji app — Cuba admin look in Procellari colours. Tokens live in brand.css. */

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14.5px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1, h2, h3 { margin: 0; color: var(--ink); line-height: 1.2; font-weight: 500; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Shell: white sidebar + top bar ---------------------------------------- */
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.rail {
  background: var(--surface); box-shadow: 0 0 21px rgba(89, 102, 122, .1); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 0 14px 18px; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; height: 72px; padding: 0 8px; border-bottom: 1px solid var(--line-2); margin: 0 -14px 14px; padding-left: 22px; color: var(--ink); }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-name { font-weight: 600; font-size: 19px; letter-spacing: -.01em; line-height: 1.05; color: var(--ink); }
.brand-name small { display: block; font-weight: 400; font-size: 11.5px; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.nav-label { font-size: 11.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 12px 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--text); font-weight: 500; transition: background .2s, color .2s; }
.nav a:hover { background: var(--primary-soft); color: var(--primary); }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.nav svg { width: 19px; height: 19px; flex: none; }
.rail-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line-2); font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.rail-foot img { width: 18px; height: 18px; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 72px; background: var(--surface); box-shadow: 0 4px 24px rgba(89, 102, 122, .06); display: flex; align-items: center;
  justify-content: space-between; gap: 16px; padding: 0 clamp(16px, 3vw, 32px); position: sticky; top: 0; z-index: 4;
}
.crumb { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb b { color: var(--ink); font-weight: 500; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.top-actions select { width: auto; max-width: 200px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 600; flex: none; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip .who { line-height: 1.2; font-size: 13px; }
.user-chip .who b { color: var(--ink); font-weight: 500; display: block; }

main { padding: 28px clamp(16px, 3vw, 32px) 64px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; color: var(--muted); max-width: 64ch; }

/* Controls --------------------------------------------------------------- */
button, .btn {
  font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; line-height: 1.3;
  transition: background .2s, border-color .2s, box-shadow .2s;
}
button:hover, .btn:hover { border-color: var(--primary); color: var(--primary); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 6px 16px rgba(115, 102, 255, .25); }
.primary:hover, .btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: var(--on-primary); }
.danger { color: var(--danger); }
.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.danger.solid:hover { color: #fff; filter: brightness(1.05); }
.ghost { background: transparent; border-color: transparent; padding: 6px 10px; }
.ghost:hover { background: var(--primary-soft); border-color: transparent; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-weight: 500; font-size: 13.5px; color: var(--ink); margin-bottom: 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: 12.5px; margin-top: 5px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.6; }
input[type="checkbox"], input[type="range"] { width: auto; accent-color: var(--primary); }
input[type="range"] { width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; color: var(--text); }
.field { margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 18px; }

/* Cards ------------------------------------------------------------------ */
.card { background: var(--surface); border-radius: 15px; box-shadow: var(--shadow-sm); border: 0; }
.card-pad { padding: 22px; }
.section { padding: 22px; border-bottom: 1px solid var(--line-2); }
.section:last-child { border-bottom: 0; }
.section > h2 { margin-bottom: 4px; }
.section > .desc, .desc { color: var(--muted); margin: 0 0 16px; font-size: 13.5px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h2 { margin-bottom: 6px; }

.agents { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }
.agent-card { padding: 22px; display: flex; flex-direction: column; gap: 12px; color: inherit; transition: transform .2s, box-shadow .2s; }
a.agent-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: inherit; }
.agent-card h2 { font-size: 17px; }
.agent-card .greet { font-size: 16px; line-height: 1.55; color: var(--text); min-height: 48px; padding: 12px 14px; border-radius: 10px; background: var(--bg); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 3px 9px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.tag.plain { background: var(--line-2); color: var(--text); }

/* Tables ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12.5px; font-weight: 500; color: var(--ink); padding: 12px 16px; border-bottom: 1px solid var(--line-2); white-space: nowrap; background: var(--bg); }
td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--primary-soft); }
.filters { display: flex; gap: 10px; padding: 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.filters > * { width: auto; min-width: 150px; }
.filters .tpl-filter { min-width: 0; }

/* Status badges (dot + label, never colour alone) */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; white-space: nowrap; padding: 3px 9px; border-radius: 6px; background: var(--line-2); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s-completed { color: var(--success); background: var(--success-soft); }
.s-in_progress, .s-ringing, .s-queued, .s-running, .s-calling { color: #d9831a; background: var(--warning-soft); }
.s-in_progress::before, .s-running::before, .s-calling::before { animation: pulse 1.4s ease-in-out infinite; }
.s-failed, .s-busy { color: var(--danger); background: var(--danger-soft); }
.s-no_answer, .s-canceled, .s-paused, .s-draft, .s-retry, .s-pending, .s-dnc { color: var(--muted); }
@keyframes pulse { 50% { opacity: .3; } }

/* Turn strip: who spoke when (agent = purple, caller = orange) ------------ */
.strip { position: relative; height: 12px; border-radius: 6px; background: var(--line-2); overflow: hidden; }
.strip span { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.strip .agent { background: var(--primary); }
.strip .user { background: var(--warning); }
.strip .cut { box-shadow: inset -2px 0 0 var(--surface); }
.strip-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.strip-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Transcript ------------------------------------------------------------- */
.transcript { display: flex; flex-direction: column; gap: 10px; }
.turn { display: grid; grid-template-columns: 54px 1fr; gap: 10px; align-items: start; }
.turn .t { font-family: var(--mono); font-size: 11.5px; color: var(--muted); padding-top: 10px; text-align: right; }
.bubble { padding: 9px 13px; border-radius: 12px; font-size: 15.5px; line-height: 1.6; max-width: 62ch; color: var(--ink); }
.turn.agent .bubble { background: var(--primary-soft); border-top-left-radius: 3px; }
.turn.user .bubble { background: var(--warning-soft); border-top-left-radius: 3px; }
.turn .who { font-size: 11.5px; font-weight: 500; display: block; color: var(--muted); margin-bottom: 1px; }
.turn.tool .bubble { background: transparent; border: 1px dashed var(--line); font-family: var(--mono); font-size: 12px; color: var(--muted); }
.cut-mark { color: var(--danger); font-size: 12px; font-weight: 500; margin-left: 6px; white-space: nowrap; }

/* Agent editor ----------------------------------------------------------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 22px; align-items: start; }
.test-panel { position: sticky; top: 92px; }
.test-panel .section { padding: 20px; }
.phone-live { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.timer { font-family: var(--mono); font-size: 22px; color: var(--ink); }
.meters { display: grid; gap: 8px; margin: 14px 0 4px; }
.meter { display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.meter div { height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.meter b { display: block; height: 100%; width: 0; border-radius: 3px; transition: width 80ms linear; }
.meter.agent b { background: var(--primary); }
.meter.user b { background: var(--warning); }
.live-transcript { max-height: 380px; overflow-y: auto; }
.live-transcript .bubble { font-size: 14.5px; }

/* Drawer ----------------------------------------------------------------- */
.drawer-back { position: fixed; inset: 0; background: rgba(0, 2, 72, .25); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100%); background: var(--bg); z-index: 21; overflow-y: auto; box-shadow: var(--shadow-lg); animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer-head { position: sticky; top: 0; background: var(--surface); padding: 18px 24px; border-bottom: 1px solid var(--line-2); z-index: 1; }
.drawer-body { padding: 20px 24px 40px; display: grid; gap: 16px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px 20px; margin: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 500; color: var(--ink); }
audio { width: 100%; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; color: var(--ink); }

/* Usage ------------------------------------------------------------------ */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; margin-bottom: 22px; }
.tile { padding: 20px 22px; position: relative; overflow: hidden; }
.tile::after { content: ""; position: absolute; right: -24px; top: -24px; width: 84px; height: 84px; border-radius: 50%; background: var(--primary-soft); }
.tile .label { font-size: 13px; color: var(--muted); position: relative; z-index: 1; }
.tile .value { font-size: 28px; font-weight: 500; color: var(--ink); margin-top: 4px; position: relative; z-index: 1; }
.tile .sub { font-size: 12.5px; color: var(--muted); }
.quota { height: 6px; background: var(--line-2); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.quota b { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding-top: 8px; border-bottom: 1px solid var(--line); position: relative; }
.bars .bar { flex: 1; min-width: 4px; background: var(--primary); border-radius: 4px 4px 0 0; }
.bars .hit { flex: 1; display: flex; align-items: flex-end; height: 100%; }
.bars .hit:hover .bar, .bars .hit:focus-visible .bar { background: var(--primary-dark); }
.chart-tip { position: absolute; transform: translate(-50%, -100%); background: var(--ink); color: var(--surface); padding: 5px 9px; border-radius: 6px; font-size: 12px; pointer-events: none; white-space: nowrap; }
.axis { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 6px; font-family: var(--mono); }

.progress { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line-2); gap: 2px; min-width: 140px; }
.progress span { display: block; height: 100%; }
.p-completed { background: var(--success); }
.p-failed { background: var(--danger); }
.p-retry, .p-calling { background: var(--warning); }
.p-dnc { background: var(--muted); }

/* Auth: Procellari gradient panel + form ---------------------------------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
.auth-art { background: var(--gradient); color: #fff; padding: clamp(28px, 6vw, 72px); display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art::before { content: ""; position: absolute; inset: auto -120px -160px auto; width: 420px; height: 420px; border-radius: 50%; background: rgba(255, 255, 255, .08); }
.auth-art .brand { border: 0; margin: 0; padding: 0; height: auto; color: #fff; }
.auth-art .brand-name, .auth-art .brand-name small { color: #fff; }
.auth-art h1 { color: #fff; font-size: clamp(32px, 4vw, 50px); font-weight: 500; text-transform: uppercase; line-height: 1.08; max-width: 13ch; }
.eyebrow { font-family: var(--font-script); font-size: 24px; color: var(--warning); font-weight: 700; }
.auth-art .eyebrow { color: #ffe0b8; }
.hello-wall { font-size: clamp(20px, 2.2vw, 28px); line-height: 1.7; margin: 28px 0; }
.hello-wall span { display: inline-block; margin-right: 16px; opacity: .4; transition: opacity .4s; }
.hello-wall span.on { opacity: 1; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.auth-form form { width: min(380px, 100%); }
.auth-form h2 { font-size: 26px; margin-bottom: 4px; }
.switch { margin-top: 14px; font-size: 14px; color: var(--muted); }
.switch button { padding: 0; border: 0; background: none; color: var(--primary); font-weight: 500; box-shadow: none; }
.error { background: var(--danger-soft); color: var(--danger); padding: 10px 13px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.note { background: var(--warning-soft); color: var(--ink); padding: 11px 13px; border-radius: 8px; font-size: 13.5px; }
.secret { font-family: var(--mono); font-size: 12.5px; background: var(--line-2); padding: 9px 11px; border-radius: 8px; word-break: break-all; color: var(--ink); }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 50; }
#toast div { background: var(--ink); color: var(--surface); padding: 11px 18px; border-radius: 10px; font-weight: 500; box-shadow: var(--shadow); margin-top: 8px; }

/* Responsive ------------------------------------------------------------- */
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } .test-panel { position: static; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: sticky; top: 0; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; gap: 6px; overflow-x: auto; }
  .brand { height: auto; border: 0; margin: 0; padding: 0 6px 0 0; }
  .brand-name, .nav-label, .rail-foot { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 8px 10px; white-space: nowrap; }
  .nav a span { display: none; }
  .nav a[aria-current="page"] span { display: inline; }
  .topbar { position: static; height: auto; padding: 10px 16px; }
  .crumb, .user-chip .who { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .turn { grid-template-columns: 40px 1fr; }
}
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* Knowledge, tools & workflows ---------------------------------------------- */
.kb-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.kb-pick { padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.kb-pick:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.tool-list { display: grid; gap: 10px; margin-bottom: 12px; }
.tool-item { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; }
.tool-item .muted.small { margin-top: 2px; }
.tool-edit { margin-top: 14px; padding: 18px; border-radius: 12px; background: var(--bg); border: 1px dashed rgba(115, 102, 255, .45); }
.param-table { margin-bottom: 6px; }
.param-table th { background: transparent; padding: 6px 6px 6px 0; }
.param-table td { padding: 4px 6px 4px 0; border: 0; }
.hit-card { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--bg); }
.hit-card p { margin: 6px 0 0; white-space: pre-wrap; color: var(--ink); }
.wf-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.wf-row > select, .wf-row > input { width: auto; flex: 1 1 160px; }
.wf-inline { display: inline-flex; gap: 8px; align-items: center; flex: 2 1 320px; color: var(--muted); flex-wrap: wrap; }
.wf-inline input[data-k="url"] { flex: 1; }
.wf-step { display: inline-block; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); background: var(--primary-soft); padding: 4px 10px; border-radius: 6px; }
.add-sources input[type="file"] { padding: 8px; }
.param-table select { min-width: 100px; }
.section > h2 select { font-size: 14px; font-weight: 400; vertical-align: middle; }

/* Dashboard ------------------------------------------------------------------ */
.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 22px; margin-bottom: 22px; }
.dash-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.trend { font-size: 12.5px; color: var(--muted); }
.trend.up { color: var(--success); }
.trend.down { color: var(--danger); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.bars.stacked { gap: 6px; height: 200px; }
.bars .stack { width: 100%; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.bars .seg { min-height: 2px; }
.bars .seg:first-child { border-radius: 4px 4px 0 0; }
.bars .seg.ok { background: var(--primary); }
.bars .seg.nc { background: var(--warning); }
.bars .seg.ot { background: var(--line); }
.bars .hit:hover .seg, .bars .hit:focus-visible .seg { filter: brightness(.9); }
.outcomes { display: grid; gap: 14px; margin-top: 14px; }
.outcome .quota { margin-top: 6px; }
.checklist { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.checklist a { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); color: var(--ink); }
.checklist a:hover { border-color: var(--primary); }
.checklist .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 12px; flex: none; }
.checklist .done a { color: var(--muted); background: var(--bg); border-color: transparent; }
.checklist .done .tick { background: var(--success); border-color: var(--success); color: #fff; }
.live-now { border: 1px solid rgba(255, 169, 65, .45); }
.live-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.live-item { flex-direction: column; align-items: flex-start; gap: 2px; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 22px; border-bottom: 1px solid var(--line-2); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list li > span:first-child, .plain-list li > b + span { display: flex; flex-direction: column; }
.plain-list li.clickable { cursor: pointer; }
.plain-list li.clickable:hover { background: var(--primary-soft); }
.camp-mini { display: flex; justify-content: space-between; padding: 8px 0; color: var(--ink); border-bottom: 1px dashed var(--line-2); }
@media (max-width: 1100px) { .dash-grid, .dash-grid.three { grid-template-columns: 1fr; } }

.auth-form { position: relative; }
.auth-theme { position: absolute; top: 20px; right: 20px; }
@media (max-width: 860px) { .top-actions .theme-btn .theme-label { display: none; } }
