:root {
    --brand: #4e70f2;
    --brand-strong: #3654d9;
    --accent: #14b8a6;
    --bg: #f4f6fb;
    --surface: rgba(255, 255, 255, .88);
    --surface-solid: #fff;
    --text: #172033;
    --muted: #6d7789;
    --border: rgba(63, 76, 108, .14);
    --shadow: 0 16px 44px rgba(25, 35, 58, .08);
    --sidebar-width: 252px;
    --topbar-height: 68px;
    --radius: 18px;
}

html[data-theme="dark"] {
    --bg: #0e1420;
    --surface: rgba(23, 32, 49, .88);
    --surface-solid: #172031;
    --text: #edf2ff;
    --muted: #98a4b8;
    --border: rgba(255, 255, 255, .1);
    --shadow: 0 20px 60px rgba(0, 0, 0, .28);
}

html { font-size: 15px; }
body { color: var(--text); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-strong); }
code { color: #4962c8; }
html[data-theme="dark"] code { color: #aebcff; }

.admin-body { min-height: 100vh; margin: 0; }
.admin-app { min-height: 100vh; }
.admin-topbar {
    position: fixed; inset: 0 0 auto 0; z-index: 1040; height: var(--topbar-height);
    display: flex; align-items: center; justify-content: space-between; gap: 20px;
    padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border);
    backdrop-filter: blur(18px);
}
.brand-mark { display: flex; align-items: baseline; gap: 9px; letter-spacing: -.03em; }
.brand-mark span { color: var(--brand); font-weight: 850; font-size: 1.15rem; }
.brand-mark strong { color: var(--text); font-size: 1.05rem; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.topbar-actions form { margin: 0; }
.user-email { color: var(--muted); font-size: .875rem; margin-right: 8px; }
.mobile-menu { display: none; }

.admin-frame { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); padding-top: var(--topbar-height); min-height: 100vh; }
.admin-sidebar {
    position: fixed; top: var(--topbar-height); bottom: 0; left: 0; width: var(--sidebar-width);
    display: flex; flex-direction: column; padding: 22px 14px; background: var(--surface);
    border-right: 1px solid var(--border); backdrop-filter: blur(18px); z-index: 1030;
}
.nav-section { display: grid; gap: 5px; }
.nav-heading { padding: 8px 13px; color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: 12px; color: var(--muted); font-weight: 600; }
.nav-link:hover { color: var(--text); background: rgba(78, 112, 242, .08); }
.nav-link.active { color: var(--brand); background: rgba(78, 112, 242, .13); }
.nav-icon { display: grid; place-items: center; width: 24px; font-size: 1.1rem; }
.sidebar-note { display: flex; gap: 10px; align-items: flex-start; margin: 26px 8px 0; padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: rgba(78, 112, 242, .05); }
.sidebar-note div { display: grid; }
.sidebar-note strong { font-size: .82rem; }
.sidebar-note small { color: var(--muted); line-height: 1.35; }
.status-dot { flex: 0 0 auto; width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(20, 184, 166, .12); }
.sidebar-footer { margin-top: auto; padding: 10px 5px 0; }
.admin-contentwrap { grid-column: 2; min-width: 0; }
.admin-content { max-width: 1500px; margin: 0 auto; }
.admin-overlay { display: none; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-heading h1 { margin: 0 0 4px; font-size: 1.7rem; font-weight: 760; letter-spacing: -.025em; }
.page-heading p { margin: 0; color: var(--muted); }
.page-actions, .table-actions { display: flex; align-items: center; gap: 8px; }
.eyebrow { color: var(--brand); font-size: .72rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }

.btn { border-radius: 11px; font-weight: 650; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-ghost { color: var(--muted); border: 1px solid transparent; }
.btn-ghost:hover { color: var(--text); background: rgba(78, 112, 242, .08); }
.icon-button { border: 0; background: transparent; color: var(--text); font-size: 1.35rem; }

.admin-card, .metric-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(14px); overflow: hidden; }
.card-header, .card-footer { border-color: var(--border); background: transparent; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px; }
.card-heading div { display: grid; }
.card-heading small { color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.metric-card { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px; }
.metric-card div { display: grid; }
.metric-card span, .metric-card small { color: var(--muted); }
.metric-card strong { font-size: 2.1rem; letter-spacing: -.04em; }
.metric-card b { display: grid; place-items: center; width: 45px; height: 45px; border-radius: 14px; color: var(--brand); background: rgba(78, 112, 242, .12); font-size: 1.25rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(340px, .8fr); gap: 20px; align-items: start; }

.table { --bs-table-bg: transparent; --bs-table-color: var(--text); --bs-table-border-color: var(--border); margin: 0; }
.table thead th { padding: 12px 18px; color: var(--muted); background: rgba(78, 112, 242, .04); border-bottom-width: 1px; font-size: .75rem; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.table tbody td { padding: 14px 18px; vertical-align: middle; }
.table tbody tr:hover { background: rgba(78, 112, 242, .035); }
.table td > small, .table-link + small { display: block; color: var(--muted); font-size: .78rem; }
.table-link { color: var(--text); font-weight: 700; }
.empty-table { display: grid; place-items: center; gap: 3px; min-height: 120px; color: var(--muted); text-align: center; }
.empty-inline { padding: 16px; color: var(--muted); background: rgba(78, 112, 242, .05); border: 1px dashed var(--border); border-radius: 12px; }

.status-badge { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; font-size: .74rem; font-weight: 750; white-space: nowrap; }
.status-success { color: #087f6d; background: rgba(20, 184, 166, .14); }
.status-warning { color: #9a5b00; background: rgba(245, 158, 11, .16); }
.status-danger { color: #b42336; background: rgba(239, 68, 68, .14); }
.status-info { color: #3654d9; background: rgba(78, 112, 242, .14); }
.status-neutral { color: var(--muted); background: rgba(109, 119, 137, .12); }
html[data-theme="dark"] .status-success { color: #6ee7d8; }
html[data-theme="dark"] .status-warning { color: #fbd38d; }
html[data-theme="dark"] .status-danger { color: #fda4af; }
html[data-theme="dark"] .status-info { color: #aebcff; }

.activity-list { display: grid; }
.activity-item { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 14px 18px; color: var(--text); border-top: 1px solid var(--border); }
.activity-item:first-child { border-top: 0; }
.activity-item:hover { color: var(--text); background: rgba(78, 112, 242, .04); }
.activity-item span:nth-child(2) { display: grid; }
.activity-item small { color: var(--muted); }
.activity-item b { color: var(--muted); font-size: .8rem; }
.activity-dot { width: 9px; height: 9px; border-radius: 50%; }
.activity-dot.status-success { background: var(--accent); }
.activity-dot.status-warning { background: #f59e0b; }
.activity-dot.status-danger { background: #ef4444; }
.activity-dot.status-info { background: var(--brand); }
.activity-dot.status-neutral { background: #8b95a7; }

.admin-form-card-sm { max-width: 620px; }
.admin-form-card-lg { max-width: 1000px; }
.admin-formgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.admin-span-2 { grid-column: span 2; }
.form-control, .form-select, .input-group-text { color: var(--text); background: rgba(255, 255, 255, .35); border-color: var(--border); border-radius: 12px; }
html[data-theme="dark"] .form-control, html[data-theme="dark"] .form-select, html[data-theme="dark"] .input-group-text { background: rgba(255, 255, 255, .04); color: var(--text); }
.form-control:focus, .form-select:focus { color: var(--text); background: var(--surface-solid); border-color: rgba(78, 112, 242, .55); box-shadow: 0 0 0 .22rem rgba(78, 112, 242, .13); }
.form-label { color: var(--text); font-weight: 650; }
.form-text { color: var(--muted); }
.stack-form { display: grid; gap: 18px; }
.form-section { padding: 8px 0 26px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { margin-bottom: 0; border-bottom: 0; }
.form-section-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.form-section-heading > span { display: grid; place-items: center; flex: 0 0 auto; width: 31px; height: 31px; border-radius: 10px; color: var(--brand); background: rgba(78, 112, 242, .12); font-weight: 800; }
.form-section-heading div { display: grid; }
.form-section-heading strong, .choice-card strong, .admin-toggle strong { color: var(--text); }
.form-section-heading small { color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; }

.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.choice-card { display: flex; align-items: flex-start; gap: 11px; padding: 16px; border: 1px solid var(--border); border-radius: 14px; cursor: pointer; }
.choice-card:has(input:checked) { border-color: rgba(78, 112, 242, .55); background: rgba(78, 112, 242, .08); }
.choice-card input { margin-top: 4px; }
.choice-card span { display: grid; }
.choice-card small { color: var(--muted); }
.selected-container-panel { display: none; padding: 17px; border: 1px solid var(--border); border-radius: 14px; background: rgba(78, 112, 242, .03); }
.selected-container-panel.visible { display: block; }
.container-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 9px; max-height: 330px; overflow: auto; }
.container-option { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; cursor: pointer; }
.container-option:has(input:checked) { border-color: rgba(20, 184, 166, .45); background: rgba(20, 184, 166, .07); }

.admin-toggle { position: relative; display: inline-flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.admin-toggle-input { position: absolute; opacity: 0; }
.admin-toggle-ui { position: relative; flex: 0 0 auto; width: 45px; height: 24px; border: 1px solid var(--border); border-radius: 999px; background: rgba(109, 119, 137, .18); transition: .18s; }
.admin-toggle-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 3px 9px rgba(0, 0, 0, .2); transition: .18s; }
.admin-toggle-input:checked + .admin-toggle-ui { background: var(--brand); border-color: var(--brand); }
.admin-toggle-input:checked + .admin-toggle-ui::after { transform: translateX(21px); }
.admin-toggle > span:last-child { display: grid; }
.admin-toggle small { color: var(--muted); }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border: 1px solid rgba(239, 68, 68, .25); border-radius: var(--radius); background: rgba(239, 68, 68, .05); }
.danger-zone p { margin: 2px 0 0; color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 20px; align-items: start; }
.summary-status { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.definition-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: 0; }
.definition-grid-wide { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.definition-grid div { min-width: 0; }
.definition-grid dt { color: var(--muted); font-size: .75rem; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.definition-grid dd { margin: 4px 0 0; overflow-wrap: anywhere; }
.run-message { margin-top: 18px; padding: 13px 15px; border-radius: 12px; color: var(--muted); background: rgba(109, 119, 137, .08); }
.decision-list { display: grid; gap: 8px; }
.decision-list > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.decision-list > div:last-child { border-bottom: 0; }

.alert { border: 1px solid var(--border); border-radius: 14px; }
.alert-success { color: #087f6d; background: rgba(20, 184, 166, .12); }
.alert-info { color: #3654d9; background: rgba(78, 112, 242, .12); }
.alert-warning { color: #8a5300; background: rgba(245, 158, 11, .13); }
.alert-danger { color: #a91e32; background: rgba(239, 68, 68, .12); }

.public-body { min-height: 100vh; background: radial-gradient(circle at top left, rgba(78, 112, 242, .18), transparent 36%), var(--bg); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 430px); padding: 35px; border: 1px solid var(--border); border-radius: 24px; background: rgba(255, 255, 255, .9); box-shadow: 0 28px 80px rgba(25, 35, 58, .14); }
.brand-mark-login { margin-bottom: 34px; }
.login-heading { margin-bottom: 24px; }
.login-heading h1 { margin: 0 0 7px; font-size: 1.75rem; font-weight: 780; letter-spacing: -.03em; }
.login-heading p { margin: 0; color: var(--muted); }

@media (max-width: 1050px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 767.98px) {
    .admin-topbar { padding: 0 14px; }
    .mobile-menu { display: block; order: -1; }
    .user-email { display: none; }
    .admin-frame { display: block; }
    .admin-contentwrap { margin-left: 0; }
    .admin-sidebar { transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-overlay { position: fixed; inset: var(--topbar-height) 0 0; z-index: 1020; background: rgba(9, 14, 24, .45); }
    .admin-overlay.open { display: block; }
    .page-heading, .danger-zone { align-items: stretch; flex-direction: column; }
    .page-actions { flex-wrap: wrap; }
    .admin-formgrid, .choice-grid, .definition-grid, .definition-grid-wide { grid-template-columns: 1fr; }
    .admin-span-2 { grid-column: span 1; }
    .metric-grid { grid-template-columns: 1fr; }
    .topbar-actions .btn { padding-inline: 7px; }
}
