/* ============================================================
   Read N Brew — Enterprise UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,300;0,14..32,400;0,14..32,500;0,14..32,600;0,14..32,700;0,14..32,800;0,14..32,900&display=swap');

:root {
    --bg:         #f0f2f5;
    --bg2:        #ffffff;
    --bg3:        #e8ecf2;
    --border:     #d1d9e6;
    --text:       #0d1117;
    --text2:      #374151;
    --text3:      #6b7280;
    --brand:      #c8860a;
    --brand-lt:   #fef3c7;
    --brand-dk:   #92400e;
    --sidebar:    #111827;
    --sidebar2:   #1f2937;
    --sidebar3:   #374151;
    --shadow-xs:  0 1px 2px rgba(0,0,0,0.07);
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md:  0 4px 8px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg:  0 12px 24px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.08);
    --r-sm:  0.5rem;
    --r-md:  0.75rem;
    --r-lg:  1rem;
    --r-xl:  1.25rem;
    --r-2xl: 1.5rem;
}

html.dark {
    --bg:         #0d1117;
    --bg2:        #161b22;
    --bg3:        #21262d;
    --border:     #30363d;
    --text:       #e6edf3;
    --text2:      #8b949e;
    --text3:      #484f58;
    --brand:      #d97706;
    --brand-lt:   rgba(217,119,6,0.12);
    --sidebar:    #010409;
    --sidebar2:   #0d1117;
    --sidebar3:   #161b22;
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
    --shadow-md:  0 4px 8px rgba(0,0,0,0.5);
    --shadow-lg:  0 12px 24px rgba(0,0,0,0.6);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: background 0.2s, color 0.15s;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Transitions (selective — not on all) ──────────────────── */
a, button, input, select, textarea,
.bg-white, .bg-slate-50, .bg-slate-100,
aside, main { transition: background-color 0.2s, border-color 0.2s, color 0.15s; }

