/* ===== CSS Variables / Theming ===== */
:root {
    --font-en: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-ar: 'Noto Sans Arabic', 'Inter', sans-serif;

    /* Light theme */
    --bg-primary: #f8f9fb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f3f5;
    --text-primary: #1a1a2e;
    --text-secondary: #5a5a7a;
    --text-tertiary: #8a8aaa;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd1;
    --accent-light: rgba(108, 92, 231, 0.1);
    --border: #e8e8ef;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.1);
    --success: #00b894;
    --error: #e17055;
    --warning: #fdcb6e;
    --bubble-ai: #f1f3f5;
    --bubble-user: var(--accent);
    --progress-bg: #e8e8ef;
    --progress-fill: var(--accent);
    --toast-bg: #1a1a2e;
    --toast-text: #ffffff;
    --input-bg: #ffffff;
    --input-border: #ddd;
    --card-bg: #ffffff;
}

[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0c0;
    --text-tertiary: #6a6a8a;
    --accent: #a29bfe;
    --accent-hover: #8b82f0;
    --accent-light: rgba(162, 155, 254, 0.12);
    --border: #2a2a45;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --success: #55efc4;
    --error: #ff7675;
    --warning: #ffeaa7;
    --bubble-ai: #252540;
    --bubble-user: var(--accent);
    --progress-bg: #252540;
    --toast-bg: #e8e8f0;
    --toast-text: #1a1a2e;
    --input-bg: #252540;
    --input-border: #3a3a55;
    --card-bg: #1a1a2e;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-en);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
    line-height: 1.6;
}

[dir="rtl"] body {
    font-family: var(--font-ar);
}

/* ===== Header ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--accent);
}

.logo-text {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lang-toggle,
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: 0.8rem;
}

.lang-toggle {
    width: auto;
    padding: 0 12px;
    font-family: var(--font-en);
}

.lang-toggle:hover,
.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

/* Theme toggle icon visibility */
[data-theme="light"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }

/* ===== Progress Bar ===== */
.progress-container {
    position: fixed;
    top: 57px;
    left: 0;
    right: 0;
    z-index: 99;
    display: none;
    align-items: center;
    gap: 12px;
    padding: 0.6rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.progress-container.visible {
    display: flex;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--progress-bg);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}

.progress-text {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-tertiary);
    white-space: nowrap;
    min-width: 100px;
    text-align: right;
}

[dir="rtl"] .progress-text {
    text-align: left;
}

/* ===== Screens ===== */
.screen {
    display: none;
    padding-top: 80px;
    min-height: 100vh;
    animation: fadeIn 0.4s ease;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

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

/* ===== Introduction Screen ===== */
.intro-card {
    max-width: 600px;
    width: 90%;
    text-align: center;
    padding: 2rem 0;
}

.intro-icon {
    color: var(--accent);
    margin-bottom: 1.5rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.intro-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.intro-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    line-height: 1.5;
}

.guidelines {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    text-align: left;
    box-shadow: var(--shadow-sm);
}

[dir="rtl"] .guidelines {
    text-align: right;
}

.guidelines-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    margin-bottom: 1rem;
}

.guidelines-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.guidelines-list li {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
}

.guideline-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--accent-light);
    color: var(--accent);
}

.guidelines-list li strong {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.1rem;
}

.guidelines-list li span {
    font-size: 0.88rem;
    color: var(--text-secondary);
}

/* ===== Language Chooser ===== */
.lang-chooser {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.lang-buttons {
    display: flex;
    gap: 0.75rem;
}

.lang-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 1rem;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.lang-btn:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.lang-btn.selected {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.lang-btn-flag {
    font-size: 1.4rem;
    line-height: 1;
}

.lang-btn-label {
    font-size: 1rem;
}

/* ===== Buttons ===== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 2.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    letter-spacing: 0.01em;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

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

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-secondary:hover {
    color: var(--error);
    border-color: var(--error);
    background: rgba(225, 112, 85, 0.08);
}

/* ===== Interview Screen ===== */
.interview-card {
    max-width: 700px;
    width: 90%;
    margin: 0 auto;
    padding: 2rem 0 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
}

.question-area {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: slideIn 0.4s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-12px); }
    to { opacity: 1; transform: translateX(0); }
}

[dir="rtl"] .question-area {
    animation-name: slideInRtl;
}

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

.ai-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: var(--accent-light);
    color: var(--accent);
}

.question-bubble {
    background: var(--bubble-ai);
    padding: 1rem 1.25rem;
    border-radius: 4px 16px 16px 16px;
    max-width: calc(100% - 52px);
    box-shadow: var(--shadow-sm);
}

[dir="rtl"] .question-bubble {
    border-radius: 16px 4px 16px 16px;
}

.question-text {
    font-size: 1.05rem;
    line-height: 1.6;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: none;
    align-items: flex-start;
    gap: 0.75rem;
}

