/* ════════════════════════════════════════════════════
   Smart Teacher Hub — Main Stylesheet
   RTL Arabic-first design
   ════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800&display=swap');

/* ─── CSS Variables ─────────────────────────────── */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --primary-50: #eff6ff;
    --accent: #f59e0b;
    --accent-dark: #d97706;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    --bg: #f8fafc;
    --bg-card: #ffffff;
    --bg-dark: #0f172a;
    --text: #1e293b;
    --text-light: #64748b;
    --text-lighter: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.06);

    --font: 'Tajawal', sans-serif;
    --transition: all 0.2s ease;
}

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

html {
    direction: rtl;
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; display: block; }

/* ─── Container ─────────────────────────────────── */
.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.25rem;
}

.container-sm { max-width: 640px; }
.container-md { max-width: 800px; }

/* ─── Navigation ────────────────────────────────── */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background: rgba(255,255,255,0.95);
}

.navbar .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-brand span { font-size: 1.5rem; }

.navbar-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    list-style: none;
}

.navbar-links a {
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
}

.navbar-links a:hover,
.navbar-links a.active {
    background: var(--primary-50);
    color: var(--primary);
}

.navbar-links .btn-sm {
    background: var(--primary);
    color: #fff !important;
    padding: 0.5rem 1.25rem;
}

.navbar-links .btn-sm:hover {
    background: var(--primary-dark);
}

/* Mobile nav toggle */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text);
}

@media (max-width: 768px) {
    .nav-toggle { display: block; }
    .navbar-links {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        left: 0;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        padding: 1rem;
        box-shadow: var(--shadow-lg);
    }
    .navbar-links.open { display: flex; }
    .navbar-links a { width: 100%; text-align: center; padding: 0.75rem; }
}

/* ─── Buttons ───────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    line-height: 1.4;
}

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

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}
.btn-accent:hover:not(:disabled) {
    background: var(--accent-dark);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-outline:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
}

.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-light); }
.btn-ghost:hover { background: var(--border-light); color: var(--text); }

.btn-lg { padding: 1rem 2rem; font-size: 1.1rem; border-radius: var(--radius); }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.875rem; }
.btn-block { width: 100%; }

/* ─── Cards ─────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text);
}

/* ─── Forms ─────────────────────────────────────── */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text);
    font-size: 0.9rem;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: var(--font);
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    transition: var(--transition);
    direction: rtl;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-textarea {
    min-height: 180px;
    resize: vertical;
    line-height: 1.8;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-lighter);
    margin-top: 0.35rem;
}

/* ─── Alerts / Flash Messages ───────────────────── */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #93c5fd; }

/* ─── Hero Section (Landing) ────────────────────── */
.hero {
    padding: 4rem 0 3rem;
    text-align: center;
    background: linear-gradient(135deg, var(--primary-50) 0%, #fff 50%, #fefce8 100%);
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -20%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(37,99,235,0.06) 0%, transparent 70%);
    border-radius: 50%;
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    color: var(--text);
    margin-bottom: 1rem;
    line-height: 1.3;
}

.hero h1 .highlight {
    color: var(--primary);
    position: relative;
}

.hero p {
    font-size: 1.15rem;
    color: var(--text-light);
    max-width: 600px;
    margin: 0 auto 2rem;
    line-height: 1.8;
}

.hero-cta {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ─── Features Grid ─────────────────────────────── */
.features {
    padding: 3rem 0;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.feature-card {
    text-align: center;
    padding: 2rem 1.5rem;
}

.feature-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    display: block;
}

.feature-card h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.feature-card p {
    color: var(--text-light);
    font-size: 0.95rem;
    line-height: 1.7;
}

/* ─── App Page ──────────────────────────────────── */
.app-container {
    padding: 2rem 0 3rem;
}

.quota-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1.25rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.quota-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.quota-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.quota-badge.free { background: var(--primary-light); color: var(--primary); }
.quota-badge.paid { background: #d1fae5; color: #065f46; }

.quota-count {
    font-weight: 700;
    color: var(--text);
    font-size: 0.95rem;
}

.quota-count .num { color: var(--primary); font-size: 1.1rem; }

/* Mode Tabs */
.mode-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.mode-tab {
    flex: 1;
    min-width: 120px;
    padding: 0.875rem 1rem;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text);
}

.mode-tab:hover {
    border-color: var(--primary);
    background: var(--primary-50);
}

.mode-tab.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.mode-tab .tab-icon { font-size: 1.2rem; }

/* Upload Area */
.upload-area {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--border-light);
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-light);
}

.upload-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-50);
}