/* ── Dark mode overrides ───────────────────────────────────── */
html.dark .bg-white        { background: var(--bg2) !important; }
html.dark .bg-slate-50     { background: var(--bg)  !important; }
html.dark .bg-slate-100    { background: var(--bg3) !important; }
html.dark .bg-slate-200    { background: var(--bg3) !important; }
html.dark .text-slate-800  { color: var(--text)  !important; }
html.dark .text-slate-700  { color: var(--text)  !important; }
html.dark .text-slate-600  { color: var(--text2) !important; }
html.dark .text-slate-500  { color: var(--text2) !important; }
html.dark .text-slate-400  { color: var(--text3) !important; }
html.dark .border-slate-100,
html.dark .border-slate-200 { border-color: var(--border) !important; }
html.dark .divide-slate-100 > * + * { border-color: var(--border) !important; }
html.dark thead  { background: #010409 !important; }
html.dark tbody tr:hover { background: var(--bg3) !important; }
html.dark input, html.dark select, html.dark textarea {
    background: var(--bg3) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}
html.dark input::placeholder,
html.dark textarea::placeholder { color: var(--text3) !important; }

/* ── Light mode: ensure Tailwind text classes are readable ─── */
html:not(.dark) .text-slate-400 { color: #6b7280 !important; }
html:not(.dark) .text-slate-500 { color: #4b5563 !important; }
html:not(.dark) .text-slate-600 { color: #374151 !important; }
html:not(.dark) .text-slate-700 { color: #1f2937 !important; }
html:not(.dark) .text-slate-800 { color: #0f172a !important; }
html:not(.dark) .text-amber-600 { color: #b45309 !important; }
html:not(.dark) .text-amber-700 { color: #92400e !important; }
html:not(.dark) .text-yellow-600 { color: #854d0e !important; }
html:not(.dark) .text-yellow-700 { color: #713f12 !important; }
html:not(.dark) .text-green-600  { color: #15803d !important; }
html:not(.dark) .text-green-700  { color: #14532d !important; }
html:not(.dark) .text-blue-600   { color: #1d4ed8 !important; }
html:not(.dark) .text-blue-700   { color: #1e3a8a !important; }
html:not(.dark) .text-red-600    { color: #dc2626 !important; }
html:not(.dark) .text-red-700    { color: #b91c1c !important; }
html:not(.dark) .text-purple-600 { color: #7c3aed !important; }
html:not(.dark) .text-purple-700 { color: #6d28d9 !important; }

/* Light mode: bg overrides for Tailwind utility classes */
html:not(.dark) .bg-yellow-50  { background: #fefce8 !important; }
html:not(.dark) .bg-blue-50    { background: #eff6ff !important; }
html:not(.dark) .bg-green-50   { background: #f0fdf4 !important; }
html:not(.dark) .bg-red-50     { background: #fef2f2 !important; }
html:not(.dark) .bg-purple-50  { background: #faf5ff !important; }
html:not(.dark) .bg-amber-50   { background: #fffbeb !important; }

/* Light mode: border overrides */
html:not(.dark) .border-yellow-100 { border-color: #fef08a !important; }
html:not(.dark) .border-blue-100   { border-color: #bfdbfe !important; }
html:not(.dark) .border-green-100  { border-color: #bbf7d0 !important; }
html:not(.dark) .border-red-100    { border-color: #fecaca !important; }
html:not(.dark) .border-slate-100  { border-color: #e2e8f0 !important; }
html:not(.dark) .border-slate-200  { border-color: #cbd5e1 !important; }

/* Light mode: inputs */
html:not(.dark) input, html:not(.dark) select, html:not(.dark) textarea {
    color: #0d1117 !important;
}
html:not(.dark) input::placeholder,
html:not(.dark) textarea::placeholder { color: #9ca3af !important; }
aside {
    width: 220px !important;
    min-width: 220px !important;
    background: var(--sidebar) !important;
}
main {
    margin-left: 220px !important;
    width: calc(100% - 220px) !important;
    min-height: 100vh;
    padding: 1.5rem !important;
    overflow-x: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--r-md);
    font-size: 0.8125rem;
    font-weight: 500;
    color: #9ca3af;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}
.nav-item:hover { background: var(--sidebar2); color: #f9fafb; }
.nav-item.active {
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(200,134,10,0.35);
}
.nav-section {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #4b5563;
    padding: 0 0.75rem;
    margin-top: 1.25rem;
    margin-bottom: 0.375rem;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-xs);
}

/* ── Form inputs ───────────────────────────────────────────── */
.form-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 400;
    outline: none;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(200,134,10,0.12);
    background: var(--bg2);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: var(--r-md);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
    font-family: inherit;
    text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 1px 3px rgba(200,134,10,0.3);
}
.btn-primary:hover { background: #b07709; box-shadow: 0 3px 8px rgba(200,134,10,0.4); }
.btn-secondary {
    background: var(--bg2);
    color: var(--text2);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--bg3); color: var(--text); }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-sm { padding: 0.3rem 0.625rem; font-size: 0.75rem; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.badge-green  { background: #dcfce7; color: #14532d; }
.badge-red    { background: #fee2e2; color: #7f1d1d; }
.badge-yellow { background: #fef9c3; color: #713f12; }
.badge-blue   { background: #dbeafe; color: #1e3a8a; }
.badge-orange { background: #ffedd5; color: #7c2d12; }
.badge-gray   { background: var(--bg3); color: var(--text2); }
html.dark .badge-green  { background: rgba(22,163,74,0.15);  color: #86efac; }
html.dark .badge-red    { background: rgba(220,38,38,0.15);  color: #fca5a5; }
html.dark .badge-yellow { background: rgba(234,179,8,0.15);  color: #fde047; }
html.dark .badge-blue   { background: rgba(37,99,235,0.15);  color: #93c5fd; }
html.dark .badge-orange { background: rgba(234,88,12,0.15);  color: #fdba74; }
html.dark .badge-gray   { background: var(--bg3); color: var(--text2); }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    border-radius: var(--r-md);
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid;
}
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
html.dark .alert-success { background: rgba(22,163,74,0.08);  border-color: rgba(22,163,74,0.25);  color: #86efac; }
html.dark .alert-error   { background: rgba(220,38,38,0.08);  border-color: rgba(220,38,38,0.25);  color: #fca5a5; }
html.dark .alert-info    { background: rgba(37,99,235,0.08);  border-color: rgba(37,99,235,0.25);  color: #93c5fd; }
html.dark .alert-warning { background: rgba(245,158,11,0.08); border-color: rgba(245,158,11,0.25); color: #fcd34d; }

/* ── Tables ────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.tbl th {
    background: #1e293b;
    color: #e2e8f0;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.625rem 0.875rem;
    text-align: left;
    white-space: nowrap;
}
.tbl td { padding: 0.625rem 0.875rem; border-bottom: 1px solid var(--border); color: var(--text); }
.tbl tbody tr:hover { background: var(--bg3); }
.tbl tbody tr:last-child td { border-bottom: none; }

/* Light mode: use a softer dark header */
html:not(.dark) .tbl th {
    background: #1e293b;
    color: #f1f5f9;
}
html.dark .tbl th { background: #010409; color: #6b7280; }

/* ── Page header ───────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.page-title    { font-size: 1.125rem; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 0.75rem; color: var(--text3); margin-top: 0.125rem; }
html:not(.dark) .page-subtitle { color: #6b7280; }

/* ── Sidebar overlay ───────────────────────────────────────── */
#sidebarOverlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
}
#sidebarOverlay.active { display: block; }

/* ── Mobile ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    aside {
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
        z-index: 50;
    }
    aside.open { transform: translateX(0); }
    main {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem !important;
        padding-top: 4rem !important;
    }
    .mobile-header { display: flex !important; }
    .hide-mobile { display: none !important; }
}
@media (min-width: 769px) {
    .mobile-header { display: none !important; }
}

/* ── Print ─────────────────────────────────────────────────── */
@media print {
    aside, .no-print { display: none !important; }
    main { margin-left: 0 !important; padding: 0 !important; width: 100% !important; }
    body { background: white !important; color: black !important; font-size: 11px; }
}

/* ── Animations ────────────────────────────────────────────── */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeUp 0.25s ease forwards; }

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(6px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-in { animation: modalIn 0.2s ease forwards; }

/* ── Chart toggle buttons ──────────────────────────────────── */
.chart-btn { color: var(--text2); background: transparent; }
.active-btn { background: var(--brand) !important; color: #fff !important; box-shadow: 0 1px 4px rgba(200,134,10,0.3); }

/* ============================================================
   LIGHT MODE — Global inline-style color overrides
   These target the hardcoded hex colors used in inline styles
   across all pages so they render with proper contrast.
   ============================================================ */

/* Force body text color in light mode */
html:not(.dark) body {
    color: #0d1117 !important;
}

/* Any element using the common muted greys — make them readable */
html:not(.dark) [style*="color:#6b7280"],
html:not(.dark) [style*="color: #6b7280"] {
    color: #374151 !important;
}
html:not(.dark) [style*="color:#9ca3af"],
html:not(.dark) [style*="color: #9ca3af"] {
    color: #4b5563 !important;
}
html:not(.dark) [style*="color:#4b5563"],
html:not(.dark) [style*="color: #4b5563"] {
    color: #1f2937 !important;
}
html:not(.dark) [style*="color:#8b949e"],
html:not(.dark) [style*="color: #8b949e"] {
    color: #374151 !important;
}
html:not(.dark) [style*="color:#484f58"],
html:not(.dark) [style*="color: #484f58"] {
    color: #4b5563 !important;
}
html:not(.dark) [style*="color:#e6edf3"],
html:not(.dark) [style*="color: #e6edf3"] {
    color: #0d1117 !important;
}
html:not(.dark) [style*="color:#f0f6fc"],
html:not(.dark) [style*="color: #f0f6fc"] {
    color: #0d1117 !important;
}
html:not(.dark) [style*="color:#f9fafb"],
html:not(.dark) [style*="color: #f9fafb"] {
    color: #0d1117 !important;
}
html:not(.dark) [style*="color:#e2e8f0"],
html:not(.dark) [style*="color: #e2e8f0"] {
    color: #1f2937 !important;
}

/* Background overrides — dark backgrounds become light in light mode */
html:not(.dark) [style*="background:#0d1117"],
html:not(.dark) [style*="background: #0d1117"] {
    background: #f0f2f5 !important;
}
html:not(.dark) [style*="background:#161b22"],
html:not(.dark) [style*="background: #161b22"] {
    background: #ffffff !important;
}
html:not(.dark) [style*="background:#21262d"],
html:not(.dark) [style*="background: #21262d"] {
    background: #e8ecf2 !important;
}
html:not(.dark) [style*="background:#111827"],
html:not(.dark) [style*="background: #111827"] {
    background: #1e293b !important;
}
html:not(.dark) [style*="background:#1f2937"],
html:not(.dark) [style*="background: #1f2937"] {
    background: #e8ecf2 !important;
}
html:not(.dark) [style*="background:#30363d"],
html:not(.dark) [style*="background: #30363d"] {
    background: #d1d9e6 !important;
}

/* Border overrides */
html:not(.dark) [style*="border-color:#30363d"],
html:not(.dark) [style*="border-color: #30363d"] {
    border-color: #d1d9e6 !important;
}
html:not(.dark) [style*="border:1px solid #30363d"],
html:not(.dark) [style*="border: 1px solid #30363d"] {
    border-color: #d1d9e6 !important;
}
html:not(.dark) [style*="border-bottom:1px solid #21262d"],
html:not(.dark) [style*="border-bottom: 1px solid #21262d"] {
    border-bottom-color: #d1d9e6 !important;
}
html:not(.dark) [style*="border-top:1px solid #21262d"],
html:not(.dark) [style*="border-top: 1px solid #21262d"] {
    border-top-color: #d1d9e6 !important;
}

/* var(--text3) used in inline styles via PHP echo — already handled by :root */
/* But also catch the dashboard's hardcoded dark-mode specific colors */
html:not(.dark) p[style*="color:#6b7280"],
html:not(.dark) span[style*="color:#6b7280"],
html:not(.dark) div[style*="color:#6b7280"] {
    color: #374151 !important;
}

/* ── Light mode: catch-all for any remaining dark-theme text ─ */
/* These are the most common hardcoded colors from dark-mode inline styles */
html:not(.dark) [style*="color:#e6edf3"] { color: #0d1117 !important; }
html:not(.dark) [style*="color:#f9fafb"] { color: #0d1117 !important; }
html:not(.dark) [style*="color:#f0f6fc"] { color: #0d1117 !important; }
html:not(.dark) [style*="color:#e2e8f0"] { color: #1f2937 !important; }
html:not(.dark) [style*="color:#d1d5db"] { color: #374151 !important; }
html:not(.dark) [style*="color:#9ca3af"] { color: #4b5563 !important; }
html:not(.dark) [style*="color:#6b7280"] { color: #374151 !important; }
html:not(.dark) [style*="color:#4b5563"] { color: #1f2937 !important; }
html:not(.dark) [style*="color:#8b949e"] { color: #374151 !important; }
html:not(.dark) [style*="color:#484f58"] { color: #4b5563 !important; }

/* Dark backgrounds used in inline styles — flip to light */
html:not(.dark) [style*="background:#0d1117"]  { background: #f0f2f5 !important; color: #0d1117 !important; }
html:not(.dark) [style*="background:#161b22"]  { background: #ffffff !important; color: #0d1117 !important; }
html:not(.dark) [style*="background:#21262d"]  { background: #e8ecf2 !important; color: #0d1117 !important; }
html:not(.dark) [style*="background:#1f2937"]  { background: #e8ecf2 !important; color: #0d1117 !important; }
html:not(.dark) [style*="background:#30363d"]  { background: #d1d9e6 !important; }

/* Borders */
html:not(.dark) [style*="border-color:#30363d"] { border-color: #d1d9e6 !important; }
html:not(.dark) [style*="1px solid #30363d"]    { border-color: #d1d9e6 !important; }
html:not(.dark) [style*="1px solid #21262d"]    { border-color: #d1d9e6 !important; }

/* ── Layout ────────────────────────────────────────────────── */