/* agenticaisystems.education — dark educational theme */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #0d1117;
    --bg2:        #161b22;
    --bg3:        #21262d;
    --border:     #30363d;
    --text:       #e6edf3;
    --text-muted: #7d8590;
    --accent:     #3b82f6;
    --accent-h:   #2563eb;
    --green:      #3fb950;
    --purple:     #8957e5;
    --warning:    #d29922;
    --radius:     8px;
    --font:       'Georgia', 'Times New Roman', serif;
    --mono:       'Courier New', monospace;
}

html { font-size: 16px; }
body { background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.7; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Auth ───────────────────────────────────────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-container { width: 100%; max-width: 420px; }
.auth-logo { text-align: center; margin-bottom: 2rem; }
.logo-icon { font-size: 3rem; color: var(--accent); line-height: 1; }
.auth-logo h1 { font-size: 1.4rem; margin: 0.5rem 0 0.25rem; }
.tagline { color: var(--text-muted); font-size: 0.9rem; }

.auth-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }
.auth-card h2 { margin-bottom: 0.75rem; font-size: 1.2rem; }
.auth-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.25rem; }

.input-field { display: block; width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); padding: 0.6rem 0.9rem; font-size: 1rem; margin-bottom: 0.75rem; outline: none; font-family: var(--mono); }
.input-field:focus { border-color: var(--accent); }
.input-field::placeholder { color: var(--text-muted); }

.btn-primary { display: block; width: 100%; padding: 0.65rem; background: var(--accent); color: #fff;
    border: none; border-radius: 6px; font-size: 1rem; cursor: pointer; font-family: var(--font); }
.btn-primary:hover { background: var(--accent-h); }

.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-muted);
    padding: 0.35rem 0.9rem; border-radius: 6px; cursor: pointer; font-family: var(--font); font-size: 0.9rem; }
.btn-ghost:hover { border-color: var(--text-muted); }

.error-msg { background: rgba(248,81,73,0.1); border: 1px solid rgba(248,81,73,0.4); border-radius: 6px;
    padding: 0.75rem 1rem; margin-bottom: 1rem; font-size: 0.9rem; color: #f85149; }
.auth-switch { margin-top: 1rem; font-size: 0.85rem; color: var(--text-muted); text-align: center; }
.footer-note { text-align: center; margin-top: 2rem; font-size: 0.8rem; color: var(--text-muted); font-style: italic; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.site-header, .chat-header { background: var(--bg2); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100; }
.header-inner { max-width: 1100px; margin: 0 auto; padding: 0.75rem 1.5rem;
    display: flex; align-items: center; gap: 1rem; justify-content: space-between; }
.site-logo { font-weight: bold; font-size: 1.1rem; }
.header-right { display: flex; align-items: center; gap: 1rem; }
.user-name { color: var(--text-muted); font-size: 0.9rem; }

/* ── Dashboard ──────────────────────────────────────────────────────────────── */
.dashboard-page { min-height: 100vh; }
.dashboard-main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }
.dashboard-hero { text-align: center; margin-bottom: 2.5rem; }
.dashboard-hero h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.dashboard-hero p { color: var(--text-muted); max-width: 600px; margin: 0 auto; }

.tutors-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.25rem; }
.tutor-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.5rem; display: flex; gap: 1.25rem; transition: border-color 0.2s; text-decoration: none; color: var(--text); }
.tutor-card:hover { border-color: var(--accent); text-decoration: none; }
.tutor-avatar { width: 56px; height: 56px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem; font-weight: bold; flex-shrink: 0; }
.tutor-info { flex: 1; min-width: 0; }
.tutor-info h3 { font-size: 1.1rem; margin-bottom: 0.2rem; }
.tutor-subject { display: block; font-size: 0.8rem; color: var(--accent); text-transform: uppercase;
    letter-spacing: 0.05em; margin-bottom: 0.1rem; }
.tutor-era { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.tutor-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.75rem; line-height: 1.5; }
.session-badge { font-size: 0.75rem; background: var(--bg3); border: 1px solid var(--border);
    border-radius: 20px; padding: 0.2rem 0.6rem; color: var(--text-muted); }
.session-badge.new { color: var(--green); border-color: rgba(63,185,80,0.3); }
.empty-state { color: var(--text-muted); text-align: center; padding: 3rem; }

/* ── Chat ───────────────────────────────────────────────────────────────────── */
.chat-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.chat-header { flex-shrink: 0; }
.back-link { color: var(--text-muted); font-size: 0.9rem; white-space: nowrap; }
.tutor-header-info { display: flex; align-items: center; gap: 0.75rem; flex: 1; }
.tutor-avatar-sm { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1rem; font-weight: bold; flex-shrink: 0; }
.tutor-header-info strong { display: block; font-size: 0.95rem; line-height: 1.2; }
.tutor-subject-sm { font-size: 0.75rem; color: var(--text-muted); }

