/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
    --sb-width: 240px;
    --sb-bg: #1e293b;
    --sb-text: #94a3b8;
    --sb-text-hover: #f1f5f9;
    --sb-active-bg: rgba(255, 255, 255, 0.08);
    --sb-section-label: #475569;
    --topbar-height: 56px;
    --brand: #3b82f6;
    --brand-dark: #2563eb;
    --surface: #f8fafc;
    --border: #e2e8f0;
    --text-heading: #1e293b;
    --text-body: #334155;
    --text-muted: #64748b;
}

/* ── Base ───────────────────────────────────────────────────────────────── */
html { font-size: 14px; }
@media (min-width: 768px) { html { font-size: 15px; } }

body { background: var(--surface); color: var(--text-body); }

.btn { border-radius: .5rem; }
.btn-sm { font-size: .8rem; }
.badge { font-weight: 500; }

.btn:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .2);
    border-color: var(--brand);
}

/* ── Auth layout ────────────────────────────────────────────────────────── */
body.auth-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-card {
    background: #fff;
    border-radius: 1rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 390px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, .35);
}

.auth-logo {
    width: 58px;
    height: 58px;
    background: var(--brand);
    border-radius: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: #fff;
    margin: 0 auto 1.25rem;
}

.auth-card h2 {
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    color: var(--text-heading);
    margin-bottom: .3rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: .85rem;
    margin-bottom: 1.75rem;
}

/* ── Public layout ──────────────────────────────────────────────────────── */
.public-navbar {
    background: var(--sb-bg) !important;
}

/* ── Admin layout wrapper ───────────────────────────────────────────────── */
body.admin-layout {
    background: var(--surface);
}

#layout-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
    width: var(--sb-width);
    min-height: 100vh;
    background: var(--sb-bg);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1030;
    transition: transform .22s cubic-bezier(.4, 0, .2, 1);
    overflow-y: auto;
}

.sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 0 1.25rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    flex-shrink: 0;
}

.sidebar-brand i { font-size: 1.35rem; color: var(--brand); }
.sidebar-brand:hover { color: #fff; }

.sidebar-section-label {
    padding: 1rem 1.25rem .3rem;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--sb-section-label);
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem 1.25rem;
    color: var(--sb-text);
    text-decoration: none;
    font-size: .88rem;
    transition: color .15s, background .15s;
    border-radius: 0;
    white-space: nowrap;
}

.sidebar-nav .nav-link i {
    font-size: .95rem;
    opacity: .75;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
}

.sidebar-nav .nav-link:hover {
    color: var(--sb-text-hover);
    background: var(--sb-active-bg);
}

.sidebar-nav .nav-link:hover i { opacity: 1; }

.sidebar-nav .nav-link.active {
    color: #fff;
    background: var(--brand);
}

.sidebar-nav .nav-link.active i { opacity: 1; }

.sidebar-divider {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, .06);
    margin: .5rem 0;
}

.sidebar-badge {
    margin-left: auto;
    background: rgba(255,255,255,.15);
    color: #fff;
    font-size: .65rem;
    padding: .15rem .45rem;
    border-radius: 10rem;
}

/* ── Page content ───────────────────────────────────────────────────────── */
#page-content {
    flex: 1;
    margin-left: var(--sb-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Top bar ────────────────────────────────────────────────────────────── */
#topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: .75rem;
    position: sticky;
    top: 0;
    z-index: 1029;
    flex-shrink: 0;
}

#sidebarToggle {
    background: none;
    border: none;
    padding: .3rem .45rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.2rem;
    border-radius: .4rem;
    display: none;
    line-height: 1;
}

#sidebarToggle:hover { background: #f1f5f9; color: var(--text-heading); }

.topbar-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .75rem;
}

.topbar-user-name {
    font-size: .85rem;
    color: var(--text-body);
    font-weight: 500;
}

.topbar-user-role {
    font-size: .72rem;
    background: #eff6ff;
    color: var(--brand);
    border-radius: 10rem;
    padding: .15rem .55rem;
    font-weight: 600;
}

/* ── Page main ──────────────────────────────────────────────────────────── */
.page-main {
    flex: 1;
    padding: 1.75rem;
}

/* ── Flash messages ─────────────────────────────────────────────────────── */
.flash-area { margin-bottom: 1.25rem; }
.alert { border-radius: .6rem; font-size: .875rem; }

