/* ================================================================
   JJHA Family Admin — Styles
   ================================================================ */

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

:root {
    --color-bg: #f7f7f5;
    --color-surface: #ffffff;
    --color-text: #1a1a1a;
    --color-text-secondary: #6b6b6b;
    --color-border: #e5e5e5;
    --color-accent: #2c5f8a;
    --color-accent-hover: #1e4a6e;
    --color-accent-light: #e8f0f7;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
}

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

/* ---- Top nav ---- */
.topnav {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 2rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topnav-logo {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-accent);
    text-decoration: none;
}
.topnav-right { display: flex; align-items: center; gap: 1rem; }
.topnav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}
.topnav-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}
.topnav-link {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    text-decoration: none;
}
.topnav-link:hover { color: var(--color-text); }

/* ---- Layout ---- */
.container { max-width: 1040px; margin: 0 auto; padding: 2rem; }

/* ---- Dashboard ---- */
.dashboard-header { margin-bottom: 2rem; }
.dashboard-header h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.25rem; }
.dashboard-header p { color: var(--color-text-secondary); font-size: 0.9375rem; }

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

.app-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.app-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--color-accent);
}
.app-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--color-accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}
.app-card h3 { font-size: 1rem; font-weight: 600; }
.app-card p { font-size: 0.8125rem; color: var(--color-text-secondary); line-height: 1.5; }

/* ---- Manual viewer ---- */
.manual-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 2rem;
    align-items: start;
}

.manual-sidebar {
    position: sticky;
    top: 72px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    max-height: calc(100vh - 88px);
    overflow-y: auto;
}
.manual-sidebar h4 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
    margin-bottom: 0.75rem;
}
.manual-sidebar a {
    display: block;
    padding: 0.3rem 0;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    text-decoration: none;
    border-left: 2px solid transparent;
    padding-left: 0.75rem;
}
.manual-sidebar a:hover { color: var(--color-accent); border-left-color: var(--color-accent); }
.manual-sidebar a.indent { padding-left: 1.5rem; font-size: 0.78rem; }

.manual-content {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2rem 2.5rem;
    min-height: 60vh;
}
.manual-content h1 { font-size: 1.75rem; font-weight: 600; margin: 2rem 0 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--color-border); }
.manual-content h1:first-child { margin-top: 0; }
.manual-content h2 { font-size: 1.25rem; font-weight: 600; margin: 1.75rem 0 0.75rem; }
.manual-content h3 { font-size: 1.05rem; font-weight: 600; margin: 1.25rem 0 0.5rem; }
.manual-content p { margin-bottom: 0.75rem; font-size: 0.9375rem; }
.manual-content table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.875rem; }
.manual-content th, .manual-content td { padding: 0.5rem 0.75rem; border: 1px solid var(--color-border); text-align: left; }
.manual-content th { background: var(--color-bg); font-weight: 600; }
.manual-content blockquote {
    border-left: 3px solid var(--color-accent);
    padding: 0.5rem 1rem;
    margin: 1rem 0;
    background: var(--color-accent-light);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.875rem;
}
.manual-content a { color: var(--color-accent); }
.manual-content ul, .manual-content ol { margin: 0.5rem 0 0.75rem 1.5rem; }
.manual-content li { margin-bottom: 0.25rem; font-size: 0.9375rem; }

.manual-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}
.manual-tab {
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--color-text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.manual-tab:hover { color: var(--color-text); }
.manual-tab.active { color: var(--color-accent); border-bottom-color: var(--color-accent); }

/* ---- Chat ---- */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px - 4rem - 42px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    line-height: 1.6;
}
.chat-message.user {
    align-self: flex-end;
    background: var(--color-accent);
    color: #fff;
    border-bottom-right-radius: 2px;
}
.chat-message.assistant {
    align-self: flex-start;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 2px;
}
.chat-message.assistant p { margin-bottom: 0.5rem; }
.chat-message.assistant p:last-child { margin-bottom: 0; }
.chat-message.assistant ul, .chat-message.assistant ol { margin: 0.25rem 0 0.5rem 1.25rem; }
.chat-message.assistant strong { font-weight: 600; }

