/* Design tokens. Light is the default; dark is a second token set switched by
   data-bs-theme on <html> (set by assets/js/app.js: user choice > system preference). */

:root, [data-bs-theme="light"] {
  --primary-1: #2563eb;     /* primary blue */
  --primary-2: #1d4ed8;     /* deep blue (hover) */
  --primary-3: #dbeafe;     /* very light blue (subtle bg) */
  --bg-1: #f4f7fb;          /* page */
  --bg-2: #ffffff;          /* cards */
  --bg-3: #eef3f9;          /* table headers / inputs / chips */
  --text-1: #0f172a;
  --muted-1: #64748b;
  --border-1: #e2e8f0;
  --row-hover: #eef3f9;
  --success: #16a34a;
  --warning: #d97706;
  --danger:  #dc2626;
  --secondary: #64748b;
  --info:   #0284c7;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .04);
  --nav-bg: rgba(255, 255, 255, .72);
  --focus: rgba(37, 99, 235, .18);
}
[data-bs-theme="dark"] {
  --primary-1: #60a5fa;
  --primary-2: #93c5fd;
  --primary-3: #1e3a5f;
  --bg-1: #0b1220;
  --bg-2: #111a2b;
  --bg-3: #172238;
  --text-1: #e5edf7;
  --muted-1: #8da2bb;
  --border-1: #22304a;
  --row-hover: #172238;
  --success: #34d399;
  --warning: #fbbf24;
  --danger:  #f87171;
  --secondary: #8da2bb;
  --info:   #38bdf8;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  --nav-bg: rgba(11, 18, 32, .72);
  --focus: rgba(96, 165, 250, .25);
  color-scheme: dark;
}

html, body {
  background: var(--bg-1);
  color: var(--text-1);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  transition: background-color .2s, color .2s;
}
a { color: var(--primary-1); }
a:hover { color: var(--primary-2); }

.brand {
  font-family: 'Exo 2', 'Inter', sans-serif;
  letter-spacing: 0.3px;
  font-weight: 700;
  color: var(--primary-2);
}
h3.brand { font-size: 1.35rem; }

/* Navbar: translucent, blurred, sticky; active section underlined */
.navbar {
  background: var(--nav-bg) !important;
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  backdrop-filter: saturate(160%) blur(12px);
  border-color: var(--border-1) !important;
  box-shadow: 0 1px 0 var(--border-1);
}
.navbar .navbar-brand { display: flex; align-items: center; gap: .55rem; color: var(--text-1); }
.navbar .brand-tile {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary-1), #0ea5e9); color: #fff;
  font: 700 .72rem/1 'Exo 2', sans-serif; letter-spacing: .5px;
}
.navbar .brand-host { font: 500 .78rem/1 'Inter', sans-serif; color: var(--muted-1); }
.navbar .nav-link { color: var(--text-1); padding: .9rem .75rem; position: relative; font-weight: 500; }
.navbar .nav-link:hover { color: var(--primary-1); }
.navbar .nav-link.active { color: var(--primary-1); }
.navbar .nav-link.active::after {
  content: ""; position: absolute; left: .75rem; right: .75rem; bottom: .35rem; height: 2px;
  border-radius: 2px; background: var(--primary-1);
}
.navbar-toggler { border-color: var(--border-1); }
.theme-toggle { border: 1px solid var(--border-1); background: var(--bg-2); color: var(--text-1); width: 34px; height: 34px; border-radius: 9px; display: inline-grid; place-items: center; }
.theme-toggle:hover { color: var(--primary-1); border-color: var(--primary-1); }
[data-bs-theme="light"] .theme-toggle .i-moon { display: inline; } [data-bs-theme="light"] .theme-toggle .i-sun { display: none; }
[data-bs-theme="dark"]  .theme-toggle .i-moon { display: none; }   [data-bs-theme="dark"]  .theme-toggle .i-sun { display: inline; }

/* Cards: no borders, soft radius, hairline shadow; headers as small uppercase labels */
.card {
  background: var(--bg-2);
  border: 0;
  border-radius: 12px;
  box-shadow: var(--shadow-1);
  color: var(--text-1);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border-1);
  font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted-1);
  padding: .6rem 1rem;
}
.card-header .badge { font-size: .65rem; vertical-align: 1px; }

