/* ===================================
   Class Clinic - Clean 2-Column Design
   =================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---------- Light Theme ---------- */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.08);
    --bg: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-input: #ffffff;
    --text: #1a1a1a;
    --text-sub: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --danger: #ef4444;
    --success: #10b981;
    --radius: 12px;
}

/* ---------- Dark Theme ---------- */
[data-theme="dark"] {
    --bg: #111111;
    --bg-secondary: #1a1a1a;
    --bg-input: #222222;
    --text: #e5e5e5;
    --text-sub: #888888;
    --border: #2a2a2a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.25s, color 0.25s;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }

/* ---------- View System ---------- */
.view {
    display: none !important;
    width: 100%; height: 100vh;
}
#login-view.active-view { display: block !important; }
#main-view.active-view { display: grid !important; }

.content-section { display: none; }
.content-section.active { display: block; }

/* ===================================
   LOGIN
   =================================== */
.login-container {
    width: 100%; height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-secondary);
}

.login-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3rem 2.5rem;
    width: 100%; max-width: 400px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-card .brand-icon {
    font-size: 3rem; color: var(--primary);
    display: block; margin-bottom: 0.75rem;
}

.login-card h1 { font-size: 1.75rem; font-weight: 800; margin-bottom: 0.25rem; }
.login-card .tagline { color: var(--text-sub); font-size: 0.9rem; margin-bottom: 2rem; }

.input-group { margin-bottom: 1rem; }

.input-style {
    width: 100%; padding: 0.75rem 1rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg-input); color: var(--text);
    font-size: 0.95rem; outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-style:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.input-style::placeholder { color: var(--text-sub); }

.btn-primary {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    background: var(--primary); color: #fff; border: none;
    border-radius: var(--radius); padding: 0.75rem 1.5rem;
    font-size: 0.95rem; font-weight: 600;
    transition: background 0.2s, transform 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

/* ===================================
   2-COLUMN LAYOUT (No Right Panel)
   =================================== */
.layout-app {
    display: grid;
    grid-template-columns: 240px 1fr;
    height: 100vh; overflow: hidden;
}

/* ----- SIDEBAR ----- */
.sidebar {
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 1.25rem 0.75rem;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.5rem 0.75rem; margin-bottom: 1.5rem;
}
.sidebar-brand .material-icons-round { color: var(--primary); font-size: 1.75rem; }
.sidebar-brand h1 { font-size: 1.1rem; font-weight: 800; }

.nav-list { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.7rem 0.75rem; border-radius: 10px;
    font-size: 0.9rem; font-weight: 500; color: var(--text-sub);
    transition: all 0.15s;
}
.nav-link:hover { background: var(--bg-secondary); color: var(--text); }
.nav-link.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-link .material-icons-round { font-size: 1.35rem; }

.user-profile {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.75rem; border-top: 1px solid var(--border); margin-top: auto;
}
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--bg-secondary);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-avatar .material-icons-round { font-size: 1.25rem; color: var(--text-sub); }
.user-info { min-width: 0; }
#my-name { font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#my-role { font-size: 0.7rem; color: var(--text-sub); }

/* ----- MAIN FEED ----- */
.main-feed {
    display: flex; flex-direction: column;
    height: 100vh; min-width: 0; background: var(--bg);
}

.header {
    display: flex; align-items: center; justify-content: space-between;
    height: 56px; padding: 0 1.5rem;
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.header h2 { font-size: 1rem; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }

.icon-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px; color: var(--text-sub); transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-secondary); color: var(--text); }

.feed-scroll { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* Post Cards */
.card {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
    transition: border-color 0.15s;
}
.card:hover { border-color: var(--text-sub); }

.post-meta { display: flex; justify-content: space-between; margin-bottom: 0.75rem; font-size: 0.8rem; color: var(--text-sub); }
.post-meta .author { font-weight: 600; color: var(--text); }
.post-body { font-size: 0.95rem; margin-bottom: 0.75rem; }
.post-actions { display: flex; gap: 1.25rem; color: var(--text-sub); font-size: 0.85rem; }
.post-actions span { display: flex; align-items: center; gap: 0.3rem; }
.post-actions .material-icons-round { font-size: 1.1rem; }

/* ----- AI CHAT ----- */
.chat-wrapper {
    display: flex; flex-direction: column;
    height: calc(100vh - 56px);
    max-width: 760px; margin: 0 auto; width: 100%;
}

.chat-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 0; flex-shrink: 0; gap: 0.75rem;
    flex-wrap: wrap;
}
.chat-toolbar-left {
    display: flex; align-items: center; gap: 0.5rem;
}
.chat-toolbar-right {
    display: flex; align-items: center; gap: 0.75rem;
}
.chat-toolbar-label {
    display: flex; align-items: center; gap: 0.4rem;
    font-weight: 600; font-size: 0.9rem;
}

.model-select {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-input); color: var(--text);
    font-size: 0.8rem; outline: none;
}

/* DeepThink toggle in AI chat */
.deepthink-chip {
    display: none; /* hidden by default, shown for pro users */
    align-items: center; gap: 0.4rem;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--primary);
    border-radius: 8px; font-size: 0.8rem;
    color: var(--primary); cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}
.deepthink-chip.visible { display: inline-flex; }
.deepthink-chip.active {
    background: var(--primary); color: #fff;
}
.deepthink-chip .material-icons-round { font-size: 1rem; }

.messages-area {
    flex: 1; overflow-y: auto;
    display: flex; flex-direction: column;
    gap: 0.75rem; padding: 0.5rem 0;
}

