/**
 * Materiality Design System — Shared CSS
 *
 * @ui @design-system @shared @css-variables @dark-theme @responsive
 *
 * Centralized styles for all admin pages. Provides:
 * - CSS custom properties (light + dark themes)
 * - Base reset and typography
 * - Component classes (buttons, cards, tables, modals, badges, forms)
 * - Responsive breakpoints (1024px, 768px, 480px)
 *
 * Load BEFORE any page-specific styles:
 *   <link rel="stylesheet" href="/shared.css">
 *
 * See Also: nav_header.js (nav component styles live there)
 */

/* ================================================================
   1. CSS Variables — Design Tokens
   ================================================================ */

:root {
    /* Typography */
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

    /* Surfaces */
    --bg: #f4f3f1;
    --surface: #fff;
    --surface-hover: #fafaf9;
    --surface-raised: #fff;

    /* Borders */
    --border: #e8e6e1;
    --border-light: #f0eeeb;
    --border-focus: #667eea;

    /* Text */
    --text: #1a1816;
    --text-secondary: #6b6560;
    --text-muted: #a09a93;
    --text-inverse: #fff;

    /* Brand */
    --primary: #0071e3;
    --primary-hover: #0077ed;
    --primary-light: #eef0fd;
    --accent: #667eea;
    --accent-deep: #764ba2;

    /* Semantic */
    --success: #34c759;
    --success-hover: #30d158;
    --success-light: #dcfce7;
    --success-text: #15803d;
    --danger: #ff3b30;
    --danger-hover: #ff453a;
    --danger-light: #fee2e2;
    --danger-text: #991b1b;
    --warning: #ff9500;
    --warning-light: #fef3c7;
    --warning-text: #92400e;
    --info: #5856d6;
    --info-light: #dbeafe;
    --info-text: #1d4ed8;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(26, 24, 22, .04);
    --shadow: 0 1px 3px rgba(26, 24, 22, .06), 0 1px 2px rgba(26, 24, 22, .04);
    --shadow-md: 0 4px 12px rgba(26, 24, 22, .08), 0 1px 3px rgba(26, 24, 22, .06);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .12);

    /* Radii */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Spacing */
    --container-max: 1400px;
    --container-wide: 1600px;
    --page-padding: 20px;
}

/* ================================================================
   2. Dark Theme
   ================================================================ */

body.dark {
    --bg: #1a1a1e;
    --surface: #2a2a2e;
    --surface-hover: #333338;
    --surface-raised: #333338;
    --border: #3a3a3e;
    --border-light: #333338;
    --border-focus: #4da3ff;
    --text: #e8e6e1;
    --text-secondary: #a09a93;
    --text-muted: #6b6560;
    --primary: #4da3ff;
    --primary-hover: #6bb3ff;
    --primary-light: #1a2a3e;
    --accent: #8b9cf7;
    --accent-deep: #9b6dce;
    --success: #30d158;
    --success-light: #1a2e1a;
    --success-text: #4ade80;
    --danger: #ff453a;
    --danger-light: #2e1a1a;
    --danger-text: #fca5a5;
    --warning: #ffb340;
    --warning-light: #2e261a;
    --warning-text: #fcd34d;
    --info: #7b79f0;
    --info-light: #1a1a2e;
    --info-text: #a5b4fc;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .2);
    --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 1px 2px rgba(0, 0, 0, .2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
}

/* Dark theme overrides for elements with hardcoded backgrounds */
body.dark .mn-dropdown { background: var(--surface-raised); }
body.dark .mn-dd-item { color: var(--text); }
body.dark .mn-dd-item:hover { background: var(--surface-hover); }
body.dark .mn-dd-item.danger:hover { background: var(--danger-light); color: var(--danger-text); }
body.dark .mn-dd-divider { background: var(--border); }
body.dark .mn-modal { background: var(--surface); }
body.dark .mn-modal-header { color: var(--text); }
body.dark .mn-modal-input { background: var(--bg); border-color: var(--border); color: var(--text); }
body.dark .mn-modal-btn.secondary { background: var(--surface-hover); color: var(--text); }

/* ================================================================
   3. Reset & Base
   ================================================================ */

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

html {
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body {
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ================================================================
   4. Typography
   ================================================================ */

h1 { font-size: 26px; font-weight: 800; letter-spacing: -.03em; line-height: 1.2; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
h3 { font-size: 16px; font-weight: 600; }

.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-center { text-align: center; }
.mono { font-family: var(--mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-secondary);
}

/* ================================================================
   5. Layout
   ================================================================ */

.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: var(--page-padding);
}

.container-wide {
    max-width: var(--container-wide);
    margin: 0 auto;
    padding: var(--page-padding);
}

.page-header {
    background: var(--surface);
    padding: 20px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.action-bar {
    background: var(--surface);
    padding: 16px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: 8px; }
.gap-md { gap: 12px; }
.gap-lg { gap: 20px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ================================================================
   6. Buttons
   ================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.4;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border); }

.btn-success {
    background: var(--success);
    color: var(--text-inverse);
}
.btn-success:hover:not(:disabled) { background: var(--success-hover); }

.btn-danger {
    background: var(--danger);
    color: var(--text-inverse);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-warning {
    background: #d97706;
    color: var(--text-inverse);
}
.btn-warning:hover:not(:disabled) { background: #b45309; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-sm);
}

/* ================================================================
   7. Cards
   ================================================================ */

.card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-padded {
    padding: 20px;
}

.card-hover {
    transition: box-shadow .2s, border-color .2s, transform .2s;
    cursor: pointer;
}
.card-hover:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border);
    transform: translateY(-1px);
}
.card-hover:active {
    transform: translateY(0);
    box-shadow: var(--shadow);
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    text-align: center;
    transition: box-shadow .2s, border-color .2s;
}
.stat-card:hover { box-shadow: var(--shadow); border-color: var(--border); }

.stat-value {
    font-family: var(--mono);
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
}
.stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 8px;
}
.stat-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

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

/* ================================================================
   8. Tables
   ================================================================ */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--surface-hover);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background .15s;
}
.data-table tbody tr:hover {
    background: var(--surface-hover);
}