/* Buttons — keep text white on hover (per user's standing preference) */
.btn-warm,
.btn-primary {
  background: var(--primary-1);
  color: #fff;
  border: none;
  font-weight: 600;
}
.btn-warm:hover, .btn-warm:focus,
.btn-primary:hover, .btn-primary:focus {
  background: var(--primary-2);
  color: #fff;            /* never go to black */
}

.btn-outline-secondary {
  color: var(--text-1);
  border-color: var(--border-1);
  background: var(--bg-2);
}
.btn-outline-secondary:hover {
  color: #fff;
  background: var(--primary-1);
  border-color: var(--primary-1);
}
.btn-outline-secondary.active {
  background: var(--primary-1);
  border-color: var(--primary-1);
  color: #fff;
}
.btn-outline-warning {
  color: var(--primary-1);
  border-color: var(--primary-1);
  background: var(--bg-2);
}
.btn-outline-warning:hover {
  color: #fff;
  background: var(--primary-1);
}
.btn-outline-primary {
  color: var(--primary-1);
  border-color: var(--primary-1);
  background: var(--bg-2);
}
.btn-outline-primary:hover {
  color: #fff;
  background: var(--primary-1);
}

/* Forms */
.form-control, .form-select {
  background: var(--bg-2); color: var(--text-1);
  background: var(--bg-2);
  color: var(--text-1);
  border-color: var(--border-1);
}
.form-control:focus, .form-select:focus {
  background: var(--bg-2); color: var(--text-1); box-shadow: 0 0 0 .2rem var(--focus);
  background: var(--bg-2);
  color: var(--text-1);
  border-color: var(--primary-1);
  box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.18);
}
.form-label.text-muted { color: var(--muted-1) !important; }

/* Tables */
.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-1);
  --bs-table-hover-bg: var(--row-hover);
  --bs-table-border-color: var(--border-1);
  --bs-table-striped-bg: #f8fafc;
}
.table thead th {
  background: var(--bg-3);
  color: var(--text-1);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-1);
}
.table td {
  border-color: var(--border-1);
  vertical-align: middle;
}
.text-muted { color: var(--muted-1) !important; }

/* DataTables tweaks */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_info {
  color: var(--text-1);
}
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  padding: 4px 8px;
  border-radius: 4px;
}
.page-link {
  background: var(--bg-2);
  border-color: var(--border-1);
  color: var(--primary-1);
}
.page-link:hover { background: var(--primary-3); color: var(--primary-2); }
.page-item.active .page-link {
  background: var(--primary-1);
  border-color: var(--primary-1);
  color: #fff;
}

/* Badges (using bootstrap default but ensure text contrast) */
.badge.bg-success    { background: var(--success) !important; }
.badge.bg-warning    { background: var(--warning) !important; color: #fff; }
.badge.bg-danger     { background: var(--danger)  !important; }
.badge.bg-secondary  { background: var(--secondary) !important; }
.badge.bg-info       { background: var(--info)    !important; color: #fff; }
.badge.bg-primary    { background: var(--primary-1) !important; }

/* Stat cards */
.stat-card { border-width: 1px !important; }
.stat-card .stat-value {
  font-family: 'Exo 2', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
}
.stat-card .text-primary    { color: var(--primary-1) !important; }
.stat-card .text-success    { color: var(--success) !important; }
.stat-card .text-warning    { color: var(--warning) !important; }
.stat-card .text-danger     { color: var(--danger)  !important; }
.stat-card .text-info       { color: var(--info)    !important; }
.stat-card .text-secondary  { color: var(--secondary) !important; }
.border-primary { border-color: var(--primary-1) !important; }
.border-success { border-color: var(--success) !important; }
.border-warning { border-color: var(--warning) !important; }
.border-danger  { border-color: var(--danger)  !important; }
.border-info    { border-color: var(--info)    !important; }
.border-secondary { border-color: var(--secondary) !important; }

/* Timeline */
.timeline { padding: 1rem 1rem 1rem 2rem; position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  left: 1.25rem;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--border-1);
}
.timeline-item {
  position: relative;
  padding: 0.5rem 0 0.5rem 1.5rem;
  margin-left: -1.5rem;
}
.timeline-dot {
  position: absolute;
  left: -0.4rem;
  top: 0.85rem;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--bg-2);
  box-shadow: 0 0 0 2px var(--border-1);
}
.timeline-content { padding-left: 0.5rem; }

