/* HH Insurance Calling Portal — sidebar layout, light theme.
   Color tokens adapted from the Hans Hyundai Calling Portal's own design
   system (same accessible-contrast discipline: blue is the single accent,
   green/amber/red mean performance only) so the two sibling portals read as
   one family, not two unrelated tools. */

:root {
  color-scheme: light;

  --ink:     #0e1016;
  --ink-2:   #171a22;
  --ink-3:   #232732;

  --page:      #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #f4f5f7;
  --surface-3: #eceef2;
  --zebra:     #fbfbfc;

  --text:   #12141a;
  --text-2: #565b68;
  --text-3: #6b7280;

  --border:        #e4e6eb;
  --border-strong: #d3d7de;

  --accent:      #2454ff;
  --accent-hover:#1b45e0;
  --accent-soft: #eef2ff;

  --good:      #0a7a4d;
  --good-soft: #e6f6ef;
  --warn:      #a85a06;
  --warn-soft: #fdf3e3;
  --crit:      #c0201a;
  --crit-soft: #fdeceb;

  --shadow-sm: 0 1px 2px rgba(14,16,22,0.05);
  --shadow:    0 1px 2px rgba(14,16,22,0.04), 0 10px 28px -8px rgba(14,16,22,0.14);
  --shadow-lg: 0 8px 40px rgba(14,16,22,0.18);

  --sidebar-w: 224px;
  --r-sm: 7px;
  --r:    10px;
  --r-lg: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--page);
  color: var(--text);
}

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: linear-gradient(180deg, var(--ink-3) 0%, var(--ink) 55%, #0a0b10 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 18px 18px 16px; }
.brand-mark {
  width: 36px; height: 36px; flex: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
  display: grid; place-items: center;
}
.brand-name { font-weight: 700; font-size: 14px; line-height: 1.25; }
.brand-sub { font-size: 11.5px; color: rgba(255,255,255,0.5); }

.sidebar-nav { flex: 1; padding: 4px 10px 16px; }
.nav-group + .nav-group { margin-top: 16px; }
.nav-group-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: rgba(255,255,255,0.58); padding: 10px 8px 6px;
}
.tab {
  display: flex; align-items: center; gap: 9px; width: 100%; font: inherit;
  font-size: 13px; font-weight: 500; text-align: left;
  color: rgba(255,255,255,0.68); background: transparent; border: none;
  border-radius: var(--r-sm); padding: 9px 10px; cursor: pointer;
}
.tab:hover { background: rgba(255,255,255,0.06); color: #fff; }
.tab.active { background: var(--accent); color: #fff; }
.tab svg { flex: none; opacity: 0.85; }
.tab.active svg { opacity: 1; }

.sidebar-footer { padding: 10px 10px 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.connection-status {
  display: flex; align-items: center; gap: 7px; padding: 8px 10px 10px;
  font-size: 12px; font-weight: 600; color: rgba(255,255,255,0.75);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,0.2); flex: none; }
.status-dot.down { background: var(--crit); box-shadow: 0 0 0 3px rgba(192,32,26,0.2); }

.sign-out {
  background: transparent; color: rgba(255,255,255,0.55);
  border: 1px solid rgba(255,255,255,0.15); font-size: 12.5px;
  padding: 8px 10px; width: 100%;
}
.sign-out:hover { background: rgba(255,255,255,0.06); color: #fff; }

/* ---------- Main content ---------- */
.content { flex: 1; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.last-updated { font-size: 12px; color: var(--text-3); }

.content-body { padding: 24px; }

input[type="date"], input[type="text"], select {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 7px 10px; border-radius: var(--r-sm); font-size: 13px;
}
button {
  background: var(--accent); color: #fff; border: none; padding: 8px 14px;
  border-radius: var(--r-sm); cursor: pointer; font-size: 13px; font-weight: 500;
}
button:hover { background: var(--accent-hover); }
button.secondary { background: var(--surface-3); color: var(--text); }
button.secondary:hover { background: var(--border-strong); }
button:disabled { opacity: 0.5; cursor: wait; }
.icon-btn { background: transparent; color: var(--text-2); padding: 4px 8px; font-size: 16px; }
.icon-btn:hover { background: var(--surface-2); }

/* Quick-range pills */
.date-presets { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.preset {
  font: inherit; font-size: 11.5px; font-weight: 600; color: var(--text-2);
  background: transparent; border: none; border-radius: 5px; padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.preset:hover { color: var(--text); background: var(--surface); }
.preset.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

.date-range { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px 6px; }
.date-range input[type="date"] { border: none; padding: 3px 4px; font-size: 12.5px; width: 128px; }
.date-sep { color: var(--text-3); font-size: 11px; }
.date-range-clear { background: var(--surface-3); color: var(--text-2); border: none; border-radius: 5px; width: 22px; height: 22px; cursor: pointer; font-size: 11px; line-height: 1; flex: none; padding: 0; }
.date-range-clear:hover { background: var(--border-strong); color: var(--text); }

.btn-refresh, .btn-ghost { font: inherit; font-weight: 600; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); cursor: pointer; white-space: nowrap; font-size: 12.5px; padding: 7px 13px; }
.btn-refresh:hover, .btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn-refresh { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn-refresh:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ---------- Persistent stat strip ---------- */
.stat-row { display: flex; align-items: stretch; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 20px; }
.stat-row-label {
  display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 12px 16px;
  background: var(--surface-2); border-right: 1px solid var(--border);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-2);
  white-space: nowrap; flex: none;
}
.stat-row-scope { font-size: 10.5px; font-weight: 500; letter-spacing: 0.02em; text-transform: none; color: var(--text-3); }
.stat-cells { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); flex: 1; min-width: 0; }
.stat-cell { padding: 11px 16px; min-width: 0; border-left: 1px solid var(--border); position: relative; }
.stat-cell:first-child { border-left: none; }
.stat-cell::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
.stat-cell--calls::before { background: #2454ff; }
.stat-cell--contacts::before { background: #ff6a45; }
.stat-cell--rate::before { background: var(--border-strong); }
.stat-cell--rate.rate-good::before { background: var(--good); }
.stat-cell--rate.rate-warning::before { background: var(--warn); }
.stat-cell--rate.rate-critical::before { background: var(--crit); }
.stat-cell--bookings::before { background: #8b3dff; }
.stat-label { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.stat-value { font-size: 20px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
@media (max-width: 860px) {
  .stat-row { flex-direction: column; }
  .stat-cells { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Stat tiles ---------- */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-tile { background: var(--surface); border-radius: var(--r); padding: 14px 16px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.stat-tile .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); margin-bottom: 6px; }
.stat-tile .value { font-size: 22px; font-weight: 700; color: var(--text); }
.stat-tile.pending { border-color: #f3d8ac; background: var(--warn-soft); }
.stat-tile.pending .value { color: var(--warn); font-size: 13px; font-weight: 600; }

/* ---------- Overview: leaderboards + charts ---------- */
.overview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .overview-grid { grid-template-columns: 1fr; } }
.overview-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow-sm); min-width: 0; }
.overview-card-title { font-size: 13.5px; font-weight: 600; margin-bottom: 12px; }
.overview-card-sub { font-size: 11.5px; font-weight: 500; color: var(--text-3); }

.leaderboard { display: flex; flex-direction: column; gap: 8px; }
.leaderboard-row { display: grid; grid-template-columns: minmax(0,1fr) 100px 42px; align-items: center; gap: 10px; }
.leaderboard-name { font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-track { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.leaderboard-fill { display: block; height: 100%; border-radius: 999px; }
.leaderboard-value { font-size: 12px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.leaderboard-empty { font-size: 12.5px; color: var(--text-3); padding: 10px 0; }

.chart-legend { display: flex; gap: 14px; margin-bottom: 6px; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-2); font-weight: 500; }
.chart-legend-swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.chart-container { width: 100%; overflow: hidden; }
.chart-container svg { display: block; width: 100%; height: auto; }
.chart-bar { transition: opacity 0.1s ease; cursor: pointer; }
.chart-bar:hover { opacity: 0.75; }
.chart-axis-label { font-size: 10px; fill: var(--text-3); font-family: "Inter", sans-serif; }
.chart-gridline { stroke: var(--border); stroke-width: 1; }
.chart-tooltip {
  position: fixed; z-index: 60; background: var(--ink); color: #fff; font-size: 11.5px; line-height: 1.5;
  border-radius: var(--r-sm); padding: 7px 10px; pointer-events: none; transform: translate(12px, -50%);
  box-shadow: var(--shadow-lg); font-variant-numeric: tabular-nums;
}

/* Color-coded rate badges — used in table cells for Contact% etc. */
.rate { font-weight: 600; font-variant-numeric: tabular-nums; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.rate-good { color: var(--good); background: var(--good-soft); }
.rate-warning { color: var(--warn); background: var(--warn-soft); }
.rate-critical { color: var(--crit); background: var(--crit-soft); }

/* ---------- Table toolbar (search) ---------- */
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.table-toolbar input[type="text"] { min-width: 260px; }
.table-row-count { font-size: 12px; color: var(--text-3); white-space: nowrap; }

/* ---------- Overview dashboard: pipeline chart + due-soon list ---------- */
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.dash-card-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.dash-card-header h3 { margin: 0; font-size: 14px; font-weight: 600; }
.dash-card-sub { color: var(--text-3); font-size: 11.5px; font-weight: 400; }
.dash-card-link { color: var(--accent); font-size: 12.5px; cursor: pointer; font-weight: 500; }
.dash-card-link:hover { text-decoration: underline; }
.dash-empty { color: var(--text-3); font-size: 13px; margin: 0; }

.pipeline-bar { display: flex; width: 100%; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.pipeline-seg { height: 100%; min-width: 2px; }
.pipeline-legend { display: flex; flex-direction: column; gap: 7px; margin-top: 14px; }
.pipeline-legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.pipeline-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.due-soon-list { display: flex; flex-direction: column; gap: 2px; }
.due-soon-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.due-soon-row:last-child { border-bottom: none; }
.due-soon-customer { font-size: 13px; font-weight: 500; color: var(--text); }
.due-soon-date { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- Banner ---------- */
.banner { background: var(--warn-soft); color: var(--warn); padding: 12px 16px; border-radius: var(--r); margin-bottom: 16px; font-size: 13px; border: 1px solid #f3d8ac; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
th, td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); color: var(--text-3); text-transform: uppercase; font-size: 11px; letter-spacing: 0.04em; }
tbody tr:nth-child(even) { background: var(--zebra); }
tbody tr:last-child td { border-bottom: none; }
.cre-link { color: var(--accent); cursor: pointer; font-weight: 500; }
.cre-link:hover { text-decoration: underline; }

/* ---------- Feed list ---------- */
.feed-list { display: flex; flex-direction: column; gap: 8px; }
.feed-item { background: var(--surface); border-radius: var(--r); padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--border); border-left: 3px solid var(--border-strong); font-size: 13px; }
.feed-item.ring { border-left-color: var(--warn); }
.feed-item.answer { border-left-color: var(--good); }
.feed-item.hangup { border-left-color: var(--text-3); }
.feed-item .meta { color: var(--text-3); font-size: 12px; }

/* ---------- Toolbar (CRE Queue / Lookup) ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
select {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 7px 10px; border-radius: var(--r-sm); font-size: 13px; min-width: 220px;
}

/* ---------- CRE Queue buckets ---------- */
.queue-bucket { margin-bottom: 18px; }
.queue-bucket-header { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.queue-bucket-toggle { cursor: pointer; user-select: none; }
.queue-chevron { color: var(--text-3); width: 10px; display: inline-block; }
.queue-bucket-count { background: var(--surface-3); color: var(--text-2); border-radius: 999px; padding: 1px 9px; font-size: 11.5px; }
.queue-empty { color: var(--text-3); font-size: 13px; padding: 8px 0 16px; }

/* ---------- Customer Lookup ---------- */
.lookup-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.lookup-card h3 { margin: 0 0 4px; font-size: 15px; }
.lookup-card .phones { color: var(--text-3); font-size: 13px; margin-bottom: 10px; }

/* ---------- Spinner ---------- */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; margin-right: 6px; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- CRE 360 Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(14,16,22,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px; max-height: 85vh; overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-group-label { display: none; }
}
