/* ═══════════════════════════════════════════════════════════
   SIDEBAR + TOP MENU — Mobile-friendly stylesheet
   Works alongside dashboard_style.css (which provides theme vars)
   ═══════════════════════════════════════════════════════════ */

/* ---------- Root tokens (fallbacks if theme vars aren't set) ---------- */
:root {
    --sb-width: 260px;
    --sb-width-collapsed: 72px;
    --topbar-height: 60px;
    --gold: gold;
    --cream: var(--muted);
    --sb-bg: var(--sidebar-bg, #1c1a16);
    --sb-fg: var(--sidebar-fg, #f5f2eb);
    --sb-fg-muted: var(--sidebar-fg-muted, rgba(245, 242, 235, 0.6));
    --sb-accent: var(--accent, #2c5f2e);
    --sb-hover: var(--sidebar-hover, rgba(255, 255, 255, 0.6));
    --sb-active: var(--sidebar-active, rgba(255, 255, 255, 0.1));
    --sb-border: var(--sidebar-border, rgba(255, 255, 255, 0.08));

    --top-bg: var(--topbar-bg, #ffffff);
    --top-fg: var(--topbar-fg, #1c1a16);
    --top-border: var(--topbar-border, rgba(0, 0, 0, 0.08));
    --top-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);

    --z-sidebar: 1000;
    --z-overlay: 999;
    --z-topbar: 900;
    --z-palette: 1100;
}

/* ---------- Base reset for layout elements ---------- */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    background: var(--bg, #f5f2eb);
    color: var(--fg, #1c1a16);
    -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sb-width);
    background: var(--sb-bg);
    color: var(--sb-fg);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    z-index: var(--z-sidebar);
    border-right: 1px solid var(--sb-border);
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease;
    -webkit-overflow-scrolling: touch;
}

/* Brand / logo */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px 18px;
    border-bottom: 1px solid var(--sb-border);
    margin-bottom: 14px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--sb-accent), #4a8a4c);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.brand-text .brand-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

/* Nav */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sb-fg-muted);
    padding: 14px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    color: var(--sb-fg);
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    transition:
        background 0.15s ease,
        transform 0.1s ease;
    font-family: inherit;
}

.nav-item:hover {
    background: var(--sb-hover);
}

.nav-item:active {
    transform: scale(0.98);
}

.nav-item.active {
    background: var(--sb-active);
    color: var(--sb-fg);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--sb-accent);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    display: inline-flex;
    justify-content: center;
    flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
    order: 3;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--sb-border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.api-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--sb-hover);
    border-radius: 999px;
    font-size: 12px;
    color: var(--sb-fg-muted);
    width: fit-content;
}

.api-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f59e0b;
    animation: pulse 2s infinite;
}

.api-dot.ok {
    background: #22c55e;
}
.api-dot.err {
    background: #ef4444;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.sidebar-back {
    font-size: 12px;
    color: var(--sb-fg-muted);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.15s;
}

.sidebar-back:hover {
    background: var(--sb-hover);
    color: var(--sb-fg);
}

/* Sidebar overlay for mobile */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-overlay);
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

#sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════════════════════ */
.main {
    margin-left: var(--sb-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

/* ═══════════════════════════════════════════════════════════
   TOPBAR / TOP MENU
   ═══════════════════════════════════════════════════════════ */
.topbar {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--topbar-height);
    padding: 0 20px;
    background: var(--top-bg);
    color: var(--top-fg);
    border-bottom: 1px solid var(--top-border);
    box-shadow: var(--top-shadow);
    z-index: var(--z-topbar);
}

#menu-toggle {
    display: none;
    background: transparent;
    border: none;
    font-size: 22px;
    color: var(--top-fg);
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 8px;
    line-height: 1;
    transition: background 0.15s;
}

#menu-toggle:hover {
    background: rgba(0, 0, 0, 0.05);
}

#menu-toggle:active {
    transform: scale(0.95);
}

.topbar-title {
    font-size: 17px;
    font-weight: 600;
    flex: 0 0 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Search box */
.topbar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid transparent;
    border-radius: 999px;
    transition:
        border-color 0.15s,
        background 0.15s;
    min-width: 180px;
}

