:root {
    --sidebar-bg: #16283b;
    --sidebar-bg-2: #1d334a;
    --sidebar-text: #c6d3e1;
    --sidebar-muted: #6f8399;
    --sidebar-hover: rgba(255, 255, 255, 0.07);
    --sidebar-active-bg: rgba(59, 130, 246, 0.16);
    --accent: #1b4b7a;
    --accent-hover: #143a5e;
    --accent-soft: #eaf1f9;
    --canvas: #f4f6fa;
    --surface: #ffffff;
    --border: #e3e8f0;
    --border-strong: #cbd5e1;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-faint: #94a3b8;
    --success: #0e9f6e;
    --success-bg: #e4f8ef;
    --success-border: #b6e6d2;
    --danger: #d64550;
    --danger-bg: #fdeced;
    --danger-border: #f3c2c6;
    --warning: #b8860b;
    --warning-bg: #fbf3dc;
    --warning-border: #ecd99a;
    --neutral: #5a6572;
    --neutral-bg: #edf0f4;
    --neutral-border: #d8dee6;
    --radius: 10px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 2px 8px rgba(16, 24, 40, 0.06);
    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
    --mono: "Cascadia Code", Consolas, "Courier New", monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font);
    font-size: 14px;
    background: var(--canvas);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
}

.app {
    display: flex;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 238px;
    background: linear-gradient(180deg, var(--sidebar-bg-2) 0%, var(--sidebar-bg) 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 60;
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.15);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand img {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    flex: none;
}

.brand-name {
    color: #ffffff;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.15;
}

.brand-sub {
    color: var(--sidebar-muted);
    font-size: 11px;
    margin-top: 2px;
}

.nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: var(--sidebar-muted);
    padding: 12px 10px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    position: relative;
    transition: background 0.12s ease, color 0.12s ease;
}

.nav-item svg {
    width: 17px;
    height: 17px;
    flex: none;
    opacity: 0.9;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #ffffff;
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: #ffffff;
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: -10px;
    top: 7px;
    bottom: 7px;
    width: 3px;
    border-radius: 2px;
    background: #3b82f6;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #3b82f6;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.user-meta {
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: #e8eef5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: var(--sidebar-muted);
}

.sidebar-links {
    display: flex;
    gap: 6px;
    margin-top: 9px;
}

.sidebar-links a,
.sidebar-links button {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 8px;
    border-radius: var(--radius-sm);
    border: none;
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text);
    font-family: var(--font);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s ease;
}

.sidebar-links a:hover,
.sidebar-links button:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.sidebar-links svg {
    width: 14px;
    height: 14px;
}

/* ---------- Main / topbar ---------- */
.main {
    margin-left: 238px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    display: none;
    align-items: center;
    gap: 10px;
    height: 54px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar .topbar-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    color: var(--text);
}

.topbar .topbar-brand img {
    width: 28px;
    height: 28px;
    border-radius: 7px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.icon-btn:hover {
    background: var(--canvas);
    color: var(--text);
}

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

.page {
    padding: 26px 30px 48px;
    width: 100%;
    max-width: 1420px;
}

.page-header {
    margin-bottom: 20px;
}

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 21px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.01em;
}

.page-desc {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
    max-width: 640px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
    margin-bottom: 14px;
}

.back-link:hover {
    color: var(--accent);
}

.back-link svg {
    width: 15px;
    height: 15px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.card-title .card-desc {
    font-size: 12.5px;
    font-weight: 400;
    color: var(--text-muted);
}

/* ---------- Stat tiles ---------- */
.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 13px;
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.stat-icon svg {
    width: 21px;
    height: 21px;
}

.stat-icon.blue { background: var(--accent-soft); color: var(--accent); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }
.stat-icon.amber { background: var(--warning-bg); color: var(--warning); }

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.1;
}

.stat-label {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ---------- Tables ---------- */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    font-size: 13.5px;
}

.data-table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.data-table tbody tr {
    transition: background 0.1s ease;
}

.data-table tbody tr:hover {
    background: #fafcff;
}

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

