/* public/css/app.css */

/* ─────────────────────────────────────────
   BRISK CREDIT — GLOBAL THEME & DESIGN TOKENS
   ───────────────────────────────────────── */

:root {
    color-scheme: light dark;
    
    /* Brand Colors (consistent across themes) */
    --bc-orange:          #E8650A;
    --bc-orange-light:    #F47B2B;
    --bc-orange-dark:     #B84E08;
    --bc-orange-subtle:   rgba(232, 101, 10, 0.08);
    --bc-orange-subtle2:  rgba(232, 101, 10, 0.15);
    --bc-blue:            #1A9FE0;
    --bc-blue-light:      #3DB5F0;
    --bc-blue-dark:       #0D7AB5;
    --bc-blue-subtle:     rgba(26, 159, 224, 0.08);
    --bc-blue-subtle2:    rgba(26, 159, 224, 0.15);
    --bc-gold:            #F4A623;
    --bc-green:           #3ECF8E;
    
    /* Fonts */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* Spacing */
    --space-1:4px;--space-2:8px;--space-3:12px;--space-4:16px;--space-5:20px;--space-6:24px;
    --radius-sm:4px;--radius-md:7px;--radius-lg:10px;--radius-xl:12px;
    
    /* Layout */
    --sidebar-width: 220px;
    --topbar-height: 54px;
    
    /* ── Persistent Dark Tokens ──────────────────────────────────────
       The sidebar & topbar stay dark in BOTH themes. These tokens never
       change per-theme, which is what keeps the left menu the same colour
       whether the app is light or dark. Both naming conventions the
       components use (--pd-text vs --pd-text-primary, --pd-btn-* vs
       --pd-btn-icon-*) are provided so every reference resolves. */
    --pd-bg: #0B2545;          /* deep navy — sidebar (matches the login panel) */
    --pd-bg-alt: #123461;      /* lighter navy — hovers / raised */
    --pd-bg-surface: #0B2545;
    --pd-bg-surface-alt: #123461;
    --pd-text: rgba(255, 255, 255, 0.92);
    --pd-text-primary: rgba(255, 255, 255, 0.95);
    --pd-text-secondary: rgba(255, 255, 255, 0.72);
    --pd-text-muted: rgba(255, 255, 255, 0.5);
    --pd-border: rgba(255, 255, 255, 0.1);
    --pd-divider: rgba(255, 255, 255, 0.08);
    --pd-btn-bg: rgba(255, 255, 255, 0.05);
    --pd-btn-border: rgba(255, 255, 255, 0.08);
    --pd-btn-text: rgba(255, 255, 255, 0.5);
    --pd-btn-icon-bg: rgba(255, 255, 255, 0.05);
    --pd-btn-icon-border: rgba(255, 255, 255, 0.08);
    --pd-btn-icon-text: rgba(255, 255, 255, 0.5);
    --pd-input-bg: rgba(255, 255, 255, 0.06);
    --pd-input-border: rgba(255, 255, 255, 0.1);
    --pd-input-placeholder: rgba(255, 255, 255, 0.3);
    
    /* Native controls (scrollbars, date/color pickers) follow the app. */
    color-scheme: light;

    /* ── LIGHT MODE — the default theme (bright & modern, slate-tinted) ──
       Dark is available via the topbar toggle ([data-theme="dark"] below). */
    --bg-main: #F8F8F0;
    --bg-surface-1: #FFFFFF;
    --bg-surface-2: #FFFFFF;
    --bg-surface-3: #EEF2F7;
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --border-subtle: #E8ECF2;
    --border-medium: #D4DBE4;
    --border-orange: rgba(232, 101, 10, 0.25);
    --border-blue: rgba(26, 159, 224, 0.25);
    --input-bg: #FFFFFF;
    --input-border: #D4DBE4;
    --input-placeholder: #94A3B8;
    --btn-secondary-bg: #FFFFFF;
    --btn-secondary-text: #334155;
    --btn-secondary-border: #D4DBE4;
    --btn-icon-bg: #F1F4F9;
    --btn-icon-border: #E2E8F0;
    --btn-icon-text: #64748B;
    --scrollbar-thumb: #CBD5E1;
    --scrollbar-thumb-hover: #94A3B8;
    --scrollbar-track: transparent;
    --alert-text: #475569;
    --progress-track: #E8ECF2;
    --divider: #EDF1F6;
    --card-border: #E8ECF2;
    --stripe: rgba(15, 23, 42, 0.028);   /* zebra striping for tables/lists */

    /* Legacy dark-era surface aliases — map to theme surfaces so they flip. */
    --bc-dark:  var(--bg-surface-1);
    --bc-dark2: var(--bg-surface-2);
    --bc-dark3: var(--bg-surface-3);
}