.topbar-search:focus-within {
    border-color: var(--sb-accent);
    background: #fff;
}

.topbar-search span {
    font-size: 14px;
    opacity: 0.6;
}

.topbar-search input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: var(--top-fg);
    width: 100%;
    font-family: inherit;
}

.topbar-search input::placeholder {
    color: rgba(0, 0, 0, 0.4);
}

/* Avatar */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sb-accent), #4a8a4c);
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid var(--top-bg);
    box-shadow: 0 0 0 1px var(--top-border);
}

/* Hide the old dup mobile toggle — we use #menu-toggle */
.mob-toggle {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════
   THEME PICKER
   ═══════════════════════════════════════════════════════════ */
.theme-picker {
    position: relative;
}

.theme-pick-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--top-border);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--top-fg);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.theme-pick-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.theme-palette {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 280px;
    max-width: 320px;
    background: #fff;
    border: 1px solid var(--top-border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
    padding: 14px;
    display: none;
    z-index: var(--z-palette);
}

.theme-palette.open {
    display: block;
}

.palette-label {
    margin: 0 0 10px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(0, 0, 0, 0.5);
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.swatch {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;

    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    transition:
        background 0.15s,
        border-color 0.15s;
}

.swatch:hover {
    background: rgba(0, 0, 0, 0.06);
}

.swatch.active {
    border-color: var(--sb-accent);
    background: rgba(44, 95, 46, 0.08);
}

.swatch-colors {
    display: inline-flex;
    gap: 2px;
    flex-shrink: 0;
}

.swatch-colors i {
    display: block;
    width: 12px;
    height: 18px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.swatch-name {
    font-size: 13px;
    font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════
   CONTENT AREA
   ═══════════════════════════════════════════════════════════ */
.content {
    flex: 1;
    padding: 24px;
    max-width: 100%;
    overflow-x: hidden;
}

.page {
    display: none;
    animation: fadeIn 0.25s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE RESPONSIVE — the main show
   ═══════════════════════════════════════════════════════════ */

/* Tablet and below */
@media (max-width: 1024px) {
    :root {
        --sb-width: 240px;
    }

    .content {
        padding: 20px;
    }

    .topbar-search {
        min-width: 140px;
    }
}

/* Mobile — collapse sidebar to drawer */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
    }

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

    .main {
        margin-left: 0;
    }

    #menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .topbar {
        padding: 0 14px;
        gap: 8px;
    }

    .topbar-title {
        font-size: 16px;
        flex: 1;
    }

    .topbar-right {
        gap: 8px;
    }

    /* Hide search on small mobile, show icon only */
    .topbar-search {
        min-width: auto;
        padding: 8px;
    }

    .topbar-search input {
        display: none;
    }

    /* Theme picker — show icon only */
    .theme-pick-btn span:not(.swatch-name) {
        display: none;
    }

    .theme-pick-btn {
        padding: 7px 9px;
    }

    .theme-palette {
        right: -40px;
        min-width: 260px;
    }

    .content {
        padding: 16px;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    :root {
        --topbar-height: 54px;
    }

    .topbar {
        padding: 0 10px;
    }

    .topbar-title {
        font-size: 15px;
    }

    .avatar {
        width: 32px;
        height: 32px;
    }

    .sidebar {
        width: 85vw;
        max-width: 300px;
    }

    .theme-palette {
        position: fixed;
        top: var(--topbar-height);
        right: 8px;
        left: 8px;
        max-width: none;
    }

    .palette-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .content {
        padding: 12px;
    }
}

/* Prevent body scroll when sidebar is open on mobile */
body.sidebar-open {
    overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════
   UTILITY / EXISTING CLASSES (kept compatible)
   ═══════════════════════════════════════════════════════════ */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
}

.page-sub {
    font-size: 13px;

    margin-top: 4px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    position: relative;
    padding: 18px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--top-border);
    overflow: hidden;
}

.stat-label {
    font-size: 12px;
    color: rgba(0, 0, 0, 0.55);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-top: 6px;
}

.stat-icon {
    position: absolute;
    top: 14px;
    right: 14px;
    font-size: 22px;
    opacity: 0.25;
}

@media (max-width: 480px) {
    .page-title {
        font-size: 20px;
    }
    .stat-value {
        font-size: 22px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
}