/* Live event stream */
.event-stream {
  max-height: 600px;
  overflow-y: auto;
  font-family: 'Inter', monospace;
  font-size: 0.85rem;
}
.event-stream .event-row {
  padding: 0.4rem 1rem;
  border-bottom: 1px solid var(--border-1);
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
.event-stream .event-row.is-new {
  background: var(--primary-3);
  animation: fadein 1.2s ease-out;
}
@keyframes fadein {
  from { background: rgba(37, 99, 235, 0.30); }
  to   { background: var(--primary-3); }
}

/* Heatmap */
#heatmap table { border-collapse: separate; border-spacing: 2px; }
#heatmap td {
  width: 28px; height: 22px;
  text-align: center;
  font-size: 0.7rem;
  border-radius: 3px;
  background: #f1f5f9;
  color: var(--text-1);
}
#heatmap th { font-size: 0.75rem; color: var(--muted-1); padding: 2px 6px; }

/* Modal */
.modal-content { background: var(--bg-2); color: var(--text-1); border: 1px solid var(--border-1); }
.modal-header  { border-bottom-color: var(--border-1); }

/* Audio player default styling on most browsers is fine on light theme */

/* Play link in table */
.play-link {
  color: var(--primary-1);
  text-decoration: none;
  font-size: 1.05rem;
}
.play-link:hover { color: var(--primary-2); }

