:root {
    color-scheme: dark;
    --theme-bg: #0b1220;
    --theme-card: #172033;
    --theme-surface: #223049;
    --theme-surface-hover: #2d3d58;
    --theme-text: #e8eef8;
    --theme-muted: #9eacc0;
    --theme-border: #35445e;
    --theme-input: #0e192c;
    --theme-accent: #ff8d08;
    --theme-accent-strong: #e97800;
    --theme-shadow: 0 14px 35px rgba(0, 0, 0, .28);
    --theme-success-bg: #064e3b;
    --theme-success-text: #a7f3d0;
    --theme-danger-bg: #4c0519;
    --theme-danger-text: #fecdd3;
}

:root[data-theme="light"] {
    color-scheme: light;
    --theme-bg: #eef3f8;
    --theme-card: #ffffff;
    --theme-surface: #e6edf5;
    --theme-surface-hover: #d7e2ee;
    --theme-text: #172033;
    --theme-muted: #5e6d82;
    --theme-border: #c9d5e3;
    --theme-input: #f8fafc;
    --theme-accent: #e97800;
    --theme-accent-strong: #c96100;
    --theme-shadow: 0 12px 30px rgba(41, 57, 78, .12);
    --theme-success-bg: #d1fae5;
    --theme-success-text: #065f46;
    --theme-danger-bg: #ffe4e6;
    --theme-danger-text: #9f1239;
}

html { background: var(--theme-bg); }
body {
    background: var(--theme-bg) !important;
    background-image:
        radial-gradient(circle at 8% 0%, color-mix(in srgb, #38bdf8 10%, transparent), transparent 30%),
        radial-gradient(circle at 92% 8%, color-mix(in srgb, var(--theme-accent) 9%, transparent), transparent 28%) !important;
    background-attachment: fixed !important;
    color: var(--theme-text) !important;
    transition: background-color .2s ease, color .2s ease;
}

.container, .card, .box, .result-panel, .price-box, .login-box, .empty, .empty-state {
    background: var(--theme-card) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
    box-shadow: var(--theme-shadow);
    background-image: linear-gradient(145deg, color-mix(in srgb, var(--theme-card) 96%, white), var(--theme-card)) !important;
}

.card, .box, .result-panel, .price-box { position: relative; overflow: hidden; }
.card::after, .box::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--section-color, var(--theme-border));
    opacity: .9;
}

.section-title {
    --section-color: var(--theme-accent);
    display: flex;
    align-items: center;
    gap: 10px;
    width: fit-content;
    max-width: 100%;
    margin-bottom: 16px !important;
    padding: 8px 13px 8px 10px;
    border: 1px solid color-mix(in srgb, var(--section-color) 35%, var(--theme-border));
    border-radius: 10px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--section-color) 16%, var(--theme-card)), color-mix(in srgb, var(--section-color) 3%, var(--theme-card)));
    color: var(--theme-text) !important;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--section-color) 10%, transparent);
}
.section-title::before {
    content: attr(data-icon);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: color-mix(in srgb, var(--section-color) 22%, var(--theme-surface));
    color: var(--section-color);
    font-size: 18px;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--section-color) 35%, transparent);
}
.section-title.has-native-icon::before { display: none; }
h1.section-title { font-size: clamp(22px, 3vw, 30px); padding: 10px 16px 10px 11px; }
h3.section-title { font-size: 15px; }

