:root {
    --bg: #0c0f14;
    --bg2: #121824;
    --surface: #161d2a;
    --surface2: #1c2535;
    --border: #2a3548;
    --text: #e8ecf4;
    --muted: #8b96ab;
    --accent: #5b8cff;
    --accent2: #3d6fd8;
    --danger: #f87171;
    --ok: #4ade80;
    --radius: 10px;
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
    --sidebar-w: 260px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

[data-density="compact"] {
    --space: 0.5rem;
    --radius: 8px;
}

[data-density="comfortable"] {
    --space: 0.75rem;
    --radius: 10px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(ellipse 80% 60% at 50% -20%, rgba(91, 140, 255, 0.22), transparent),
        var(--bg);
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.login-brand {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.75rem;
}

.login-brand h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
}

.icon-lg {
    width: 40px;
    height: 40px;
    color: var(--accent);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
}

.field input {
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg2);
    color: var(--text);
    font-size: 1rem;
}

.field input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
    border-color: var(--accent);
}

.form-error {
    color: var(--danger);
    font-size: 0.9rem;
    margin: 0;
}

.hp-field {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.hp-field input {
    width: 1px;
    height: 1px;
}

.login-lockout {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--danger);
    background: rgba(248, 113, 113, 0.08);
    color: var(--text);
}

.login-lockout svg {
    width: 22px;
    height: 22px;
    color: var(--danger);
    flex-shrink: 0;
    margin-top: 2px;
}

.login-lockout p {
    margin: 0;
    font-size: 0.95rem;
}

.captcha-turnstile {
    display: flex;
    justify-content: center;
    min-height: 65px;
}

/* App shell */
.admin-app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transition: transform 0.2s ease;
}

.sidebar[data-collapsed="1"] {
    width: 72px;
}

.sidebar[data-collapsed="1"] .sidebar-head span,
.sidebar[data-collapsed="1"] .nav-item span,
.sidebar[data-collapsed="1"] .sidebar-foot .nav-item span {
    display: none;
}

.sidebar-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.1rem 1rem;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.sidebar-head svg {
    width: 22px;
    height: 22px;
    color: var(--accent);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.65rem 0.85rem;
    margin-bottom: 2px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-size: 0.92rem;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--surface2);
    color: var(--text);
}

.nav-item.active {
    background: rgba(91, 140, 255, 0.15);
    color: var(--accent);
}

.sidebar-foot {
    padding: 0.5rem;
    border-top: 1px solid var(--border);
}

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.2s ease;
}

.sidebar[data-collapsed="1"] ~ .main {
    margin-left: 72px;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-title {
    flex: 1;
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.content {
    padding: 1.25rem;
    flex: 1;
}

.panel {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.dashboard-lead {
    margin: 0 0 1.25rem;
    max-width: 720px;
    font-size: 0.95rem;
    line-height: 1.55;
}

.dashboard-stats-host {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

.dashboard-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.15rem 1.25rem;
}

.dashboard-section-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.dashboard-section-head svg {
    width: 20px;
    height: 20px;
    color: var(--accent);
    flex-shrink: 0;
}

.dashboard-section-head span {
    flex: 1;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
}

.stat-card h4 {
    margin: 0 0 0.35rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-card .val {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text);
}

.stat-card .hint {
    margin: 0.35rem 0 0;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--muted);
    line-height: 1.35;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
}

.toolbar input[type="search"],
.toolbar input[type="text"],
.toolbar select {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    min-width: 200px;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

table.data th,
table.data td {
    padding: 0.65rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

table.data th {
    background: var(--surface2);
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}

table.data tr:last-child td {
    border-bottom: none;
}

table.data tr:hover td {
    background: rgba(91, 140, 255, 0.04);
}

.thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--bg2);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    cursor: pointer;
}

.btn:hover {
    border-color: var(--muted);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent2);
    color: #fff;
}

.btn-primary:hover {
    filter: brightness(1.06);
}

.btn-danger {
    background: rgba(248, 113, 113, 0.15);
    border-color: var(--danger);
    color: var(--danger);
}

.btn-block {
    justify-content: center;
    width: 100%;
    padding: 0.75rem;
}

.btn-sm {
    padding: 0.25rem 0.55rem;
    font-size: 0.8rem;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

.icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal {
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid var(--border);
}

.modal-head h3 {
    margin: 0;
    font-size: 1.05rem;
}

.modal-body {
    padding: 1rem 1.1rem;
    overflow-y: auto;
    flex: 1;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.85rem 1.1rem;
    border-top: 1px solid var(--border);
}

.modal-form-grid {
    display: grid;
    gap: 0.85rem;
}

.modal-form-grid .field-full {
    grid-column: 1 / -1;
}

@media (min-width: 520px) {
    .modal-form-grid.cols-2 {
        grid-template-columns: 1fr 1fr;
    }
}

/* Toasts */
.toast-host {
    position: fixed;
    top: 72px;
    right: 1rem;
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: var(--surface2);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    max-width: 360px;
    animation: slideIn 0.2s ease;
}

.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(12px); }
    to { opacity: 1; transform: none; }
}

.mobile-only {
    display: none;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 35;
}

@media (max-width: 900px) {
    .mobile-only {
        display: inline-flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main {
        margin-left: 0 !important;
    }

    .sidebar-overlay.active {
        display: block;
    }
}

@media (max-width: 900px) {
    :root {
        --sidebar-w: 260px;
    }
}