/* Code blocks */
code {
  background: var(--bg-3);
  color: var(--primary-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}

/* Compact calls list */
.calls-compact { font-size: .9rem; }
.calls-compact td { padding-top: .35rem; padding-bottom: .35rem; vertical-align: middle; }
.calls-compact td.party { max-width: 220px; line-height: 1.15; }
.calls-compact td.party .num { white-space: nowrap; }
.calls-compact td.party .pname { font-size: .78rem; max-width: 210px; color: var(--primary-2); text-decoration: none; }
.calls-compact td.party .pname:hover { text-decoration: underline; }
.calls-compact td.party span.pname { color: #6b7a8c; }
.calls-compact td.op { max-width: 140px; }
.calls-compact .dir { display: inline-block; width: 1.1em; font-weight: 700; margin-right: .25rem; }
.calls-compact .dir-in  { color: var(--success); }
.calls-compact .dir-out { color: var(--primary-2); }
.calls-compact .st { white-space: nowrap; }
.calls-compact .st i { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .35rem; vertical-align: 0; }
.calls-compact .st-success i { background: var(--success); }
.calls-compact .st-warning i { background: var(--warning); }
.calls-compact .st-danger  { color: var(--danger); font-weight: 600; }
.calls-compact .st-danger  i { background: var(--danger); }
.calls-compact .st-secondary i { background: var(--secondary); }
.calls-compact .st-info i { background: var(--info); }
.calls-compact .ab-add { display: inline-block; width: 1.25rem; height: 1.25rem; line-height: 1.15rem; text-align: center; border: 1px solid var(--primary-2); border-radius: 50%; color: var(--primary-2); text-decoration: none; font-weight: 700; font-size: .85rem; opacity: 0; transition: opacity .12s; vertical-align: 1px; }
.calls-compact tr:hover .ab-add { opacity: 1; }
.calls-compact .ab-add:hover { background: var(--primary-2); color: #fff; }
.calls-compact .row-actions a { opacity: .25; transition: opacity .12s; text-decoration: none; font-size: 1rem; }
.calls-compact tr:hover .row-actions a { opacity: 1; }
.calls-compact .open-link { color: var(--primary-1); }

/* Dark-mode touch-ups for third-party widgets */
[data-bs-theme="dark"] .table { --bs-table-striped-bg: #0f1727; }
[data-bs-theme="dark"] .modal-content { background: var(--bg-2); }
[data-bs-theme="dark"] .form-control::placeholder { color: #6b7f99; }
[data-bs-theme="dark"] .btn-outline-secondary { color: var(--text-1); border-color: var(--border-1); }
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_info, [data-bs-theme="dark"] .dataTables_wrapper .dataTables_length label,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter label { color: var(--muted-1); }
[data-bs-theme="dark"] .page-link { background: var(--bg-2); border-color: var(--border-1); color: var(--text-1); }
[data-bs-theme="dark"] .alert-success { background: #0f2e1f; color: #bbf7d0; border-color: #166534; }
[data-bs-theme="dark"] .alert-danger  { background: #3a1216; color: #fecaca; border-color: #991b1b; }
[data-bs-theme="dark"] .alert-warning { background: #3a2a0a; color: #fde68a; border-color: #92400e; }
[data-bs-theme="dark"] code { color: #93c5fd; }
.table thead th { font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted-1); background: transparent; }
.btn { border-radius: 8px; }
.btn-sm { border-radius: 7px; }
.form-control, .form-select { border-radius: 8px; }
.badge { border-radius: 6px; font-weight: 600; }

/* ---- Calls page: KPI strip, chips, day rows, hover card, player bar, keyboard focus ---- */
.kpi { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.kpi:hover { transform: translateY(-1px); }
.kpi.is-active { outline: 2px solid var(--primary-1); outline-offset: -2px; }
.kpi-label { font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-1); }
.kpi-value { font: 600 1.35rem/1.2 'Exo 2', 'Inter', sans-serif; color: var(--text-1); }
.kpi-success .kpi-value { color: var(--success); } .kpi-danger .kpi-value { color: var(--danger); } .kpi-info .kpi-value { color: var(--info); }
.kpi-spark { opacity: .9; }

.opchip { display: inline-flex; align-items: center; gap: .4rem; max-width: 150px; }
.opchip i { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; font: 600 .62rem/1 'Inter', sans-serif; font-style: normal; flex: 0 0 22px; }
.opchip > span { overflow: hidden; }

.calls-compact tr.day-row td { background: var(--bg-3); color: var(--text-1); font-size: .74rem; padding: .3rem .6rem; border-top: 0; position: sticky; top: 56px; z-index: 1; }
.calls-compact tr.day-row .day-label { font-weight: 600; text-transform: capitalize; margin-right: .6rem; }
.calls-compact tbody tr[data-uid] td:first-child { border-left: 3px solid transparent; }
.calls-compact tbody tr.k-missed td:first-child { border-left-color: var(--danger); }
.calls-compact tbody tr.k-ivr td:first-child { border-left-color: var(--warning); }
.calls-compact tbody tr.is-focus td { background: var(--primary-3) !important; }
.calls-compact td.party { position: relative; overflow: visible; }

.hover-card { position: absolute; left: 0; top: 100%; z-index: 30; min-width: 280px; max-width: 360px; background: var(--bg-2); border: 1px solid var(--border-1); border-radius: 10px; box-shadow: var(--shadow-1); padding: .6rem .75rem; font-size: .82rem; line-height: 1.3; }
.hover-card .hc-head { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; }
.hover-card .hc-num { font-weight: 600; white-space: nowrap; }
.hover-card .hc-name { font-weight: 600; text-decoration: none; text-align: right; }
.hover-card .hc-nums { font-size: .74rem; margin-top: .15rem; }
.hover-card .hc-sub { font-size: .66rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-1); margin: .5rem 0 .2rem; }
.hover-card .hc-row { display: grid; grid-template-columns: 1.2em 5.5em 1fr auto; gap: .4rem; align-items: center; color: var(--text-1); text-decoration: none; padding: .15rem 0; border-top: 1px solid var(--border-1); }
.hover-card .hc-row:hover { color: var(--primary-1); }
.hover-card .hc-actions { margin-top: .5rem; padding-top: .4rem; border-top: 1px solid var(--border-1); }
.hover-card .hc-actions .ab-add { opacity: 1; width: auto; height: auto; border: 0; border-radius: 0; line-height: inherit; font-weight: 600; }
.hover-card .hc-actions .ab-add:hover { background: transparent; color: var(--primary-2); }

.player-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: var(--nav-bg); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-top: 1px solid var(--border-1); box-shadow: 0 -4px 20px rgba(0,0,0,.08); }
.player-bar .player-meta { min-width: 0; flex: 0 1 300px; }
.player-bar .player-title { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-bar .player-sub { font-size: .72rem; }
.player-bar audio { flex: 1 1 auto; height: 36px; min-width: 200px; }
body.has-player main { padding-bottom: 70px; }
.kbd-hint { margin-top: .75rem; }
.kbd-hint kbd { background: var(--bg-3); color: var(--text-1); border: 1px solid var(--border-1); border-radius: 4px; padding: 0 .35em; font-size: .72rem; margin-right: .1rem; }

/* Toasts */
.toast-host { position: fixed; right: 1rem; bottom: 1rem; z-index: 1060; display: flex; flex-direction: column; gap: .5rem; }
.toast-item { background: var(--text-1); color: var(--bg-2); padding: .55rem .9rem; border-radius: 9px; font-size: .85rem; box-shadow: var(--shadow-1); opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s; }
.toast-item.show { opacity: 1; transform: none; }
.toast-item.toast-err { background: var(--danger); color: #fff; }
body.has-player .toast-host { bottom: 76px; }

/* DataTables processing → skeleton-ish */
.dataTables_wrapper .dataTables_processing { background: var(--bg-2); color: var(--muted-1); border: 1px solid var(--border-1); border-radius: 10px; box-shadow: var(--shadow-1); }

/* ---- Live call cards, empty states, voicemail tick ---- */
.live-card { display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem; border-radius: 10px; background: var(--bg-3); margin-bottom: .5rem; border-left: 3px solid var(--secondary); }
.live-card.is-ringing { border-left-color: var(--warning); animation: pulse 1.4s ease-in-out infinite; }
.live-card.is-answered { border-left-color: var(--success); }
.live-card .live-dir { font-weight: 700; color: var(--primary-1); width: 1.2em; }
.live-card .live-body { min-width: 0; flex: 1; }
.live-card .live-who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-card .live-sub { font-size: .76rem; }
.live-card .live-timer { font-size: .95rem; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(217,119,6,.0); } 50% { box-shadow: 0 0 0 4px rgba(217,119,6,.15); } }
.empty-state { text-align: center; color: var(--muted-1); padding: 1.5rem 1rem; }
.empty-state .empty-icon { font-size: 1.6rem; opacity: .5; margin-bottom: .25rem; }
.cb-tick { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border-1); background: transparent; color: var(--muted-1); font-weight: 700; line-height: 1; }
.cb-tick:hover { border-color: var(--success); color: var(--success); }
.cb-tick.is-on { background: var(--success); border-color: var(--success); color: #fff; }
.vm-play-link { text-decoration: none; color: var(--primary-1); }

/* ---- Mobile: the calls list becomes a card per call ---- */
@media (max-width: 767.98px) {
  .calls-compact thead { display: none; }
  .calls-compact tbody tr[data-uid] { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "time from act" "time to act" "op status status"; gap: 0 .6rem; padding: .5rem .25rem; border-bottom: 1px solid var(--border-1); }
  .calls-compact tbody tr[data-uid] td { display: block; border: 0 !important; padding: .1rem 0; }
  .calls-compact tbody tr[data-uid] td.col-time { grid-area: time; } .calls-compact tbody tr[data-uid] td.party:nth-child(2) { grid-area: from; }
  .calls-compact tbody tr[data-uid] td.party:nth-child(3) { grid-area: to; } .calls-compact tbody tr[data-uid] td.op { grid-area: op; }
  .calls-compact tbody tr[data-uid] td:nth-child(5) { grid-area: status; text-align: left; } .calls-compact tbody tr[data-uid] td:nth-child(6) { grid-area: status; margin-left: 4.5rem; }
  .calls-compact tbody tr[data-uid] td.notes { display: none; } .calls-compact tbody tr[data-uid] td.row-actions { grid-area: act; align-self: center; }
  .calls-compact tbody tr[data-uid] .row-actions a, .calls-compact .ab-add { opacity: 1; }
  .calls-compact tr.day-row td { position: static; }
  .kbd-hint { display: none !important; }
  .player-bar { flex-wrap: wrap; gap: .5rem; } .player-bar .player-speed { order: 3; }
  .navbar .brand-host { display: none; }
}
