/* ==== Design tokens: light (default) and dark (data-bs-theme="dark", toggled in the header) ==== */
:root, [data-bs-theme="light"] {
    --cc-bg: #f2f4f8;
    --cc-surface: #ffffff;
    --cc-surface-2: #f7f9fc;
    --cc-border: #e2e7ef;
    --cc-border-strong: #cbd3df;
    --cc-text: #18212f;
    --cc-muted: #5d6b7e;
    --cc-brand: #2563eb;
    --cc-brand-soft: #e6eefe;
    --cc-header: #0f1b33;
    --cc-header-2: #172a4d;
    --cc-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --cc-shadow-lg: 0 10px 30px rgba(16, 24, 40, .14);

    --cc-ok: #15803d;      --cc-ok-soft: #dcfce7;
    --cc-warn: #b45309;    --cc-warn-soft: #fef3c7;
    --cc-bad: #b91c1c;     --cc-bad-soft: #fee2e2;
    --cc-info: #1d4ed8;    --cc-info-soft: #dbeafe;
    --cc-idle: #64748b;    --cc-idle-soft: #eef1f5;
    --cc-bar: #cfe0fb;     --cc-bar-bad: #f8d0d0;

    --bs-body-bg: var(--cc-bg);
    --bs-body-color: var(--cc-text);
    --bs-border-color: var(--cc-border);
    --bs-secondary-color: var(--cc-muted);
    --bs-link-color: var(--cc-brand);
    --bs-link-color-rgb: 37, 99, 235;
    --bs-primary: #2563eb;
    --bs-primary-rgb: 37, 99, 235;
}

[data-bs-theme="dark"] {
    --cc-bg: #0a101c;
    --cc-surface: #111a2b;
    --cc-surface-2: #162238;
    --cc-border: #233250;
    --cc-border-strong: #31446a;
    --cc-text: #e4e9f2;
    --cc-muted: #93a1b9;
    --cc-brand: #60a5fa;
    --cc-brand-soft: #1b2d4f;
    --cc-header: #070c16;
    --cc-header-2: #0f1a2e;
    --cc-shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --cc-shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);

    --cc-ok: #4ade80;      --cc-ok-soft: rgba(34, 197, 94, .16);
    --cc-warn: #fbbf24;    --cc-warn-soft: rgba(245, 158, 11, .16);
    --cc-bad: #f87171;     --cc-bad-soft: rgba(239, 68, 68, .18);
    --cc-info: #60a5fa;    --cc-info-soft: rgba(59, 130, 246, .18);
    --cc-idle: #94a3b8;    --cc-idle-soft: rgba(148, 163, 184, .14);
    --cc-bar: rgba(96, 165, 250, .28); --cc-bar-bad: rgba(248, 113, 113, .3);

    --bs-body-bg: var(--cc-bg);
    --bs-body-color: var(--cc-text);
    --bs-border-color: var(--cc-border);
    --bs-secondary-color: var(--cc-muted);
    --bs-link-color: var(--cc-brand);
    --bs-link-color-rgb: 96, 165, 250;
    --bs-link-hover-color: #93c5fd;
    color-scheme: dark;
}

