/* ==========================================================================
   Admin portal – builds on css/app.css design tokens
   ========================================================================== */

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

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--brand-600) 18%, transparent), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 2rem; }
.login-card .brand { margin-bottom: 1.5rem; }
.login-card h1 { font-size: 1.3rem; margin-bottom: .25rem; }
.login-card p { color: var(--text-2); font-size: .9rem; margin-bottom: 1.25rem; }
.login-error { display: none; background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: .6rem .8rem; font-size: .85rem; margin-bottom: 1rem; }
.login-error.show { display: block; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 2.8rem; }
.pw-wrap button { position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--text-3); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; }
.pw-wrap button:hover { color: var(--text); background: var(--surface-2); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .85rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: .25rem; z-index: 1040; }
.sidebar .brand { padding: .25rem .5rem 1rem; }
.sidebar .nav-sec { font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); padding: .9rem .6rem .35rem; }
.sidebar a.nav-item { display: flex; align-items: center; gap: .7rem; padding: .6rem .7rem; border-radius: 10px; color: var(--text-2); text-decoration: none; font-weight: 600; font-size: .9rem; transition: all .15s; }
.sidebar a.nav-item i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar a.nav-item:hover { background: var(--surface-2); color: var(--text); }
.sidebar a.nav-item.active { background: var(--brand-soft); color: var(--brand-700); }
[data-theme="dark"] .sidebar a.nav-item.active { color: #fff; }
.sidebar a.nav-item .badge-n { margin-left: auto; font-size: .7rem; background: var(--surface-3); color: var(--text-2); padding: .1rem .45rem; border-radius: 999px; font-weight: 700; }
.sidebar .sb-foot { margin-top: auto; padding: .5rem .6rem; font-size: .75rem; color: var(--text-3); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 1035; }
@media (max-width: 991px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: fixed; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: none; }
    .sidebar-overlay.show { display: block; }
}

.topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: .75rem; padding: .7rem 1.25rem; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 1.1rem; }
.topbar .sub { font-size: .78rem; color: var(--text-3); }
.topbar .spacer { flex: 1; }
.page { padding: 1.25rem; max-width: 1500px; }
.view { display: none; }
.view.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- KPI tiles ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .9rem 1rem; box-shadow: var(--shadow); display: flex; gap: .8rem; align-items: center; }
.tile .t-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; color: #fff; font-size: 1.1rem; flex: none; }
.tile .t-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.tile .t-value { font-size: 1.35rem; font-weight: 800; line-height: 1.15; }
.tile .t-sub { font-size: .72rem; color: var(--text-3); }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 1rem; }
.panel-head { display: flex; align-items: center; gap: .6rem; padding: .85rem 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h2 { font-size: .98rem; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 1rem; }
.panel-body.p-0 { padding: 0; }
.chart-box { position: relative; height: 280px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 991px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.toolbar .input, .toolbar .select { height: 38px; font-size: .85rem; width: auto; min-width: 140px; }
.toolbar .search { flex: 1 1 220px; }
.toolbar .search .input { width: 100%; }
.toolbar label.chk { display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--text-2); margin: 0; white-space: nowrap; }
.bulk-bar { display: none; align-items: center; gap: .6rem; padding: .55rem 1rem; background: var(--brand-soft); border-bottom: 1px solid var(--border); font-size: .85rem; font-weight: 600; }
.bulk-bar.show { display: flex; flex-wrap: wrap; }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tbl th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: .6rem .7rem; border-bottom: 1px solid var(--border); white-space: nowrap; z-index: 1; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .sort-ind { opacity: .4; margin-left: .2rem; }
.tbl th.sorted .sort-ind { opacity: 1; color: var(--brand); }
.tbl td { padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.selected { background: var(--brand-soft); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .cell-main { font-weight: 600; color: var(--text); }
.tbl .cell-sub { font-size: .74rem; color: var(--text-3); }
.tbl .row-actions { display: flex; gap: .25rem; justify-content: flex-end; }
.tbl .row-actions .icon-btn { width: 32px; height: 32px; border-radius: 8px; }
.tbl .row-actions .icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }
.tbl input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--brand-600); }
.tbl-empty { padding: 2.5rem 1rem; text-align: center; color: var(--text-2); }
.tbl-empty i { font-size: 2.2rem; color: var(--text-3); display: block; margin-bottom: .4rem; }
.table-scroll { overflow-x: auto; max-height: 70vh; }
.pager { display: flex; align-items: center; gap: .5rem; padding: .7rem 1rem; border-top: 1px solid var(--border); font-size: .82rem; color: var(--text-2); flex-wrap: wrap; }
.pager .spacer { flex: 1; }
.pager button { height: 32px; min-width: 32px; padding: 0 .55rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .8rem; cursor: pointer; }
.pager button.active { background: var(--brand-600); color: #fff; border-color: var(--brand-600); }
.pager button:disabled { opacity: .45; cursor: not-allowed; }

.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.warn { background: var(--warning-soft); color: var(--warning); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.brand { background: var(--brand-soft); color: var(--brand-700); }
[data-theme="dark"] .pill.brand { color: #fff; }
.pill i { font-size: .75rem; }
.cat-ico { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-3); display: grid; place-items: center; color: var(--brand); font-size: 1rem; flex: none; }
.cell-eq { display: flex; align-items: center; gap: .6rem; min-width: 200px; }
.contact-links a { color: var(--text-2); margin-right: .4rem; text-decoration: none; }
.contact-links a:hover { color: var(--brand); }

/* ---------- detail modal ---------- */
.modal-xl .modal-content { border-radius: 16px; }
.detail-hero { background: linear-gradient(135deg, #0f172a, #1e3a8a 70%, #2563eb); color: #fff; border-radius: 12px; padding: 1rem 1.1rem; display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center; }
.detail-hero .dh-name { font-weight: 800; font-size: 1.1rem; }
.detail-hero .dh-sub { font-size: .8rem; opacity: .85; }
.detail-hero .dh-total { text-align: right; }
.detail-hero .dh-total .v { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.detail-hero .dh-total .l { font-size: .72rem; opacity: .8; text-transform: uppercase; letter-spacing: .04em; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem; font-size: .85rem; }
.kv .k { color: var(--text-2); padding: .3rem 0; border-bottom: 1px dashed var(--border); }
.kv .v { font-weight: 600; text-align: right; padding: .3rem 0; border-bottom: 1px dashed var(--border); font-variant-numeric: tabular-nums; }
.kv .v.total { color: var(--success); }
.detail-sec { margin-top: 1rem; }
.detail-sec h6 { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin-bottom: .5rem; }
.mini-stack { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-3); margin: .4rem 0 .6rem; }
.mini-stack span { display: block; height: 100%; }

/* ---------- settings ---------- */
.danger-zone { border: 1.5px solid color-mix(in srgb, var(--danger) 45%, var(--border)); border-radius: 14px; }
.danger-zone .panel-head { background: var(--danger-soft); border-radius: 14px 14px 0 0; }
.danger-zone .panel-head h2 { color: var(--danger); }
.danger-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .75rem 0; border-bottom: 1px dashed var(--border); }
.danger-row:last-child { border-bottom: 0; }
.danger-row .d-text { flex: 1 1 260px; font-size: .85rem; color: var(--text-2); }
.danger-row .d-text b { color: var(--text); display: block; margin-bottom: .1rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-outline-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-outline-danger:hover:not(:disabled) { background: var(--danger-soft); }
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .6rem; }
.health-grid .h { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem; }
.health-grid .h .l { font-size: .7rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.health-grid .h .v { font-weight: 700; font-size: .95rem; }

.spinner-inline { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
.loading-row td { text-align: center; padding: 2rem; color: var(--text-2); }