.chat-typing {
    align-self: flex-start;
    padding: 0.75rem 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.chat-input-area {
    border-top: 1px solid var(--color-border);
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    align-items: end;
}
.chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.6rem 0.75rem;
    font-family: var(--font);
    font-size: 0.9375rem;
    line-height: 1.4;
    min-height: 42px;
    max-height: 120px;
    outline: none;
}
.chat-input:focus { border-color: var(--color-accent); }
.chat-send {
    background: var(--color-accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 0.6rem 1.25rem;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.chat-send:hover { background: var(--color-accent-hover); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Login page ---- */
.login-card {
    max-width: 420px;
    margin: 4rem auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    text-align: center;
}
.login-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.5rem; }
.login-subtitle { color: var(--color-text-secondary); font-size: 0.9375rem; margin-bottom: 1.5rem; }
.login-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    text-align: left;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #991b1b;
}
.login-error p { margin-bottom: 0.5rem; }
.login-error p:last-child { margin-bottom: 0; }
.login-button {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.5rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--color-text);
    text-decoration: none;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.login-button:hover { box-shadow: var(--shadow-lg); border-color: var(--color-accent); }

/* ---- Google Drive browser ---- */
.drive-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.drive-header h1 { font-size: 1.5rem; font-weight: 600; }

.drive-actions { position: relative; }

.create-menu {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    flex-direction: column;
    overflow: hidden;
    z-index: 50;
}
.create-menu button {
    padding: 0.6rem 1.25rem;
    background: none;
    border: none;
    font-family: var(--font);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}
.create-menu button:hover { background: var(--color-bg); }

.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--color-border);
}
.btn-primary { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-bg); }

.drive-search {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.drive-search-input {
    flex: 1;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9375rem;
    outline: none;
}
.drive-search-input:focus { border-color: var(--color-accent); }

.drive-file-list {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.drive-file-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9375rem;
}
.drive-file-row:last-child { border-bottom: none; }
.drive-file-row:hover { background: var(--color-bg); }
.drive-file-icon { font-size: 1.125rem; flex-shrink: 0; }
.drive-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drive-file-date { font-size: 0.8125rem; color: var(--color-text-secondary); flex-shrink: 0; }

.drive-loading {
    padding: 2rem;
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 0.9375rem;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 400px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }
.modal input { width: 100%; margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

/* ---- Onboarding ---- */
.onboarding-layout {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

.ob-sidebar {
    width: 280px;
    min-width: 280px;
    background: #1E293B;
    color: #fff;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow: hidden;
}
.ob-sidebar.collapsed { width: 0; min-width: 0; }

.ob-sidebar-header {
    padding: 1.5rem 1.25rem 1rem;
    border-bottom: 1px solid #334155;
}
.ob-sidebar-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #94A3B8;
    margin-bottom: 0.25rem;
}
.ob-sidebar-title { font-size: 1.125rem; font-weight: 700; margin: 0; }
.ob-progress-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #94A3B8;
    margin: 0.75rem 0 0.25rem;
}
.ob-progress-bar {
    width: 100%;
    background: #334155;
    border-radius: 999px;
    height: 6px;
    overflow: hidden;
}
.ob-progress-fill {
    height: 100%;
    background: #22C55E;
    border-radius: 999px;
    transition: width 0.5s ease;
}

.ob-sidebar-nav { flex: 1; overflow-y: auto; padding: 0.5rem 0; }
.ob-nav-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.6rem 1.25rem;
    border: none;
    cursor: pointer;
    text-align: left;
    background: transparent;
    color: #CBD5E1;
    border-left: 3px solid transparent;
    font-family: var(--font);
    font-size: 0.8125rem;
    transition: all 0.15s;
}
.ob-nav-item:hover { background: rgba(255,255,255,0.05); }
.ob-nav-item.active { background: #334155; color: #fff; font-weight: 600; }
.ob-nav-icon { font-size: 1.125rem; width: 1.75rem; text-align: center; flex-shrink: 0; }

.ob-sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid #334155;
    text-align: center;
}

