/* =====================================================================
   AIDAKI — Study companion UI
   Light, friendly, education-focused green design system.
   NOTE: class names & CSS variable names are kept stable because
   script.js toggles/reads several of them. Do not rename without
   updating the JS in lockstep.
   ===================================================================== */

:root {
    /* Brand (green — matches logo). Purple kept as a subtle accent. */
    --primary: #1f9e5a;
    --primary-bright: #34c759;
    --primary-deep: #0e7a43;
    --primary-glow: rgba(31, 158, 90, 0.12);
    --accent: #8c52ff;
    --warm: #ffb020;
    --success: #16a34a;
    --danger: #e5484d;

    /* Surfaces & text */
    --bg: #f1faf4;
    --bg-tint: #e9f6ee;
    --surface: #ffffff;
    --surface-2: #f6fbf8;
    --text-main: #16241c;
    --text-body: #1f2933;
    --text-dim: #6b7280;

    /* Lines */
    --border-glass: #e4eae6;
    --border: #e5e7eb;

    /* Radius */
    --radius-sm: 10px;
    --radius-md: 12px;
    --radius: 14px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --pill: 999px;

    /* Shadow */
    --shadow-sm: 0 2px 8px rgba(16, 122, 67, 0.06);
    --shadow-md: 0 8px 24px rgba(16, 122, 67, 0.09);
    --shadow-lg: 0 16px 40px rgba(16, 122, 67, 0.12);

    --spring: cubic-bezier(0.22, 1, 0.36, 1);
    --focus: 0 0 0 3px rgba(31, 158, 90, 0.35);

    --font-display: 'Poppins', 'DM Serif Display', 'Cairo', sans-serif;
    --font-body: 'Inter', 'Cairo', system-ui, sans-serif;
}

/* =====================================================================
   Dark theme — toggled via [data-theme="dark"] on <html> (see ThemeManager
   in script.js). Same variable names, dark-appropriate values only.
   ===================================================================== */
:root[data-theme="dark"] {
    --primary: #34c759;
    --primary-bright: #4ade80;
    --primary-deep: #22c55e;
    --primary-glow: rgba(52, 199, 89, 0.18);
    --accent: #b389ff;
    --warm: #ffc247;
    --success: #34d399;
    --danger: #f87171;

    --bg: #0d1512;
    --bg-tint: #121d18;
    --surface: #17221c;
    --surface-2: #1c2921;
    --text-main: #f1faf4;
    --text-body: #e3ebe6;
    --text-dim: #93a39a;

    --border-glass: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.12);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);

    --focus: 0 0 0 3px rgba(52, 199, 89, 0.4);
}

/* A handful of surfaces use a hardcoded light color instead of a variable
   (translucent header, hover/active states) — patch those for dark mode. */
[data-theme="dark"] .header { background: rgba(13, 21, 18, 0.85); }
[data-theme="dark"] .option-card:hover { background: var(--surface-2); }
[data-theme="dark"] .file-chip { background: var(--surface); }
[data-theme="dark"] .segmented .btn.active { background: var(--surface); }
[data-theme="dark"] .aidaki-content.editing-active { background: var(--surface); }
[data-theme="dark"] .quiz-option:hover { background: var(--surface-2); }
[data-theme="dark"] .iframe-frame,
[data-theme="dark"] #presentation-generator,
[data-theme="dark"] #reformulation-generator { background: var(--surface); }

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text-body);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Soft decorative background blobs (light, non-essential) */
.mesh-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.mesh-1,
.mesh-2 {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.5;
}

.mesh-1 {
    width: 480px;
    height: 480px;
    top: -140px;
    right: -100px;
    background: radial-gradient(circle, rgba(52, 199, 89, 0.35), transparent 70%);
}

.mesh-2 {
    width: 420px;
    height: 420px;
    bottom: -160px;
    left: -120px;
    background: radial-gradient(circle, rgba(140, 82, 255, 0.18), transparent 70%);
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    color: var(--text-main);
    line-height: 1.2;
}

a {
    color: var(--primary-deep);
}

::selection {
    background: var(--primary-glow);
    color: var(--primary-deep);
}

/* Accessible focus rings everywhere */
:focus-visible {
    outline: none;
    box-shadow: var(--focus);
    border-radius: 8px;
}

