:root {
    /* Design System Variables */
    --primary: #4f46e5; /* Indigo 600 */
    --primary-hover: #4338ca; /* Indigo 700 */
    --secondary: #64748b; /* Slate 500 */
    --bg-body: #f8fafc; /* Slate 50 */
    --bg-card: #ffffff;
    --text-main: #0f172a; /* Slate 900 */
    --text-muted: #64748b; /* Slate 500 */
    --border: #e2e8f0; /* Slate 200 */
    --danger: #ef4444; /* Red 500 */
    --success: #22c55e; /* Green 500 */
    --warning: #f59e0b; /* Amber 500 */
    
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
}

/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-main);
}

a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary-hover); }

/* Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    font-size: 0.875rem;
    gap: 0.5rem;
}

.btn-primary { background-color: var(--primary); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }

.btn-secondary { background-color: var(--bg-card); border-color: var(--border); color: var(--text-main); }
.btn-secondary:hover { background-color: var(--bg-body); }

.btn-danger { background-color: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }

.btn-block { width: 100%; }

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    border: 1px solid var(--border);
}

.input-group { margin-bottom: 1rem; }
.input-group label { display: block; margin-bottom: 0.5rem; font-weight: 500; color: var(--text-main); }
.input-group input, .input-group select {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Numpad UI */
.numpad-container {
    max-width: 320px;
    margin: 0 auto;
}

.pin-display {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.pin-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--border);
    transition: background-color 0.2s;
}
.pin-dot.filled { background-color: var(--primary); }

.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.num-btn {
    aspect-ratio: 1;
    border-radius: 50%;
    background-color: white;
    border: 1px solid var(--border);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.num-btn:active { transform: scale(0.95); background-color: var(--bg-body); }
.num-btn.action-btn { font-size: 1rem; color: var(--text-muted); background-color: transparent; border-color: transparent; box-shadow: none; }
.num-btn.action-btn:hover { color: var(--text-main); background-color: var(--bg-body); }

/* Account Switcher */
.account-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.account-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.account-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.account-item.active { border-color: var(--primary); background-color: rgba(79, 70, 229, 0.05); }

.account-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    margin-right: 0.75rem;
}

.account-info { flex: 1; }
.account-name { font-weight: 600; display: block; }
.account-role { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.account-remove {
    padding: 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.account-remove:hover { color: var(--danger); background-color: rgba(239, 68, 68, 0.1); }

/* Layouts */
.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

/* Admin & Dashboard Overrides */
.admin-layout { display: flex; min-height: 100vh; }
.sidebar { width: 260px; background: #1e293b; color: white; flex-shrink: 0; }
.sidebar .brand { padding: 1.5rem; font-size: 1.25rem; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar nav { padding: 1rem 0; }
.sidebar nav a { display: block; padding: 0.75rem 1.5rem; color: #94a3b8; }
.sidebar nav a:hover, .sidebar nav a.active { color: white; background: rgba(255,255,255,0.05); }
.content { flex: 1; padding: 2rem; overflow-y: auto; background: var(--bg-body); }

/* Utilities */
.text-center { text-align: center; }
.mb-4 { margin-bottom: 1rem; }
.mt-4 { margin-top: 1rem; }
.hidden { display: none !important; }

/* Public Site Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--radius-lg);
}

header {
    background: var(--primary);
    color: white;
    padding: 1rem 0;
    box-shadow: var(--shadow-md);
}

header .header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header nav a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    margin-left: 1rem;
    font-weight: 500;
}

header nav a:hover { color: white; }

.theme-toggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin: 0 0.5rem;
    font-size: 1.2rem;
    transition: all 0.2s;
}
.theme-toggle:hover {
    background: rgba(255,255,255,0.1);
}

.intro {
    text-align: center;
    margin: 2rem 0;
    padding: 2rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.category-filters {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--primary);
    background: transparent;
    color: var(--primary);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover, .filter-btn.active {
    background: var(--primary);
    color: white;
}

.courses-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.course-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

.course-card:hover { transform: translateY(-5px); }

.course-header {
    padding: 1rem;
    background: var(--bg-body);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.course-body {
    padding: 1rem;
    flex: 1;
}

.course-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
    text-align: right;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Admin Tables */
.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th, .admin-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.admin-table th { font-weight: 600; color: var(--text-muted); }

/* Admin Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    text-align: center;
    border: 1px solid var(--border);
}

.stat-card h3 { font-size: 2.5rem; color: var(--primary); margin-bottom: 0.5rem; }
.stat-card.warning { border-left: 4px solid var(--warning); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

input, select, textarea {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Badges */
.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge.premiere { background: #e0f2fe; color: #0284c7; }
.badge.terminale { background: #fef3c7; color: #d97706; }
.badge-count {
    background: var(--danger);
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.75rem;
    margin-left: 5px;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-danger { background: #fee2e2; color: #991b1b; }

.inline-form { display: inline-block; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1.2rem; }

.attachment-link {
    display: block;
    font-size: 0.85rem;
    color: var(--primary);
    margin-top: 0.25rem;
    text-decoration: underline;
}
.attachment-link:hover { color: var(--primary-hover); }