html, body { background: var(--cc-bg); color: var(--cc-text); }
body { font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
h1:focus { outline: none; }
.icon { flex-shrink: 0; vertical-align: -.15em; }
.text-secondary { color: var(--cc-muted) !important; }
code { color: var(--cc-text); background: var(--cc-surface-2); border: 1px solid var(--cc-border); border-radius: .3rem; padding: .05rem .35rem; font-size: .82em; }

/* ==== Header ==== */
.app-container { max-width: 1680px; padding-left: 1.25rem; padding-right: 1.25rem; }
.app-header { background: linear-gradient(90deg, var(--cc-header), var(--cc-header-2)); color: #fff; padding: .55rem 0; position: sticky; top: 0; z-index: 1030; box-shadow: 0 1px 0 rgba(255, 255, 255, .06), 0 4px 14px rgba(0, 0, 0, .18); }
.app-brand { display: inline-flex; align-items: center; gap: .55rem; color: #fff; font-weight: 650; font-size: 1.05rem; letter-spacing: .01em; text-decoration: none; margin-right: .75rem; }
.app-brand:hover { color: #fff; }
.app-brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #3b82f6, #6366f1); box-shadow: 0 2px 8px rgba(59, 130, 246, .45); }
.app-nav-list { display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; }
.app-nav { display: inline-flex; align-items: center; gap: .4rem; color: #b8c6dc; text-decoration: none; padding: .38rem .7rem; border-radius: .5rem; font-size: .9rem; font-weight: 500; transition: background .15s, color .15s; }
.app-nav:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.app-nav.active { color: #fff; background: rgba(255, 255, 255, .14); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08); }
.app-nav-sep { width: 1px; height: 20px; background: rgba(255, 255, 255, .18); margin: 0 .4rem; }
.app-icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: .5rem; border: 1px solid rgba(255, 255, 255, .16); background: transparent; color: #d5deec; }
.app-icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.theme-when-dark { display: none; }
[data-bs-theme="dark"] .theme-when-dark { display: inline; }
[data-bs-theme="dark"] .theme-when-light { display: none; }

/* ==== Page furniture ==== */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.5rem; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-sub { color: var(--cc-muted); margin: .2rem 0 0; max-width: 80ch; font-size: .92rem; }
.card, .panel { background: var(--cc-surface); border: 1px solid var(--cc-border); border-radius: .75rem; box-shadow: var(--cc-shadow); }
.card { --bs-card-bg: var(--cc-surface); --bs-card-border-color: var(--cc-border); }
a.card { color: inherit; transition: border-color .15s, transform .15s, box-shadow .15s; }
a.card:hover { border-color: var(--cc-brand); transform: translateY(-1px); box-shadow: var(--cc-shadow-lg); }
.panel { overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: .5rem; padding: .7rem 1rem; border-bottom: 1px solid var(--cc-border); font-weight: 600; font-size: .95rem; }
.panel-head .icon { color: var(--cc-muted); }
.panel-head .count { margin-left: .15rem; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 1rem; background: var(--cc-idle-soft); color: var(--cc-muted); }
.panel-head .count.hot { background: var(--cc-warn-soft); color: var(--cc-warn); }
.panel-tools { margin-left: auto; font-weight: 400; font-size: .8rem; color: var(--cc-muted); }
.panel-empty { padding: 1.25rem 1rem; color: var(--cc-muted); font-size: .9rem; display: flex; align-items: center; gap: .5rem; }
.panel .table { margin-bottom: 0; }
.panel-foot { padding: .6rem 1rem; border-top: 1px solid var(--cc-border); font-size: .8rem; color: var(--cc-muted); background: var(--cc-surface-2); }
.border-dashed { border-style: dashed; }
.nav-tabs { --bs-nav-tabs-border-color: var(--cc-border); --bs-nav-tabs-link-active-bg: var(--cc-surface); --bs-nav-tabs-link-active-border-color: var(--cc-border) var(--cc-border) var(--cc-surface); }
.nav-tabs .nav-link { color: var(--cc-muted); font-weight: 500; }
.nav-tabs .nav-link.active { color: var(--cc-text); }
.form-control, .form-select { background-color: var(--cc-surface); border-color: var(--cc-border-strong); color: var(--cc-text); }
.alert { border-radius: .6rem; }

/* ==== Accounts ==== */
.auth-card { max-width: 440px; margin: 2.5rem auto; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, max-content); gap: .25rem 1.5rem; font-size: 1.1rem; }
.qr { width: 200px; height: 200px; background: #fff; padding: 8px; border: 1px solid var(--cc-border); border-radius: .5rem; }
.pick-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--cc-border); border-radius: .5rem; padding: .5rem .75rem; background: var(--cc-surface); }
.badge-soft { background: var(--cc-brand-soft); color: var(--cc-text); font-weight: 500; }
#blazor-error-ui { background: #fff3cd; color: #3d2f00; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, .2); display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* ==== Dashboard tiles ==== */
.tile-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: .6rem; background: var(--cc-brand-soft); color: var(--cc-brand); margin-bottom: .75rem; }

/* ==== Reports & realtime ==== */
.filter-bar .form-label { color: var(--cc-muted); }
.picker { position: relative; }
.picker > summary { list-style: none; cursor: pointer; }
.picker > summary::-webkit-details-marker { display: none; }
.picker-panel { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 280px; max-width: 90vw; background: var(--cc-surface); border: 1px solid var(--cc-border-strong); border-radius: .6rem; box-shadow: var(--cc-shadow-lg); padding: .6rem .75rem; }
.picker-list { max-height: 300px; overflow-y: auto; }
.realtime-picker { min-width: 260px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .85rem; }
.stat { position: relative; display: flex; flex-direction: column; gap: .1rem; background: var(--cc-surface); border: 1px solid var(--cc-border); border-radius: .75rem; padding: .8rem 1rem .85rem; color: inherit; text-decoration: none; box-shadow: var(--cc-shadow); overflow: hidden; }
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--stat-accent, transparent); }
.stat-link:hover { border-color: var(--cc-brand); color: inherit; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.stat-label { font-size: .72rem; color: var(--cc-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat-icon { color: var(--stat-accent, var(--cc-muted)); opacity: .85; }
.stat-value { font-size: 1.75rem; line-height: 1.15; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-sub { font-size: .8rem; color: var(--cc-muted); }
.stat-ok { --stat-accent: var(--cc-ok); }
.stat-info { --stat-accent: var(--cc-info); }
.stat-warn { --stat-accent: var(--cc-warn); background: var(--cc-warn-soft); border-color: color-mix(in srgb, var(--cc-warn) 35%, transparent); }
.stat-bad { --stat-accent: var(--cc-bad); background: var(--cc-bad-soft); border-color: color-mix(in srgb, var(--cc-bad) 40%, transparent); }
.stat-bad .stat-value { color: var(--cc-bad); }

.report-table { --bs-table-bg: var(--cc-surface); --bs-table-color: var(--cc-text); --bs-table-hover-bg: var(--cc-surface-2); --bs-table-border-color: var(--cc-border); font-size: .875rem; }
.report-table > :not(caption) > * > * { padding: .5rem .75rem; }
.report-table th { font-weight: 600; color: var(--cc-muted); white-space: nowrap; background: var(--cc-surface-2); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.report-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.report-table a { text-decoration: none; }
.report-table a:hover { text-decoration: underline; }
.table-responsive > .report-table:not(.panel .report-table) { border: 1px solid var(--cc-border); border-radius: .6rem; overflow: hidden; }
.bar-cell { position: relative; min-width: 90px; }
.bar-cell > * { position: relative; }
.bar-cell > .bar { position: absolute; left: 0; top: 18%; height: 64%; background: var(--cc-bar); border-radius: 3px; z-index: 0; }
.bar-cell > .bar.bar-bad { background: var(--cc-bar-bad); }
.stale { opacity: .55; transition: opacity .2s; }
.report-loading { color: var(--cc-muted); margin-bottom: .75rem; }
.num-input { width: 6.5rem; }
.calls-table .call-events > td { background: var(--cc-surface-2); padding: .5rem 1rem; }
.outcome { white-space: nowrap; }
.outcome-1, .outcome-2 { color: var(--cc-ok); }
.outcome-3 { color: var(--cc-bad); }
.outcome-4 { color: var(--cc-warn); }
.row-warn > td { background: var(--cc-warn-soft) !important; }
.row-bad > td { background: var(--cc-bad-soft) !important; }
.muted-row > td { color: var(--cc-muted); }

/* ==== Realtime ==== */
.live-pill { display: inline-flex; align-items: center; gap: .45rem; padding: .3rem .7rem; border-radius: 2rem; background: var(--cc-surface); border: 1px solid var(--cc-border); font-size: .8rem; color: var(--cc-muted); box-shadow: var(--cc-shadow); }
.live-dot { position: relative; display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: #22c55e; }
.live-dot::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; animation: live-ping 2s cubic-bezier(0, 0, .2, 1) infinite; }
.live-dot-bad { background: #ef4444; }
@keyframes live-ping { 75%, 100% { transform: scale(2.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .live-dot::after { animation: none; } }

.feed-alert { display: flex; align-items: center; gap: .6rem; padding: .6rem .9rem; border-radius: .6rem; background: var(--cc-warn-soft); color: var(--cc-text); border: 1px solid color-mix(in srgb, var(--cc-warn) 35%, transparent); font-size: .875rem; margin-bottom: .75rem; }
.feed-alert .icon { color: var(--cc-warn); }

.queue-name { font-weight: 600; white-space: nowrap; }
.pill-num { display: inline-block; min-width: 1.9rem; text-align: center; padding: .05rem .45rem; border-radius: 1rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.pill-warn { background: var(--cc-warn-soft); color: var(--cc-warn); }
.pill-bad { background: var(--cc-bad-soft); color: var(--cc-bad); }
.pill-info { background: var(--cc-info-soft); color: var(--cc-info); }
.zero { color: color-mix(in srgb, var(--cc-muted) 60%, transparent); }
.sla { display: inline-flex; align-items: center; gap: .5rem; justify-content: flex-end; }
.sla-track { width: 54px; height: 6px; border-radius: 3px; background: var(--cc-idle-soft); overflow: hidden; }
.sla-fill { height: 100%; border-radius: 3px; background: var(--cc-ok); }
.sla-fill.mid { background: var(--cc-warn); }
.sla-fill.low { background: var(--cc-bad); }

.agent-cell { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; font-size: .72rem; font-weight: 700; letter-spacing: .02em; flex-shrink: 0; background: var(--cc-idle-soft); color: var(--cc-idle); box-shadow: 0 0 0 2px var(--cc-surface), 0 0 0 3.5px var(--ring, transparent); }
.agent-status { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem; border-radius: 1rem; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.agent-status::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; }
.agent-oncall { background: var(--cc-info-soft); color: var(--cc-info); }
.agent-paused { background: var(--cc-warn-soft); color: var(--cc-warn); }
.agent-ready { background: var(--cc-ok-soft); color: var(--cc-ok); }
.agent-notloggedin { background: var(--cc-idle-soft); color: var(--cc-idle); }
.ring-oncall { --ring: var(--cc-info); }
.ring-paused { --ring: var(--cc-warn); }
.ring-ready { --ring: var(--cc-ok); }
.agent-othercall { background: var(--cc-brand-soft); color: var(--cc-brand); }
.agent-ringing { background: var(--cc-info-soft); color: var(--cc-info); animation: cc-blink 1.2s ease-in-out infinite; }
.agent-phoneoffline { background: var(--cc-bad-soft); color: var(--cc-bad); }
.ring-othercall { --ring: var(--cc-brand); }
.ring-ringing { --ring: var(--cc-info); }
.ring-phoneoffline { --ring: var(--cc-bad); }
@keyframes cc-blink { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .agent-ringing { animation: none; } }
.cmd-note { display: block; margin-top: .2rem; font-size: .74rem; color: var(--cc-muted); white-space: normal; max-width: 22rem; }
.cmd-note.bad { color: var(--cc-bad); }

/* Active / All switch in a panel header. */
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--cc-border); border-radius: .5rem; background: var(--cc-surface-2); }
.seg > button { border: 0; background: transparent; color: var(--cc-muted); font-size: .78rem; font-weight: 600; padding: .2rem .7rem; border-radius: .38rem; line-height: 1.3; }
.seg > button:hover { color: var(--cc-text); }
.seg > button.active { background: var(--cc-surface); color: var(--cc-brand); box-shadow: var(--cc-shadow); }

/* Pause / log-out menu on agent rows (opened by click). */
.agent-menu { position: relative; display: inline-block; }
.icon-btn { display: inline-grid; place-items: center; width: 28px; height: 28px; border: 1px solid transparent; border-radius: .45rem; background: transparent; color: var(--cc-muted); }
.icon-btn:hover, .icon-btn[aria-expanded="true"] { border-color: var(--cc-border); background: var(--cc-surface-2); color: var(--cc-brand); }
.agent-menu-body { position: absolute; right: 0; top: calc(100% + 4px); z-index: 40; display: flex; flex-direction: column; gap: .3rem; width: 250px; padding: .55rem; background: var(--cc-surface); border: 1px solid var(--cc-border-strong); border-radius: .6rem; box-shadow: var(--cc-shadow-lg); text-align: left; white-space: normal; }
.agent-menu-body .title { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--cc-muted); font-weight: 600; }
.agent-menu-body > button { display: flex; align-items: center; gap: .45rem; width: 100%; border: 0; background: transparent; color: var(--cc-text); padding: .35rem .45rem; border-radius: .4rem; font-size: .85rem; text-align: left; }
.agent-menu-body > button:hover { background: var(--cc-surface-2); color: var(--cc-brand); }
.agent-menu-body > button.danger { color: var(--cc-bad); }
.agent-menu-body > button.danger:hover { background: var(--cc-bad-soft); color: var(--cc-bad); }
.agent-menu-body .menu-note { font-size: .78rem; color: var(--cc-muted); }

/* Hover / focus pop-over (pure CSS, so it works in static and interactive pages and on touch via focus). */
.hover-pop { position: relative; display: inline-block; }
.hover-pop > button { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--cc-border); background: var(--cc-surface-2); color: var(--cc-muted); border-radius: .45rem; padding: .15rem .45rem; font-size: .78rem; line-height: 1.2; }
.hover-pop > button:hover, .hover-pop:focus-within > button { color: var(--cc-brand); border-color: var(--cc-brand); }
.hover-pop-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px; max-width: 340px; padding: .55rem .75rem; background: var(--cc-surface); border: 1px solid var(--cc-border-strong); border-radius: .6rem; box-shadow: var(--cc-shadow-lg); font-size: .82rem; text-align: left; white-space: normal; visibility: hidden; opacity: 0; transform: translateY(-3px); transition: opacity .12s, transform .12s, visibility .12s; }
.hover-pop:hover .hover-pop-body, .hover-pop:focus-within .hover-pop-body { visibility: visible; opacity: 1; transform: none; }
.hover-pop-body .title { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--cc-muted); font-weight: 600; margin-bottom: .3rem; }
.hover-pop-body ul { list-style: none; margin: 0; padding: 0; }
.hover-pop-body li { padding: .12rem 0; }
/* Tables with pop-overs: let the pop-over escape the scroll box on screens wide enough not to need sideways scrolling. */
@media (min-width: 992px) {
    .panel.panel-pop, .panel-pop > .table-responsive { overflow: visible; }
}