.mode-toggle { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.mode-toggle label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.mode-toggle input[type=checkbox] { width: 36px; height: 20px; appearance: none; background: var(--bg3);
    border: 1px solid var(--border); border-radius: 20px; cursor: pointer; position: relative; transition: background 0.2s; }
.mode-toggle input[type=checkbox]::after { content: ''; position: absolute; top: 2px; left: 2px;
    width: 14px; height: 14px; background: var(--text-muted); border-radius: 50%; transition: left 0.2s; }
.mode-toggle input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
.mode-toggle input[type=checkbox]:checked::after { left: 18px; background: white; }
.mode-label { font-size: 0.85rem; font-weight: 600; min-width: 50px; }
.mode-info { font-size: 0.75rem; color: var(--text-muted); }

.chat-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; max-width: 800px;
    margin: 0 auto; width: 100%; padding: 0 1rem; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1.5rem 0; display: flex; flex-direction: column; gap: 1.25rem; }

.welcome-msg { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.5rem; text-align: center; }
.welcome-msg p { color: var(--text-muted); margin-bottom: 0.5rem; }

.msg { display: flex; gap: 0.75rem; align-items: flex-start; }
.msg-user { flex-direction: row-reverse; }
.msg-user .msg-content { background: var(--accent); color: white; border-radius: 12px 12px 4px 12px; }
.msg-assistant .msg-content { background: var(--bg2); border: 1px solid var(--border); border-radius: 4px 12px 12px 12px; }
.msg.mode-modern .msg-assistant .msg-content { border-color: var(--purple); }

.msg-content { padding: 0.75rem 1rem; font-size: 0.95rem; max-width: 85%; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.msg-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1rem; font-weight: bold; flex-shrink: 0; margin-top: 2px; }

.typing-indicator { display: flex; gap: 0.75rem; align-items: center; }
.typing-dots { display: flex; gap: 4px; padding: 0.75rem 1rem; background: var(--bg2);
    border: 1px solid var(--border); border-radius: 4px 12px 12px 12px; }
.typing-dots span { width: 8px; height: 8px; background: var(--text-muted); border-radius: 50%;
    animation: bounce 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100% { transform: scale(0.8); opacity: 0.5; } 40% { transform: scale(1.1); opacity: 1; } }

.chat-input-area { flex-shrink: 0; padding: 1rem 0 1.5rem; border-top: 1px solid var(--border); }
.chat-input-area form { display: flex; gap: 0.75rem; align-items: flex-end; }
#message-input { flex: 1; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 0.65rem 1rem; font-size: 0.95rem; font-family: var(--font);
    resize: none; min-height: 52px; max-height: 200px; outline: none; }
#message-input:focus { border-color: var(--accent); }
.btn-send { background: var(--accent); color: white; border: none; border-radius: 8px;
    padding: 0.65rem 1.25rem; font-size: 0.95rem; cursor: pointer; font-family: var(--font); white-space: nowrap; }
.btn-send:hover { background: var(--accent-h); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 600px) {
    .header-inner { padding: 0.6rem 1rem; }
    .mode-info { display: none; }
    .tutor-desc { display: none; }
    .chat-container { padding: 0 0.5rem; }
}

/* ── Portrait image — constrained container (issue 1) ───────────────────── */
.tutor-portrait { width: 72px; height: 92px; border-radius: 6px; overflow: hidden; flex-shrink: 0; background: var(--bg3); }
.tutor-portrait img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.tutor-portrait .tutor-avatar { width: 100% !important; height: 100% !important; border-radius: 4px !important; font-size: 2rem !important; }

/* ── Badge alignment — pin to card bottom (issue 3) ─────────────────────── */
.tutor-info { display: flex !important; flex-direction: column; }
.tutor-info .tutor-desc { flex: 1; }

/* ── Education chat modal (issue 2) ─────────────────────────────────────── */
.edu-modal { position: fixed; inset: 0; z-index: 9000; background: rgba(0,0,0,0.72);
    display: flex; align-items: center; justify-content: center; padding: 1rem;
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.edu-modal-container { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
    width: min(640px, 100%); max-height: calc(100vh - 2rem);
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.65); }

