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

:root {
    --bg-deep: #060b18;
    --bg-card: #0d1526;
    --bg-card-hover: #131d35;
    --bg-sidebar: #0a1120;
    --accent: #f0a030;
    --accent-glow: rgba(240, 160, 48, 0.15);
    --accent-soft: #ffd48a;
    --text-primary: #e8ecf4;
    --text-secondary: #8a94a8;
    --text-muted: #5a6478;
    --border: rgba(255,255,255,0.06);
    --danger: #ef4444;
    --success: #4ade80;
    --sidebar-width: 280px;
}

html, body { height: 100%; }

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    overflow: hidden;
    line-height: 1.6;
}

.hidden { display: none !important; }
.screen { height: 100vh; }

/* ==================== AUTH ==================== */
#auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-deep);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(240,160,48,0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(167,139,250,0.03) 0%, transparent 50%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 24px;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--accent);
    font-size: 1.4rem;
    font-weight: 700;
    justify-content: center;
    margin-bottom: 32px;
}

.logo-icon {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #000;
    font-weight: 700;
    font-size: 18px;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
}

.auth-tabs {
    display: flex;
    gap: 4px;
    background: rgba(255,255,255,0.04);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 24px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.auth-tab.active {
    background: var(--accent);
    color: #000;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-group input {
    padding: 12px 14px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group input::placeholder { color: var(--text-muted); }

.form-error {
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 0;
}

.btn { border: none; cursor: pointer; font-family: inherit; transition: all 0.2s; }
.btn-primary {
    background: var(--accent);
    color: #000;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 12px 28px;
    border-radius: 10px;
}
.btn-primary:hover {
    background: var(--accent-soft);
    transform: translateY(-1px);
}
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}
.btn-full { width: 100%; }

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ==================== MAIN APP LAYOUT ==================== */
#main-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Mobile header */
#mobile-header {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
}

.hamburger {
    background: none; border: none; cursor: pointer;
    display: flex; flex-direction: column; gap: 5px; padding: 8px;
}
.hamburger span {
    width: 20px; height: 2px;
    background: var(--text-secondary);
    border-radius: 2px;
}

.header-title {
    font-weight: 700;
    color: var(--accent);
    font-size: 1.1rem;
}

.new-chat-btn-mobile {
    width: 32px; height: 32px;
    background: var(--accent);
    color: #000;
    border: none; border-radius: 8px;
    font-size: 1.2rem; font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* ==================== SIDEBAR ==================== */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--accent);
    font-size: 1.2rem;
    font-weight: 700;
}

.logo-icon-sm {
    width: 28px; height: 28px;
    background: var(--accent);
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    color: #000;
    font-weight: 700;
    font-size: 15px;
}

.sidebar-nav {
    padding: 12px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    text-align: left;
    width: 100%;
}

.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); }

.nav-icon { font-size: 1.1rem; }

.checkin-dot {
    width: 8px; height: 8px;
    background: var(--accent);
    border-radius: 50%;
    margin-left: auto;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 16px;
}

.sessions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.new-chat-btn {
    width: 24px; height: 24px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.new-chat-btn:hover { background: var(--accent); color: #000; border-color: var(--accent); }

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}
.session-item:hover { background: rgba(255,255,255,0.04); }
.session-item.active { background: var(--accent-glow); }

.session-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-item.active .session-title { color: var(--accent); }

.session-preview {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.session-module-badge {
    display: inline-block;
    font-size: 0.65rem;
    background: rgba(255,255,255,0.06);
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--text-muted);
    margin-top: 3px;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.user-avatar {
    width: 32px; height: 32px;
    background: var(--accent-glow);
    border: 1px solid rgba(240,160,48,0.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    flex-shrink: 0;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    background: none; border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.15s;
    display: flex;
}
.logout-btn:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 199;
}

/* ==================== CONTENT ==================== */
#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==================== CHAT VIEW ==================== */
.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-header-title {
    font-size: 1rem;
    font-weight: 600;
}

.chat-header-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 720px;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.message-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    background: var(--accent-glow);
    margin-top: 2px;
}

.message-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.6;
}

.message.assistant .message-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
}

.message.user .message-content {
    background: var(--accent);
    color: #000;
    border-top-right-radius: 4px;
}

.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content strong { font-weight: 600; }
.message-content em { font-style: italic; }

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px 8px;
}

.typing-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    background: var(--accent-glow);
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    border-top-left-radius: 4px;
}

.typing-dots span {
    width: 6px; height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Chat input */
.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px 8px 8px 16px;
    transition: border-color 0.2s;
}