.app {
    max-width: 1700px;
    margin: 0 auto;
    padding: 0 clamp(16px, 4vw, 40px) 64px;
}

/* =====================================================================
   HEADER
   ===================================================================== */
.header {
    position: sticky;
    top: 0;
    z-index: 40;
    padding: 14px 0;
    margin-bottom: 8px;
    background: rgba(241, 250, 244, 0.85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-glass);
}

.header-content {
    display: flex;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    height: 46px;
    width: auto;
    display: block;
}

.brand-logo-fallback {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-bright), var(--primary-deep));
    color: #fff;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.04em;
}

.brand-titles h1 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-main);
}

.brand-titles .subtitle {
    margin-top: 2px;
    font-size: 0.74rem;
    color: var(--text-dim);
    letter-spacing: 0.02em;
}

.badge-pill {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--primary-deep);
    background: var(--primary-glow);
    border: 1px solid rgba(31, 158, 90, 0.25);
    border-radius: var(--pill);
    padding: 3px 10px;
}

.header-actions {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-left: auto;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(22, 163, 74, 0.08);
    padding: 6px 14px;
    border-radius: var(--pill);
    border: 1px solid rgba(22, 163, 74, 0.2);
}

.status-indicator .dot {
    width: 7px;
    height: 7px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--success);
    animation: pulse 2s infinite;
}

.status-indicator span {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--success);
}

/* Language segmented control */
.lang-switch {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--pill);
    padding: 3px;
    box-shadow: var(--shadow-sm);
}

.language-btn {
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.05em;
    padding: 6px 14px;
    border-radius: var(--pill);
    cursor: pointer;
    transition: all 0.2s var(--spring);
}

.language-btn:hover {
    color: var(--primary-deep);
}

.language-btn.active {
    background: var(--primary);
    color: #fff;
}

/* Theme toggle (light/dark) */
.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: var(--surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--pill);
    color: var(--text-dim);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s var(--spring);
}

.theme-toggle-btn:hover {
    color: var(--primary-deep);
    border-color: var(--primary-bright);
}

.theme-toggle-btn .icon-moon { display: none; }
.theme-toggle-btn .icon-sun { display: block; }

[data-theme="dark"] .theme-toggle-btn .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle-btn .icon-moon { display: block; }

/* =====================================================================
   TABS NAV
   ===================================================================== */
.tabs-nav {
    margin: 20px 0 40px;
}

.tabs-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--pill);
    padding: 6px;
    box-shadow: var(--shadow-sm);
    width: fit-content;
    max-width: 100%;
}

.tabs-list .tab-btn {
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.85rem;
    padding: 10px 22px;
    border-radius: var(--pill);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.25s var(--spring);
}

.tabs-list .tab-btn:hover {
    color: var(--primary-deep);
    background: var(--primary-glow);
}

.tabs-list .tab-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(31, 158, 90, 0.28);
}

/* =====================================================================
   TAB CONTENT
   ===================================================================== */
.main-content {
    position: relative;
}

.tab-content {
    display: none;
    animation: fadeInUp 0.5s var(--spring);
}

.tab-content.active {
    display: block;
}

.tab-header {
    margin-bottom: 2.5rem;
}

.tab-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--primary-glow);
    border: 1px solid rgba(31, 158, 90, 0.2);
    border-radius: var(--pill);
    color: var(--primary-deep);
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 0.85rem;
}

.tab-header h2 {
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tab-header p {
    color: var(--text-dim);
    max-width: 560px;
    margin-top: 0.6rem;
    font-size: 0.98rem;
}

/* =====================================================================
   LAYOUT
   ===================================================================== */
.layout-with-sidebar {
    display: grid;
    grid-template-columns: 1fr 440px;
    gap: 2.5rem;
    align-items: start;
}

/* =====================================================================
   CARDS
   ===================================================================== */
.card,
.glass-card,
.result-panel {
    background: var(--surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.result-panel {
    padding: 2rem;
    min-height: 520px;
}

.control-sidebar {
    background: var(--surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    padding: 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
    position: sticky;
    top: 90px;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}

.control-sidebar::-webkit-scrollbar {
    width: 8px;
}

.control-sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}

.control-sidebar:hover::-webkit-scrollbar-thumb {
    background: var(--primary-bright);
}

.sidebar-section {
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-glass);
}

.sidebar-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.section-header {
    margin-bottom: 1rem;
}

.section-header h3 {
    font-family: var(--font-body);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-dim);
}

/* =====================================================================
   FORMS
   ===================================================================== */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-body);
    margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="color"],
