:root {
    --bg: #052325;
    --surface: #0a3031;
    --surface-2: #104142;
    --line: #285254;
    --text: #f1faf4;
    --muted: #b5c9c3;
    --dim: #76918b;
    --gold: #baff2b;
    --gold-soft: #ddff9b;
    --cyan: #50ead3;
    --red: #f09883;
    --max: 1180px;
    --app-max: 2400px;
    --pad: clamp(1.15rem, 4vw, 3rem);
    --shadow: 0 12px 36px rgba(0, 0, 0, .35);
    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    --font-num: "Roboto Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

:root[data-theme="light"] {
    --bg: #f3f7f5;
    --surface: #ffffff;
    --surface-2: #e7f0ec;
    --line: #cbe0d8;
    --text: #052325;
    --muted: #3d5e58;
    --dim: #6c8a84;
    --gold: #0b6e5f;
    --gold-soft: #09594d;
    --cyan: #0b7a75;
    --red: #c83e2b;
    --shadow: 0 10px 28px rgba(5, 35, 37, .08);
}

:root[data-theme="light"] .slogo,
:root[data-theme="light"] .btn:not(.ghost):not(.danger):not(.cyan),
:root[data-theme="light"] .sitem.on,
:root[data-theme="light"] .tab.on,
:root[data-theme="light"] .chip.on,
:root[data-theme="light"] .cal-d.sel {
    background: #baff2b;
    color: #052325;
    border-color: #98d815;
}
:root[data-theme="light"] .btn:not(.ghost):not(.danger):not(.cyan):hover:not(:disabled) {
    background: #aae820;
    box-shadow: 0 6px 16px rgba(5, 35, 37, .12);
}
:root[data-theme="light"] .btn.ghost:hover:not(:disabled) {
    background: #d9e8e2;
    border-color: #0b7a75;
}
:root[data-theme="light"] .bar > span:not(.cyan):not(.red) {
    background: #0b6e5f;
}
:root[data-theme="light"] .pill.good {
    background: rgba(11, 110, 95, .12);
    color: #09594d;
    border-color: rgba(11, 110, 95, .3);
}
:root[data-theme="light"] .pill.info {
    background: rgba(11, 122, 117, .12);
    color: #0b7a75;
    border-color: rgba(11, 122, 117, .3);
}
:root[data-theme="light"] .pill.warn {
    background: rgba(186, 255, 43, .35);
    color: #052325;
    border-color: #98d815;
}
:root[data-theme="light"] .pill.bad {
    background: rgba(200, 62, 43, .1);
    color: #c83e2b;
    border-color: rgba(200, 62, 43, .3);
}
:root[data-theme="light"] .modal-wrap {
    background: rgba(5, 35, 37, .45);
}


* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 14.5px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--cyan); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
h1, h2, h3, h4 { margin: 0; text-wrap: balance; }