/*
 * OS-PREFERENCE AUTO-SWITCH — intentionally left disabled.
 *
 * Light is the app default; users flip to dark with the topbar toggle, which
 * persists in localStorage ("brisk-theme") and is applied via data-theme on
 * <html>. We deliberately do NOT auto-switch from the OS prefers-color-scheme
 * so the toggle stays the single source of truth. The media query below is
 * kept, commented, for reference only.
 *
 * @media (prefers-color-scheme: light) {
 *     :root {
 *         --bg-main: #F9FAFB;
 *         --bg-surface-1: #FFFFFF;
 *         --bg-surface-2: #F3F4F6;
 *         --bg-surface-3: #E5E7EB;
 *         --text-primary: #111827;
 *         --text-secondary: #4B5563;
 *         --text-muted: #9CA3AF;
 *         --border-subtle: #E5E7EB;
 *         --border-medium: #D1D5DB;
 *         --border-orange: rgba(232, 101, 10, 0.2);
 *         --border-blue: rgba(26, 159, 224, 0.2);
 *         --input-bg: #FFFFFF;
 *         --input-border: #D1D5DB;
 *         --input-placeholder: #9CA3AF;
 *         --btn-secondary-bg: #F3F4F6;
 *         --btn-secondary-text: #374151;
 *         --btn-secondary-border: #D1D5DB;
 *         --btn-icon-bg: #F3F4F6;
 *         --btn-icon-border: #E5E7EB;
 *         --btn-icon-text: #6B7280;
 *         --scrollbar-thumb: #D1D5DB;
 *         --scrollbar-thumb-hover: #9CA3AF;
 *         --scrollbar-track: transparent;
 *         --alert-text: #6B7280;
 *         --progress-track: #E5E7EB;
 *         --divider: #F3F4F6;
 *         --card-border: #E5E7EB;
 *     }
 * }
 */

/* Allow manual theme override via data-theme attribute */
[data-theme="dark"] {
    --bg-main: #0A0F1A;
    --bg-surface-1: #0A0F1A;
    --bg-surface-2: #111827;
    --bg-surface-3: #1C2535;
    --text-primary: rgba(255, 255, 255, 0.85);
    --text-secondary: rgba(255, 255, 255, 0.5);
    --text-muted: rgba(255, 255, 255, 0.3);
    --border-subtle: rgba(255, 255, 255, 0.07);
    --border-medium: rgba(255, 255, 255, 0.12);
    --border-orange: rgba(232, 101, 10, 0.3);
    --border-blue: rgba(26, 159, 224, 0.3);
    --input-bg: rgba(255, 255, 255, 0.06);
    --input-border: rgba(255, 255, 255, 0.1);
    --input-placeholder: rgba(255, 255, 255, 0.3);
    --btn-secondary-bg: rgba(255, 255, 255, 0.06);
    --btn-secondary-text: rgba(255, 255, 255, 0.65);
    --btn-secondary-border: rgba(255, 255, 255, 0.1);
    --btn-icon-bg: rgba(255, 255, 255, 0.05);
    --btn-icon-border: rgba(255, 255, 255, 0.08);
    --btn-icon-text: rgba(255, 255, 255, 0.5);
    --scrollbar-thumb: rgba(255, 255, 255, 0.1);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.18);
    --scrollbar-track: transparent;
    --alert-text: rgba(255, 255, 255, 0.55);
    --progress-track: rgba(255, 255, 255, 0.08);
    --divider: rgba(255, 255, 255, 0.06);
    --card-border: rgba(255, 255, 255, 0.07);
    --stripe: rgba(255, 255, 255, 0.03);
}

