/* ============================================================
   CMS Admin - design tokens
   Every class name below is unchanged from the previous version
   of this file, so every view (~30+ .php templates) that already
   uses .panel/.btn-primary/.data-table/etc. picks up the new look
   automatically with zero markup changes required.
   ============================================================ */
:root {
    --bg: #f6f7fb;
    --panel: #ffffff;
    --border: #e7e9f2;
    --border-soft: #eef0f7;
    --text: #171a24;
    --muted: #6b7180;
    --muted-soft: #9498a6;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eeecfd;
    --danger: #dc2626;
    --danger-soft: #fdeeee;
    --ok: #059669;
    --ok-soft: #e8f8f1;
    --sidebar-bg: #14121f;
    --sidebar-bg-2: #1b1830;
    --sidebar-text: #a9a7bd;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(23, 26, 36, 0.05), 0 1px 1px rgba(23, 26, 36, 0.03);
    --shadow-md: 0 6px 16px rgba(23, 26, 36, 0.07), 0 2px 6px rgba(23, 26, 36, 0.04);
    --shadow-lg: 0 20px 44px rgba(20, 18, 31, 0.16);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }

/* ---------------- Shell / sidebar / topbar ---------------- */

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

.sidebar {
    width: 240px;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
    flex-shrink: 0;
    padding: 22px 0 28px;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.01em;
    color: #fff;
    padding: 0 22px 24px;
}
.sidebar-brand-mark {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: 8px;
    background: linear-gradient(135deg, #7c74f0, var(--primary));
    box-shadow: 0 3px 10px rgba(79, 70, 229, 0.5);
}
.sidebar nav { display: flex; flex-direction: column; padding: 0 12px; }
.sidebar nav a, .sidebar nav .nav-disabled {
    padding: 9px 14px;
    margin-bottom: 2px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: 9px;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79, 70, 229, 0.45); }
.sidebar nav .nav-disabled { color: #55536b; cursor: default; }
.nav-group-label {
    padding: 18px 14px 6px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #59566f;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 28px;
    background: rgba(255,255,255,0.85);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-title { font-weight: 700; font-size: 16.5px; letter-spacing: -0.01em; }
.logout-form { display: flex; align-items: center; gap: 14px; }
.topbar-role {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: capitalize;
    letter-spacing: .02em;
}

.content { padding: 28px; max-width: 1140px; }

/* ---------------- Stat cards ---------------- */

.stat-grid { display: flex; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 22px;
    min-width: 150px;
    box-shadow: var(--shadow-sm);
    border-left: 3px solid var(--primary);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-value { font-size: 27px; font-weight: 800; letter-spacing: -0.02em; }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; margin-top: 2px; }

/* ---------------- Panels ---------------- */

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.panel h2 { margin-top: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }

/* ---------------- Forms ---------------- */

.form label { display: block; margin-bottom: 15px; font-size: 13px; font-weight: 600; color: var(--text); }
.form input, .form select {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 400;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form input:focus, .form select:focus, .form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}
.hint-inline { font-weight: 400; color: var(--muted); font-size: 12px; }

.checkbox-label { display: flex !important; align-items: center; gap: 8px; }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--primary); }

/* ---------------- Buttons ---------------- */

.btn-primary, .btn-secondary {
    display: inline-block;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 14px rgba(79, 70, 229, 0.45); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: #f0f1f7; color: var(--text); }
.btn-secondary:hover { background: #e6e8f2; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 600; padding: 0; }
.btn-link.btn-danger { color: var(--danger); }

/* ---------------- Tables ---------------- */

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.data-table th, .data-table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; }
.data-table th { background: #fafafe; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-soft); }
.data-table tbody tr { transition: background-color 0.12s ease; }
.data-table tbody tr:hover { background: #fafafe; }
.data-table tbody tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 12px; align-items: center; }
.row-actions form { display: inline; }

/* ---------------- Badges ---------------- */

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; letter-spacing: .01em; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: var(--danger-soft); color: var(--danger); }

/* ---------------- Toolbar / search ---------------- */

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; }
.search-form input {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: 240px;
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14); }

/* ---------------- Tabs ---------------- */

.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tabs a {
    padding: 9px 16px;
    text-decoration: none;
    color: var(--muted);
    font-weight: 500;
    border-bottom: 2px solid transparent;
    font-size: 13.5px;
    margin-bottom: -1px;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 700; }

/* ---------------- Pagination ---------------- */

