/* ============================================================
   SCLS Base — Reset, Typography, Global Styles
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Alexandria:wght@300;400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500&display=swap');

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

html {
    direction: rtl;
    text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    font-size: var(--text-base);
    font-weight: var(--weight-normal);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--surface-1);
    min-height: 100vh;
    overflow-x: hidden;
}

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
}

input, button, textarea, select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

a {
    color: var(--text-link);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--brand-primary-dark);
}

ul, ol {
    list-style: none;
}

table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* --- Selection --- */
::selection {
    background-color: var(--brand-primary-light);
    color: var(--text-inverse);
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

/* --- Focus --- */
:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
    font-weight: var(--weight-bold);
    line-height: var(--leading-tight);
    color: var(--text-primary);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-md); }

p {
    margin-bottom: var(--space-4);
    color: var(--text-secondary);
}

p:last-child {
    margin-bottom: 0;
}

small {
    font-size: var(--text-sm);
}

strong, b {
    font-weight: var(--weight-semibold);
}

code, kbd, pre {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

code {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: var(--radius-xs);
}

hr {
    border: none;
    border-top: 1px solid var(--border-default);
    margin: var(--space-6) 0;
}

/* --- Text Utilities --- */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.text-4xl { font-size: var(--text-4xl); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-brand { color: var(--brand-primary); }
.text-success { color: var(--status-success); }
.text-warning { color: var(--status-warning); }
.text-danger { color: var(--status-danger); }

.font-normal { font-weight: var(--weight-normal); }
.font-medium { font-weight: var(--weight-medium); }
.font-semibold { font-weight: var(--weight-semibold); }
.font-bold { font-weight: var(--weight-bold); }

.text-center { text-align: center; }
.text-start { text-align: start; }
.text-end { text-align: end; }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* --- Spacing Utilities --- */
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

/* --- Flex Utilities --- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }

/* --- Grid Utilities --- */
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* --- Display --- */
.hidden { display: none; }
.block { display: block; }
.inline-block { display: inline-block; }
.inline-flex { display: inline-flex; }

/* --- Misc --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.relative { position: relative; }
.overflow-hidden { overflow: hidden; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.rounded-full { border-radius: var(--radius-full); }

/* =====================
   Legacy Utility Aliases
   (maps simple class names to design-system tokens)
   ===================== */
.card { background: var(--surface-card); border-radius: var(--radius-lg); border: 1px solid var(--border-default); box-shadow: var(--shadow-xs); }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-subtle); }
.card-header h2 { font-size: var(--text-base); font-weight: 600; margin: 0; }
.card-body { padding: var(--space-4) var(--space-5); }