/* Explicit light selection (set when a user toggles back from dark). Mirrors
   the :root default so both paths land on the same bright palette. */
[data-theme="light"] {
    color-scheme: light;
    --bg-main: #F8F8F0;
    --bg-surface-1: #FFFFFF;
    --bg-surface-2: #FFFFFF;
    --bg-surface-3: #EEF2F7;
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --border-subtle: #E8ECF2;
    --border-medium: #D4DBE4;
    --border-orange: rgba(232, 101, 10, 0.25);
    --border-blue: rgba(26, 159, 224, 0.25);
    --input-bg: #FFFFFF;
    --input-border: #D4DBE4;
    --input-placeholder: #94A3B8;
    --btn-secondary-bg: #FFFFFF;
    --btn-secondary-text: #334155;
    --btn-secondary-border: #D4DBE4;
    --btn-icon-bg: #F1F4F9;
    --btn-icon-border: #E2E8F0;
    --btn-icon-text: #64748B;
    --scrollbar-thumb: #CBD5E1;
    --scrollbar-thumb-hover: #94A3B8;
    --scrollbar-track: transparent;
    --alert-text: #475569;
    --progress-track: #E8ECF2;
    --divider: #EDF1F6;
    --card-border: #E8ECF2;
    --stripe: rgba(15, 23, 42, 0.028);
}

/* ── Sidebar (locked to dark navy in BOTH themes) ──
   Every semantic token is remapped to a persistent-dark value here, so the
   whole subtree renders dark regardless of the page theme. Custom properties
   cascade to descendants, so nav items, the logo, etc. all inherit these.
   `color` is pinned too as a safety net for inherited text colour.
   The TOPBAR is intentionally NOT in this rule — it follows the theme and is
   white in light mode. */
.app-sidebar {
    background-color: var(--pd-bg) !important;
    color: var(--pd-text);
    color-scheme: dark;
    --bg-main: var(--pd-bg);
    --bg-surface-1: var(--pd-bg);
    --bg-surface-2: var(--pd-bg);
    --bg-surface-3: var(--pd-bg-alt);
    --border-subtle: var(--pd-border);
    --border-medium: var(--pd-border);
    --card-border: var(--pd-border);
    --text-primary: var(--pd-text);
    --text-secondary: var(--pd-text-secondary);
    --text-muted: var(--pd-text-muted);
    --btn-icon-bg: var(--pd-btn-bg);
    --btn-icon-border: var(--pd-btn-border);
    --btn-icon-text: var(--pd-btn-text);
    --btn-secondary-bg: var(--pd-btn-bg);
    --btn-secondary-text: var(--pd-text-secondary);
    --btn-secondary-border: var(--pd-btn-border);
    --divider: var(--pd-divider);
    --input-bg: var(--pd-input-bg);
    --input-border: var(--pd-input-border);
    --input-placeholder: var(--pd-text-muted);
}

/* ── Card primitives (GLOBAL) ──
   These are global (not scoped to the <x-ui.card> component's own <style>) so
   that pages using raw `.bc-card` markup — e.g. the user-edit page — get the
   correct structure and padding too. Without this, such pages rendered cards
   with no header/body padding (content hugging the edges). */
