[hidden] { display: none !important; }
/* Pancake Dashboard: styles. Dark by default, light via the ◐ button. */
/* Agent Hub by CredoPH: light (default) and dark themes. CredoPH navy #04415E + charcoal #323232. */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface-1: #ffffff;
  --surface-2: #eef2f5;
  --border: #e0e6eb;
  --grid: #e9edf1;
  --text-primary: #1f2428;
  --text-secondary: #50585f;
  --text-muted: #838b92;
  --series-1: #1b6a93;   /* CredoPH blue */
  --series-2: #eb6834;   /* orange */
  --accent: #04415e;
  --accent-soft: #e2edf2;
  --accent-grad: linear-gradient(135deg, #0b5a7e, #04415e);
  --tone-violet: #efeafe; --tone-violet-fg: #6a4fe0;
  --tone-orange: #fdeee6; --tone-orange-fg: #c4521f;
  --tone-aqua:   #e3f6ef; --tone-aqua-fg:   #13805a;
  --tone-blue:   #e6f0fc; --tone-blue-fg:   #256abf;
  --warn-bg: #fff4d6; --warn-fg: #7a5200;
  --err-bg: #fde8e8;  --err-fg: #9b1c1c;
  --info-bg: #e2edf2; --info-fg: #04415e;
  --good: #008300; --serious: #c0302f;
  --shadow: 0 1px 2px rgba(23,21,31,.04), 0 4px 16px rgba(4,65,94,.06);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1115;
  --surface-1: #141a20;
  --surface-2: #1b232a;
  --border: #27313a;
  --grid: #222b33;
  --text-primary: #eef2f5;
  --text-secondary: #bfc8cf;
  --text-muted: #87929b;
  --series-1: #5aa6cc;
  --series-2: #d95926;
  --accent: #5aa6cc;
  --accent-soft: #12303f;
  --accent-grad: linear-gradient(135deg, #1f6f96, #0b4a68);
  --tone-violet: #2a2442; --tone-violet-fg: #b3a6f5;
  --tone-orange: #3a2418; --tone-orange-fg: #f0a07a;
  --tone-aqua:   #142e25; --tone-aqua-fg:   #6fd4ae;
  --tone-blue:   #15263d; --tone-blue-fg:   #8fbcf2;
  --warn-bg: #3a2a07; --warn-fg: #f4c86a;
  --err-bg: #3b1414;  --err-fg: #f3a0a0;
  --info-bg: #12303f; --info-fg: #a6d3e8;
  --good: #0ca30c; --serious: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
.muted { color: var(--text-secondary); margin: 0; }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* buttons & inputs */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  border-radius: 8px; padding: 7px 14px; font: inherit; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary { background: var(--accent-grad); border-color: transparent; color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; }
.link-btn { background: none; border: 0; color: var(--text-secondary); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; }
input, select {
  background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font: inherit;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; padding: 28px; }
.login-card .field input { width: 100%; }

/* top bar & filters */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.brand { display: flex; gap: 12px; align-items: center; }
.logo { width: 38px; height: 38px; border-radius: 10px; background: #fff; border: 1px solid var(--border); display: grid; place-items: center; flex: none; padding: 4px; }
.logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-logo { display: block; background: #fff; border-radius: 12px; padding: 14px 18px; margin: 0 auto 14px; width: 200px; }
.brand-logo img { width: 100%; display: block; }
.actions { display: flex; gap: 8px; }

.filters {
  display: flex; flex-wrap: wrap; align-items: end; gap: 12px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px;
}
.field { display: grid; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--surface-2); color: var(--text-secondary); border: 0; padding: 7px 12px; font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.small-seg button { padding: 5px 10px; font-size: 12px; }

/* banners */
.alert { border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; font-size: 13px; }
.alert-warn  { background: var(--warn-bg); color: var(--warn-fg); }
.alert-error { background: var(--err-bg);  color: var(--err-fg); }
.alert-info  { background: var(--info-bg); color: var(--info-fg); }
.alert code { font-size: 12px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 14px 16px; display: grid; gap: 4px; min-width: 0; align-content: start;
}
.kpi-label { font-size: 12px; color: var(--text-secondary); }
.kpi-value { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-muted); min-height: 1em; }

/* cards grid */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.card.loading .chart, .card.loading .hbars, .card.loading tbody { opacity: .45; transition: opacity .2s; }

/* charts */
.chart { position: relative; width: 100%; height: 260px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--text-muted); stroke-width: 1; opacity: .5; }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dlabel { font-size: 11px; font-weight: 600; fill: var(--text-secondary); }
.empty { display: grid; place-items: center; height: 100%; color: var(--text-muted); font-size: 13px; }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

/* horizontal bars (tags) */
.hbars { display: grid; gap: 9px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary); }
.hbar .val { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.hbar .track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); }
.hbar .fill { height: 100%; border-radius: 4px; background: var(--series-1); min-width: 2px; }

