:root {
    color-scheme: dark;
    font-family: "Segoe UI", Arial, sans-serif;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    --window: #09111f;
    --header: #101c2e;
    --surface: #121f32;
    --surface-raised: #192a40;
    --border: #2b415e;
    --text: #f3f7fc;
    --text-secondary: #a9bad0;
    --text-muted: #758aa4;
    --accent: #4d9bff;
    --accent-soft: #1b385d;
    --success: #22c88b;
    --warning: #ffbd4a;
    --danger: #ff6470;
    --shadow: 0 10px 28px rgb(0 0 0 / 14%);
}

:root[data-theme="light"] {
    color-scheme: light;
    --window: #f1f5fa;
    --header: #142742;
    --surface: #ffffff;
    --surface-raised: #f4f7fb;
    --border: #d7e0eb;
    --text: #18263a;
    --text-secondary: #53657c;
    --text-muted: #75859a;
    --accent: #1674df;
    --accent-soft: #e5f0ff;
    --success: #16885d;
    --warning: #bd7700;
    --danger: #d94350;
    --shadow: 0 8px 24px rgb(27 47 75 / 8%);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { width: 100%; height: 100%; margin: 0; }

body {
    display: flex;
    min-width: 320px;
    min-height: 100vh;
    flex-direction: column;
    overflow: hidden;
    color: var(--text);
    background: var(--window);
}

button, select { font: inherit; }

.toolbar {
    z-index: 2;
    display: flex;
    min-height: 72px;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 10px clamp(16px, 2vw, 34px);
    background: var(--header);
    box-shadow: var(--shadow);
}

.brand, .toolbar-actions, .status-items { display: flex; align-items: center; }
.brand { gap: 12px; }
.brand-mark {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 11px;
    color: white;
    background: linear-gradient(145deg, #58a8ff, #2475df);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .04em;
}
.brand strong, .brand span:not(.brand-mark) { display: block; }
.brand strong { color: #f7fbff; font-size: 15px; letter-spacing: .01em; }
.brand div > span { margin-top: 2px; color: #a9bad0; font-size: 11px; }
.toolbar-actions { gap: 9px; }

.line-picker select, .toolbar-button {
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    background: var(--surface-raised);
}
.line-picker select { min-width: 220px; max-width: min(38vw, 360px); padding: 0 34px 0 12px; }
.toolbar-button { padding: 0 14px; cursor: pointer; transition: filter .15s ease, transform .15s ease; }
.toolbar-button:hover { filter: brightness(1.12); }
.toolbar-button:active { transform: translateY(1px); }
.toolbar-button.primary { border-color: #3989ec; color: white; background: #287fe3; }

.dashboard-main {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    gap: clamp(12px, 1.5vh, 20px);
    padding: clamp(14px, 1.4vw, 24px) clamp(14px, 1.25vw, 24px) 12px;
}

.overview { flex: 0 0 auto; }
.overview h1 {
    margin: 0 0 10px 2px;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: .075em;
}

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.summary-card {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 108px;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    overflow: hidden;
    padding: 14px 18px 13px 21px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.summary-card::before { position: absolute; inset: 12px auto 12px 0; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent); content: ""; }
.summary-label { color: var(--text-secondary); font-size: 10px; font-weight: 750; letter-spacing: .04em; }
.summary-value { overflow: hidden; padding-bottom: 2px; color: var(--text); font-size: clamp(19px, 1.8vw, 29px); font-weight: 720; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.summary-caption, .summary-foot { color: var(--text-muted); font-size: 10px; }
.summary-foot { display: flex; min-height: 12px; align-items: center; justify-content: space-between; gap: 10px; }
.progress-track { height: 4px; flex: 1; overflow: hidden; border-radius: 99px; background: var(--border); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--success); transition: width .25s ease; }

.operations-section { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.section-header {
    display: grid;
    min-height: 29px;
    flex: 0 0 auto;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: clamp(10px, 1.3vw, 22px);
    padding: 0 2px 8px;
}
.section-header h2, .section-header p { margin: 0; font-size: 11px; }
.section-header h2 { color: var(--text-secondary); font-weight: 800; letter-spacing: .035em; white-space: nowrap; }
.section-header p { color: var(--text-secondary); font-weight: 650; white-space: nowrap; }
.section-header .last-activity { justify-self: end; color: var(--text-muted); font-size: 10px; font-weight: 500; }

.operation-grid {
    display: grid;
    min-height: 0;
    flex: 1;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr));
    grid-auto-rows: minmax(188px, auto);
    align-content: start;
    gap: 10px;
    overflow: auto;
    padding: 2px 3px 12px 1px;
    scrollbar-color: var(--border) transparent;
    scrollbar-width: thin;
}

.operation-card {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 188px;
    flex-direction: column;
    overflow: hidden;
    padding: 11px 12px 12px 15px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.operation-card::before { position: absolute; inset: 12px auto 12px 0; width: 4px; border-radius: 0 4px 4px 0; background: var(--efficiency-color, var(--danger)); content: ""; }
.operation-card::after { position: absolute; right: 14px; bottom: 7px; left: 14px; height: 3px; border-radius: 3px; background: linear-gradient(to right, var(--efficiency-color, var(--danger)) var(--efficiency, 0%), var(--border) var(--efficiency, 0%)); content: ""; }
.operation-card-header { display: grid; min-height: 38px; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: start; gap: 9px; }
.operation-index { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 5px; color: var(--accent); background: var(--accent-soft); font-size: 14px; font-weight: 800; }
.operation-heading { min-width: 0; padding-top: 1px; }
.operation-heading h3 { overflow: hidden; margin: 0 0 3px; color: var(--text); font-size: 13px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.operation-heading p { overflow: hidden; margin: 0; color: var(--text-secondary); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.efficiency { padding-top: 4px; color: var(--efficiency-color, var(--danger)); font-size: 9px; font-weight: 750; white-space: nowrap; }
.operation-card-content { display: grid; min-height: 0; flex: 1; grid-template-columns: minmax(62px, .43fr) minmax(0, 1fr); align-items: center; gap: 10px; padding: 7px 0 3px; }
.operation-total { min-width: 0; }
.operation-total span { display: block; margin-bottom: 3px; color: var(--text-muted); font-size: 9px; font-weight: 700; }
.operation-total strong { display: block; overflow: hidden; color: var(--text); font-size: clamp(23px, 2vw, 32px); font-weight: 750; line-height: 1; text-overflow: ellipsis; }
.button-list { display: grid; min-width: 0; gap: 3px; }
.button-row { display: flex; min-width: 0; min-height: 23px; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 7px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-raised); font-size: 10px; }
.button-worker { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.button-count { flex: 0 0 auto; color: var(--text); font-size: 11px; font-weight: 750; text-align: right; }

.empty-state { display: grid; min-height: 160px; flex: 1; place-items: center; color: var(--text-secondary); font-size: 15px; text-align: center; }
.status-bar { display: flex; min-height: 39px; align-items: center; justify-content: space-between; gap: 16px; padding: 0 clamp(16px, 2vw, 32px); border-top: 1px solid var(--border); background: var(--surface); color: var(--text-muted); font-size: 10px; }
.status-items { gap: clamp(12px, 2vw, 26px); white-space: nowrap; }
.status-bar form { margin: 0; }
.forget-tv-button { padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px; color: var(--text-secondary); background: var(--surface-raised); font: inherit; cursor: pointer; }
.forget-tv-button:hover { color: var(--text); border-color: var(--accent); }
.connection-status { font-weight: 700; }
.connection-status::before { margin-right: 5px; content: "●"; }
.connection-status.connected { color: var(--success); }
.connection-status.error { color: var(--danger); }
.connection-status.pending { color: var(--warning); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

body.is-fullscreen .toolbar-actions { display: none; }
body.is-fullscreen .toolbar { min-height: 55px; }
body.is-fullscreen .operation-grid { grid-auto-rows: minmax(184px, auto); gap: 8px; padding-bottom: 4px; }
body.is-fullscreen .operation-card { min-height: 184px; padding-top: 9px; padding-bottom: 9px; }
body.is-fullscreen .operation-card-header { min-height: 36px; }
body.is-fullscreen .button-row { min-height: 22px; padding-top: 1px; padding-bottom: 1px; }

@media (max-width: 1050px) {
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .summary-card { min-height: 94px; }
    .section-header { grid-template-columns: auto 1fr; }
    .section-header .last-activity { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 650px) {
    body { overflow: auto; }
    .toolbar { align-items: flex-start; flex-direction: column; gap: 12px; }
    .toolbar-actions { width: 100%; }
    .line-picker { min-width: 0; flex: 1; }
    .line-picker select { width: 100%; min-width: 0; max-width: none; }
    .toolbar-button { padding: 0 10px; }
    .dashboard-main { overflow: visible; }
    .operations-section { min-height: 430px; }
    .operation-grid { grid-auto-rows: auto; overflow: visible; }
    .section-header { grid-template-columns: 1fr; gap: 4px; padding-bottom: 10px; }
    .section-header .last-activity { grid-column: auto; }
    .status-bar { align-items: flex-start; flex-direction: column; gap: 4px; padding-top: 8px; padding-bottom: 8px; }
    .status-items { width: 100%; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
