:root {
    color-scheme: dark;
    --bg: #171719;
    --panel: #202124;
    --panel-2: #292a2e;
    --line: #3d3e43;
    --text: #f7f7f5;
    --muted: #b8b9bd;
    --green: #ff4b0b;
    --green-strong: #df3b00;
    --green-soft: rgba(255, 75, 11, .14);
    --red: #f87171;
    --amber: #fbbf24;
    --blue: #60a5fa;
    --shadow: 0 18px 50px rgba(0, 0, 0, .36);
    --sidebar: #1b1b1e;
    --topbar: rgba(23, 23, 25, .9);
    --field: #18181b;
    --subpanel: #1c1c1f;
    --code-bg: #111113;
    --kpi-end: #28292d;
    --feature-bg: rgba(32, 33, 36, .7);
    --radius: 14px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f4f2;
    --panel: #ffffff;
    --panel-2: #eeeeef;
    --line: #d2d3d6;
    --text: #202124;
    --muted: #66686d;
    --green-soft: rgba(255, 75, 11, .11);
    --shadow: 0 18px 50px rgba(32, 33, 36, .13);
    --sidebar: #ffffff;
    --topbar: rgba(244, 244, 242, .91);
    --field: #ffffff;
    --subpanel: #f7f7f6;
    --code-bg: #f1f1f2;
    --kpi-end: #f0f0ef;
    --feature-bg: rgba(255, 255, 255, .75);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
button, input, select, textarea { font: inherit; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.65rem, 2.5vw, 2.25rem); margin-bottom: .35rem; }
h2 { font-size: 1.15rem; }
.muted, small { color: var(--muted); }
.eyebrow { color: var(--green); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; font-size: .72rem; }