.data-table td.mono,
.data-table .mono {
    font-family: var(--mono);
    font-size: 12.5px;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

.badge-active { background: var(--success-bg); color: var(--success); }
.badge-released { background: var(--neutral-bg); color: var(--neutral); }
.badge-blocked { background: var(--danger-bg); color: var(--danger); }
.badge-inactive { background: var(--warning-bg); color: var(--warning); }
.badge-plain { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- Buttons ---------- */
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    background: var(--accent);
    color: #fff;
    border: 1px solid transparent;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

button:hover, .btn:hover {
    background: var(--accent-hover);
}

button:focus-visible, .btn:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(27, 75, 122, 0.22);
}

button svg, .btn svg {
    width: 15px;
    height: 15px;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-secondary:hover {
    background: var(--canvas);
    color: var(--text);
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #b33843;
}

.btn-warning {
    background: var(--warning);
}

.btn-warning:hover {
    background: #8f6a09;
}

.btn-sm {
    padding: 5px 11px;
    font-size: 12.5px;
    border-radius: 7px;
}

.btn-sm svg {
    width: 13px;
    height: 13px;
}

.linkbtn {
    background: none;
    border: none;
    padding: 0;
    color: var(--sidebar-text);
    font: inherit;
    cursor: pointer;
}

/* ---------- Forms ---------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px 18px;
}

.form-row {
    margin-bottom: 14px;
}

.form-grid .form-row {
    margin-bottom: 0;
}

label {
    display: block;
    font-weight: 600;
    font-size: 12.5px;
    color: var(--text);
    margin-bottom: 6px;
}

label .hint {
    font-weight: 400;
    color: var(--text-faint);
}

input[type="text"],
input[type="password"],
input[type="date"],
select {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13.5px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
select:focus {
    border-color: var(--accent);
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 16px;
}

.inline-form {
    display: inline;
    margin: 0;
}

/* ---------- Alerts ---------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.45;
}

.alert svg {
    width: 18px;
    height: 18px;
    flex: none;
    margin-top: 1px;
}

.alert-error {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: #8f1d26;
}

.alert-success {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: #14522f;
}

.alert-warning {
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    color: #6b5600;
}

/* ---------- Empty state ---------- */
.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    width: 40px;
    height: 40px;
    color: var(--text-faint);
    margin-bottom: 10px;
}

.empty-state .empty-title {
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
    margin-bottom: 3px;
}

.empty-state .empty-desc {
    font-size: 12.5px;
}

/* ---------- Mono / code ---------- */
code, .mono {
    font-family: var(--mono);
    font-size: 12.5px;
    background: #f4f6f9;
    border: 1px solid var(--border);
    padding: 2px 7px;
    border-radius: 6px;
    word-break: break-all;
}

.mono-nowrap {
    white-space: nowrap;
}

textarea.mono, pre.mono-block {
    width: 100%;
    min-height: 170px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.5;
    resize: vertical;
    background: #f8fafc;
    color: var(--text);
    word-break: break-all;
    white-space: pre-wrap;
}

pre.mono-block {
    margin: 0;
}

/* ---------- Key-value detail ---------- */
.detail-list {
    width: 100%;
}

.detail-list .detail-row {
    display: flex;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}

.detail-list .detail-row:last-child {
    border-bottom: none;
}

.detail-list .detail-key {
    width: 170px;
    flex: none;
    color: var(--text-muted);
    font-size: 13px;
}

.detail-list .detail-value {
    font-size: 13.5px;
    color: var(--text);
    word-break: break-all;
}

/* ---------- Footer ---------- */
.page-footer {
    padding: 16px 28px;
    color: var(--text-faint);
    font-size: 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

/* ---------- Login ---------- */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(1000px 500px at 15% -10%, rgba(27, 75, 122, 0.22), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, rgba(59, 130, 246, 0.14), transparent 60%),
        linear-gradient(180deg, #eef2f8 0%, #e3e9f2 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    padding: 32px;
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 22px;
}

.login-brand img {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    margin-bottom: 12px;
}

.login-title {
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

.login-card .form-row {
    margin-bottom: 15px;
}

.login-card .btn {
    width: 100%;
    padding: 10px 16px;
    margin-top: 4px;
}

.login-footer {
    margin-top: 18px;
    text-align: center;
    font-size: 11.5px;
    color: var(--text-faint);
}

/* ---------- Table toolbar / search ---------- */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.table-toolbar-title {
    font-size: 15px;
    font-weight: 600;
    color: #0f172a;
}

.table-toolbar-title .count {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 13px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-bar input {
    width: 260px;
    max-width: 100%;
}

/* ---------- Pager ---------- */
.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.pager-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.pager-btn:hover {
    background: var(--canvas);
    border-color: var(--accent);
    color: var(--accent);
}

.pager-btn.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pager-btn.is-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.pager-ellipsis {
    color: var(--text-faint);
    padding: 0 2px;
}

/* ---------- Modal ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 100;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 16px;
    overflow-y: auto;
}

.modal-overlay.open {
    display: flex;
}

body.modal-open {
    overflow: hidden;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.modal-close:hover {
    background: var(--canvas);
    color: var(--text);
}

.modal-close svg {
    width: 17px;
    height: 17px;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

.modal .form-row {
    margin-bottom: 14px;
}

.modal .form-row:last-child {
    margin-bottom: 0;
}

/* ---------- Responsive ---------- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 55;
}

@media (max-width: 920px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

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

    .sidebar-backdrop.show {
        display: block;
    }

    .main {
        margin-left: 0;
    }

    .topbar {
        display: flex;
    }

    .page {
        padding: 20px 16px 40px;
    }
}
