:root {
    color-scheme: dark;
    --bg: #080b0f;
    --surface: #0d1218;
    --surface-2: #111820;
    --surface-3: #151e27;
    --line: #24303b;
    --line-soft: #1a242d;
    --text: #edf3f5;
    --muted: #91a0aa;
    --faint: #5f6d77;
    --cyan: #38c8d8;
    --green: #42d392;
    --red: #ff6b6b;
    --amber: #f4bc52;
    --violet: #a58bfa;
    --blue: #5ba7ff;
    --radius: 6px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    letter-spacing: 0;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
    margin: 0;
    min-width: 320px;
    background:
        linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
        var(--bg);
    background-size: 48px 48px;
    color: var(--text);
}

button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.login-body { min-height: 100vh; }

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel {
    width: min(100%, 440px);
    padding: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(13, 18, 24, .96);
    box-shadow: 0 24px 70px rgba(0,0,0,.38);
}

.brand-mark {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    background: var(--cyan);
    color: #051014;
    font-size: 25px;
    font-weight: 900;
}

.brand-mark.small { width: 36px; height: 36px; font-size: 17px; }

.login-kicker, .eyebrow {
    margin: 26px 0 6px;
    color: var(--cyan);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

.login-panel h1 { margin: 0; font-size: 34px; line-height: 1.15; }
.login-copy { color: var(--muted); line-height: 1.65; margin: 14px 0 26px; }

.login-form { display: grid; gap: 10px; }
.login-form label { color: #c8d2d7; font-size: 13px; font-weight: 650; }

.login-form input,
.date-fields input,
.sim-filters select {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #080e13;
    color: var(--text);
    outline: none;
}

.login-form input { padding: 0 14px; font-size: 18px; }
.login-form input:focus, .date-fields input:focus, .sim-filters select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(56,200,216,.12); }

.login-form button, .primary-button {
    min-height: 42px;
    border: 0;
    border-radius: var(--radius);
    background: var(--cyan);
    color: #061014;
    font-weight: 800;
}

.login-form button { margin-top: 8px; }
.login-form button:hover, .primary-button:hover { filter: brightness(1.08); }

.form-error, .error-banner, .quality-banner {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.5;
}

.form-error { margin-top: 16px; color: #ffb4b4; background: rgba(255,107,107,.09); border: 1px solid rgba(255,107,107,.35); }
.error-banner { margin-bottom: 14px; color: #ffd0d0; background: rgba(255,107,107,.08); border: 1px solid rgba(255,107,107,.32); }
.quality-banner { margin-bottom: 14px; color: #ebd8aa; background: rgba(244,188,82,.07); border: 1px solid rgba(244,188,82,.25); }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 0 28px;
    border-bottom: 1px solid var(--line-soft);
    background: rgba(8,11,15,.92);
    backdrop-filter: blur(18px);
}

.topbar-brand, .topbar-status { display: flex; align-items: center; gap: 12px; }
.topbar-brand strong { display: block; font-size: 15px; }
.topbar-brand span, .topbar-status > span:not(.live-pill) { display: block; color: var(--muted); font-size: 11px; }
.topbar-status { justify-content: flex-end; }

.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--green);
    font-size: 11px;
    font-weight: 800;
}

.live-pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 14px currentColor; }

.icon-button {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--muted);
    font-size: 20px;
}

.icon-button:hover { color: var(--text); border-color: #3b4b58; }

.dashboard-shell { width: min(100%, 1680px); margin: 0 auto; padding: 24px 28px 50px; }

.toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    padding: 16px 0 22px;
}

.date-fields, .range-control, .sim-filters { display: flex; align-items: center; gap: 8px; }
.date-fields label { display: grid; gap: 5px; }
.date-fields label span { color: var(--faint); font-size: 10px; text-transform: uppercase; font-weight: 700; }
.date-fields input { width: 142px; padding: 0 10px; color-scheme: dark; }
.primary-button { padding: 0 18px; align-self: end; }

.range-control {
    padding: 3px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: var(--surface);
}

.range-control button {
    min-height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}

.range-control button:hover, .range-control button.active { color: var(--text); background: var(--surface-3); }

.section-block, .chart-panel, .table-panel {
    border-top: 1px solid var(--line);
    padding: 24px 0 28px;
}

.section-heading, .panel-heading {
    min-height: 42px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-heading h2, .panel-heading h2 { margin: 0; font-size: 17px; line-height: 1.3; }
.section-heading .eyebrow, .panel-heading .eyebrow { margin: 0 0 4px; }
.section-meta, .panel-heading > span { color: var(--faint); font-size: 11px; text-align: right; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(130px, 1fr));
    gap: 10px;
}

.kpi-card {
    min-height: 118px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: var(--surface);
}

.kpi-card::before { content: ""; width: 28px; height: 2px; background: var(--faint); }
.kpi-card.positive::before, .kpi-card.profit::before, .kpi-card.health::before { background: var(--green); }
.kpi-card.negative::before { background: var(--red); }
.kpi-card.info::before { background: var(--cyan); }
.kpi-card.warm::before { background: var(--amber); }
.kpi-card.violet::before { background: var(--violet); }
.kpi-card.neutral::before { background: var(--blue); }

.kpi-card span { color: var(--muted); font-size: 11px; font-weight: 650; }
.kpi-card strong { margin-top: 10px; font-size: clamp(20px, 1.7vw, 28px); line-height: 1; font-variant-numeric: tabular-nums; }
.kpi-card small { color: var(--faint); font-size: 10px; line-height: 1.25; }
.kpi-card.positive strong, .kpi-card.profit strong { color: var(--green); }
.kpi-card.negative strong { color: var(--red); }

.cost-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 1px;
    margin-top: 10px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--line-soft);
}