/* App Shell */
#app { height: 100%; display: flex; min-height: 0; }
.side {
    width: 260px; flex: none; background: var(--surface); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; min-height: 0; transition: transform .2s ease;
}
.sbrand { display: flex; align-items: center; gap: 11px; padding: 18px 18px 15px; border-bottom: 1px solid var(--line); }
.slogo {
    width: 36px; height: 36px; border-radius: 10px; background: var(--gold); color: #052325;
    display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: none;
}
.sbrand { flex-direction: column; align-items: flex-start; gap: 6px; }
.sbrand small { display: block; font-size: 11.5px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Brand wordmark (logo-white on dark theme, logo-color on light theme) */
.brand-wm { display: block; height: 34px; width: auto; max-width: 100%; flex: none; }
.wm-light { display: none; }
:root[data-theme="light"] .wm-dark { display: none; }
:root[data-theme="light"] .wm-light { display: block; }
.sgroups { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 14px; }
.slabel { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--dim); padding: 4px 10px 4px; }
.sitem {
    display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent;
    text-align: left; padding: 9px 11px; border-radius: 10px; color: var(--muted); font-weight: 500; font-size: 13.8px;
}
.sitem:hover { background: var(--surface-2); color: var(--text); }
.sitem.on { background: var(--gold); color: #052325; font-weight: 700; }
.sitem svg { width: 18px; height: 18px; flex: none; }
.sbadge {
    margin-left: auto; background: var(--red); color: #052325; font-size: 11px; font-weight: 800;
    min-width: 20px; height: 20px; border-radius: 99px; display: grid; place-items: center; padding: 0 6px;
}
.sitem.on .sbadge { background: #052325; color: var(--gold); }
.suser { border-top: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.sme {
    display: flex; align-items: center; gap: 10px; border: 0; background: var(--surface-2);
    text-align: left; padding: 9px 10px; border-radius: 10px; width: 100%; border: 1px solid var(--line);
}
.sme b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sme small { display: block; font-size: 11.5px; color: var(--muted); }

/* Main area */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.apphead {
    background: var(--surface); border-bottom: 1px solid var(--line);
    padding: 13px var(--pad); display: flex; align-items: center; gap: 12px; min-height: 62px; flex-wrap: wrap;
}
.apphead h2 { font-size: 20px; letter-spacing: -.01em; flex: 1; min-width: 180px; }
.menu-toggle { display: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 8px; padding: 6px 10px; }
.content {
    flex: 1; overflow-y: auto; padding: 22px var(--pad) 48px;
    display: flex; flex-direction: column; gap: 16px;
}
.content-inner { max-width: var(--app-max); width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.content-inner > * { animation: pageFadeUp .32s cubic-bezier(.22, 1, .36, 1) both; }
.content-inner > *:nth-child(2) { animation-delay: .04s; }
.content-inner > *:nth-child(3) { animation-delay: .08s; }
.content-inner > *:nth-child(4) { animation-delay: .11s; }
.content-inner > *:nth-child(5) { animation-delay: .14s; }

/* Cards, Grids, Tables */
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px;
    transition: border-color .2s ease, box-shadow .22s ease, transform .22s ease;
}
.card.alt { background: var(--surface-2); }
.card h3 { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
/* KPI grid: always fills the row, and never leaves a lone orphan card */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 12px; }
.kpis:has(> :nth-child(4):last-child) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis:has(> :nth-child(6):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (min-width: 1400px) {
    .kpis:has(> :nth-child(6):last-child) { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
.kpi {
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
    display: flex; flex-direction: column; gap: 4px;
    transition: transform .2s cubic-bezier(.22, 1, .36, 1), border-color .2s ease, box-shadow .22s ease;
}
.kpi:hover { transform: translateY(-2px); border-color: rgba(186, 255, 43, .45); box-shadow: 0 10px 26px rgba(0, 0, 0, .25); }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 21px; font-weight: 800; font-family: var(--font-num); color: var(--gold); }
.kpi .s { font-size: 12px; color: var(--dim); }

.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap-row { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.strong { font-weight: 700; }
.big { font-size: 22px; font-weight: 800; }

/* Buttons & Inputs */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; font-size: 13.5px;
    background: var(--gold); color: #052325; text-decoration: none;
    transition: transform .14s ease, background-color .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.btn:hover:not(:disabled) { background: var(--gold-soft); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(186, 255, 43, .18); }
.btn:active:not(:disabled) { transform: translateY(0) scale(.985); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.btn.ghost:hover:not(:disabled) { border-color: var(--cyan); background: #144d4f; box-shadow: 0 6px 16px rgba(80, 234, 211, .12); }
.btn.cyan { background: var(--cyan); color: #052325; }
.btn.danger { background: rgba(240, 152, 131, .14); border: 1px solid var(--red); color: var(--red); }
.btn.danger:hover:not(:disabled) { background: rgba(240, 152, 131, .24); box-shadow: 0 6px 16px rgba(240, 152, 131, .16); }
.btn.small { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.iconbtn {
    border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
    width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
    transition: border-color .18s ease, color .18s ease, transform .14s ease;
}
.iconbtn:hover { border-color: var(--gold); color: var(--gold); transform: translateY(-1px); }

label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
label.f input, label.f select, label.f textarea, .inp {
    font-weight: 400; font-size: 13.8px; border: 1px solid var(--line); background: var(--bg);
    color: var(--text); border-radius: 10px; padding: 9px 11px; width: 100%;
}
label.f textarea { min-height: 70px; resize: vertical; }
label.f input:focus, label.f select:focus, label.f textarea:focus, .inp:focus { outline: 2px solid var(--gold); border-color: var(--gold); }

/* Pills, Chips, Bars, Lists */
.pill {
    display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700;
    padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.pill.good { background: rgba(186, 255, 43, .16); color: var(--gold); border: 1px solid rgba(186, 255, 43, .35); }
.pill.info { background: rgba(80, 234, 211, .15); color: var(--cyan); border: 1px solid rgba(80, 234, 211, .35); }
.pill.warn { background: rgba(221, 255, 155, .12); color: var(--gold-soft); border: 1px solid rgba(221, 255, 155, .3); }
.pill.bad { background: rgba(240, 152, 131, .16); color: var(--red); border: 1px solid rgba(240, 152, 131, .4); }
.pill.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
    border: 1px solid var(--line); background: var(--bg); color: var(--muted);
    border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600;
}
.chip[aria-pressed="true"], .chip.on { background: var(--gold); color: #052325; border-color: var(--gold); }

.bar { height: 9px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--gold); border-radius: 99px; }
.bar > span.cyan { background: var(--cyan); }
.bar > span.red { background: var(--red); }

.mrow { display: grid; grid-template-columns: 165px minmax(0, 1fr) 90px; gap: 10px; align-items: center; font-size: 13px; padding: 5px 0; }
.mrow .t { height: 13px; background: var(--bg); border-radius: 5px; position: relative; overflow: hidden; }
.mrow .t span { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: var(--gold); }

.listitem {
    display: flex; gap: 12px; align-items: flex-start; padding: 13px 15px; width: 100%;
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-align: left;
}
button.listitem:hover { border-color: var(--gold); background: var(--surface-2); }

/* Tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 700; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; white-space: nowrap; }

/* Calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-head span { font-size: 11.5px; font-weight: 700; color: var(--dim); padding: 4px 0; }
.cal-d {
    position: relative; border: 1px solid transparent; background: var(--bg); color: var(--text);
    border-radius: 10px; height: 42px; font-size: 13.5px; font-family: var(--font-num); font-weight: 600;
}
.cal-d:hover { border-color: var(--line); background: var(--surface-2); }
.cal-d.past { color: var(--dim); }
.cal-d.tod { border-color: var(--cyan); color: var(--cyan); }
.cal-d.sel { background: var(--gold); color: #052325; border-color: var(--gold); font-weight: 800; }
.cal-dot {
    position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%);
    width: 6px; height: 6px; border-radius: 99px; background: var(--cyan);
}
.cal-d.sel .cal-dot { background: #052325; }

/* Banners & Alerts */
.banner {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
}
.banner.warn { border-color: var(--gold); background: rgba(186, 255, 43, .08); }
.banner.bad { border-color: var(--red); background: rgba(240, 152, 131, .12); }

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.tab {
    border: 1px solid var(--line); background: var(--bg); color: var(--muted);
    border-radius: 9px; padding: 7px 14px; font-weight: 600; font-size: 13px;
}
.tab.on { background: var(--gold); color: #052325; border-color: var(--gold); font-weight: 700; }

/* Login / Register */
.loginwrap {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: 24px; overflow-y: auto;
    background: radial-gradient(circle at top right, rgba(80, 234, 211, .12), transparent 45%), var(--bg);
}
.loginbox {
    width: 460px; max-width: 100%; background: var(--surface); border: 1px solid var(--line);
    border-radius: 20px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}

/* Modal, SweetAlert & Toastr Stack */
.modal-wrap {
    position: fixed; inset: 0; background: rgba(2, 14, 15, .74); backdrop-filter: blur(5px);
    display: none; align-items: center; justify-content: center; z-index: 50; padding: 18px;
}
.modal-wrap.open { display: flex; animation: fadeIn .18s ease-out; }
.modal {
    position: relative; width: 640px; max-width: 100%; max-height: 90vh; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
    padding: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 13px;
}
.modal-wrap.open .modal { animation: modalZoomIn .24s cubic-bezier(.22, 1, .36, 1); }
.modal.wide { width: 820px; }
.modalx {
    position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border: 0;
    border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 20px; line-height: 1;
}
.modalx:hover { color: var(--text); background: var(--line); }

.swal-wrap { z-index: 70; }
.swal-modal { width: 420px; text-align: center; align-items: center; padding: 28px 24px 24px; gap: 12px; }
.swal-icon {
    width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
    animation: swalPop .38s cubic-bezier(.22, 1.4, .36, 1);
}
.swal-icon.success { background: rgba(186, 255, 43, .14); border: 2px solid var(--gold); color: var(--gold); }
.swal-icon.info { background: rgba(80, 234, 211, .14); border: 2px solid var(--cyan); color: var(--cyan); }
.swal-icon.warning { background: rgba(221, 255, 155, .14); border: 2px solid var(--gold-soft); color: var(--gold-soft); }
.swal-icon.error { background: rgba(240, 152, 131, .16); border: 2px solid var(--red); color: var(--red); }
.swal-icon svg { width: 30px; height: 30px; }
.swal-title { font-size: 19px; font-weight: 800; }
.swal-text { font-size: 13.8px; color: var(--muted); line-height: 1.5; }
.swal-actions { display: flex; gap: 10px; width: 100%; justify-content: center; margin-top: 6px; }
.swal-actions .btn { min-width: 120px; }

.toast-stack {
    position: fixed; right: 20px; bottom: 20px; z-index: 80;
    display: flex; flex-direction: column; gap: 10px; width: min(370px, calc(100vw - 32px));
    pointer-events: none;
}
.toast-item {
    pointer-events: auto; position: relative; overflow: hidden;
    background: var(--surface-2); border: 1px solid var(--line); border-left-width: 4px;
    border-radius: 13px; padding: 12px 14px 14px; box-shadow: var(--shadow);
    display: flex; gap: 11px; align-items: flex-start;
    animation: toastSlideIn .28s cubic-bezier(.22, 1, .36, 1);
}
.toast-item.out { animation: toastSlideOut .22s ease forwards; }
.toast-item.success { border-left-color: var(--gold); }
.toast-item.info { border-left-color: var(--cyan); }
.toast-item.warning { border-left-color: var(--gold-soft); }
.toast-item.error { border-left-color: var(--red); }
.toast-ico { width: 22px; height: 22px; flex: none; margin-top: 1px; }
.toast-item.success .toast-ico { color: var(--gold); }
.toast-item.info .toast-ico { color: var(--cyan); }
.toast-item.warning .toast-ico { color: var(--gold-soft); }
.toast-item.error .toast-ico { color: var(--red); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 13px; font-weight: 800; margin-bottom: 2px; }
.toast-msg { font-size: 12.8px; color: var(--muted); line-height: 1.4; }
.toast-close {
    border: 0; background: transparent; color: var(--dim); font-size: 18px; line-height: 1; padding: 0 4px;
}
.toast-close:hover { color: var(--text); }
.toast-bar {
    position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
    background: currentColor; opacity: .55; transform-origin: left;
    animation: toastProgress 3.8s linear forwards;
}

.bar > span, .mrow .t span { transition: width .65s cubic-bezier(.22, 1, .36, 1); }
.sitem, .listitem, .tab, .chip { transition: background-color .18s ease, border-color .18s ease, color .18s ease, transform .14s ease; }
.listitem:hover { transform: translateY(-1px); }

@keyframes pageFadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalZoomIn {
    from { opacity: 0; transform: scale(.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes swalPop {
    0% { opacity: 0; transform: scale(.65); }
    70% { transform: scale(1.07); }
    100% { opacity: 1; transform: scale(1); }
}
@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(24px) scale(.96); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastSlideOut {
    to { opacity: 0; transform: translateX(24px) scale(.96); }
}
@keyframes toastProgress {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

.errbox {
    padding: 9px 12px; border-radius: 10px; font-size: 13px; font-weight: 600;
    background: rgba(240, 152, 131, .14); border: 1px solid var(--red); color: var(--red);
}
.okbox {
    padding: 9px 12px; border-radius: 10px; font-size: 13px; font-weight: 600;
    background: rgba(80, 234, 211, .12); border: 1px solid var(--cyan); color: var(--cyan);
}

svg text { fill: var(--muted); font-family: var(--font-body); }

@media (max-width: 1100px) {
    /* tablet & phone: tidy 2-column KPI grid instead of 3 + 1 orphan */
    .kpis, .kpis:has(> :nth-child(4):last-child), .kpis:has(> :nth-child(6):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
    .grid2, .grid3 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    .content { padding: 14px 12px 40px; }
    .kpis { gap: 10px; }
    .kpi { padding: 12px 13px; }
    .kpi .v { font-size: 19px; overflow-wrap: anywhere; }
    .kpi .k, .kpi .s { font-size: 11.5px; }
    .card { padding: 14px 15px; }
}
@media (max-width: 820px) {
    .side {
        position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
        transform: translateX(-100%);
    }
    .side.open { transform: translateX(0); box-shadow: var(--shadow); }
    .menu-toggle { display: inline-flex; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