/* tables */
.table-wrap { overflow-x: auto; max-height: 460px; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl th { color: var(--text-secondary); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface-1); }
.tbl th[data-sort] { cursor: pointer; user-select: none; }
.tbl th[data-sort].asc::after { content: " ▲"; font-size: 9px; }
.tbl th[data-sort].desc::after { content: " ▼"; font-size: 9px; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tbody tr:hover { background: var(--surface-2); }
.inline-bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--series-1); vertical-align: middle; margin-right: 8px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 11px; color: var(--text-secondary); margin-right: 4px; }
.status { font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.status.wait { color: var(--serious); }
.status.ok { color: var(--text-muted); }
.data-table { width: 100%; }

/* tooltip */
.tooltip {
  position: fixed; pointer-events: none; z-index: 50; opacity: 0; transition: opacity .1s;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; color: var(--text-primary); box-shadow: 0 6px 20px rgba(0,0,0,.3);
  min-width: 140px;
}
.tooltip.show { opacity: 1; }
.tooltip .tt-title { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; }
.tooltip .tt-row i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.tooltip b { font-variant-numeric: tabular-nums; }

/* responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .span-3 { grid-column: span 2; }
}
@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: span 1; }
  .topbar { flex-wrap: wrap; }

}

/* ---------- app shell ---------- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; padding: 22px clamp(12px, 2.5vw, 32px) 48px; }
.sidebar {
  width: 236px; flex: none; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface-1); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 14px;
}
.sidebar .brand strong { display: block; font-size: 15px; }
.sidebar .brand .small { display: block; }
.sidebar nav { display: grid; gap: 2px; }
.nav-head { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--text-secondary); text-decoration: none; font-size: 13.5px;
}
.nav-item svg, .kpi-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.active { background: var(--accent-grad); color: #fff; box-shadow: 0 4px 12px rgba(4,65,94,.25); }
.nav-item.soon { cursor: default; opacity: .65; }
.nav-item.soon:hover { background: transparent; color: var(--text-secondary); }
.soon-chip { margin-left: auto; font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.side-foot { margin-top: auto; display: grid; gap: 10px; }
.role { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px; background: var(--surface-2); }
.role strong { display: block; font-size: 13px; }
.role .small { display: block; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.btn-block { justify-content: center; }
.topbar h1 { font-size: 22px; }

/* KPI icons */
.kpi-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; margin-bottom: 4px; }
.kpi-icon svg { width: 16px; height: 16px; }
.kpi-icon.violet { background: var(--tone-violet); color: var(--tone-violet-fg); }
.kpi-icon.orange { background: var(--tone-orange); color: var(--tone-orange-fg); }
.kpi-icon.aqua   { background: var(--tone-aqua);   color: var(--tone-aqua-fg); }
.kpi-icon.blue   { background: var(--tone-blue);   color: var(--tone-blue-fg); }
.login .brand { display: flex; gap: 10px; align-items: center; }

/* ---------- responsive shell (must come after the shell rules) ---------- */
@media (max-width: 1100px) {
  .sidebar { width: 76px; padding: 16px 10px; }
  .sidebar .brand div, .nav-head, .nav-item span, .soon-chip, .role div { display: none; }
  .nav-item { justify-content: center; }
  .side-foot .btn { padding: 7px 4px; font-size: 11px; }
}
@media (max-width: 720px) {
  .app { display: block; }
  .sidebar {
    position: sticky; top: 0; z-index: 30; width: auto; height: auto; flex-direction: row; align-items: center;
    gap: 8px; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .sidebar nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
  .sidebar .nav-item.soon { display: none; }
  .side-foot { margin: 0; display: flex; gap: 6px; align-items: center; }
  .side-foot .role { display: none; }
  .side-foot .nav-item { display: none; }
  .side-foot .btn { width: auto; }
  .main { padding: 14px 12px 40px; }
  .topbar .actions { flex-wrap: wrap; }
}

.live-chip { color: var(--good) !important; border-color: currentColor !important; background: transparent !important; }
.nav-item.active .live-chip { color: #fff !important; }

/* keep top-bar controls on one line; let them drop below the title when space runs out */
.topbar { flex-wrap: wrap; }
.topbar .actions { flex-wrap: wrap; justify-content: flex-end; }
.topbar .actions .btn, .topbar .actions .live-ind { white-space: nowrap; }

/* sidebar count (password reset requests) */
.count-chip { background: var(--serious) !important; color: #fff !important; border-color: transparent !important; font-weight: 700; }
/* show-password eye */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 42px !important; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 30px; border: 0; background: transparent; color: var(--text-muted); border-radius: 6px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.pw-eye:hover { color: var(--text-primary); background: var(--surface-2); }
.pw-eye svg { width: 18px; height: 18px; }
.login-links { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-top: -4px; }
.login-links a { color: var(--accent); text-decoration: none; font-weight: 500; }
.login-links a:hover { text-decoration: underline; }
.table-wrap.full { max-height: none; overflow-y: visible; }
/* Overview staff and conversation tables: let names wrap so the table fits narrower screens */
#staff td, #staff th, #convs td:first-child, #convs td:nth-child(2) { white-space: normal; }
