/* ============================
   CSS Variables & Base Styles
   ============================ */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --bg-card: rgba(26, 26, 37, 0.8);

    --text-primary: #f5f5f7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;

    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);

    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.3);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-arabic: 'Noto Sans Arabic', 'Inter', sans-serif;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.2);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;
}

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

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;

    /* Subtle background pattern */
    background-image:
        radial-gradient(circle at 20% 80%, rgba(99, 102, 241, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(139, 92, 246, 0.05) 0%, transparent 50%);
}

/* ============================
   Login Overlay
   ============================ */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(10, 10, 15, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity var(--transition-slow);
}

.login-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: var(--spacing-2xl);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xl);
}

.login-header svg {
    width: 28px;
    height: 28px;
    color: var(--accent-primary);
}

.login-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-body .input-group {
    margin-bottom: var(--spacing-lg);
}

.login-body input[type="password"] {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    transition: all var(--transition-base);
}

.login-body input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--border-glow);
}

.login-error {
    color: var(--error);
    font-size: 0.875rem;
    margin-bottom: var(--spacing-md);
    min-height: 1.25rem;
}

/* Logout Button */
.logout-btn {
    position: absolute;
    top: var(--spacing-lg);
    right: var(--spacing-lg);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
    cursor: pointer;
    transition: all var(--transition-base);
}

.logout-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.logout-btn:hover {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

.logout-btn:hover svg {
    color: var(--error);
}

/* ============================
   Layout
   ============================ */
.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--spacing-lg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================
   Header
   ============================ */
.header {
    text-align: center;
    padding: var(--spacing-2xl) 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--spacing-xl);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.5));
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-family: var(--font-arabic);
    font-size: 1.1rem;
    color: var(--text-secondary);
    direction: rtl;
}

/* ============================
   Main Content
   ============================ */
.main-content {
    flex: 1;
}

/* ============================
   Input Section
   ============================ */
.input-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-lg);
}

.input-group {
    margin-bottom: var(--spacing-lg);
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

.url-input-wrapper,
.question-input-wrapper {
    position: relative;
}

.input-icon {
    position: absolute;
    left: var(--spacing-md);
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
}

input[type="url"],
textarea {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    transition: all var(--transition-base);
}

input[type="url"] {
    padding-left: 3rem;
}

input[type="url"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--border-glow);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 80px;
    font-family: var(--font-arabic);
}

/* ============================
   Submit Button
   ============================ */
.submit-btn {
    width: 100%;
    padding: var(--spacing-md) var(--spacing-xl);
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow), var(--shadow-lg);
}

.submit-btn:active:not(:disabled) {
    transform: translateY(0);
}

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

.submit-btn .btn-loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
}

.submit-btn.loading .btn-text {
    display: none;
}

.submit-btn.loading .btn-loading {
    display: flex;
}

.spinner {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ============================
   Response Section
   ============================ */
.response-section {
    display: none;
    margin-top: var(--spacing-xl);
    animation: fadeIn var(--transition-slow) ease;
}

.response-section.visible {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.video-info {
    display: none;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md) var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
}

.video-info.visible {
    display: flex;
}

.video-info h3 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.video-duration {
    font-size: 0.875rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
}

/* ============================
   Answer Container
   ============================ */
.answer-container {
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-lg);
}

.answer-container.visible {
    display: block;
}

.answer-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.answer-header svg {
    width: 18px;
    height: 18px;
    color: var(--accent-primary);
}

/* Copy Answer Button */
.copy-answer-btn {
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    cursor: pointer;
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.copy-answer-btn svg {
    width: 16px;
    height: 16px;
    color: var(--accent-primary);
}

.copy-answer-btn:hover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
}

.copy-answer-btn:hover svg {
    color: var(--accent-primary);
}