.ob-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--color-bg); }

.ob-topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.ob-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.125rem;
    padding: 0.25rem;
    color: var(--color-text-secondary);
}
.ob-topbar-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 99px;
}
.ob-topbar-title { font-weight: 700; color: var(--color-text); }
.ob-topbar-meta { color: #94A3B8; font-size: 0.8125rem; margin-left: auto; }

.ob-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.ob-lesson-title { font-size: 1.375rem; font-weight: 700; color: var(--color-text); margin-bottom: 0.25rem; }
.ob-accent-bar { height: 3px; width: 48px; border-radius: 99px; margin-bottom: 1.25rem; }

.ob-h3 { font-size: 1.0625rem; font-weight: 700; margin: 1.25rem 0 0.5rem; color: #1E293B; }
.ob-p { margin: 0.5rem 0; line-height: 1.65; color: #334155; font-size: 0.9375rem; }
.ob-list { margin: 0.5rem 0 0.5rem 1.25rem; line-height: 1.7; color: #334155; font-size: 0.9375rem; }
.ob-list li { margin-bottom: 0.25rem; }

.ob-callout {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin: 0.75rem 0;
    font-size: 0.875rem;
    line-height: 1.6;
    border-left: 4px solid;
}
.ob-callout-info { background: #EFF6FF; border-color: #3B82F6; color: #1E40AF; }
.ob-callout-warning { background: #FFFBEB; border-color: #F59E0B; color: #92400E; }

.ob-kv { margin: 0.5rem 0; display: grid; grid-template-columns: 1fr; gap: 0.25rem; }
.ob-kv-row { display: flex; gap: 1rem; font-size: 0.875rem; padding: 0.25rem 0; }
.ob-kv-key { font-weight: 600; color: #475569; min-width: 140px; flex-shrink: 0; }
.ob-kv-val { color: #1E293B; }

.ob-table-wrap { overflow-x: auto; margin: 0.75rem 0; }
.ob-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.ob-table th { text-align: left; padding: 0.5rem 0.625rem; background: #F1F5F9; border-bottom: 2px solid #CBD5E1; font-weight: 700; color: #334155; }
.ob-table td { padding: 0.5rem 0.625rem; border-bottom: 1px solid #E2E8F0; color: #475569; vertical-align: top; }
.ob-stripe td { background: #F8FAFC; }

.ob-bottomnav {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.ob-dots { display: flex; gap: 6px; }
.ob-dot { width: 8px; height: 8px; border-radius: 99px; transition: background 0.2s; }

/* Quiz */
.ob-quiz-progress { display: flex; align-items: center; margin-bottom: 1rem; font-size: 0.8125rem; color: #64748B; font-weight: 600; }
.ob-quiz-q { font-size: 1rem; font-weight: 600; color: #1E293B; margin-bottom: 1rem; line-height: 1.5; }
.ob-quiz-options { display: flex; flex-direction: column; gap: 0.5rem; }
.ob-quiz-opt {
    text-align: left;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 2px solid #E2E8F0;
    background: #F8FAFC;
    color: #334155;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.875rem;
    line-height: 1.5;
    transition: all 0.15s;
}
.ob-quiz-opt:hover:not(:disabled) { border-color: var(--color-accent); background: #EFF6FF; }
.ob-quiz-opt:disabled { cursor: default; }
.ob-opt-correct { background: #ECFDF5 !important; border-color: #059669 !important; color: #065F46 !important; }
.ob-opt-wrong { background: #FEF2F2 !important; border-color: #DC2626 !important; color: #991B1B !important; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .manual-layout { grid-template-columns: 1fr; }
    .manual-sidebar { display: none; }
    .container { padding: 1rem; }
    .chat-message { max-width: 92%; }
    .ob-sidebar { width: 0; min-width: 0; }
    .ob-sidebar:not(.collapsed) { position: fixed; left: 0; top: 56px; bottom: 0; width: 280px; min-width: 280px; z-index: 150; }
    .ob-content { padding: 1rem; }
    .ob-bottomnav { padding: 0.75rem 1rem; }
}