.chat-input-wrap:focus-within { border-color: var(--accent); }

#chat-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 4px 0;
}

#chat-input::placeholder { color: var(--text-muted); }

.send-btn {
    width: 36px; height: 36px;
    background: var(--accent);
    border: none; border-radius: 10px;
    color: #000;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.send-btn:hover { background: var(--accent-soft); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-disclaimer {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Module lesson banner in chat */
.lesson-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--accent-glow);
    border: 1px solid rgba(240,160,48,0.15);
    border-radius: 12px;
    margin: 0 24px;
    flex-shrink: 0;
}

.lesson-banner-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 500;
}

.lesson-advance-btn {
    padding: 6px 14px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.lesson-advance-btn:hover { background: var(--accent-soft); }

/* ==================== MODULES VIEW ==================== */
.view-header {
    padding: 32px 32px 24px;
    flex-shrink: 0;
}
.view-header h2 { font-size: 1.5rem; margin-bottom: 6px; }
.view-header p { color: var(--text-secondary); font-size: 0.95rem; }

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    padding: 0 32px 32px;
    overflow-y: auto;
}

.module-card-app {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    transition: all 0.2s;
    cursor: pointer;
}
.module-card-app:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255,255,255,0.1);
    transform: translateY(-2px);
}

.module-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.module-card-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.module-card-title { font-size: 1.05rem; font-weight: 600; }

.module-card-desc {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin-bottom: 16px;
}

.module-progress-bar {
    height: 6px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.module-progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.module-progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.module-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 600;
}

.module-badge.completed {
    background: rgba(74,222,128,0.12);
    color: var(--success);
}

.module-badge.in-progress {
    background: var(--accent-glow);
    color: var(--accent);
}

/* ==================== CHECKIN VIEW ==================== */
#checkin-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 32px 32px;
}

.checkin-form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    max-width: 540px;
}

.checkin-section {
    margin-bottom: 24px;
}

.checkin-section label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.mood-selector {
    display: flex;
    gap: 12px;
}

.mood-btn {
    width: 56px; height: 56px;
    border-radius: 14px;
    border: 2px solid var(--border);
    background: rgba(255,255,255,0.02);
    font-size: 28px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.mood-btn:hover { border-color: var(--accent); transform: scale(1.08); }
.mood-btn.selected {
    border-color: var(--accent);
    background: var(--accent-glow);
    transform: scale(1.1);
}

.checkin-textarea {
    width: 100%;
    padding: 12px 14px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    outline: none;
    min-height: 80px;
    transition: border-color 0.2s;
}
.checkin-textarea:focus { border-color: var(--accent); }
.checkin-textarea::placeholder { color: var(--text-muted); }

.checkin-submit {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.checkin-submit:hover { background: var(--accent-soft); }
.checkin-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.checkin-done-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    max-width: 540px;
}

.checkin-done-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.checkin-done-header .icon { font-size: 28px; }
.checkin-done-header h3 { font-size: 1.1rem; }

.checkin-mood-display {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.checkin-mood-display .mood-dot {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    background: rgba(255,255,255,0.04);
}
.checkin-mood-display .mood-dot.active {
    background: var(--accent-glow);
    border: 1px solid var(--accent);
}

.checkin-ai-response {
    padding: 16px;
    background: rgba(255,255,255,0.03);
    border-radius: 12px;
    border-left: 3px solid var(--accent);
    margin-top: 16px;
}
.checkin-ai-response p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.checkin-goal-display {
    margin-top: 12px;
    padding: 12px;
    background: rgba(255,255,255,0.02);
    border-radius: 8px;
}
.checkin-goal-display .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}
.checkin-goal-display .value {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Mood history mini chart */
.mood-history {
    margin-top: 24px;
}
.mood-history h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.mood-bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 60px;
}
.mood-bar {
    flex: 1;
    border-radius: 3px 3px 0 0;
    transition: height 0.3s;
    max-width: 20px;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* ==================== MOBILE ==================== */
@media (max-width: 768px) {
    #mobile-header { display: flex; }

    #sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        z-index: 200;
        transition: left 0.3s ease;
    }
    #sidebar.open { left: 0; }
    .sidebar-overlay.open { display: block; }

    #content { padding-top: 56px; }

    .messages { padding: 16px; }
    .chat-input-area { padding: 12px 16px; }
    .chat-header { padding: 12px 16px; }

    .view-header { padding: 24px 20px 16px; }
    .modules-grid { padding: 0 20px 20px; grid-template-columns: 1fr; }
    #checkin-content { padding: 0 20px 20px; }

    .lesson-banner { margin: 0 16px; }
}