.bc-card {
    background: var(--bg-surface-3);
    border: 0.5px solid var(--card-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.bc-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 0.5px solid var(--divider);
}
.bc-card-title  { font-size: 13px; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; }
.bc-card-action { font-size: 11px; color: var(--bc-blue-light); text-decoration: none; transition: color 0.15s; }
.bc-card-action:hover { color: var(--bc-blue); }
.bc-card-body   { padding: 18px 20px; }
.bc-card-footer { padding: 14px 20px; border-top: 0.5px solid var(--divider); }

/* Light mode: card panels are WHITE and lift off the warm canvas with a soft
   shadow. (Their base token is --bg-surface-3, which is a subtle grey reused
   for chips/fills/hovers — so we whiten the card roots specifically rather than
   the token.) Dark mode stays flat with its raised dark surface. */
:root:not([data-theme="dark"]) .bc-card,
:root:not([data-theme="dark"]) .stat-card,
:root:not([data-theme="dark"]) .admin-stat-tile,
:root:not([data-theme="dark"]) .announce-card,
:root:not([data-theme="dark"]) .staff-card {
    background: #FFFFFF;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 2px 6px rgba(15, 23, 42, 0.05);
}

/* The light content canvas is a solid warm ivory (--bg-main: #F8F8F0); white
   cards lift off it. No per-element override needed — .app-main already paints
   var(--bg-main), which is ivory in light and dark navy-black in dark. */

/* Zebra striping for tables and list views (both themes via --stripe).
   The data-table's .adt-row:hover (higher specificity) still wins on hover.
   For the resources list, the stripe sits on the .doc-row-link anchor and
   shows through the transparent .doc-row, so .doc-row:hover still covers it. */
tbody tr:nth-child(even)          { background: var(--stripe); }
.lr-row:nth-child(even)           { background: var(--stripe); }
.doc-row-link:nth-child(even)     { background: var(--stripe); }

.sidebar-user-name { color: var(--pd-text-secondary) !important; }
.sidebar-user-role { color: var(--pd-text-muted) !important; }

/* ── Anti-flicker ── */
[x-cloak] { display: none !important; }

/* Desktop: sidebar always visible, no transition on first paint */
.app-sidebar {
    transition: none;
}
/* Re-enable transition after Alpine loads */
.alpine-ready .app-sidebar {
    transition: transform 0.25s ease, width 0.25s ease, min-width 0.25s ease;
}

/* Mobile: hide sidebar off-screen before Alpine touches it */
@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
        transform: translateX(-100%);
        z-index: 100;
    }
    .app-sidebar:not(.sidebar-collapsed) {
        transform: translateX(0);
    }
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-sans);
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── Scrollbar ── */
::-webkit-scrollbar               { width: 4px; height: 4px; }
::-webkit-scrollbar-track         { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb         { background: var(--scrollbar-thumb); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover   { background: var(--scrollbar-thumb-hover); }

/* ── Typography helpers ── */
.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary);  }
.text-muted     { color: var(--text-muted);  }
.text-orange    { color: var(--bc-orange-light); }
.text-blue      { color: var(--bc-blue-light);   }
.text-gold      { color: var(--bc-gold);         }
.text-green     { color: var(--bc-green);        }

/* ── Surface helpers ── */
.surface-1 { background: var(--bg-surface-1);  }
.surface-2 { background: var(--bg-surface-2); }
.surface-3 { background: var(--bg-surface-3); }

/* ── Border helpers ── */
.border-subtle  { border: 0.5px solid var(--border-subtle); }
.border-medium  { border: 0.5px solid var(--border-medium); }
.border-orange  { border-color: var(--border-orange);          }
.border-blue    { border-color: var(--border-blue);           }

/* ── Focus ring ── */
:focus-visible {
    outline: 2px solid var(--bc-blue);
    outline-offset: 2px;
}

/* ── Transition default ── */
.transition { transition: all 0.15s ease; }

/* ── Progress bar ── */
.progress-track {
    background: var(--progress-track);
    border-radius: var(--radius-sm);
    height: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 4px;
    border-radius: var(--radius-sm);
    background: var(--bc-orange);
    transition: width 0.4s ease;
}
.progress-fill.blue { background: var(--bc-blue); }

/* ── Badge ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 500;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
}
.badge-orange { background: var(--bc-orange-subtle2); color: var(--bc-orange-light); }
.badge-blue   { background: var(--bc-blue-subtle);    color: var(--bc-blue-light);   }
.badge-gold   { background: rgba(244,166,35,0.15);     color: var(--bc-gold);         }
.badge-green  { background: rgba(62,207,142,0.12);     color: var(--bc-green);        }

/* ── Divider ── */
.divider { height: 0.5px; background: var(--divider); }