.layout { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 16px; border-right: 1px solid var(--line); background: var(--sidebar); z-index: 30; }
.brand { display: flex; align-items: center; gap: 11px; padding: 5px 8px 25px; text-decoration: none; font-weight: 800; }
.brand-mark { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 10px; color: #171719; background: linear-gradient(135deg, #ff6b35, #e63e00); box-shadow: 0 8px 22px rgba(255, 75, 11, .22); }
.brand-copy small { display: block; margin-top: 2px; font-size: .68rem; font-weight: 600; }
.nav { display: grid; gap: 5px; }
.nav a { padding: 11px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 650; }
.nav a:hover, .nav a.active { color: var(--text); background: var(--green-soft); }
.nav a.active { box-shadow: inset 3px 0 var(--green); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 12px clamp(18px, 3vw, 38px); background: var(--topbar); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.topbar-title { font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.menu-toggle { display: none; }
.user-menu { position: relative; }
.user-button { display: flex; align-items: center; gap: 10px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--panel); cursor: pointer; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: #171719; background: var(--green); font-weight: 900; }
.user-dropdown { display: none; position: absolute; right: 0; top: calc(100% + 8px); width: 220px; padding: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.user-dropdown.is-open { display: block; }
.user-dropdown a, .user-dropdown button { display: block; width: 100%; padding: 10px; color: var(--text); background: none; border: 0; border-radius: 7px; text-align: left; text-decoration: none; cursor: pointer; }
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--green-soft); }
.user-dropdown .theme-choice { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 0; }
.theme-choice-icon { display: grid; place-items: center; width: 26px; height: 26px; flex: 0 0 auto; border-radius: 50%; color: #171719; background: var(--green); font-weight: 900; }
.user-copy { display: grid; gap: 2px; text-align: left; }
.user-copy small { font-size: .7rem; text-transform: capitalize; }
.content { width: min(1480px, 100%); margin: 0 auto; padding: 30px clamp(18px, 3vw, 38px) 60px; flex: 1; }
.footer { padding: 20px 38px; color: var(--muted); border-top: 1px solid var(--line); font-size: .82rem; }

.page-head, .section-head, .card-head, .role-head, .dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.page-head { margin-bottom: 24px; align-items: flex-end; }
.page-head p { margin-bottom: 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 39px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--panel-2); text-decoration: none; font-weight: 750; cursor: pointer; }
.button:hover { border-color: #6a4b40; transform: translateY(-1px); }
.button.primary { color: #171719; border-color: var(--green); background: var(--green); box-shadow: 0 7px 18px rgba(255, 75, 11, .16); }
.button.primary:hover { background: var(--green-strong); border-color: var(--green-strong); }
.button.secondary { background: transparent; }
.button.danger { color: #fecaca; border-color: rgba(248, 113, 113, .4); background: rgba(248, 113, 113, .08); }
.button.small { min-height: 32px; padding: 5px 9px; font-size: .8rem; }
.icon-danger { color: var(--red); }

.card { padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 7px 25px rgba(0, 0, 0, .12); }
.card + .card { margin-top: 18px; }
.card-head { margin-bottom: 18px; }
.card-head h2 { margin-bottom: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi { position: relative; overflow: hidden; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(145deg, var(--panel), var(--kpi-end)); }
.kpi::after { content: ''; position: absolute; width: 80px; height: 80px; right: -30px; bottom: -40px; border-radius: 50%; background: var(--green-soft); }
.kpi strong { display: block; margin-top: 7px; font-size: 1.8rem; }
.kpi span { color: var(--muted); font-weight: 650; }
.app-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.app-grid + .card { margin-top: 32px; }
.application-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 18px; color: inherit; text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.application-card:hover { border-color: var(--green); background: var(--panel-2); }
.app-icon { display: grid; place-items: center; width: 45px; height: 45px; border-radius: 12px; color: #171719; background: var(--green); font-weight: 900; }
.application-card h3 { margin: 0 0 4px; }
.application-card p { margin: 0; color: var(--muted); font-size: .85rem; }

.admin-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(290px, .8fr); gap: 20px; align-items: start; }
.sticky { position: sticky; top: 90px; }
.stack { display: grid; gap: 15px; }
.form-grid, .form-row, .detail-grid { display: grid; gap: 14px; }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row { grid-template-columns: 1fr auto; align-items: end; }
.detail-grid { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); }
.full { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: var(--muted); font-size: .83rem; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 41px; padding: 9px 11px; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 8px; outline: none; }
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.password-field { position: relative; }
.password-field input { padding-right: 48px; }
.password-toggle { position: absolute; top: 50%; right: 5px; display: grid; place-items: center; width: 36px; height: 34px; padding: 0; transform: translateY(-50%); color: var(--muted); background: transparent; border: 0; border-radius: 7px; cursor: pointer; }
.password-toggle:hover { color: var(--text); background: var(--green-soft); }
.password-toggle:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.password-toggle svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.password-toggle .eye-off { display: none; }
.password-toggle[aria-pressed="true"] .eye-on { display: none; }
.password-toggle[aria-pressed="true"] .eye-off { display: inline; }
input[type="checkbox"] { width: 18px; min-height: 18px; accent-color: var(--green); }
.search { max-width: 310px; }
.disabled { opacity: .55; pointer-events: none; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 11px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .018); }
.tag, .status, .version-badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: .73rem; font-weight: 800; }
.tag, .version-badge { color: #ffb294; background: var(--green-soft); }
.status.on { color: #b9f6c5; background: rgba(86, 194, 113, .13); }
.status.off { color: #fecaca; background: rgba(248, 113, 113, .12); }
.empty { padding: 40px 20px; color: var(--muted); text-align: center; }
.alert { margin-bottom: 18px; padding: 13px 15px; border: 1px solid; border-radius: 10px; }
.alert.success { color: #b9f6c5; border-color: rgba(86,194,113,.35); background: rgba(86,194,113,.09); }
.alert.warning { color: #fde68a; border-color: rgba(251,191,36,.35); background: rgba(251,191,36,.08); }
.alert.danger { color: #fecaca; border-color: rgba(248,113,113,.35); background: rgba(248,113,113,.08); }
.alert.info { color: #bfdbfe; border-color: rgba(96,165,250,.35); background: rgba(96,165,250,.08); }

.tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 10px 13px; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--green); border-color: var(--green); }
.permission-list, .permission-checks { display: grid; gap: 8px; }
.permission-list article { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--subpanel); }
.permission-list article > div { display: grid; gap: 3px; }
.permission-list article form { margin-left: auto; }
.permission-list .icon-danger, .role-card .icon-danger { border: 0; background: transparent; cursor: pointer; font-size: 1.25rem; }
.permission-checks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.permission-checks label { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.role-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.role-card { padding: 16px; border: 1px solid var(--line); border-radius: 11px; background: var(--subpanel); }
.role-head h3 { margin-bottom: 3px; }
.credential-box, pre { overflow: auto; padding: 14px; color: var(--text); background: var(--code-bg); border: 1px solid var(--line); border-radius: 9px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .82rem; }
.client-panel { padding: 14px; border-left: 3px solid var(--green); background: var(--green-soft); }

dialog { width: min(650px, calc(100% - 28px)); padding: 0; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(3px); }
.dialog-head { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; }
.dialog-body { padding: 20px; }
.dialog-head + form { padding: 20px; }
.dialog-close { border: 0; color: var(--muted); background: transparent; font-size: 1.5rem; cursor: pointer; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 30px; background: radial-gradient(circle at 12% 18%, rgba(255,75,11,.16), transparent 35%), var(--bg); }
.auth-layout { width: min(1040px, 100%); display: grid; grid-template-columns: 1.2fr .8fr; gap: clamp(30px, 7vw, 85px); align-items: center; }
.auth-copy h1 { max-width: 680px; font-size: clamp(2.2rem, 5vw, 4.5rem); line-height: 1.02; }
.auth-copy > p { max-width: 600px; color: var(--muted); font-size: 1.05rem; }
.auth-brand { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 50px; font-weight: 850; }
.auth-features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 35px; }
.auth-features div, .auth-features span { padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: var(--feature-bg); }
.auth-card { padding: clamp(24px, 4vw, 38px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.auth-brand > span { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; color: #171719; background: var(--green); box-shadow: 0 8px 22px rgba(255, 75, 11, .22); }
.auth-brand div { display: grid; gap: 2px; }
.auth-brand small { font-size: .72rem; }
.auth-layout.single { grid-template-columns: minmax(0, 520px); justify-content: center; }
.auth-form-links { margin-top: -7px; text-align: right; }
.auth-form-links a, .auth-back-link { color: var(--green); font-size: .82rem; font-weight: 750; text-decoration: none; }
.auth-form-links a:hover, .auth-back-link:hover { text-decoration: underline; }
.auth-back-link { display: block; text-align: center; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, .75fr); gap: 20px; align-items: start; }
.checkbox-card { display: flex; align-items: center; gap: 11px; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--green-soft); }
.checkbox-card span { display: grid; gap: 3px; }
.auth-card .button { width: 100%; }
.narrow { width: min(620px, 100%); margin: 0 auto; }

.docs-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; align-items: start; }
.docs-nav { position: sticky; top: 90px; display: grid; gap: 5px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.docs-nav a { padding: 9px; color: var(--muted); text-decoration: none; border-radius: 7px; }
.docs-nav a:hover { color: var(--text); background: var(--green-soft); }
.docs-content { min-width: 0; }
.docs-content section { scroll-margin-top: 95px; margin-bottom: 18px; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.docs-content li { margin-bottom: 8px; color: var(--text); }
.callout { padding: 14px 16px; border-left: 3px solid var(--green); background: var(--green-soft); border-radius: 0 8px 8px 0; }

html[data-theme="light"] tbody tr:hover { background: rgba(32, 33, 36, .035); }
html[data-theme="light"] .tag,
html[data-theme="light"] .version-badge { color: #a93005; }
html[data-theme="light"] .status.on,
html[data-theme="light"] .alert.success { color: #216e39; }
html[data-theme="light"] .status.off,
html[data-theme="light"] .alert.danger,
html[data-theme="light"] .button.danger { color: #a62c2c; }
html[data-theme="light"] .alert.warning { color: #805900; }
html[data-theme="light"] .alert.info { color: #245e9b; }

@media (max-width: 1050px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .app-grid { grid-template-columns: repeat(2, 1fr); }
    .admin-grid { grid-template-columns: 1fr; }
    .sticky { position: static; }
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -270px; width: 250px; transition: left .2s ease; box-shadow: var(--shadow); }
    .sidebar-open .sidebar { left: 0; }
    .sidebar-open::after { content: ''; position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.6); }
    .menu-toggle { display: inline-flex; }
    .topbar { padding-inline: 15px; }
    .topbar-title, .user-copy { display: none; }
    .content { padding: 22px 15px 45px; }
    .page-head, .section-head { align-items: flex-start; flex-direction: column; }
    .page-head .actions { width: 100%; }
    .form-grid, .role-grid, .permission-checks, .detail-grid { grid-template-columns: 1fr; }
    .app-grid { grid-template-columns: 1fr; }
    .docs-layout { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
    .docs-nav { position: static; grid-template-columns: repeat(2, 1fr); }
    .auth-page { padding: 20px; }
    .auth-layout { grid-template-columns: 1fr; }
    .auth-copy { display: none; }
}

@media (max-width: 470px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .button { width: 100%; }
    .actions { width: 100%; }
    .docs-nav { grid-template-columns: 1fr; }
}