.pagination { display: flex; gap: 6px; margin-top: 16px; }
.pagination a {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
.pagination a:hover { background: var(--primary-soft); border-color: var(--primary); }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------------- Alerts ---------------- */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid transparent;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }

.empty-state { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 30px; line-height: 1.6; }

/* ---------------- Auth / install ---------------- */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(circle at 15% 15%, rgba(124, 116, 240, 0.35), transparent 45%),
        radial-gradient(circle at 85% 85%, rgba(79, 70, 229, 0.25), transparent 45%),
        var(--sidebar-bg);
}
.auth-card { background: var(--panel); border-radius: 18px; padding: 36px; width: 340px; box-shadow: var(--shadow-lg); }
.auth-card h1 { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; margin-top: 0; }
.auth-card label { display: block; margin-bottom: 15px; font-size: 13px; font-weight: 600; }
.auth-card input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 400;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.auth-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14); }

/* Install wizard: same auth-card look, but wider (more fields per step)
   and with select/textarea covered too — .auth-card alone only styled
   input, since the login form never needed a dropdown. */
.install-card { width: 520px; }
.install-card select, .install-card textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 400;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.install-card select:focus, .install-card textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14); }
.install-steps { display: flex; gap: 6px; margin-bottom: 22px; font-size: 12px; color: var(--muted); }
.install-steps span { padding: 5px 12px; border-radius: 20px; background: #f0f1f7; font-weight: 500; }
.install-steps span.current { background: var(--primary); color: #fff; font-weight: 700; }
.install-steps span.done { background: var(--ok); color: #fff; }
.check-list { list-style: none; padding: 0; margin: 0 0 20px; }
.check-list li { padding: 9px 12px; border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 13px; font-weight: 500; display: flex; justify-content: space-between; gap: 12px; }
.check-list li.ok { background: var(--ok-soft); color: var(--ok); }
.check-list li.fail { background: var(--danger-soft); color: var(--danger); }
.check-list li .detail { color: inherit; opacity: 0.8; font-weight: 400; }

/* ---------------- Mobile / responsive ---------------- */
/* Below 860px: the sidebar becomes an off-canvas drawer (toggled by
   .menu-toggle in the topbar, only visible at this width - see
   layout.php's inline script), tables scroll horizontally instead of
   squeezing/overflowing the page, and toolbars/forms stack instead of
   staying in a single cramped row. Purely structural - unchanged from
   the previous version of this file. */

.menu-toggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--panel);
        cursor: pointer;
        margin-right: 12px;
        flex-shrink: 0;
        padding: 0;
    }
    .menu-toggle span, .menu-toggle span::before, .menu-toggle span::after {
        content: ''; display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px;
    }
    .menu-toggle span { position: relative; }
    .menu-toggle span::before, .menu-toggle span::after { position: absolute; left: 0; }
    .menu-toggle span::before { top: -6px; }
    .menu-toggle span::after { top: 6px; }

    .sidebar {
        position: fixed;
        top: 0; bottom: 0; left: 0;
        z-index: 40;
        width: 250px;
        max-width: 82vw;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    .app-shell.nav-open .sidebar { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.3); }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 13, 26, 0.5);
        z-index: 30;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }
    .app-shell.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

    .content { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .topbar-title { font-size: 15px; }

    .stat-grid { gap: 10px; }
    .stat-card { min-width: calc(50% - 5px); padding: 12px 14px; }
    .stat-value { font-size: 22px; }

    .panel { padding: 16px; }

    .tabs { flex-wrap: wrap; gap: 4px 6px; }
    .tabs a { padding: 7px 10px; font-size: 13px; }

    .toolbar { flex-direction: column; align-items: stretch; }
    .search-form { width: 100%; }
    .search-form input { min-width: 0; flex: 1; }

    /* Plain <table> elements don't reflow on narrow screens - scroll
       the table itself horizontally rather than letting it force the
       whole page wider, or truncating columns unreadably. Only the
       outer <table> box becomes block-level; tbody/tr/td keep their
       normal table layout inside it, so this is safe in every modern
       browser. */
    .data-table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    .data-table th, .data-table td { padding: 8px 10px; }

    .row-actions { flex-wrap: wrap; }

    .auth-card { width: calc(100% - 32px); max-width: 400px; }
    .install-card { width: calc(100% - 32px); max-width: 520px; }

    .pagination { flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .stat-card { min-width: 100%; }
}