.cost-part { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; background: var(--surface); }
.cost-part span { color: var(--muted); font-size: 11px; }
.cost-part strong { font-size: 13px; font-variant-numeric: tabular-nums; }

.chart-layout, .split-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; }
.chart-panel, .table-panel { min-width: 0; }
.chart-frame { position: relative; width: 100%; height: 280px; }
.chart-frame canvas { display: block; width: 100%; height: 100%; }

.chart-legend { display: flex; gap: 18px; margin-top: 12px; color: var(--muted); font-size: 10px; }
.chart-legend span::before { content: ""; display: inline-block; width: 14px; height: 2px; margin-right: 6px; vertical-align: middle; background: currentColor; }
.chart-legend .revenue, .chart-legend .profit { color: var(--green); }
.chart-legend .cost { color: var(--red); }
.chart-legend .calls { color: var(--blue); }
.chart-legend .answered { color: var(--cyan); }

.channel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 12px; }
.channel-card, .operator-card {
    padding: 18px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: var(--surface);
}

.channel-title, .operator-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.channel-title h3, .operator-title h3 { margin: 0; font-size: 15px; }
.channel-title span, .operator-title span { color: var(--faint); font-size: 10px; }
.metric-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.metric-row div { min-width: 0; }
.metric-row span { display: block; color: var(--faint); font-size: 9px; text-transform: uppercase; }
.metric-row strong { display: block; margin-top: 5px; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

.operator-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; }
.operator-card .operator-health { display: flex; gap: 8px; margin-top: 16px; }
.health-chip { padding: 5px 8px; border-radius: 4px; font-size: 10px; background: var(--surface-3); color: var(--muted); }
.health-chip.good { color: var(--green); }
.health-chip.idle { color: var(--amber); }
.health-chip.dead { color: var(--red); }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 700px; background: rgba(13,18,24,.66); }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); text-align: right; white-space: nowrap; font-size: 11px; font-variant-numeric: tabular-nums; }
th { color: var(--faint); font-size: 9px; text-transform: uppercase; font-weight: 750; background: var(--surface); }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255,255,255,.018); }
td.primary-cell { color: var(--text); font-weight: 650; }
td.positive { color: var(--green); }
td.negative { color: var(--red); }
td.muted { color: var(--faint); }

.live-section { min-height: 180px; }
.live-call-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.live-call {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 10px 12px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: var(--surface);
}

.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px rgba(244,188,82,.45); }
.live-call.up .state-dot { background: var(--green); box-shadow: 0 0 10px rgba(66,211,146,.45); }
.live-call strong { display: block; font-size: 11px; }
.live-call small { display: block; color: var(--faint); font-size: 9px; margin-top: 3px; }
.live-call time { color: var(--muted); font-size: 11px; }
.empty-state { grid-column: 1 / -1; padding: 28px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--faint); text-align: center; font-size: 12px; }

.sim-heading { align-items: center; }
.sim-filters select { min-height: 36px; padding: 0 32px 0 10px; font-size: 11px; }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); gap: 7px; }

.sim-card {
    min-height: 112px;
    padding: 11px;
    border: 1px solid var(--line-soft);
    border-left: 3px solid var(--faint);
    border-radius: var(--radius);
    background: var(--surface);
}

.sim-card.good { border-left-color: var(--green); }
.sim-card.idle { border-left-color: var(--amber); }
.sim-card.dead { border-left-color: var(--red); }
.sim-card-head { display: flex; justify-content: space-between; gap: 8px; }
.sim-card-head strong { font-size: 11px; }
.sim-card-head span { color: var(--faint); font-size: 9px; }
.sim-card .operator { margin-top: 14px; color: var(--muted); font-size: 10px; }
.sim-card .phone { margin-top: 4px; color: var(--text); font-size: 11px; font-variant-numeric: tabular-nums; }
.sim-card-meta { display: flex; justify-content: space-between; gap: 6px; margin-top: 12px; color: var(--faint); font-size: 9px; }

.site-footer { display: flex; justify-content: space-between; gap: 20px; padding-top: 22px; border-top: 1px solid var(--line-soft); color: var(--faint); font-size: 10px; }

.loading .kpi-card strong, .loading .channel-card, .loading .operator-card {
    color: transparent;
    background-image: linear-gradient(90deg, var(--surface) 0%, var(--surface-3) 50%, var(--surface) 100%);
    background-size: 200% 100%;
    animation: loading 1.2s linear infinite;
}

@keyframes loading { to { background-position: -200% 0; } }

@media (max-width: 1380px) {
    .kpi-grid { grid-template-columns: repeat(4, minmax(145px, 1fr)); }
}

@media (max-width: 980px) {
    .chart-layout, .split-layout { grid-template-columns: 1fr; gap: 0; }
    .toolbar { align-items: flex-start; flex-direction: column; }
    .range-control { width: 100%; overflow-x: auto; }
    .cost-strip { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .topbar { padding: 0 14px; }
    .topbar-status > span:not(.live-pill) { display: none; }
    .dashboard-shell { padding: 16px 14px 36px; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .date-fields { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
    .date-fields label, .date-fields input { width: 100%; }
    .date-fields .primary-button { grid-column: 1 / -1; }
    .sim-heading { align-items: flex-start; flex-direction: column; }
    .sim-filters { width: 100%; }
    .sim-filters select { width: 50%; }
    .site-footer { flex-direction: column; }
}

@media (max-width: 480px) {
    .login-panel { padding: 28px 22px; }
    .login-panel h1 { font-size: 28px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
    .kpi-card { min-height: 106px; padding: 12px; }
    .channel-grid, .operator-grid { grid-template-columns: 1fr; }
    .metric-row { grid-template-columns: 1fr 1fr; }
    .sim-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
