/* =====================================================
   Diễn đàn THCS Khai Thái
   Light/Dark Theme auto theo hệ thống
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ==================== LIGHT THEME ==================== */
:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-input: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: rgba(37, 99, 235, 0.08);
    --primary-border: rgba(37, 99, 235, 0.2);
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --transition: all 0.2s ease;
    --sidebar-width: 280px;
}

/* ==================== DARK THEME ==================== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-card: #1e293b;
        --bg-hover: #334155;
        --bg-input: #1e293b;
        --border-color: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #cbd5e1;
        --text-muted: #64748b;
        --primary-light: rgba(37, 99, 235, 0.15);
        --primary-border: rgba(37, 99, 235, 0.3);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.5);
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; height: auto; }

/* ==================== CONTAINER ==================== */
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* ==================== NAVBAR ==================== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.navbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.navbar-brand i { color: var(--primary); font-size: 1.4rem; }

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
}

.navbar-menu a {
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
}

.navbar-menu a:hover, .navbar-menu a.active {
    color: var(--primary);
    background: var(--primary-light);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.notif-btn {
    position: relative;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.notif-btn:hover { background: var(--bg-hover); color: var(--primary); }

.notif-count {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px 4px 4px;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    cursor: pointer;
    position: relative;
}

.user-menu .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
}

.user-menu .name {
    font-weight: 600;
    font-size: 0.85rem;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); color: white; transform: translateY(-1px); }

.btn-secondary { background: var(--bg-hover); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; color: white; }

.btn-ghost { background: none; color: var(--text-secondary); padding: 6px 12px; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--primary); }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-block { width: 100%; }

/* ==================== FORMS ==================== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

textarea.form-control { min-height: 120px; resize: vertical; }

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-help { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.form-check input { accent-color: var(--primary); }

/* ==================== CARDS ==================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.card-title { font-size: 1rem; font-weight: 700; }

/* ==================== POST CARD ==================== */
.post-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.post-card:hover { box-shadow: var(--shadow-md); }

.post-card.sticky {
    border-left: 3px solid var(--primary);
    background: var(--primary-light);
}

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

.post-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.post-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

.post-meta .author {
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.post-meta .info {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.post-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.4;
}

.post-title a { color: var(--text-primary); }
.post-title a:hover { color: var(--primary); }

.post-content {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.7;
    margin-bottom: 12px;
    max-height: 200px;
    overflow: hidden;
    position: relative;
}

.post-content.expanded { max-height: none; }

.post-attachments {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.post-attachments img {
    max-width: 300px;
    max-height: 200px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    cursor: pointer;
}

.post-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 8px;
}

.post-actions {
    display: flex;
    gap: 4px;
}

.post-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.post-action-btn:hover { background: var(--bg-hover); color: var(--primary); }
.post-action-btn.active { color: var(--primary); }

/* ==================== BADGES ==================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-admin { background: rgba(220, 38, 38, 0.1); color: #dc2626; }
.badge-teacher { background: rgba(37, 99, 235, 0.1); color: #2563eb; }
.badge-class { background: rgba(22, 163, 74, 0.1); color: #16a34a; }
.badge-category {
    background: var(--primary-light);
    color: var(--primary);
    padding: 3px 10px;
    font-size: 0.75rem;
}

@media (prefers-color-scheme: dark) {
    .badge-admin { background: rgba(220, 38, 38, 0.2); color: #f87171; }
    .badge-teacher { background: rgba(37, 99, 235, 0.2); color: #60a5fa; }
    .badge-class { background: rgba(22, 163, 74, 0.2); color: #4ade80; }
}

/* ==================== SIDEBAR ==================== */
.layout {
    display: grid;
    grid-template-columns: 1fr var(--sidebar-width);
    gap: 24px;
    padding: 24px 0;
}

.sidebar {
    position: sticky;
    top: 84px;
    height: fit-content;
}

.sidebar .card { margin-bottom: 16px; }
.sidebar .card-title { font-size: 0.9rem; margin-bottom: 12px; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: var(--transition);
}

.sidebar-link:hover, .sidebar-link.active {
    background: var(--primary-light);
    color: var(--primary);
}

.sidebar-link i { width: 18px; text-align: center; }

/* ==================== COMMENT ==================== */
.comment {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.comment:last-child { border-bottom: none; }

.comment .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.7rem;
    flex-shrink: 0;
}

.comment .body { flex: 1; }

.comment .author {
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.comment .text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.6;
}

.comment .time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.comment .actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.comment .actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: inherit;
}