.msg {
    max-width: 80%; padding: 0.85rem 1.1rem;
    border-radius: 16px; font-size: 0.9rem;
    line-height: 1.65; word-break: break-word;
}
.msg-user {
    align-self: flex-end; background: var(--primary);
    color: #fff; border-bottom-right-radius: 4px;
}
.msg-ai {
    align-self: flex-start; background: var(--bg-secondary);
    border: 1px solid var(--border); border-bottom-left-radius: 4px;
}

.msg-ai p { margin-bottom: 0.5em; }
.msg-ai p:last-child { margin-bottom: 0; }
.msg-ai code { background: var(--border); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.85em; }
.msg-ai pre { background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; margin: 0.5rem 0; overflow-x: auto; }
.msg-ai pre code { background: none; padding: 0; }
.msg-ai ul, .msg-ai ol { margin: 0.5em 0; padding-left: 1.5em; }
.msg-ai .katex-display { margin: 0.5rem 0; overflow-x: auto; }

.chat-input-box { flex-shrink: 0; padding: 0.75rem 0; }
.chat-input-inner {
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 14px; padding: 0.5rem 0.5rem 0.5rem 1rem;
    box-shadow: var(--shadow);
}
.chat-input-inner textarea {
    flex: 1; background: none; border: none; outline: none;
    resize: none; font: inherit; color: var(--text);
    padding: 0.4rem 0; max-height: 120px; line-height: 1.5;
}
.chat-input-inner textarea::placeholder { color: var(--text-sub); }

.send-btn {
    width: 36px; height: 36px;
    background: var(--primary); color: #fff;
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background 0.15s;
}
.send-btn:hover { background: var(--primary-hover); }
.send-btn .material-icons-round { font-size: 1.15rem; }

/* ----- SETTINGS ----- */
.settings-wrapper { max-width: 560px; }

.settings-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.7rem 0.75rem; border-radius: 10px;
    font-size: 0.9rem; color: var(--text-sub);
    transition: background 0.15s; cursor: pointer;
}
.settings-row:hover { background: var(--bg-secondary); color: var(--text); }
.settings-row.danger { color: var(--danger); }
.settings-row .material-icons-round { font-size: 1.25rem; }

.info-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.6rem 0.75rem; font-size: 0.9rem;
}
.info-row .label { color: var(--text-sub); }
.info-row .value { font-weight: 600; }

.badge-role {
    display: inline-block; padding: 0.15rem 0.5rem;
    border-radius: 6px; font-size: 0.75rem; font-weight: 700;
    text-transform: uppercase;
}
.badge-role.basic { background: #e5e7eb; color: #374151; }
.badge-role.early { background: #dbeafe; color: #1d4ed8; }
.badge-role.pro { background: var(--primary); color: #fff; }

/* Admin section */
.admin-input-row {
    display: flex; gap: 0.5rem; margin-top: 0.5rem;
}
.admin-input-row .input-style { flex: 1; padding: 0.5rem 0.75rem; font-size: 0.85rem; }
.admin-input-row .btn-primary { padding: 0.5rem 1rem; font-size: 0.85rem; }

.student-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 0; border-bottom: 1px solid var(--border);
}
.student-row:last-child { border-bottom: none; }
.student-name { font-weight: 600; font-size: 0.9rem; }
.student-meta { font-size: 0.75rem; color: var(--text-sub); }
.student-actions { display: flex; align-items: center; gap: 0.5rem; }

.mini-select {
    padding: 0.2rem 0.4rem; border: 1px solid var(--border);
    border-radius: 6px; background: var(--bg-input); color: var(--text);
    font-size: 0.75rem; outline: none;
}
.btn-sm {
    padding: 0.2rem 0.6rem; border-radius: 6px;
    font-size: 0.75rem; font-weight: 600;
    border: 1px solid; background: none; cursor: pointer;
}
.btn-sm.danger { color: var(--danger); border-color: var(--danger); }
.btn-sm.success { color: var(--success); border-color: var(--success); }

/* ===================================
   OVERLAYS
   =================================== */
.toast-popup {
    position: fixed; bottom: 1.5rem; left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text); color: var(--bg);
    padding: 0.65rem 1.5rem; border-radius: 999px;
    font-size: 0.85rem; font-weight: 500;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 9999; pointer-events: none;
}
.toast-popup.show { transform: translateX(-50%) translateY(0); }

.loader-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 9998;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Modal ----- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 9000;
}

.modal-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%; max-width: 480px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-weight: 700; font-size: 1rem; }

.modal-body { padding: 1.25rem; }
.modal-footer { padding: 0 1.25rem 1.25rem; }

/* Detail Modal Specifics */
.comment-item {
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-radius: 12px;
}
.comment-author { font-weight: 700; font-size: 0.85rem; margin-bottom: 0.2rem; }
.comment-text { font-size: 0.9rem; color: var(--text); }
.comment-date { font-size: 0.75rem; color: var(--text-sub); margin-top: 0.3rem; }

#detail-like-btn.liked {
    color: var(--danger);
}
#detail-like-btn.liked .material-icons-round {
    font-variation-settings: 'FILL' 1;
}

/* ===================================
   RESPONSIVE
   =================================== */
@media (max-width: 768px) {
    .layout-app {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 56px;
    }
    .sidebar {
        order: 2; flex-direction: row;
        border-right: none; border-top: 1px solid var(--border);
        padding: 0; overflow-x: auto;
    }
    .sidebar-brand, .user-profile { display: none; }
    .nav-list { flex-direction: row; width: 100%; justify-content: space-around; }
    .nav-link span:not(.material-icons-round) { display: none; }
    .nav-link { padding: 0.75rem; justify-content: center; }
    .main-feed { order: 1; height: calc(100vh - 56px); }
}