select,
textarea {
    width: 100%;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-main);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input::placeholder,
textarea::placeholder {
    color: #9aa3af;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus);
    background: var(--surface);
}

textarea {
    resize: vertical;
    min-height: 90px;
    line-height: 1.5;
}

input[type="color"] {
    height: 44px;
    padding: 4px;
    cursor: pointer;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    padding-right: 36px;
    cursor: pointer;
}

.help-text {
    display: block;
    margin-top: 6px;
    font-size: 0.72rem;
    color: var(--text-dim);
}

/* Checkbox rows (quiz/exo types) */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.checkbox-group label {
    margin: 0;
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
}

input[type="checkbox"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
    position: relative;
    flex: none;
    transition: all 0.2s var(--spring);
}

input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}

input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg);
}

input[type="checkbox"]:focus-visible {
    box-shadow: var(--focus);
}

/* =====================================================================
   GENERATION OPTION CARDS
   (wrap the same gen-* checkboxes — values unchanged)
   ===================================================================== */
.option-cards {
    display: grid;
    gap: 10px;
}

.option-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    cursor: pointer;
    transition: all 0.2s var(--spring);
    margin: 0;
}

.option-card:hover {
    border-color: var(--primary-bright);
    background: #fff;
    transform: translateY(-1px);
}

.option-card input[type="checkbox"] {
    margin-left: auto;
    order: 3;
}

.option-card__icon {
    font-size: 1.25rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-glow);
    border-radius: 10px;
    flex: none;
}

.option-card__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.option-card__title {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-main);
}

.option-card__desc {
    font-size: 0.74rem;
    color: var(--text-dim);
}

.option-card:has(input:checked) {
    border-color: var(--primary);
    background: linear-gradient(180deg, rgba(31, 158, 90, 0.08), rgba(31, 158, 90, 0.03));
    box-shadow: var(--shadow-sm);
}

.option-card:has(input:checked) .option-card__icon {
    background: var(--primary);
    filter: none;
}

/* =====================================================================
   DROPZONE (wraps #pdf-file — file still read from the input)
   ===================================================================== */
.dropzone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 28px 18px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s var(--spring);
}

.dropzone:hover,
.dropzone.is-dragover {
    border-color: var(--primary);
    background: var(--primary-glow);
}

.dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.dropzone__icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 8px;
}

.dropzone__title {
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.92rem;
}

.dropzone__hint {
    font-size: 0.74rem;
    color: var(--text-dim);
    margin-top: 4px;
}

/* Selected-file chip */
.file-chip {
    display: none;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.file-chip.show {
    display: flex;
}

.file-chip__icon {
    font-size: 1.1rem;
}

.file-chip__meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.file-chip__name {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 210px;
}

.file-chip__size {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.file-chip__remove {
    margin-left: auto;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
}

.file-chip__remove:hover {
    color: var(--danger);
    background: rgba(229, 72, 77, 0.08);
}

/* Segmented source switcher */
.segmented {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 14px;
}

.segmented .btn {
    flex: 1;
    height: auto;
    padding: 8px 6px;
    font-size: 0.75rem;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    box-shadow: none;
}

.segmented .btn.active {
    background: #fff;
    color: var(--primary-deep);
    box-shadow: var(--shadow-sm);
}

/* =====================================================================
   BUTTONS
   ===================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.86rem;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s var(--spring);
    text-decoration: none;
    line-height: 1.1;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary-bright), var(--primary));
    color: #fff;
    box-shadow: 0 4px 14px rgba(31, 158, 90, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-body);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary-deep);
    background: var(--primary-glow);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-small {
    padding: 8px 14px;
    font-size: 0.78rem;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    top: calc(50% - 9px);
    left: calc(50% - 9px);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* =====================================================================
   STATUS BAR / PROGRESS / LOADER
   ===================================================================== */
.status-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface-2);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: 0.86rem;
    color: var(--text-body);
}

.status-bar.loading {
    border-color: var(--primary);
    background: var(--primary-glow);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
    flex: none;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-left: auto;
    max-width: 160px;
}