.btn { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); font-family: inherit; font-size: var(--text-sm); font-weight: 500; border: 1px solid transparent; cursor: pointer; transition: all var(--transition-normal); text-decoration: none; }
.btn-primary { background: var(--brand-primary); color: var(--text-inverse); }
.btn-primary:hover { background: var(--brand-primary-dark); }
.btn-outline { background: transparent; border-color: var(--border-default); color: var(--text-secondary); }
.btn-outline:hover { background: var(--surface-2); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-danger { background: var(--status-danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: var(--radius-sm); font-size: var(--text-xs); font-weight: 500; }
.badge-green { background: var(--status-success-bg); color: #065F46; }
.badge-blue { background: var(--status-info-bg); color: #1E40AF; }
.badge-gray { background: var(--surface-2); color: var(--text-secondary); }
.badge-red { background: var(--status-danger-bg); color: #991B1B; }
.badge-amber { background: var(--status-warning-bg); color: #92400E; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-6); }
.page-header h1 { font-size: var(--text-xl); font-weight: 700; margin: 0; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); }
.stat-card { background: var(--surface-card); border-radius: var(--radius-lg); border: 1px solid var(--border-default); padding: var(--space-5); display: flex; align-items: center; gap: var(--space-4); box-shadow: var(--shadow-xs); }
.stat-icon { width: 44px; height: 44px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff; }
.stat-icon.bg-blue { background: var(--status-info); }
.stat-icon.bg-green { background: var(--status-success); }
.stat-icon.bg-purple { background: var(--brand-secondary); }
.stat-icon.bg-amber { background: var(--status-warning); }
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: var(--text-2xl); font-weight: 700; line-height: 1.2; }
.stat-label { font-size: var(--text-sm); color: var(--text-secondary); }

.scores-grid { display: grid; gap: var(--space-3); }
.score-bar-item .score-bar-header { display: flex; justify-content: space-between; margin-bottom: var(--space-1); font-size: var(--text-sm); }
.progress-bar { height: 6px; background: var(--surface-2); border-radius: var(--radius-full); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--radius-full); transition: width 600ms var(--ease-out); }

.session-item { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) 0; border-bottom: 1px solid var(--border-subtle); }
.session-item:last-child { border-bottom: none; }
.session-info { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.session-code { font-size: var(--text-sm); color: var(--text-secondary); }

.lesson-item { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) 0; border-bottom: 1px solid var(--border-subtle); }
.lesson-item:last-child { border-bottom: none; }
.lesson-info { display: flex; flex-direction: column; gap: 2px; }
.lesson-meta { display: flex; align-items: center; gap: var(--space-3); }

.empty-state { text-align: center; padding: var(--space-8) var(--space-4); color: var(--text-tertiary); }
.empty-state i { font-size: 2.5rem; margin-bottom: var(--space-3); display: block; opacity: 0.3; }
.empty-state p { margin-bottom: var(--space-4); }

.text-muted { color: var(--text-secondary); font-size: var(--text-sm); }
.mt-6 { margin-top: var(--space-6); }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.form-grid .full-width { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: var(--space-1); }
.form-group label { font-size: var(--text-sm); font-weight: 500; color: var(--text-primary); }
.form-input, .form-select, .form-textarea {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--text-sm);
    background: var(--surface-0);
    transition: border-color var(--transition-fast);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.1);
}
.form-textarea { resize: vertical; min-height: 60px; }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-3); }
.template-option { cursor: pointer; }
.template-option input[type="radio"] { display: none; }
.template-card { padding: var(--space-3); border: 2px solid var(--border-default); border-radius: var(--radius-md); text-align: center; transition: all var(--transition-fast); }
.template-card span { display: block; font-size: var(--text-sm); font-weight: 500; margin-top: var(--space-1); }
.template-card small { display: block; font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 2px; }
.template-option input:checked + .template-card { border-color: var(--brand-primary); background: rgba(13, 148, 136, 0.04); }
.template-card:hover { border-color: var(--brand-primary-light); }

/* Page-level layout utilities */
.filters-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.search-form { display: flex; gap: var(--space-2); }
.search-form .form-input { min-width: 220px; }
.filter-tabs { display: flex; gap: var(--space-1); }
.tab { padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: 500; color: var(--text-secondary); text-decoration: none; transition: all var(--transition-fast); }
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--brand-primary); color: #fff; }

.lessons-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-4); }
.lesson-card { background: var(--surface-card); border: 1px solid var(--border-default); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); transition: box-shadow var(--transition-fast); overflow: hidden; }
.lesson-card:hover { box-shadow: var(--shadow-md); }
.lesson-card-header { display: flex; align-items: flex-start; justify-content: space-between; padding: var(--space-4) var(--space-4) 0; }
.lesson-card-header h3 { font-size: var(--text-base); font-weight: 600; margin: 0; }
.lesson-card-body { padding: var(--space-3) var(--space-4); }
.lesson-meta-row { display: flex; gap: var(--space-4); font-size: var(--text-xs); color: var(--text-secondary); }
.lesson-meta-row i { margin-inline-end: 4px; }
.lesson-outcome { font-size: var(--text-sm); color: var(--text-secondary); margin-top: var(--space-2); line-height: 1.6; }
.lesson-card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding: 0 var(--space-4) var(--space-3); }
.lesson-card-delete-form { display: inline; margin: 0; }
.lesson-card-footer { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-subtle); }