.typing-indicator.visible {
    display: flex;
}

.typing-bubble {
    background: var(--bubble-ai);
    padding: 1rem 1.25rem;
    border-radius: 4px 16px 16px 16px;
    display: flex;
    gap: 4px;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

[dir="rtl"] .typing-bubble {
    border-radius: 16px 4px 16px 16px;
}

.typing-bubble .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: bounce 1.4s ease-in-out infinite;
}

.typing-bubble .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ===== Answer Area ===== */
.answer-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    animation: fadeIn 0.3s ease;
}

.answer-area.hidden {
    display: none;
}

#inputContainer textarea {
    width: 100%;
    min-height: 120px;
    padding: 1rem;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.6;
    background: var(--input-bg);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-radius: 12px;
    resize: vertical;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

#inputContainer textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

#inputContainer textarea::placeholder {
    color: var(--text-tertiary);
}

/* Choice buttons */
.choices-container {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.choice-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1.2rem;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-primary);
    transition: all 0.2s ease;
    text-align: left;
}

[dir="rtl"] .choice-btn {
    text-align: right;
}

.choice-btn:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.choice-btn.selected {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 500;
}

.choice-btn .choice-indicator {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.choice-btn.selected .choice-indicator {
    border-color: var(--accent);
    background: var(--accent);
}

.choice-btn.selected .choice-indicator::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
}

/* Yes/No buttons */
.yesno-container {
    display: flex;
    gap: 0.75rem;
}

.yesno-btn {
    flex: 1;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.yesno-btn:hover {
    border-color: var(--accent);
}

.yesno-btn.selected {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

/* Scale input */
.scale-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.scale-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

.scale-buttons {
    display: flex;
    gap: 0.4rem;
}

.scale-btn {
    flex: 1;
    padding: 0.75rem 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    background: var(--input-bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.scale-btn:hover {
    border-color: var(--accent);
}

.scale-btn.selected {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

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

/* ===== Results Screen ===== */
.results-card {
    max-width: 700px;
    width: 90%;
    padding: 2rem 0 3rem;
    text-align: center;
}

.thank-you-icon {
    color: var(--success);
    margin-bottom: 1rem;
}

.results-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.results-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.answers-summary {
    text-align: left;
    margin-bottom: 2rem;
}

[dir="rtl"] .answers-summary {
    text-align: right;
}

.answers-summary h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.answer-item {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
}

.answer-item .q-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    margin-bottom: 0.3rem;
}

.answer-item .q-text {
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.answer-item .a-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding-left: 0.75rem;
    border-left: 2px solid var(--accent-light);
}

[dir="rtl"] .answer-item .a-text {
    padding-left: 0;
    padding-right: 0.75rem;
    border-left: none;
    border-right: 2px solid var(--accent-light);
}

/* Follow-up pairs */
.answer-item .followup-pair {
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px dashed var(--border);
}

.answer-item .followup-pair .q-label {
    color: var(--text-tertiary);
}

/* Storage info */
.storage-info {
    text-align: left;
    margin-bottom: 2rem;
}

[dir="rtl"] .storage-info {
    text-align: right;
}

.storage-info h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.storage-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.storage-option {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.storage-option .option-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.storage-option .option-desc {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.results-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.toast {
    background: var(--toast-bg);
    color: var(--toast-text);
    padding: 0.85rem 1.5rem;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3s forwards;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.error {
    background: var(--error);
    color: #fff;
}

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

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

/* ===== Validation Errors ===== */
.validation-error {
    color: var(--error);
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.validation-error::before {
    content: '\26A0';
    font-size: 0.95rem;
}

#inputContainer textarea.input-error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(225, 112, 85, 0.15);
}

#inputContainer textarea.input-error:focus {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(225, 112, 85, 0.25);
}

.choices-container.input-error,
.yesno-container.input-error,
.scale-container.input-error {
    padding: 0.5rem;
    border: 2px solid var(--error);
    border-radius: 14px;
    box-shadow: 0 0 0 3px rgba(225, 112, 85, 0.15);
}

/* ===== Follow-up Badge ===== */
.followup-badge {
    display: inline-block;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    margin-bottom: 0.3rem;
    vertical-align: middle;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    .header {
        padding: 0.6rem 1rem;
    }

    .intro-title {
        font-size: 1.6rem;
    }

    .intro-subtitle {
        font-size: 0.95rem;
    }

    .guidelines {
        padding: 1.25rem;
    }

    .interview-card {
        width: 95%;
    }

    .yesno-container {
        flex-direction: column;
    }

    .answer-actions {
        flex-direction: column-reverse;
    }

    .answer-actions .btn-secondary {
        width: 100%;
    }

    .answer-actions .btn-primary {
        width: 100%;
    }

    .results-actions {
        flex-direction: column;
    }

    .results-actions button {
        width: 100%;
    }

    .scale-buttons {
        flex-wrap: wrap;
    }
}