.upload-name {
    font-size: 0.85rem;
    color: var(--text-light);
}

/* Result Area */
.result-area {
    display: none;
    margin-top: 1.5rem;
}

.result-area.visible { display: block; }

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.result-header h3 { font-size: 1.1rem; font-weight: 700; }

.result-content {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    line-height: 2;
    font-size: 0.95rem;
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.result-content h1, .result-content h2, .result-content h3 {
    margin: 1rem 0 0.5rem;
    font-weight: 700;
}
.result-content h2 { font-size: 1.15rem; }
.result-content h3 { font-size: 1.05rem; }
.result-content ul, .result-content ol { padding-right: 1.5rem; margin: 0.5rem 0; }
.result-content li { margin-bottom: 0.35rem; }
.result-content strong { color: var(--primary-dark); }
.result-content p { margin-bottom: 0.75rem; }
.result-content hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* Loading */
.loading-overlay {
    display: none;
    text-align: center;
    padding: 3rem 1rem;
}

.loading-overlay.visible { display: block; }

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
    color: var(--text-light);
    font-weight: 500;
}

/* ─── Exhausted Modal ───────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.visible {
    display: flex;
}

.modal-box {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 460px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-box .icon { font-size: 3rem; margin-bottom: 1rem; display: block; }
.modal-box h3 { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.75rem; }
.modal-box p { color: var(--text-light); margin-bottom: 1.5rem; line-height: 1.7; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }

/* ─── Pricing ───────────────────────────────────── */
.pricing-section { padding: 3rem 0; }

.pricing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    max-width: 750px;
    margin: 0 auto;
}

.pricing-card {
    text-align: center;
    padding: 2rem;
    position: relative;
}

.pricing-card.featured {
    border-color: var(--primary);
    border-width: 2px;
    transform: scale(1.02);
}

.pricing-card .badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 0.25rem 1rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.pricing-card h3 { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.5rem; }

.pricing-price {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary);
    margin: 1rem 0;
}

.pricing-price small { font-size: 0.9rem; font-weight: 500; color: var(--text-light); }

.pricing-features {
    list-style: none;
    padding: 0;
    margin: 1.5rem 0;
    text-align: right;
}

.pricing-features li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.pricing-features li::before {
    content: '✓';
    color: var(--success);
    font-weight: 700;
}

/* ─── Account Page ──────────────────────────────── */
.account-section { padding: 2rem 0; }

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

.stat-number {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
}

/* ─── History ───────────────────────────────────── */
.history-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: var(--transition);
}

.history-item:hover { background: var(--primary-50); }
.history-item:last-child { border-bottom: none; }

.history-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.history-mode {
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--primary-light);
    color: var(--primary);
}

.history-date { color: var(--text-lighter); }
.history-preview { color: var(--text-light); font-size: 0.9rem; }

/* ─── Auth Pages ────────────────────────────────── */
.auth-page {
    padding: 3rem 0;
    display: flex;
    justify-content: center;
}

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

.auth-card h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.auth-divider {
    text-align: center;
    margin: 1.5rem 0;
    color: var(--text-lighter);
    font-size: 0.875rem;
}

/* ─── Footer ────────────────────────────────────── */
.footer {
    margin-top: auto;
    padding: 1.5rem 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-lighter);
}

.footer a { color: var(--text-light); }
.footer a:hover { color: var(--primary); }

/* ─── Utilities ─────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.hidden { display: none !important; }

/* ─── Section Titles ────────────────────────────── */
.section-title {
    text-align: center;
    margin-bottom: 2rem;
}

.section-title h2 {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.section-title p {
    color: var(--text-light);
    font-size: 1rem;
}

/* ─── Responsive ────────────────────────────────── */
@media (max-width: 768px) {
    .hero { padding: 2.5rem 0 2rem; }
    .hero h1 { font-size: 1.75rem; }
    .features-grid { grid-template-columns: 1fr; }
    .pricing-grid { grid-template-columns: 1fr; }
    .pricing-card.featured { transform: none; }
    .account-grid { grid-template-columns: 1fr; }
    .quota-bar { flex-direction: column; text-align: center; }
    .mode-tabs { flex-direction: column; }
}

/* ─── Markdown rendering in results ─────────────── */
.result-content code {
    background: var(--border-light);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9em;
}

.result-content pre {
    background: var(--bg-dark);
    color: #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0.75rem 0;
}

.result-content blockquote {
    border-right: 4px solid var(--primary);
    padding: 0.75rem 1rem;
    background: var(--primary-50);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin: 0.75rem 0;
}