.accent-printer { --section-color: #38bdf8; }
.accent-cost { --section-color: #fb923c; }
.accent-supply { --section-color: #f472b6; }
.accent-counter { --section-color: #60a5fa; }
.accent-maintenance { --section-color: #34d399; }
.accent-paper { --section-color: #fbbf24; }
.accent-job { --section-color: #a78bfa; }
.accent-security { --section-color: #f87171; }
.accent-default { --section-color: var(--theme-accent); }

.card.accent-printer, .box.accent-printer { --section-color:#38bdf8; }
.card.accent-cost, .box.accent-cost { --section-color:#fb923c; }
.card.accent-supply, .box.accent-supply { --section-color:#f472b6; }
.card.accent-counter, .box.accent-counter { --section-color:#60a5fa; }
.card.accent-maintenance, .box.accent-maintenance { --section-color:#34d399; }
.card.accent-paper, .box.accent-paper { --section-color:#fbbf24; }
.card.accent-job, .box.accent-job { --section-color:#a78bfa; }

.section-title + .muted { margin-top: -8px; }
.card:hover { border-color: color-mix(in srgb, var(--section-color, var(--theme-accent)) 35%, var(--theme-border)) !important; }

.inline-form, .table-container, .table-wrap, .file-info-box, .progress-wrapper,
.upload-area, .markup, .price-big-box {
    background: var(--theme-surface) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
}

input, select, textarea {
    background: var(--theme-input) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
}

input::placeholder, textarea::placeholder { color: var(--theme-muted) !important; }
label, .muted, .list-label, .card-size, .price-sub, .price-detail { color: var(--theme-muted) !important; }
h1, h2, h3, strong, .card-title, .list-val { color: var(--theme-text); }

table, thead, tbody, tfoot, tr, th, td {
    border-color: var(--theme-border) !important;
}
table { background: var(--theme-card) !important; color: var(--theme-text) !important; }
th { background: var(--theme-surface) !important; color: var(--theme-muted) !important; }
th { border-top: 2px solid color-mix(in srgb, var(--section-color, var(--theme-accent)) 50%, transparent) !important; }
td { background: var(--theme-card) !important; color: var(--theme-text); }
tr:hover td { background: var(--theme-surface) !important; }

.btn, .btn-link, a.btn, .device, .btn-toggle {
    background: var(--theme-surface) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
}
.btn:hover, .btn-link:hover, a.btn:hover, .device:hover, .device.active {
    background: var(--theme-surface-hover) !important;
}
.btn.primary, .btn-save, #btn-save-log, button[type="submit"] {
    background: linear-gradient(135deg, var(--theme-accent), var(--theme-accent-strong)) !important;
    color: #fff !important;
    border-color: var(--theme-accent) !important;
}
.btn-toggle.active { background: var(--theme-accent) !important; color: #fff !important; }
.notice.ok, .ok { background: var(--theme-success-bg) !important; color: var(--theme-success-text) !important; }
.notice.bad, .error { background: var(--theme-danger-bg) !important; color: var(--theme-danger-text) !important; }
.badge {
    border: 1px solid color-mix(in srgb, var(--section-color, var(--theme-accent)) 28%, var(--theme-border));
    background: color-mix(in srgb, var(--section-color, var(--theme-accent)) 10%, var(--theme-surface)) !important;
    color: var(--theme-text) !important;
}
.tag { color: #fb923c !important; font-weight: 700; }

.theme-toggle {
    position: fixed;
    z-index: 9999;
    right: 18px;
    bottom: 18px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 10px 14px;
    border: 1px solid var(--theme-border);
    border-radius: 999px;
    background: var(--theme-card);
    color: var(--theme-text);
    box-shadow: var(--theme-shadow);
    cursor: pointer;
    font: 700 13px Inter, system-ui, sans-serif;
}
.theme-toggle:hover { background: var(--theme-surface); transform: translateY(-1px); }
.theme-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--theme-accent) 35%, transparent); outline-offset: 2px; }

@media print {
    :root { color-scheme: light; }
    body, .container, .card, .box, table, th, td { background: #fff !important; color: #111 !important; box-shadow: none !important; }
    .theme-toggle, .nav, .actions { display: none !important; }
}

@media (max-width: 600px) {
    .theme-toggle { right: 10px; bottom: 10px; padding: 10px 12px; }
    .theme-toggle .theme-label { display: none; }
}