.edu-modal-header { padding: 0.875rem 1.125rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.edu-modal-tutor { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; overflow: hidden; }
.edu-modal-portrait { width: 44px; height: 56px; border-radius: 4px; overflow: hidden; flex-shrink: 0; background: var(--bg3); }
.edu-modal-portrait img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.edu-modal-portrait .tutor-avatar { width: 100% !important; height: 100% !important; font-size: 1.4rem !important; border-radius: 4px !important; }
.edu-modal-header strong { display: block; font-size: 1rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.edu-modal-tutor > div > span { font-size: 0.72rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; display: block; }

.edu-modal-controls { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.edu-mode-toggle { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.edu-mode-btn { padding: 0.28rem 0.65rem; font-size: 0.72rem; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; font-family: var(--font); transition: all 0.15s; white-space: nowrap; }
.edu-mode-btn.active { background: var(--accent); color: white; }
.edu-mode-btn:hover:not(.active) { background: var(--bg3); }
.edu-voice-btn { background: transparent; border: 1px solid var(--border); border-radius: 6px;
    padding: 0.28rem 0.55rem; cursor: pointer; font-size: 0.85rem; line-height: 1;
    transition: all 0.15s; color: var(--text-muted); }
.edu-voice-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(56,189,248,0.08); }
.edu-modal-close { background: transparent; border: none; color: var(--text-muted);
    font-size: 1.5rem; cursor: pointer; padding: 0 0.35rem; line-height: 1; }
.edu-modal-close:hover { color: var(--text); }

.edu-modal-body { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column;
    gap: 0.75rem; min-height: 320px; }
.edu-modal-body video { width: 100%; border-radius: 8px; display: block; }
.edu-video-skip { align-self: flex-end; background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.2); color: var(--text); padding: 0.3rem 0.85rem;
    border-radius: 20px; cursor: pointer; font-size: 0.78rem; font-family: var(--font); }
.edu-video-skip:hover { background: rgba(255,255,255,0.18); }

.edu-msg { padding: 0.65rem 0.9rem; border-radius: 8px; font-size: 0.88rem;
    line-height: 1.65; max-width: 88%; word-break: break-word; }
.edu-msg strong { font-weight: 600; }
.edu-msg em { font-style: italic; }
.edu-msg code { font-family: monospace; background: rgba(0,0,0,0.25); padding: 0.1em 0.35em; border-radius: 3px; font-size: 0.85em; }
.edu-msg ul, .edu-msg ol { margin: 0.35em 0 0.35em 1.25em; }
.edu-msg li { margin-bottom: 0.2em; }
.edu-msg h2, .edu-msg h3, .edu-msg h4 { margin: 0.5em 0 0.2em; font-size: 0.95em; font-weight: 700; }
.edu-msg-user { background: var(--accent); color: white; align-self: flex-end; border-radius: 10px 10px 2px 10px; }
.edu-msg-assistant { background: var(--bg3); border: 1px solid var(--border); align-self: flex-start; border-radius: 2px 10px 10px 10px; color: #c8a96e; }
.edu-welcome { text-align: center; color: var(--text-muted); font-size: 0.88rem; padding: 2rem 1rem; align-self: center; line-height: 1.7; }
.edu-typing-indicator { display: flex; gap: 4px; padding: 0.6rem 0.9rem;
    background: var(--bg3); border: 1px solid var(--border); border-radius: 2px 10px 10px 10px; align-self: flex-start; }
.edu-typing-indicator span { width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%; animation: bounce 1.2s infinite; }
.edu-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.edu-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
.edu-mode-sep { text-align: center; font-size: 0.72rem; color: var(--text-muted); padding: 0.35rem 0; letter-spacing: 0.03em; border-top: 1px solid var(--border); }

.edu-modal-input-area { flex-shrink: 0; padding: 0.75rem 1rem 1rem; border-top: 1px solid var(--border); }
.edu-modal-input-area form { display: flex; gap: 0.5rem; align-items: flex-end; }
#edu-chat-input { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 0.6rem 0.85rem; font-size: 0.9rem; font-family: var(--font);
    resize: none; min-height: 44px; max-height: 140px; outline: none; line-height: 1.5; }
#edu-chat-input:focus { border-color: var(--accent); }
.edu-send-btn { background: var(--accent); color: white; border: none; border-radius: 8px;
    padding: 0.6rem 1.1rem; font-size: 0.9rem; cursor: pointer; font-family: var(--font); flex-shrink: 0; }
.edu-send-btn:hover { opacity: 0.85; }
.edu-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

@media (max-width: 600px) {
    .edu-modal { padding: 0; align-items: flex-end; }
    .edu-modal-container { width: 100%; border-radius: 16px 16px 0 0; max-height: 90vh; }
}

/* Narrator text (italics) vs tutor speech */
.edu-msg-assistant em { color: #a8b8d0; font-style: italic; }
.edu-log-msg-assistant em { color: #a8b8d0; font-style: italic; }
