* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

:root {
    --bg: rgb(10, 10, 10);
    --surface: rgb(15, 15, 15);
    --surface-hover: rgb(20, 20, 20);
    --border: rgb(28, 28, 28);
    --border-light: rgb(35, 35, 35);
    --text: rgb(240, 240, 240);
    --text-muted: rgb(140, 140, 140);
    --accent: rgb(99, 130, 255);
    --accent-hover: rgb(120, 145, 255);
    --danger: rgb(220, 70, 70);
    --danger-hover: rgb(240, 90, 90);
    --success: rgb(70, 200, 120);
    --radius: 12px;
    --radius-lg: 16px;
}

body {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

/* Sidebar */

.sidebar {
    width: 240px;
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
}

.sidebar h2 {
    font-size: 18px;
    font-weight: 600;
    padding: 0 12px;
    margin-bottom: 28px;
    color: var(--text);
}

.sidebar nav {
    flex: 1;
}

.sidebar a {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    padding: 11px 14px;
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.sidebar a:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.sidebar a.active {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border-light);
}

.logout-form {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Main layout */

.main {
    flex: 1;
    padding: 32px 36px;
    overflow-y: auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 28px;
}

.header h1 {
    font-size: 26px;
    font-weight: 600;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.welcome {
    color: var(--text-muted);
    font-size: 14px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.welcome strong {
    color: var(--text);
}

/* Stats */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.card h3 {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.card p {
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
}

/* Panels */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 16px;
    font-weight: 600;
}

/* Tables */

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: rgb(12, 12, 12);
    text-align: left;
    padding: 12px 22px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

td {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}

.muted {
    color: var(--text-muted);
}

/* Roles & badges */

.role {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.role.admin {
    background: rgba(255, 80, 80, 0.12);
    color: rgb(255, 120, 120);
}

.role.user {
    background: rgba(99, 130, 255, 0.12);
    color: rgb(140, 165, 255);
}

.plan-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    background: rgba(70, 200, 120, 0.1);
    color: var(--success);
}

.expiry-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 4px;
}

.expiry-badge.expired {
    background: rgba(220, 70, 70, 0.12);
    color: rgb(255, 120, 120);
}

.expiry-badge.active {
    background: rgba(70, 200, 120, 0.1);
    color: var(--success);
}

.expiry-form input[type="date"] {
    padding: 6px 10px;
    font-size: 12px;
    max-width: 150px;
}

/* API docs */

.docs-section {
    margin-bottom: 20px;
}

.docs-body {
    padding: 20px 22px;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.6;
}

.docs-body p {
    margin-bottom: 12px;
}

.endpoint {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    margin-bottom: 16px;
}

.endpoint-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.endpoint-header code {
    font-size: 15px;
    color: var(--text);
}

.endpoint-desc {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 16px;
}

.endpoint h4 {
    font-size: 13px;
    color: var(--text-muted);
    margin: 16px 0 8px;
    font-weight: 600;
}

.method {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    font-family: monospace;
}

.method.get { background: rgba(99, 130, 255, 0.15); color: rgb(140, 165, 255); }
.method.post { background: rgba(70, 200, 120, 0.15); color: var(--success); }
.method.delete { background: rgba(220, 70, 70, 0.15); color: rgb(255, 120, 120); }

.badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
    color: var(--text-muted);
}

.badge.public { border-color: rgba(70, 200, 120, 0.3); color: var(--success); }
.badge.auth { border-color: rgba(99, 130, 255, 0.3); color: rgb(140, 165, 255); }
.badge.admin { border-color: rgba(255, 120, 120, 0.3); color: rgb(255, 120, 120); }

.status {
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.status.ok { background: rgba(70, 200, 120, 0.15); color: var(--success); }
.status.err { background: rgba(220, 70, 70, 0.15); color: rgb(255, 120, 120); }

pre {
    background: rgb(12, 12, 12);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    overflow-x: auto;
    margin-bottom: 8px;
}

pre code {
    font-family: "Cascadia Code", "Consolas", monospace;
    font-size: 13px;
    color: rgb(200, 210, 230);
    line-height: 1.5;
}

code {
    font-family: "Cascadia Code", "Consolas", monospace;
    font-size: 13px;
    background: rgb(12, 12, 12);
    padding: 2px 6px;
    border-radius: 4px;
    color: rgb(180, 190, 220);
}

.error-list {
    list-style: none;
    font-size: 14px;
    color: var(--text-muted);
}

.error-list li {
    margin-bottom: 6px;
}

.hint-inline {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.sync-indicator {
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.sync-indicator.sync-active {
    color: var(--success);
    border-color: rgba(70, 200, 120, 0.3);
}

/* Plans grid */

.plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    padding: 20px 22px;
}

.plan-card {
    background: rgb(12, 12, 12);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.plan-card-manage {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.plan-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.plan-card h3 {
    font-size: 16px;
    font-weight: 600;
}

.plan-id {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface);
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.plan-price {
    font-size: 28px;
    font-weight: 700;
}

.plan-price span {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-muted);
}

.plan-desc {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.4;
}

.plan-limit,
.plan-subs {
    font-size: 13px;
    color: var(--text-muted);
}

.plan-subs {
    margin-bottom: 8px;
}

/* Forms */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 22px;
}

.form-grid-wide {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.span-full {
    grid-column: 1 / -1;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label span {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

input,
select {
    background: rgb(12, 12, 12);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    color: var(--text);
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus,
select:focus {
    border-color: var(--accent);
}

input::placeholder {
    color: rgb(80, 80, 80);
}

.hint {
    font-size: 11px;
    color: var(--text-muted);
}

.form-actions {
    display: flex;
    align-items: flex-end;
}

.inline-form {
    display: inline;
}

.inline-form select {
    padding: 6px 10px;
    font-size: 13px;
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-light);
}

.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-full {
    width: 100%;
}

/* Login page */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px;
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-header h1 {
    font-size: 22px;
    margin-bottom: 6px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Alerts & flash */

.alert,
.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 20px;
}

.alert-error,
.flash.error {
    background: rgba(220, 70, 70, 0.12);
    border: 1px solid rgba(220, 70, 70, 0.3);
    color: rgb(255, 130, 130);
}

.flash.success {
    background: rgba(70, 200, 120, 0.12);
    border: 1px solid rgba(70, 200, 120, 0.3);
    color: var(--success);
}

.hidden {
    display: none;
}

/* Responsive */

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
    }

    .sidebar h2 {
        margin-bottom: 0;
        width: 100%;
    }

    .sidebar nav {
        display: flex;
        gap: 4px;
        flex: 1;
    }

    .logout-form {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
    }

    .main {
        padding: 20px 16px;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
    }
}