/* ── Card base ── */
.card {
    background: var(--bg-surface-3);
    border: 0.5px solid var(--card-border);
    border-radius: var(--radius-lg);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* ── Button base ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--bc-orange);
    color: #fff;
    padding: 8px 16px;
}
.btn-primary:hover { background: var(--bc-orange-light); }

.btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border: 0.5px solid var(--btn-secondary-border);
    padding: 8px 16px;
    transition: all 0.15s ease;
}
.btn-secondary:hover { 
    background: var(--bg-surface-2); 
    color: var(--text-primary);
}

.btn-blue {
    background: var(--bc-blue-dark);
    color: #fff;
    padding: 8px 16px;
}
.btn-blue:hover { background: var(--bc-blue); }

.btn-ghost {
    background: transparent;
    color: var(--bc-blue-light);
    padding: 6px 10px;
    font-size: 11px;
}
.btn-ghost:hover { color: var(--bc-blue); }

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    background: var(--btn-icon-bg);
    border: 0.5px solid var(--btn-icon-border);
    color: var(--btn-icon-text);
    border-radius: var(--radius-md);
    font-size: 15px;
    transition: all 0.15s ease;
}
.btn-icon:hover { 
    background: var(--bg-surface-2); 
    color: var(--text-primary);
}

/* ── Form inputs ── */
.input {
    background: var(--input-bg);
    border: 0.5px solid var(--input-border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    width: 100%;
    transition: border-color 0.15s, background-color 0.15s;
}
.input::placeholder { color: var(--input-placeholder); }
.input:focus {
    outline: none;
    border-color: var(--bc-blue);
    background: var(--bg-surface-1);
}

/* ── Alert strip ── */
.alert-strip {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 11px;
    color: var(--alert-text);
    line-height: 1.5;
    transition: all 0.3s ease;
}
.alert-strip strong { font-weight: 500; }
.alert-strip.orange {
    background: linear-gradient(90deg, rgba(232,101,10,0.12), rgba(26,159,224,0.06));
    border: 0.5px solid rgba(232,101,10,0.2);
}
.alert-strip.orange strong { color: var(--bc-orange-light); }
.alert-strip.blue {
    background: rgba(26,159,224,0.08);
    border: 0.5px solid rgba(26,159,224,0.2);
}
.alert-strip.blue strong { color: var(--bc-blue-light); }

/* ── Locked state overlay ── */
.locked {
    position: relative;
    opacity: 0.45;
    pointer-events: none;
}
.locked::after {
    content: '🔒';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
}

/* ── Avatar ── */
.avatar {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    color: #fff;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--bc-blue-dark), var(--bc-blue));
}
.avatar-sm  { width: 24px; height: 24px; font-size: 9px;  }
.avatar-md  { width: 30px; height: 30px; font-size: 11px; }
.avatar-lg  { width: 40px; height: 40px; font-size: 14px; }

/* ── Global loading feedback ──────────────────────────────────────
   A thin top bar shown while the browser navigates or submits a form
   (server-rendered app → otherwise the wait has no feedback), plus a
   spinner state for submit buttons. Driven by partials/loading-indicator. */
#app-progress {
    position: fixed;
    top: 0; left: 0;
    height: 3px;
    width: 0;
    z-index: 10000;
    background: linear-gradient(90deg, var(--bc-orange), var(--bc-gold));
    box-shadow: 0 0 8px rgba(232, 101, 10, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: width 0.2s ease, opacity 0.3s ease;
}
#app-progress.is-visible { opacity: 1; }

@keyframes btn-spin { to { transform: rotate(360deg); } }
.btn.is-loading {
    color: transparent !important;   /* hides label + tabler icon glyph */
    pointer-events: none;
    position: relative;
}
.btn.is-loading::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 14px; height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}