.progress-fill {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, var(--primary-bright), var(--primary));
    border-radius: 999px;
    animation: indeterminate 1.4s var(--spring) infinite;
}

.loader-glow {
    width: 42px;
    height: 42px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* =====================================================================
   PREVIEW / EMPTY STATES
   ===================================================================== */
.preview-container {
    min-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    overflow: hidden;
}

.preview-container img,
.preview-container video {
    max-width: 100%;
    border-radius: var(--radius-sm);
}

.placeholder {
    text-align: center;
    color: var(--text-dim);
}

.placeholder p:first-child {
    font-weight: 600;
    color: var(--text-body);
}

.placeholder p {
    font-size: 0.9rem;
}

.info-box {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: var(--surface-2);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
}

.info-content p {
    font-size: 0.88rem;
    margin-bottom: 6px;
}

.info-content strong {
    color: var(--primary-deep);
}

.download-box {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: var(--primary-glow);
    border: 1px solid rgba(31, 158, 90, 0.25);
    border-radius: var(--radius);
    text-align: center;
}

.download-box h3 {
    font-size: 1rem;
    margin-bottom: 6px;
}

.download-box p {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-bottom: 1rem;
}

/* =====================================================================
   AIDAKI RESULTS
   ===================================================================== */
.aidaki-results-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 1.75rem;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 1rem;
}

.aidaki-result-tab {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.78rem;
    padding: 8px 16px;
    border-radius: var(--pill);
    cursor: pointer;
    transition: all 0.2s var(--spring);
}

.aidaki-result-tab:hover {
    color: var(--primary-deep);
    border-color: var(--primary-bright);
}

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

.aidaki-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

#aidaki-content-container {
    padding: 2.5rem !important;
    background: var(--surface-2) !important;
    border: 1px solid var(--border-glass) !important;
    border-radius: var(--radius-lg) !important;
    min-height: 400px !important;
}

.aidaki-content {
    color: var(--text-body);
    font-size: 0.98rem;
    line-height: 1.75;
}

.aidaki-content h1,
.aidaki-content h2,
.aidaki-content h3 {
    color: var(--primary-deep);
    margin: 1.4rem 0 0.7rem;
}

.aidaki-content h1 { font-size: 1.7rem; }
.aidaki-content h2 { font-size: 1.35rem; }
.aidaki-content h3 { font-size: 1.1rem; }

.aidaki-content p { margin-bottom: 1rem; }

.aidaki-content ul,
.aidaki-content ol {
    margin: 0 0 1rem 1.4rem;
}

.aidaki-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.2rem 0;
    font-size: 0.88rem;
    overflow: hidden;
    border-radius: var(--radius-sm);
}

.aidaki-content th,
.aidaki-content td {
    border: 1px solid var(--border);
    padding: 10px 12px;
    text-align: left;
}

.aidaki-content th {
    background: var(--primary-glow);
    color: var(--primary-deep);
    font-weight: 700;
}

.aidaki-content pre {
    background: #0e1b14;
    color: #e6f4ec;
    padding: 1.2rem;
    border-radius: var(--radius-sm);
    overflow: auto;
    font-size: 0.82rem;
}

.aidaki-content code {
    font-family: 'JetBrains Mono', monospace;
    background: var(--primary-glow);
    color: var(--primary-deep);
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 0.85em;
}

.aidaki-content pre code {
    background: none;
    color: inherit;
    padding: 0;
}

/* Editable mode */
.aidaki-content.editing-active {
    outline: 2px dashed var(--primary);
    outline-offset: 6px;
    border-radius: var(--radius-sm);
    background: #fff;
}

/* =====================================================================
   QUIZ (rendered by script.js)
   ===================================================================== */
