/* TRC BUILDER — Core Layout (Mobile-First) */
/* Default: Light theme matching production TRC Portal */
:root {
    --brand-primary: #0d9488;
    --brand-primary-light: #14b8a6;
    --brand-primary-dark: #0f766e;
    --brand-secondary: #2563eb;
    --brand-accent: #d97706;
    --bg-body: #faf8f5;
    --bg-surface: #ffffff;
    --bg-surface-2: #f5f0e8;
    --bg-surface-3: #eee9e0;
    --bg-card: rgba(255, 255, 255, 0.95);
    --bg-glass: rgba(255, 255, 255, 0.85);
    --bg-hover: rgba(13, 148, 136, 0.06);
    --bg-active: rgba(13, 148, 136, 0.12);
    --text-primary: #1a1a2e;
    --text-secondary: #5a5a72;
    --text-tertiary: #9a9ab0;
    --text-inverse: #f1f5f9;
    --border-color: rgba(0, 0, 0, 0.08);
    --border-color-light: rgba(0, 0, 0, 0.04);
    --border-color-strong: rgba(0, 0, 0, 0.15);
    --success: #059669;
    --success-bg: rgba(5, 150, 105, 0.1);
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.1);
    --danger: #e11d48;
    --danger-bg: rgba(225, 29, 72, 0.1);
    --info: #2563eb;
    --info-bg: rgba(37, 99, 235, 0.1);
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --radius-sm: 10px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px rgba(13, 148, 136, 0.1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
}

/* ── Dark Theme ─────────────────────────────────────── */
[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-2: #253347;
    --bg-surface-3: #334155;
    --bg-card: rgba(30, 41, 59, 0.8);
    --bg-glass: rgba(30, 41, 59, 0.6);
    --bg-hover: rgba(99, 102, 241, 0.08);
    --bg-active: rgba(99, 102, 241, 0.15);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-inverse: #0f172a;
    --border-color: rgba(148, 163, 184, 0.12);
    --border-color-light: rgba(148, 163, 184, 0.06);
    --border-color-strong: rgba(148, 163, 184, 0.2);
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.12);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent
}

a {
    text-decoration: none;
    color: var(--brand-primary-light)
}

::-webkit-scrollbar {
    width: 5px;
    height: 5px
}

::-webkit-scrollbar-track {
    background: transparent
}

::-webkit-scrollbar-thumb {
    background: var(--border-color-strong);
    border-radius: 3px
}

/* Sidebar — hidden on mobile */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease-out)
}

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

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 90
}

.sidebar-overlay.active {
    display: block
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    min-height: 56px
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white
}

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

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2
}

.logo-title {
    font-weight: 800;
    font-size: 1rem;
    background: linear-gradient(135deg, var(--brand-primary-light), var(--brand-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text
}

.logo-subtitle {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 6px
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0
}

.nav-section {
    padding: 4px 12px
}

.nav-section-title {
    display: block;
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 10px 4px
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all var(--duration-fast);
    position: relative
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary)
}

.nav-item.active {
    background: var(--bg-active);
    color: var(--brand-primary-light)
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--brand-primary);
    border-radius: 0 3px 3px 0
}

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    min-width: 16px;
    text-align: center
}

.sidebar-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border-color)
}

.credit-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(6, 182, 212, 0.08));
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    border: 1px solid rgba(99, 102, 241, 0.2)
}

.credit-display svg {
    width: 16px;
    height: 16px;
    color: var(--brand-accent)
}

.credit-count {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.9rem
}

.credit-label {
    font-size: 0.7rem;
    color: var(--text-tertiary)
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    background: var(--bg-surface-3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0
}

.user-avatar svg {
    width: 14px;
    height: 14px;
    color: var(--text-tertiary)
}

.user-info {
    flex: 1;
    min-width: 0
}

.user-name {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis
}

.user-role {
    display: block;
    font-size: 0.65rem;
    color: var(--text-tertiary);
    text-transform: capitalize
}

.logout-btn {
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary)
}

.logout-btn:hover {
    background: var(--danger-bg);
    color: var(--danger)
}

.logout-btn svg {
    width: 14px;
    height: 14px
}

/* ══════════════════════════════════════════════════════════════════
   MOBILE-FIRST RESPONSIVE OVERHAUL
   Breakpoints: 480px (phone), 768px (tablet), 1024px (iPad), 1200px+
   ══════════════════════════════════════════════════════════════════ */

/* ── Mobile base: touch targets, text, spacing ── */
@media (max-width: 480px) {
    :root {
        --sidebar-width: 280px;
    }

    body {
        font-size: 14px;
        -webkit-text-size-adjust: 100%;
    }

    /* Ensure sidebar fills safely on small phones */
    .sidebar {
        width: 85vw;
        max-width: 300px;
    }

    /* Touch-friendly nav items */
    .nav-item {
        padding: 14px 12px;
        font-size: 0.9rem;
        min-height: 48px;
    }

    .nav-item svg {
        width: 20px;
        height: 20px;
    }

    .nav-section-title {
        font-size: 0.65rem;
        padding: 12px 10px 6px;
    }

    /* Sidebar footer on mobile */
    .sidebar-footer {
        padding: 12px 14px;
    }

    .credit-display {
        padding: 10px 12px;
    }

    .user-name { font-size: 0.85rem; }
    .logo-title { font-size: 0.95rem; }
}

/* ── Tablet landscape / iPad ── */
@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
    }

    .sidebar-toggle {
        display: flex;
    }

    .nav-item span {
        font-size: 0.8rem;
    }

    .logo-subtitle { display: none; }
}

/* ── Collapsed sidebar on tablet (when toggled) ── */
@media (min-width: 769px) {
    .sidebar.collapsed {
        width: 64px;
    }

    .sidebar.collapsed .nav-item span,
    .sidebar.collapsed .nav-section-title,
    .sidebar.collapsed .logo-text,
    .sidebar.collapsed .credit-display,
    .sidebar.collapsed .user-info {
        display: none;
    }

    .sidebar.collapsed .nav-item {
        justify-content: center;
        padding: 12px 8px;
    }

    .sidebar.collapsed + .sidebar-overlay + .main-content,
    .sidebar.collapsed ~ .main-content {
        margin-left: 64px;
    }
}
