:root {
    --brand: #be1e2d;
    --brand-dark: #941523;
    --brand-soft: #fff0f2;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --text: #1b1d21;
    --muted: #69707d;
    --border: #e2e5e9;
    --shadow: 0 8px 30px rgba(15, 23, 42, .07);
    --sidebar: #17191d;
    --sidebar-text: #e8eaed;
    --success: #14804a;
    --warning: #a15c00;
    --danger: #b42318;
    --info: #175cd3;
    --radius: 14px;
}

[data-theme="dark"] {
    --bg: #101215;
    --surface: #191c21;
    --surface-2: #20242a;
    --text: #f0f2f5;
    --muted: #a5acb8;
    --border: #30353d;
    --shadow: 0 10px 32px rgba(0, 0, 0, .28);
    --brand-soft: #33151a;
    --sidebar: #0a0b0d;
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]):not([data-theme="dark"]) {
        --bg: #101215;
        --surface: #191c21;
        --surface-2: #20242a;
        --text: #f0f2f5;
        --muted: #a5acb8;
        --border: #30353d;
        --shadow: 0 10px 32px rgba(0, 0, 0, .28);
        --brand-soft: #33151a;
        --sidebar: #0a0b0d;
    }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; z-index: 50; }
.brand { height: 74px; display: flex; align-items: center; gap: 12px; padding: 0 22px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--brand); display: grid; place-items: center; color: white; font-weight: 800; letter-spacing: -.04em; }
.brand-name { font-weight: 750; font-size: 15px; line-height: 1.15; }
.brand-subtitle { color: #9da3ad; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.sidebar-nav { padding: 16px 12px; overflow-y: auto; flex: 1; }
.nav-section { margin: 15px 10px 7px; font-size: 10px; font-weight: 800; color: #858b95; text-transform: uppercase; letter-spacing: .12em; }
.nav-link { display: flex; align-items: center; gap: 11px; min-height: 42px; padding: 9px 12px; border-radius: 9px; color: #c8ccd3; margin-bottom: 3px; transition: .18s ease; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: var(--brand); color: #fff; font-weight: 700; }
.nav-icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-mini { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 800; }
.user-mini strong { display: block; color: #fff; font-size: 13px; }
.user-mini small { color: #9399a3; }

.main-area { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 40; height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 28px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.page-heading h1 { margin: 0; font-size: 21px; letter-spacing: -.025em; }
.page-heading p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.mobile-menu { display: none; }
.content { padding: 26px 28px 42px; max-width: 1680px; margin: 0 auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 15px; }
.card-body { padding: 20px; }
.card-footer { padding: 15px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.wrap { flex-wrap: wrap; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-right { text-align: right; }

.metric-card { padding: 19px; position: relative; overflow: hidden; }
.metric-label { color: var(--muted); font-weight: 650; font-size: 12px; }
.metric-value { margin-top: 7px; font-size: 30px; font-weight: 800; letter-spacing: -.045em; }
.metric-caption { margin-top: 5px; color: var(--muted); font-size: 11px; }
.metric-icon { position: absolute; right: 17px; top: 17px; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-size: 19px; }
.metric-card.danger .metric-value { color: var(--danger); }
.metric-card.warning .metric-value { color: var(--warning); }

.btn { min-height: 38px; border: 1px solid transparent; border-radius: 9px; padding: 8px 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-weight: 700; font-size: 12px; transition: .15s ease; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { color: var(--text); background: var(--surface); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-ghost { color: var(--muted); background: transparent; border-color: transparent; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm { min-height: 32px; padding: 6px 10px; font-size: 11px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-group { min-width: 0; }
.form-group.full { grid-column: 1 / -1; }
.form-label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 750; }
.required::after { content: " *"; color: var(--brand); }
.form-control { width: 100%; min-height: 42px; border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; color: var(--text); background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s; }
.form-control:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent); }
textarea.form-control { min-height: 105px; resize: vertical; }
.form-help { margin-top: 5px; color: var(--muted); font-size: 11px; }
.form-error { color: var(--danger); font-size: 11px; margin-top: 5px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--brand); }
.form-section { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.form-section-title { padding: 12px 15px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 800; }
.form-section-body { padding: 16px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.filters { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.filters .form-group { min-width: 145px; }
.filters .search { min-width: 260px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 13px; text-align: left; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
td { padding: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.table-title { font-weight: 750; }
.table-subtitle { color: var(--muted); font-size: 11px; margin-top: 2px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 4px 8px; font-size: 10px; font-weight: 800; background: #eef0f3; color: #4c5564; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-red { color: #b42318; background: #fee4e2; }
.badge-green, .badge-emerald { color: #067647; background: #dcfae6; }
.badge-blue { color: #175cd3; background: #dbeafe; }
.badge-yellow, .badge-orange { color: #b54708; background: #fef0c7; }
.badge-purple { color: #6941c6; background: #ebe9fe; }
.badge-cyan { color: #0e7090; background: #cff9fe; }
.badge-gray { color: #475467; background: #eaecf0; }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 18px; border: 1px solid; display: flex; justify-content: space-between; gap: 10px; }
.alert-success { color: var(--success); background: color-mix(in srgb, var(--success) 9%, var(--surface)); border-color: color-mix(in srgb, var(--success) 25%, var(--border)); }
.alert-warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 9%, var(--surface)); border-color: color-mix(in srgb, var(--warning) 25%, var(--border)); }
.alert-danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 25%, var(--border)); }
.alert button { border: 0; background: transparent; color: inherit; }

.chart { min-height: 235px; display: flex; align-items: end; gap: 13px; padding-top: 18px; }
.chart-group { flex: 1; height: 210px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 7px; min-width: 44px; }
.chart-bars { height: 175px; display: flex; align-items: end; gap: 4px; }
.chart-bar { width: 14px; min-height: 3px; border-radius: 5px 5px 2px 2px; background: var(--brand); }
.chart-bar.secondary { background: #6b7280; }
.chart-label { color: var(--muted); font-size: 9px; white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--brand); margin-right: 5px; }
.legend .secondary::before { background: #6b7280; }

.ranking-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.ranking-item:last-child { border: 0; }
.progress { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 7px; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }

.details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.detail { padding: 12px; background: var(--surface-2); border-radius: 9px; }
.detail dt { color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.detail dd { margin: 4px 0 0; font-weight: 700; }
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding: 0 0 18px 10px; }
.timeline-item::before { content: ""; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }
.timeline-item strong { font-size: 12px; }
.timeline-item p { margin: 3px 0; color: var(--muted); font-size: 11px; }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 34px; margin-bottom: 8px; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; }
.pagination-links { display: flex; gap: 5px; }
.page-link { min-width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 11px; }
.page-link.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.page-link.disabled { opacity: .45; pointer-events: none; }

.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(300px, 42%) minmax(0, 1fr); }
.auth-brand { background: #17191d; color: #fff; padding: 58px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-brand::after { content: ""; width: 420px; height: 420px; border-radius: 50%; position: absolute; right: -190px; bottom: -170px; background: var(--brand); opacity: .9; }
.auth-brand h1 { font-size: clamp(30px, 4vw, 52px); line-height: 1.03; max-width: 520px; letter-spacing: -.05em; position: relative; z-index: 1; }
.auth-brand p { color: #b7bbc2; max-width: 480px; position: relative; z-index: 1; }
.auth-form-area { display: grid; place-items: center; padding: 30px; background: var(--bg); }
.auth-card { width: min(430px, 100%); }
.auth-card h2 { margin: 0 0 5px; font-size: 25px; letter-spacing: -.035em; }
.auth-card > p { margin: 0 0 24px; color: var(--muted); }
.password-wrap { position: relative; }
.password-wrap .form-control { padding-right: 46px; }
.password-toggle { position: absolute; right: 5px; top: 5px; height: 32px; border: 0; background: transparent; color: var(--muted); }

.public-machine { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.public-machine-card { width: min(620px, 100%); }
.public-brand { height: auto; padding: 0; border: 0; color: var(--text); }
.qr-box { padding: 16px; background: #fff; border-radius: 12px; display: inline-block; border: 1px solid var(--border); }
.machine-photo { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; background: var(--surface-2); }

@media (max-width: 1050px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 800px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -280px; width: 260px; transition: left .22s ease; }
    body.sidebar-open .sidebar { left: 0; }
    body.sidebar-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.48); z-index: 45; }
    .mobile-menu { display: inline-flex; }
    .topbar { height: 64px; padding: 0 16px; }
    .content { padding: 18px 14px 34px; }
    .page-heading p { display: none; }
    .auth-page { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .grid-2, .grid-3, .grid-4, .form-grid, .details { grid-template-columns: 1fr; }
    .span-2, .span-3 { grid-column: auto; }
    .toolbar { align-items: stretch; flex-direction: column; }
    .filters { align-items: stretch; }
    .filters .form-group, .filters .search { min-width: 0; flex: 1 1 100%; }
    .top-actions .desktop-label { display: none; }
}

@media print {
    .sidebar, .topbar, .toolbar, .btn, .alert { display: none !important; }
    .app-shell { display: block; }
    .content { padding: 0; max-width: none; }
    .card { box-shadow: none; break-inside: avoid; }
    body { background: white; color: black; }
}
.text-center { text-align: center; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.inline-editor { position: absolute; right: 24px; margin-top: 8px; z-index: 20; width: min(360px, calc(100vw - 50px)); display: grid; gap: 9px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.inline-editor-wide { width: min(520px, calc(100vw - 50px)); }
progress { width: 100%; height: 7px; border: 0; border-radius: 999px; overflow: hidden; accent-color: var(--brand); }
progress::-webkit-progress-bar { background: var(--border); }
progress::-webkit-progress-value { background: var(--brand); }
pre.audit-json { white-space: pre-wrap; word-break: break-word; max-width: 560px; max-height: 240px; overflow: auto; margin: 0; font-size: 10px; }
.calendar-strip { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); gap: 8px; }
.calendar-day { min-height: 92px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.calendar-date { font-size: 11px; color: var(--muted); font-weight: 800; }
.calendar-event { display: block; margin-top: 5px; padding: 5px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); font-size: 10px; font-weight: 700; }
.item-builder-row { display: grid; grid-template-columns: minmax(0,1fr) 140px 90px 42px; gap: 8px; align-items: center; }
@media(max-width:800px){.item-builder-row{grid-template-columns:1fr 1fr}.item-builder-row .item-label{grid-column:1/-1}.calendar-strip{grid-template-columns:1fr}.inline-editor{position:fixed;left:14px;right:14px;bottom:14px;width:auto;max-height:80vh;overflow:auto}}
.text-danger { color: var(--danger); font-weight: 700; }
code { white-space: pre-wrap; display: block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.8; }
.notification-button { position: relative; }
.notification-count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 9px; display: grid; place-items: center; border: 2px solid var(--surface); }
.notification-row { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 13px; color: var(--text); display: grid; grid-template-columns: 10px minmax(0,1fr) auto; gap: 10px; text-align: left; align-items: center; }
.notification-row.unread { background: var(--brand-soft); border-color: color-mix(in srgb,var(--brand) 35%,var(--border)); }
.notification-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.notification-row.unread .notification-dot { background: var(--brand); }