/* ── Page header ────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.75rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-header-left h1 {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-heading);
    margin: 0 0 .2rem;
}

.page-header-left .breadcrumb {
    margin: 0;
    font-size: .78rem;
}

.page-header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Back link ──────────────────────────────────────────────────────────── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: .85rem;
    margin-bottom: 1.25rem;
    padding: .3rem 0;
    transition: color .15s;
}

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

/* ── Stat cards ─────────────────────────────────────────────────────────── */
.stat-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: .75rem;
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: .6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.stat-icon.blue   { background: #eff6ff; color: #3b82f6; }
.stat-icon.green  { background: #f0fdf4; color: #22c55e; }
.stat-icon.gray   { background: #f1f5f9; color: #64748b; }
.stat-icon.amber  { background: #fffbeb; color: #f59e0b; }
.stat-icon.red    { background: #fef2f2; color: #ef4444; }
.stat-icon.purple { background: #faf5ff; color: #a855f7; }
.stat-icon.teal   { background: #f0fdfa; color: #14b8a6; }

.stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-heading);
    line-height: 1;
}

.stat-label {
    font-size: .76rem;
    color: var(--text-muted);
    margin-top: .15rem;
}

/* ── Content card ───────────────────────────────────────────────────────── */
.content-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: .75rem;
    overflow: hidden;
}

.card-header-bar {
    padding: .85rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
}

.card-header-bar h5 {
    margin: 0;
    font-size: .92rem;
    font-weight: 600;
    color: var(--text-heading);
}

.card-body-pad { padding: 1.25rem; }

/* ── Table inside content-card ──────────────────────────────────────────── */
.content-card .table { margin: 0; }

.content-card .table thead th {
    background: #f8fafc;
    color: #475569;
    font-size: .73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    border-bottom: 1px solid var(--border);
    padding: .65rem 1rem;
    white-space: nowrap;
}

.content-card .table tbody td {
    padding: .7rem 1rem;
    vertical-align: middle;
    color: var(--text-body);
    border-bottom: 1px solid #f1f5f9;
    font-size: .875rem;
}

.content-card .table tbody tr:last-child td { border-bottom: 0; }
.content-card .table tbody tr:hover td { background: #f8fafc; }
.content-card .table tfoot td {
    padding: .7rem 1rem;
    background: #f8fafc;
    border-top: 2px solid var(--border);
    font-size: .875rem;
}

/* ── Form card ──────────────────────────────────────────────────────────── */
.form-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: .75rem;
    padding: 1.75rem;
    max-width: 700px;
}

.form-section-title {
    font-size: .73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: #94a3b8;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.1rem;
    margin-top: 1.75rem;
}

.form-section-title:first-child { margin-top: 0; }

.form-label { font-size: .875rem; font-weight: 500; color: #475569; }

/* ── Action cards (dashboard quick-access) ──────────────────────────────── */
.action-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: .75rem;
    padding: 1.25rem;
    text-decoration: none;
    color: var(--text-body);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: border-color .15s, box-shadow .15s, transform .1s;
}

.action-card:hover {
    border-color: var(--brand);
    box-shadow: 0 4px 16px rgba(59, 130, 246, .12);
    transform: translateY(-1px);
    color: var(--text-body);
}

.action-card .action-icon {
    width: 44px;
    height: 44px;
    border-radius: .55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.action-card .action-label {
    font-weight: 600;
    font-size: .9rem;
    color: var(--text-heading);
}

.action-card .action-desc {
    font-size: .775rem;
    color: var(--text-muted);
    margin-top: .1rem;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.page-footer {
    padding: .7rem 1.5rem;
    font-size: .75rem;
    color: #94a3b8;
    border-top: 1px solid var(--border);
    background: #fff;
}

/* ── Sidebar overlay (mobile) ───────────────────────────────────────────── */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 1025;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
    #sidebar {
        transform: translateX(calc(-1 * var(--sb-width)));
    }

    #sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, .3);
    }

    #sidebar.open + #page-content + #sidebar-overlay,
    #sidebar-overlay.open {
        display: block;
    }

    #page-content { margin-left: 0; }
    #sidebarToggle { display: flex; }
    .page-main { padding: 1rem; }
    #topbar { padding: 0 1rem; }
}