.comment .actions button:hover { background: var(--bg-hover); color: var(--primary); }

.reply-form { margin-top: 8px; padding-left: 44px; }

/* ==================== REACTIONS ==================== */
.reactions-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.reaction-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    color: var(--text-secondary);
}

.reaction-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.reaction-btn.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

/* ==================== FILTER BAR ==================== */
.filter-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.filter-bar .form-control { width: auto; min-width: 150px; }

/* ==================== ALERT ==================== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
    font-weight: 500;
}

.alert-success { background: rgba(22, 163, 74, 0.1); border: 1px solid rgba(22, 163, 74, 0.2); color: var(--success); }
.alert-danger { background: rgba(220, 38, 38, 0.1); border: 1px solid rgba(220, 38, 38, 0.2); color: var(--danger); }

/* ==================== AUTH PAGE ==================== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background: var(--bg-primary);
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 36px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}

.auth-card .logo { text-align: center; margin-bottom: 28px; }
.auth-card .logo h2 { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.auth-card .logo p { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }
.auth-footer { text-align: center; margin-top: 20px; color: var(--text-muted); font-size: 0.85rem; }

/* ==================== TABLE ==================== */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border-color); font-size: 0.85rem; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.3px; }
tr:hover td { background: var(--bg-hover); }

/* ==================== PAGINATION ==================== */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 24px; }

.page-btn {
    padding: 7px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    text-decoration: none;
}

.page-btn:hover, .page-btn.active { background: var(--primary); border-color: var(--primary); color: white; }

/* ==================== ADMIN LAYOUT ==================== */
.admin-layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.admin-sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 20px 0;
    position: fixed;
    width: 240px;
    height: 100vh;
    overflow-y: auto;
}

.admin-sidebar .logo { padding: 0 20px 20px; border-bottom: 1px solid var(--border-color); margin-bottom: 12px; }
.admin-sidebar .logo h3 { font-size: 1.1rem; font-weight: 800; color: var(--primary); }

.admin-sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    text-decoration: none;
}

.admin-sidebar .nav-item:hover, .admin-sidebar .nav-item.active {
    color: var(--primary);
    background: var(--primary-light);
}

.admin-content { margin-left: 240px; padding: 28px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.admin-header h1 { font-size: 1.4rem; font-weight: 700; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.stat-card .icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.stat-card .icon.blue { background: rgba(37, 99, 235, 0.1); color: var(--primary); }
.stat-card .icon.green { background: rgba(22, 163, 74, 0.1); color: var(--success); }
.stat-card .icon.orange { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.stat-card .icon.red { background: rgba(220, 38, 38, 0.1); color: var(--danger); }

.stat-card .number { font-size: 1.4rem; font-weight: 800; }
.stat-card .label { color: var(--text-muted); font-size: 0.8rem; }

/* ==================== FOOTER ==================== */
.footer {
    text-align: center;
    padding: 30px 20px;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 40px;
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}

.empty-state i { font-size: 2.5rem; margin-bottom: 12px; display: block; opacity: 0.5; }

/* ==================== MODAL ==================== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 28px;
}

/* ==================== ANIMATIONS ==================== */
.fade-in {
    opacity: 0;
    transform: translateY(10px);
    animation: fadeIn 0.4s ease forwards;
}

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

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { display: none; position: fixed; top: 60px; left: 0; right: 0; background: var(--bg-secondary); z-index: 90; padding: 16px; border-bottom: 1px solid var(--border-color); }
    .sidebar.active { display: block; }
    .navbar-menu { display: none; }
    .navbar-menu.active { display: flex; flex-direction: column; position: absolute; top: 60px; left: 0; right: 0; background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); padding: 12px; }
    .mobile-toggle { display: block; }
    .form-row { grid-template-columns: 1fr; }
    .admin-layout { grid-template-columns: 1fr; }
    .admin-sidebar { display: none; }
    .admin-content { margin-left: 0; }
    .post-footer { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
    .navbar-inner { padding: 0 12px; }
    .post-card { padding: 14px; }
    .filter-bar { flex-direction: column; }
    .filter-bar .form-control { width: 100%; }
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