.quiz-container {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.quiz-card {
    background: var(--surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow-sm);
    animation: fadeInUp 0.4s var(--spring) both;
}

.quiz-difficulty {
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 3px 10px;
    border-radius: var(--pill);
    background: var(--border);
    color: var(--text-dim);
}

.quiz-difficulty.facile { background: rgba(22, 163, 74, 0.12); color: var(--success); }
.quiz-difficulty.moyen { background: rgba(255, 176, 32, 0.15); color: #b47100; }
.quiz-difficulty.difficile { background: rgba(229, 72, 77, 0.12); color: var(--danger); }

.quiz-question {
    font-size: 1.02rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quiz-option {
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s var(--spring);
}

.quiz-option:hover {
    border-color: var(--primary-bright);
    background: #fff;
}

.quiz-option.selected {
    border-color: var(--primary);
    background: var(--primary-glow);
}

.quiz-option.correct {
    border-color: var(--success);
    background: rgba(22, 163, 74, 0.12);
    color: var(--primary-deep);
    font-weight: 600;
}

.quiz-option.wrong {
    border-color: var(--danger);
    background: rgba(229, 72, 77, 0.1);
    color: var(--danger);
}

.quiz-short-answer {
    display: flex;
    gap: 10px;
}

.quiz-short-input {
    flex: 1;
}

.quiz-check-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 18px;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
}

.quiz-check-btn:hover { background: var(--primary-deep); }

.quiz-answer {
    background: var(--surface-2) !important;
    border-left: 3px solid var(--primary) !important;
}

.correct-answer.success { color: var(--success); }
.correct-answer.error { color: var(--danger); }

/* =====================================================================
   MINDMAP TAB
   ===================================================================== */
#mindmap-preview-container {
    flex: 1;
    position: relative;
    background: var(--surface-2);
    min-height: 560px;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* Absolutely fill the (position:relative) preview container so the iframe
   never collapses — percentage height on a flex:1 parent is unreliable. */
#mindmap-iframe-wrap {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#mindmap-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

#mindmap-md-text {
    height: 320px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.iframe-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: #fff;
    border-radius: var(--radius-lg);
}

/* =====================================================================
   PRESENTATION TAB
   ===================================================================== */
#presentation-generator {
    height: calc(100vh - 200px);
    padding: 0;
    overflow: hidden;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-glass);
    background: #fff;
}

#presentation-iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius-xl);
}

/* =====================================================================
   REFORMULATION TAB
   ===================================================================== */
#reformulation-generator {
    height: calc(100vh - 200px);
    padding: 0;
    overflow: hidden;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-glass);
    background: #fff;
}

#reformulation-iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius-xl);
}

/* =====================================================================
   TOASTS
   ===================================================================== */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, 90vw);
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border-glass);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 0.88rem;
    color: var(--text-main);
    animation: toastIn 0.35s var(--spring);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--accent); }

.toast.removing {
    animation: toastOut 0.5s var(--spring) forwards;
}

/* Offline overlay (created by JS) */
.offline-check-overlay {
    font-family: var(--font-body);
}

/* =====================================================================
   ANIMATIONS
   ===================================================================== */
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(320%); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    to { opacity: 0; transform: translateX(40px); }
}

/* =====================================================================
   RTL (results container only — set by JS when AR is chosen)
   ===================================================================== */
[dir="rtl"] .aidaki-content,
.aidaki-content.rtl {
    direction: rtl;
    text-align: right;
    font-family: 'Cairo', var(--font-body);
}

[dir="rtl"] .aidaki-content ul,
[dir="rtl"] .aidaki-content ol {
    margin: 0 1.4rem 1rem 0;
}

[dir="rtl"] .quiz-answer {
    border-left: none !important;
    border-right: 3px solid var(--primary) !important;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 1080px) {
    .layout-with-sidebar {
        grid-template-columns: 1fr;
    }

    .control-sidebar {
        position: static;
        max-height: none;
    }
}

@media (max-width: 720px) {
    .header-content {
        flex-wrap: wrap;
        gap: 12px;
    }

    .header-actions {
        margin-left: 0;
        width: 100%;
        justify-content: space-between;
    }

    .status-indicator {
        display: none;
    }

    .tabs-list {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .result-panel {
        padding: 1.25rem;
    }

    #presentation-generator {
        height: calc(100vh - 160px);
    }

    #reformulation-generator {
        height: calc(100vh - 160px);
    }
}

@media (max-width: 400px) {
    .app {
        padding: 0 12px 48px;
    }

    .tab-header h2 {
        font-size: 1.6rem;
    }

    .brand-titles .subtitle {
        display: none;
    }

    #toast-container {
        right: 12px;
        left: 12px;
        bottom: 12px;
        max-width: none;
    }
}

/* =====================================================================
   MOTION PREFERENCES
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
