/**
 * Univy Pro - Custom Styles v4.0
 * Developer: جامعة دمياط - كلية التربية النوعية
 * تصميم جديد: Teal + Navy, Dark/Light via html.dark class
 */

/* ============================================
   Reset & Base
   ============================================ */

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

:root {
    --vh: 1vh;
}

html, body {
    height: 100%; width: 100%; overflow: hidden;
    font-family: 'Cairo', sans-serif;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    background-color: #F8FAFC;
    color: #1e293b;
    transition: background-color 0.3s ease, color 0.3s ease;
}

html.dark body {
    background-color: #0F172A;
    color: #f8fafc;
}

/* ============================================
   App Shell
   ============================================ */

.app-shell { 
    height: 100dvh; width: 100%;
    display: flex; flex-direction: column;
    background-color: #F8FAFC;
    transition: background-color 0.3s ease;
    position: relative;
}

html.dark .app-shell {
    background-color: #0F172A;
}

/* ============================================
   Scrollbar
   ============================================ */

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

#chatArea::-webkit-scrollbar { width: 6px; }
#chatArea::-webkit-scrollbar-track { background: transparent; }
#chatArea::-webkit-scrollbar-thumb { background: rgba(13, 148, 136, 0.3); border-radius: 10px; }
#chatArea::-webkit-scrollbar-thumb:hover { background: rgba(13, 148, 136, 0.5); }

/* ============================================
   Typing Animation
   ============================================ */

.typing-dot {
    width: 6px; height: 6px; border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ============================================
   Streaming / Typing Cursor
   ============================================ */

.typing-active::after {
    content: '▊';
    display: inline;
    animation: blink-cursor 0.7s steps(1) infinite;
    color: #0D9488;
    font-weight: bold;
    margin-right: 2px;
}

@keyframes blink-cursor {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ============================================
   Messages Content
   ============================================ */

.message-content {
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.7;
}

.message-content strong { color: #0D9488; font-weight: 600; }
.message-content em { color: #14b8a6; font-style: italic; }

.message-content code {
    background: rgba(13, 148, 136, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: #0D9488;
}

html.dark .message-content strong { color: #5eead4; }
html.dark .message-content em { color: #2dd4bf; }
html.dark .message-content code {
    background: rgba(13, 148, 136, 0.15);
    color: #5eead4;
}

.message-content h1,
.message-content h2,
.message-content h3 {
    margin-top: 0.5em;
    margin-bottom: 0.3em;
    color: #0D9488;
}

html.dark .message-content h1,
html.dark .message-content h2,
html.dark .message-content h3 {
    color: #5eead4;
}

.message-content ul,
.message-content ol { padding-right: 1.5em; margin: 0.5em 0; }
.message-content li { margin: 0.25em 0; }

/* ============================================
   Citation Tags
   ============================================ */

.citations-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid rgba(13, 148, 136, 0.15);
}

.citation-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: rgba(13, 148, 136, 0.1);
    color: #0D9488;
    border: 1px solid rgba(13, 148, 136, 0.2);
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.citation-tag:hover {
    background: rgba(13, 148, 136, 0.2);
    border-color: rgba(13, 148, 136, 0.4);
    transform: translateY(-1px);
}

/* ============================================
   Books Menu Items
   ============================================ */

.book-item {
    transition: all 0.2s ease;
    cursor: pointer;
    border-radius: 12px;
    padding: 12px;
    border: 1px solid transparent;
}

.book-item:hover {
    transform: translateX(-3px);
    background: rgba(13, 148, 136, 0.05);
    border-color: rgba(13, 148, 136, 0.3);
}

html.dark .book-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(13, 148, 136, 0.3);
}

/* ============================================
   Buttons
   ============================================ */

button { transition: all 0.3s ease; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:active:not(:disabled) { transform: scale(0.95); }

/* ============================================
   Quiz
   ============================================ */

.quiz-message { animation: fadeIn 0.5s ease-out; }

.quiz-option {
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}

.quiz-option:hover:not(:disabled) { transform: translateX(-2px); }
.quiz-option:disabled { cursor: not-allowed; }

.quiz-option::before {
    content: '';
    position: absolute; top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(13, 148, 136, 0.1), transparent);
    transition: left 0.5s;
}
.quiz-option:hover::before { left: 100%; }

/* ============================================
   Animations
   ============================================ */

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

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

.animate-fade-in { animation: fadeIn 0.3s ease-out; }
.animate-slide-up { animation: slideUp 0.3s ease-out; }

/* ============================================
   Copy Toast Popup
   ============================================ */

.copy-toast {
    opacity: 0;
    transform: translateX(-50%) translateY(-16px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: none;
}

.copy-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

/* ============================================
   Loading
   ============================================ */

.loading-indicator { pointer-events: none; }

/* ============================================
   Accessibility
   ============================================ */

button:focus, input:focus, textarea:focus {
    outline: 2px solid rgba(13, 148, 136, 0.5);
    outline-offset: 2px;
}

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

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
    header { padding: 12px 16px !important; }
    #user-input { font-size: 16px !important; }
}

@media (max-width: 400px) {
    header { padding: 10px 12px !important; }
}

/* ============================================
   Safari iOS Fixes
   ============================================ */

@supports (-webkit-touch-callout: none) {
    html { height: -webkit-fill-available; }
    body { min-height: 100vh; min-height: -webkit-fill-available; }
}

@supports (padding: max(0px)) {
    footer {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* ============================================
   Print
   ============================================ */

@media print {
    header, footer, #books-menu { display: none !important; }
    #chatArea { overflow: visible !important; max-height: none !important; }
    body { background: white; color: black; }
}

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