/* ================================================================
   9. Forms
   ================================================================ */

.input, .select, .textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: border-color .2s, box-shadow .2s;
    outline: none;
}
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, .15);
}

.textarea { resize: vertical; min-height: 80px; }

.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.search-input {
    padding-left: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a09a93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

/* ================================================================
   10. Modals (page-level, not nav modals)
   ================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    opacity: 0;
    visibility: hidden;
    transition: opacity .3s, visibility .3s;
}
.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    max-width: 800px;
    width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(.95);
    transition: transform .3s;
}
.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.modal-header h2, .modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-shrink: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--surface-hover);
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background .2s;
}
.modal-close:hover { background: var(--border); }

/* ================================================================
   11. Badges
   ================================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
}
.badge-green { background: var(--success-light); color: var(--success-text); }
.badge-red { background: var(--danger-light); color: var(--danger-text); }
.badge-yellow { background: var(--warning-light); color: var(--warning-text); }
.badge-blue { background: var(--info-light); color: var(--info-text); }
.badge-purple { background: #f3e8ff; color: #7c3aed; }
.badge-gray { background: var(--surface-hover); color: var(--text-secondary); }

/* ================================================================
   12. States
   ================================================================ */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    padding: 60px 20px;
    color: var(--text-muted);
}

.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 14px;
}
.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: .5;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    border-left: 4px solid;
}
.alert-success { background: var(--success-light); color: var(--success-text); border-color: var(--success); }
.alert-danger { background: var(--danger-light); color: var(--danger-text); border-color: var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning-text); border-color: var(--warning); }
.alert-info { background: var(--info-light); color: var(--info-text); border-color: var(--info); }

/* ================================================================
   13. Tabs
   ================================================================ */

.tab-bar {
    display: flex;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
    padding: 12px 20px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: color .2s, border-color .2s;
}
.tab-btn:hover { color: var(--text-secondary); border-bottom-color: var(--border); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ================================================================
   14. Filter Bar
   ================================================================ */

.filter-bar {
    background: var(--surface);
    padding: 12px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-bar .input, .filter-bar .select {
    flex: 1;
    min-width: 150px;
    max-width: 300px;
}

/* ================================================================
   15. Animations
   ================================================================ */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .3s ease both; }

/* ================================================================
   16. Responsive
   ================================================================ */

/* Tablet */
@media (max-width: 1024px) {
    :root { --page-padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .action-bar { gap: 8px; }
    h1 { font-size: 22px; }
}

/* Phone landscape / small tablet */
@media (max-width: 768px) {
    :root { --page-padding: 12px; }
    .modal { max-width: 95vw; max-height: 95vh; border-radius: var(--radius); }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .input, .filter-bar .select { max-width: none; }
    .hide-mobile { display: none !important; }
    .action-bar { flex-direction: column; align-items: stretch; }
    .action-bar .btn { width: 100%; }
    .page-header h1 { font-size: 20px; }
    .stat-value { font-size: 22px; }
}

/* Phone portrait */
@media (max-width: 480px) {
    .container, .container-wide { padding: 8px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .modal {
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        width: 100vw;
        height: 100vh;
    }
    .modal-header { padding: 16px; }
    .modal-body { padding: 16px; }
    .page-header { padding: 16px; border-radius: var(--radius-sm); }
    .btn { padding: 12px 16px; font-size: 13px; }
    .data-table th, .data-table td { padding: 8px 10px; font-size: 12px; }
}

/* ================================================================
   17. Font Import
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap');
