:root {
  --bg: #F3F4F6;
  --panel: #FFFFFF;
  --line: #E5E7EB;
  --line-soft: #F3F4F6;
  --text: #111827;
  --muted: #4B5563;
  --head: #0F172A;
  --head-text: #F8FAFC;
  --head-muted: #CBD5E1;
  --accent: #2563EB;
  --accent-dark: #1D4ED8;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --on-bg: #FEF3C7; --on-fg: #92400E; --on-dot: #D97706;
  --ring-bg: #DBEAFE; --ring-fg: #1E40AF; --ring-dot: #2563EB;
  --free-bg: #DCFCE7; --free-fg: #166534; --free-dot: #16A34A;
  --idle-bg: #F3F4F6; --idle-fg: #374151; --idle-dot: #9CA3AF;
  --meet-bg: #EDE9FE; --meet-fg: #5B21B6; --meet-dot: #7C3AED;
  --bad-bg: #FEE2E2; --bad-fg: #991B1B; --bad-dot: #DC2626;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Bookings + Cost/booking are the 7th and 8th columns; hidden while bookings are off. */
table.no-bookings th:nth-child(n+7), table.no-bookings td:nth-child(n+7) { display: none; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; }
button, input, select { font: inherit; }
a { color: var(--accent-dark); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

/* ---------- Header ---------- */
.top { background: var(--head); color: var(--head-text); padding: 14px 24px; }
.top-inner { max-width: 1392px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.brand p { margin: 0; font-size: 13px; color: var(--head-muted); }
.top-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.chip-live { background: #14532D; color: #DCFCE7; }
.chip-live .dot { background: #4ADE80; }
.chip-off { background: #7F1D1D; color: #FEE2E2; }
.chip-off .dot { background: #FCA5A5; }
.chip-demo { background: #78350F; color: #FEF3C7; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.top label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--head-muted); }
.top select { background: #1E293B; color: var(--head-text); border: 1px solid #334155; border-radius: 6px; padding: 8px 10px; min-height: 38px; }
.top a.signout { color: var(--head-muted); font-size: 13px; padding: 8px 4px; }

/* ---------- Layout ---------- */
main { max-width: 1392px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; flex-wrap: wrap; gap: 20px; align-items: stretch; }
.row.top-align { align-items: flex-start; }
.grow { flex: 1 1 420px; min-width: 0; }
.wide { flex: 999 1 640px; min-width: 0; }

.banner { border-radius: 10px; padding: 12px 16px; background: var(--bad-bg); color: var(--bad-fg); font-size: 13px; }
.banner[hidden] { display: none; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-src { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--line-soft); padding: 3px 8px; border-radius: 999px; }
.kpi-value { font-family: var(--mono); font-size: 32px; font-weight: 600; letter-spacing: -0.02em; }
.kpi-sub { font-size: 13px; color: var(--muted); }

/* ---------- Panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.panel-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.counts { display: flex; gap: 12px; font-size: 13px; color: #374151; flex-wrap: wrap; }
.counts strong.on { color: #B45309; }
.counts strong.free { color: #15803D; }
.scroll { max-height: 620px; overflow-y: auto; }
.empty { padding: 28px 20px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.empty strong { color: var(--text); }
ul.list { list-style: none; margin: 0; padding: 0; }

/* Lines */
.line { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line-soft); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--line); color: #374151; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex: none; }
.line-main { flex: 1 1 auto; min-width: 0; }
.line-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer { font-family: var(--mono); font-size: 13px; color: #374151; min-width: 52px; text-align: right; }

/* Status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-on_call, .s-live { background: var(--on-bg); color: var(--on-fg); } .s-on_call .dot, .s-live .dot { background: var(--on-dot); }
.s-ringing { background: var(--ring-bg); color: var(--ring-fg); } .s-ringing .dot { background: var(--ring-dot); }
.s-free, .s-converted { background: var(--free-bg); color: var(--free-fg); } .s-free .dot, .s-converted .dot { background: var(--free-dot); }
.s-away, .s-offline, .s-no_convert { background: var(--idle-bg); color: var(--idle-fg); } .s-away .dot, .s-offline .dot, .s-no_convert .dot { background: var(--idle-dot); }
.s-meeting, .s-busy { background: var(--meet-bg); color: var(--meet-fg); } .s-meeting .dot, .s-busy .dot { background: var(--meet-dot); }
.s-not_connected { background: var(--bad-bg); color: var(--bad-fg); } .s-not_connected .dot { background: var(--bad-dot); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.s-ringing .dot, .s-live .dot { animation: pulse 1.2s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .s-ringing .dot, .s-live .dot { animation: none; } }

/* Calls feed */
.call { display: grid; grid-template-columns: 70px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--line-soft); }
.call.fresh { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: #EFF6FF; } to { background: transparent; } }
.call-time { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.call-pub { font-size: 14px; font-weight: 600; }
.call-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.call-money { font-family: var(--mono); font-size: 12px; color: #374151; }

/* Publisher table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 700px; }
thead tr { background: #F9FAFB; color: #374151; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
th, td { padding: 11px 12px; text-align: right; }
th:first-child, td:first-child { text-align: left; padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
thead th { font-weight: 600; }
tbody tr { border-top: 1px solid var(--line-soft); }
tbody td { font-family: var(--mono); }
tbody th { font-weight: 600; }
tfoot tr { border-top: 2px solid var(--line); background: #F9FAFB; font-weight: 600; }
tfoot td { font-family: var(--mono); }

/* Bookings */
.flag { font-size: 12px; font-weight: 600; color: #92400E; background: #FEF3C7; padding: 4px 10px; border-radius: 999px; }
.flag.ok { color: var(--free-fg); background: var(--free-bg); }
.booking { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.booking-main { flex: 1 1 150px; min-width: 0; }
.booking-name { font-size: 14px; font-weight: 600; }
.booking-sub { font-size: 12px; color: var(--muted); }
.booking select { min-height: 40px; padding: 6px 10px; border-radius: 8px; font-size: 13px; border: 1px solid #D1D5DB; background: #fff; color: var(--text); max-width: 190px; }
.booking select.needs { border-color: #D97706; background: #FFFBEB; }
.auto { font-size: 11px; font-weight: 600; color: var(--muted); }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 8px; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--line-soft); color: var(--bad-fg); }

.add-form { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; background: #F9FAFB; }
.add-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1 1 120px; }
.add-form input, .add-form select { min-height: 40px; padding: 6px 10px; border-radius: 8px; border: 1px solid #D1D5DB; background: #fff; color: var(--text); }
.btn { min-height: 40px; padding: 8px 16px; border-radius: 8px; border: none; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--accent-dark); }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid #D1D5DB; }
.btn-ghost:hover { background: var(--line-soft); }
.form-msg { font-size: 12px; color: var(--bad-fg); flex-basis: 100%; }

.foot { font-size: 12px; color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--head); }
.login-card { background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.login-card input { min-height: 44px; padding: 8px 12px; border-radius: 8px; border: 1px solid #D1D5DB; font-size: 15px; }
.login-card .btn { min-height: 44px; }
.login-err { color: var(--bad-fg); background: var(--bad-bg); padding: 10px 12px; border-radius: 8px; font-size: 13px; }

@media (max-width: 640px) {
  main { padding: 16px; }
  .top { padding: 12px 16px; }
  .kpi-value { font-size: 26px; }
  .call { grid-template-columns: 58px minmax(0, 1fr) auto; padding: 10px 16px; }
  .line, .booking { padding: 10px 16px; }
}