.copy-answer-btn.copied {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.copy-answer-btn.copied svg.check-icon {
    color: var(--success);
}

.answer-content {
    padding: var(--spacing-xl) var(--spacing-2xl);
    font-family: var(--font-arabic);
    font-size: 1.2rem;
    line-height: 2.2;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

/* Markdown Content Styling */
.answer-content h1,
.answer-content h2,
.answer-content h3,
.answer-content h4 {
    margin-top: var(--spacing-2xl);
    margin-bottom: var(--spacing-lg);
    font-weight: 700;
    line-height: 1.4;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.answer-content h1 {
    font-size: 1.75rem;
    padding-bottom: var(--spacing-sm);
    border-bottom: 2px solid var(--border-color);
}

.answer-content h2 {
    font-size: 1.5rem;
}

.answer-content h3 {
    font-size: 1.25rem;
}

.answer-content p {
    margin-bottom: var(--spacing-xl);
    color: var(--text-primary);
}

.answer-content ul,
.answer-content ol {
    margin-bottom: var(--spacing-xl);
    padding-right: var(--spacing-2xl);
    padding-left: var(--spacing-md);
}

.answer-content li {
    margin-bottom: var(--spacing-md);
    padding-right: var(--spacing-sm);
    position: relative;
}

.answer-content ul li::marker {
    color: var(--accent-primary);
}

.answer-content ol li::marker {
    color: var(--accent-secondary);
    font-weight: 600;
}

.answer-content code {
    font-family: 'Consolas', 'Monaco', 'Fira Code', monospace;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.1));
    color: #a78bfa;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.9em;
    direction: ltr;
    display: inline-block;
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.answer-content pre {
    background: linear-gradient(180deg, var(--bg-secondary), #0d0d14);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    overflow-x: auto;
    margin: var(--spacing-xl) 0;
    direction: ltr;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.3);
}

.answer-content pre code {
    background: none;
    border: none;
    padding: 0;
    color: #e2e8f0;
    line-height: 1.7;
}

.answer-content blockquote {
    border-right: 4px solid var(--accent-primary);
    background: rgba(99, 102, 241, 0.05);
    padding: var(--spacing-lg) var(--spacing-xl);
    margin: var(--spacing-xl) 0;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--text-secondary);
    font-style: italic;
}

.answer-content a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent-primary);
    transition: all var(--transition-fast);
}

.answer-content a:hover {
    color: var(--accent-secondary);
    border-bottom-style: solid;
}

.answer-content strong {
    font-weight: 700;
    color: #f0abfc;
}

.answer-content em {
    color: var(--text-secondary);
    font-style: italic;
}

.answer-content hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
    margin: var(--spacing-2xl) 0;
}

/* ============================
   History Section
   ============================ */
.history-section {
    margin-top: var(--spacing-2xl);
    padding-top: var(--spacing-xl);
    border-top: 1px solid var(--border-color);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-lg);
}

.history-header h2 {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-header h2 svg {
    width: 20px;
    height: 20px;
    color: var(--accent-primary);
}

.clear-history-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    cursor: pointer;
    transition: all var(--transition-base);
}

.clear-history-btn svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.clear-history-btn:hover {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

.clear-history-btn:hover svg {
    color: var(--error);
}

/* Search Bar */
.history-search {
    position: relative;
    margin-bottom: var(--spacing-md);
}

.history-search .search-icon {
    position: absolute;
    left: var(--spacing-md);
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.history-search input {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    padding-left: calc(var(--spacing-md) * 2 + 18px);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all var(--transition-base);
}

.history-search input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.history-search input::placeholder {
    color: var(--text-muted);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.history-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: var(--spacing-xl);
}

/* Load More Button */
.load-more-btn {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    margin-top: var(--spacing-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-base);
}

.load-more-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

/* Video Group */
.history-video-group {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.history-video-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    cursor: pointer;
    transition: all var(--transition-base);
}

.history-video-header:hover {
    background: var(--bg-secondary);
}

.history-video-title {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-video-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
}

.history-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform var(--transition-base);
}

.history-video-group.expanded .history-chevron {
    transform: rotate(180deg);
}

/* Chat List (hidden by default) */
.history-chat-list {
    display: none;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.history-video-group.expanded .history-chat-list {
    display: block;
}

.history-chat-item {
    padding: var(--spacing-sm) var(--spacing-md);
    padding-right: var(--spacing-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    border-bottom: 1px solid var(--border-color);
}

.history-chat-item:last-child {
    border-bottom: none;
}

.history-chat-item:hover {
    background: rgba(99, 102, 241, 0.1);
}

.history-chat-question {
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: rtl;
}

.history-chat-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

/* ============================
   Error Container
   ============================ */
.error-container {
    display: none;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    align-items: flex-start;
    gap: var(--spacing-md);
}

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

.error-container svg {
    width: 24px;
    height: 24px;
    color: var(--error);
    flex-shrink: 0;
}

.error-container p {
    color: var(--error);
    font-size: 0.95rem;
}

/* ============================
   Footer
   ============================ */
.footer {
    text-align: center;
    padding: var(--spacing-xl) 0;
    margin-top: var(--spacing-2xl);
    border-top: 1px solid var(--border-color);
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ============================
   Responsive Design
   ============================ */
@media (max-width: 640px) {
    .app-container {
        padding: var(--spacing-md);
    }

    .header {
        padding: var(--spacing-xl) 0;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .input-section {
        padding: var(--spacing-lg);
    }

    .video-info {
        flex-direction: column;
        align-items: flex-start;
    }

    .video-info h3 {
        white-space: normal;
    }
}

/* ============================
   Scrollbar Styling
   ============================ */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

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

/* ============================
   Selection Styling
   ============================ */
::selection {
    background: rgba(99, 102, 241, 0.3);
    color: var(--text-primary);
}