:root {
    --bg: #0a0714;
    --bg-2: #0f766e;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --primary-light: #d1fae5;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--surface-2);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Auth ---------- */
.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #0f1729 0%, #13f48d 100%);
    padding: 24px;
}
.auth-card {
    background: var(--surface);
    width: 100%;
    max-width: 420px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    margin-bottom: 8px;
}
.auth-logo .badge { font-size: 28px; }
.auth-card h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.auth-card p.sub { text-align: center; color: var(--text-muted); margin-bottom: 28px; font-size: 14px; }
@media (max-width: 480px) {
    .auth-wrap { padding: 0; align-items: flex-end; }
    .auth-card {
        border-radius: 20px 20px 0 0;
        padding: 32px 24px 36px;
        box-shadow: 0 -8px 30px rgba(0,0,0,0.15);
        max-width: 100%;
    }
}

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

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

.sidebar {
    width: 260px;
    background: var(--bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    z-index: 50;
    transition: transform 0.25s cubic-bezier(.4,0,.2,1);
}
.sidebar .brand {
    padding: 22px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.sidebar .brand .badge { font-size: 24px; }
.nav-section { padding: 16px 12px; }
.nav-section .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 8px 12px;
    font-weight: 600;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link .ico { width: 18px; text-align: center; }

.sidebar .user-box {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.user-box .name { color: #fff; font-weight: 600; font-size: 14px; }
.user-box .role { color: #64748b; font-size: 12px; }

.main { flex: 1; margin-left: 260px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar h2 { font-size: 18px; font-weight: 600; }
.content { padding: 28px; flex: 1; max-width: 1200px; width: 100%; }

/* Hamburger button (hidden on desktop) */
.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
.menu-toggle:hover { background: var(--surface-2); }
.menu-toggle span {
    display: block;
    width: 18px; height: 2px;
    background: var(--text);
    border-radius: 2px;
    position: relative;
    transition: all 0.2s;
}
.menu-toggle span::before,
.menu-toggle span::after {
    content: '';
    display: block;
    width: 18px; height: 2px;
    background: var(--text);
    border-radius: 2px;
    position: absolute;
    transition: all 0.2s;
}
.menu-toggle span::before { top: -6px; }
.menu-toggle span::after  { top:  6px; }

/* ---------- Components ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    background: var(--primary);
    color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-pad { padding: 24px; }
.card h3 { font-size: 16px; margin-bottom: 4px; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat-card { padding: 20px; display: flex; align-items: center; gap: 16px; }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: grid; place-items: center;
    font-size: 22px;
    background: var(--primary-light);
}
.stat-card .value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-card .label { font-size: 13px; color: var(--text-muted); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    transition: border 0.15s, box-shadow 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.checkbox-row input { width: 16px; height: 16px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
table.tbl td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: var(--surface-2); }

/* ---------- Badges ---------- */
.badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-green { background: var(--success-light); color: var(--success); }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-indigo { background: var(--primary-light); color: var(--primary); }
.badge-amber { background: var(--warning-light); color: var(--warning); }
.badge-gray { background: #f1f5f9; color: var(--text-muted); }

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-success { background: var(--success-light); color: #166534; }
.alert-danger { background: var(--danger-light); color: #991b1b; }

/* ---------- Page header ---------- */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-head h1 { font-size: 24px; font-weight: 700; }
.page-head .desc { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.breadcrumb a:hover { color: var(--primary); }

/* ---------- Category / version ---------- */
.cat-block { margin-bottom: 20px; }
.cat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}
.cat-head .title { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.version-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}
.version-row:last-child { border-bottom: none; }
.version-info { display: flex; align-items: center; gap: 14px; }
.version-icon {
    width: 42px; height: 42px;
    border-radius: 10px;
    background: var(--success-light);
    display: grid; place-items: center;
    font-size: 20px;
}
.version-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.version-actions { display: flex; align-items: center; gap: 8px; }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state .ico { font-size: 40px; margin-bottom: 12px; }

.inline-form { display: inline; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.fw-600 { font-weight: 600; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }

.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .perm-grid { grid-template-columns: 1fr; } }
.perm-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.perm-item input { margin-top: 3px; }
.perm-item .pname { font-weight: 600; font-size: 14px; }
.perm-item .pdesc { font-size: 12px; color: var(--text-muted); }

.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

/* ============================================================
   MOBILE RESPONSIVE  (≤ 768 px)
   ============================================================ */
@media (max-width: 768px) {

    /* Sidebar slides in as a drawer */
    .sidebar {
        transform: translateX(-260px);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    /* Main fills full width */
    .main {
        margin-left: 0;
    }

    /* Topbar */
    .topbar {
        padding: 0 16px;
        gap: 12px;
    }
    .topbar h2 { font-size: 16px; }

    /* Show hamburger */
    .menu-toggle { display: flex; }

    /* Content padding */
    .content { padding: 16px; }

    /* Page head stacks action buttons below title */
    .page-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .page-head h1 { font-size: 20px; }

    /* Version rows stack vertically */
    .version-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .version-actions {
        width: 100%;
        justify-content: flex-start;
    }

    /* Category head stacks */
    .cat-head {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Stat cards: 2 columns on mobile */
    .grid-4 { grid-template-columns: repeat(2, 1fr); }

    /* Reduce card padding */
    .card-pad { padding: 16px; }
    .stat-card { padding: 14px; }
    .stat-card .value { font-size: 22px; }

    /* Tables get horizontal scroll */
    .table-wrap { -webkit-overflow-scrolling: touch; }

    /* Profile grid stacks */
    .grid-2 { grid-template-columns: 1fr; }

    /* User box in sidebar - compact */
    .sidebar .user-box { padding: 12px; }
}

/* Tiny screens (≤ 400 px) */
@media (max-width: 400px) {
    .grid-4 { grid-template-columns: 1fr; }
    .stat-card { flex-direction: column; text-align: center; gap: 8px; }
    .version-info { flex-direction: column; align-items: flex-start; }
    .topbar h2 { font-size: 14px; }
}
