/* YSRCP Voice Agent: admin and login pages.
   Layout: official, light dashboard. Party tricolour stripe on top, deep-blue header, white cards on a
   blue-tinted canvas, green for "healthy/answered". One column on phones. */
:root {
  --ysr-blue: #0b4fa8;
  --ysr-blue-deep: #083a7c;
  --ysr-blue-soft: #e7effb;
  --ysr-green: #138a3e;
  --ysr-green-soft: #e4f4ea;
  --bg: #f2f5fa;
  --surface: #ffffff;
  --ink: #12213b;
  --muted: #5f6d86;
  --line: #dde4ef;
  --warn: #a8670b;
  --warn-soft: #fcf1de;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --idle: #8a96ab;
  --display: "Poppins", "Segoe UI", system-ui, sans-serif;
  --body: "Noto Sans", "Noto Sans Telugu", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 33, 61, 0.06), 0 8px 24px -12px rgba(16, 33, 61, 0.18);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { animation: none !important; transition: none !important; } }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14.5px/1.55 var(--body); -webkit-font-smoothing: antialiased; }
a { color: var(--ysr-blue); }
code { font: 0.9em var(--mono); background: var(--ysr-blue-soft); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--ysr-blue); outline-offset: 2px; }

/* ---------------------------------------------------------------- brand */
.flag-stripe { display: flex; height: 5px; }
.flag-stripe i { flex: 1; }
.flag-stripe i:nth-child(1) { background: var(--ysr-blue); }
.flag-stripe i:nth-child(2) { background: #ffffff; }
.flag-stripe i:nth-child(3) { background: var(--ysr-green); }
.mark { width: 42px; height: 42px; flex: none; border-radius: 12px; box-shadow: 0 4px 14px -6px rgba(11, 79, 168, 0.8); }
.mark.small { width: 22px; height: 22px; border-radius: 6px; box-shadow: none; }

.adm-head {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(100deg, var(--ysr-blue-deep), var(--ysr-blue) 60%, #0e5fc4);
  color: #fff; box-shadow: 0 6px 20px -12px rgba(8, 58, 124, 0.9);
}
.adm-head-inner {
  max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px));
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand .mark { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35); }
.brand-party { display: block; font: 600 11.5px var(--body); letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.85; }
.brand-title { display: block; font: 600 18px/1.2 var(--display); }
.adm-nav { display: flex; gap: 4px; }
.adm-nav a { color: #dbe7fb; text-decoration: none; font-weight: 600; font-size: 13.5px; padding: 7px 12px; border-radius: 8px; }
.adm-nav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.head-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: flex; background: rgba(255, 255, 255, 0.12); border-radius: 9px; padding: 3px; }
.seg-btn { border: 0; background: none; color: #dbe7fb; font: 600 13px var(--body); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg-btn.active { background: #fff; color: var(--ysr-blue-deep); }
.user-chip { font-size: 12.5px; color: #dbe7fb; display: flex; align-items: center; gap: 8px; }
.adm-head .btn { border-color: rgba(255, 255, 255, 0.35); }
.adm-head .btn.primary { background: var(--ysr-green); border-color: transparent; }
.adm-head .btn.ghost-light { background: transparent; color: #fff; }

/* ---------------------------------------------------------------- layout */
.adm-main {
  max-width: 1320px; margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 40px;
}
.section { display: flex; flex-direction: column; gap: 16px; scroll-margin-top: 90px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
h1 { font: 700 24px/1.2 var(--display); margin: 0; text-wrap: balance; }
h2 { font: 600 15.5px/1.3 var(--display); margin: 0; }
.section-head p { margin: 4px 0 0; }
.updated { display: flex; align-items: center; gap: 7px; margin: 0; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ysr-green); box-shadow: 0 0 0 3px var(--ysr-green-soft); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 9px; padding: 8px 14px; cursor: pointer;
  font: 600 13px var(--body); text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
}
.btn:hover { border-color: #b9c6dc; }
.btn.primary { background: var(--ysr-blue); color: #fff; border-color: transparent; }
.btn.primary:hover { background: var(--ysr-blue-deep); }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.pill { font: 600 11.5px var(--body); padding: 3px 9px; border-radius: 999px; background: var(--ysr-blue-soft); color: var(--ysr-blue); }

/* ---------------------------------------------------------------- KPIs */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-height: 104px; position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--line); }
.kpi.good::after { background: var(--ysr-green); }
.kpi.warn::after { background: var(--warn); }
.kpi.bad::after { background: var(--bad); }
.kpi-label { font: 600 11.5px var(--body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.kpi-value { font: 700 28px/1.15 var(--display); margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-value small { font: 600 14px var(--body); color: var(--muted); margin-left: 3px; }
.kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.skeleton { background: linear-gradient(90deg, #eef2f8, #f7f9fc, #eef2f8); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------- stage bar */
.stage-bar { display: flex; height: 22px; border-radius: 7px; overflow: hidden; background: var(--bg); }
.stage-bar i { display: block; height: 100%; min-width: 2px; }
.stage-legend { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.stage-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13.5px; }
.stage-legend .sw { width: 12px; height: 12px; border-radius: 3px; }
.stage-legend .v { font: 600 13px var(--mono); font-variant-numeric: tabular-nums; }
.stage-legend .total { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; font-weight: 600; }
.s1 { background: #7aa7e6; } .s2 { background: var(--ysr-blue); } .s3 { background: #6f42c1; }
.s4 { background: #5cbf83; } .s5 { background: var(--ysr-green); }

/* ---------------------------------------------------------------- health */
.health { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.health li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 11px 0; border-bottom: 1px solid var(--line); }
.health li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--idle); }
.dot.ok { background: var(--ysr-green); box-shadow: 0 0 0 3px var(--ysr-green-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.h-name { font-weight: 600; }
.h-detail { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.h-when { font-size: 12.5px; color: var(--muted); white-space: nowrap; text-align: right; }
.h-state { display: block; font: 600 11.5px var(--body); text-transform: uppercase; letter-spacing: 0.05em; }
.h-state.ok { color: var(--ysr-green); } .h-state.warn { color: var(--warn); } .h-state.bad { color: var(--bad); } .h-state.idle { color: var(--idle); }

/* ---------------------------------------------------------------- volume chart */
.volume svg { display: block; width: 100%; height: 190px; }
.volume .axis { fill: var(--muted); font: 11px var(--body); }
.volume .grid { stroke: var(--line); }
.legend-inline { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.legend-inline .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.sw.ok { background: var(--ysr-blue); } .sw.bad { background: var(--bad); }

/* ---------------------------------------------------------------- table */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar input, .toolbar select, textarea, .field input {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px;
}
.toolbar input { flex: 1; min-width: 200px; }
.toolbar input:focus, .toolbar select:focus, textarea:focus, .field input:focus { outline: none; border-color: var(--ysr-blue); box-shadow: 0 0 0 3px var(--ysr-blue-soft); }
.table-wrap { overflow-x: auto; max-height: 560px; overflow-y: auto; }
table.turns { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.turns th { position: sticky; top: 0; background: #f7f9fc; text-align: left; font: 600 11.5px var(--body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
.turns td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.turns tbody tr { cursor: pointer; }
.turns tbody tr:hover { background: #f6f9fe; }
.turns td.txt { max-width: 340px; min-width: 200px; }
.turns td.txt div { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.turns .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.turns td.time { white-space: nowrap; color: var(--muted); }
.turns .empty { text-align: center; padding: 40px; cursor: default; }
.st { display: inline-block; font: 600 11.5px var(--body); padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.st.done { background: var(--ysr-green-soft); color: var(--ysr-green); }
.st.active { background: var(--ysr-blue-soft); color: var(--ysr-blue); }
.st.failed { background: var(--bad-soft); color: var(--bad); }
.st.cancelled, .st.noaudio { background: var(--warn-soft); color: var(--warn); }
.type { font-size: 12.5px; white-space: nowrap; }

/* ---------------------------------------------------------------- settings */
textarea { width: 100%; resize: vertical; line-height: 1.55; font-size: 13.5px; }
#persona { font: 13px/1.6 var(--mono); }
.summary-box { margin-top: 14px; font-size: 13.5px; }
.summary-box summary { cursor: pointer; font-weight: 600; }
.summary-text { white-space: pre-wrap; font-size: 13px; max-height: 220px; overflow-y: auto; }
.facts { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 8px 18px; margin: 0; font-size: 13.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; font-weight: 500; }

/* ---------------------------------------------------------------- drawer */
.scrim { position: fixed; inset: 0; background: rgba(16, 33, 61, 0.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 41; background: var(--surface);
  box-shadow: -20px 0 40px -20px rgba(16, 33, 61, 0.45); display: flex; flex-direction: column;
  padding-right: env(safe-area-inset-right, 0px); animation: slide 0.2s ease both;
}
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); border-top: 5px solid var(--ysr-blue); }
.drawer-body { padding: 18px 22px 30px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 14px; }
.d-label { font: 600 11.5px var(--body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.d-text { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; font-size: 14.5px; }
.d-error { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 5px 0; font-size: 13.5px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: 6px; top: -9px; height: 14px; width: 2px; background: var(--line); }
.timeline li:first-child::before { display: none; }
.timeline .tdot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); }
.timeline li.done .tdot { background: var(--ysr-green); border-color: var(--ysr-green); }
.timeline li.done::before { background: var(--ysr-green); }
.timeline .tdur { font: 12.5px var(--mono); color: var(--muted); }
.ids { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; font-size: 12.5px; }
.ids code { overflow-wrap: anywhere; }
audio { width: 100%; }

/* ---------------------------------------------------------------- footer, toasts */
.adm-foot { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-size: 12.5px; padding-top: 10px; border-top: 1px solid var(--line); }
.toasts { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13.5px; max-width: 360px; box-shadow: var(--shadow); }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ysr-green); }

/* ---------------------------------------------------------------- login */
.login-body { min-height: 100vh; display: flex; flex-direction: column; background:
  radial-gradient(900px 500px at 0% 0%, rgba(11, 79, 168, 0.16), transparent 60%),
  radial-gradient(800px 500px at 100% 100%, rgba(19, 138, 62, 0.14), transparent 60%), var(--bg); }
.login-wrap { flex: 1; display: grid; place-items: center; padding: 32px max(16px, env(safe-area-inset-right, 0px)) 32px max(16px, env(safe-area-inset-left, 0px)); }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 60px -30px rgba(16, 33, 61, 0.45); overflow: hidden; }
.login-top { background: linear-gradient(120deg, var(--ysr-blue-deep), var(--ysr-blue) 65%, #0e5fc4); color: #fff; padding: 26px 28px 22px; display: flex; gap: 14px; align-items: center; }
.login-top .mark { width: 52px; height: 52px; border-radius: 14px; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3); }
.login-top .brand-title { font-size: 20px; }
.login-form { padding: 24px 28px 28px; display: flex; flex-direction: column; gap: 14px; }
.login-form h1 { font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 13px; }
.field input { font-size: 15px; padding: 11px 13px; }
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--ysr-blue); font: 600 12.5px var(--body); cursor: pointer; padding: 6px 8px; }
.login-error { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.login-btn { width: 100%; justify-content: center; padding: 12px; font-size: 14.5px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 0 0 22px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .grid-2 { grid-template-columns: 1fr; }
  .adm-nav { display: none; }
  .head-actions { margin-left: 0; width: 100%; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 23px; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
}
