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

:root {
    /* Brand Colors */
    --drilite-navy: #1a5c38;
    --drilite-navy-hover: #13472a;
    --drilite-navy-light: #2d7a4f;
    --drilite-navy-soft: #f0faf4;
    
    --drilite-brand: #F59E0B;
    --drilite-brand-hover: #d97706;
    --drilite-brand-light: #fbbf24;
    --drilite-brand-soft: #fef3c7;
    
    /* Overriding Bootstrap Variables */
    --bs-primary: var(--drilite-navy);
    --bs-primary-rgb: 26, 92, 56;
    --bs-secondary: #6b7280;
    --bs-info: #3b82f6;
    --bs-success: #10b981;
    --bs-warning: var(--drilite-brand);
    --bs-danger: #ef4444;
    --bs-light: #f3f4f6;
    --bs-dark: #111827;
    
    --bs-font-sans-serif: 'Inter', system-ui, -apple-system, sans-serif;
    --bs-body-font-family: var(--bs-font-sans-serif);
    --bs-body-bg: #f8fafc;
    --bs-body-color: #334155;
    
    /* Layout Variables */
    --sidebar-w: 260px;
    --sidebar-bg: #0f1f3a; /* Deep elegant dark for sidebar */
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active-bg: rgba(245, 158, 11, 0.15);
    --sidebar-active-color: var(--drilite-brand);
}

/* =========================================
   GLOBAL OVERRIDES
   ========================================= */
body {
    font-family: var(--bs-font-sans-serif);
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* =========================================
   COMPONENTS
   ========================================= */

/* Cards (Glassmorphism & Premium Shadows) */
.card {
    border: none !important;
    border-radius: 1rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 1), 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    background: #ffffff;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 1), 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
}

.card-header {
    background-color: transparent !important;
    border-bottom: 1px solid #f1f5f9;
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    color: #1e293b;
}

.card-body {
    padding: 1.5rem;
}

/* Buttons */
.btn {
    border-radius: 0.5rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    transition: all 0.2s ease;
    letter-spacing: 0.01em;
}

.btn-primary {
    background-color: var(--drilite-navy);
    border-color: var(--drilite-navy);
    box-shadow: 0 4px 6px -1px rgba(26, 92, 56, 0.2);
}

.btn-primary:hover, .btn-primary:focus {
    background-color: var(--drilite-navy-hover);
    border-color: var(--drilite-navy-hover);
    box-shadow: 0 6px 8px -1px rgba(26, 92, 56, 0.3);
    transform: translateY(-1px);
}

.btn-warning {
    background-color: var(--drilite-brand);
    border-color: var(--drilite-brand);
    color: #fff;
    box-shadow: 0 4px 6px -1px rgba(245, 158, 11, 0.25);
}

.btn-warning:hover, .btn-warning:focus {
    background-color: var(--drilite-brand-hover);
    border-color: var(--drilite-brand-hover);
    color: #fff;
    transform: translateY(-1px);
}

.btn-outline-primary {
    color: var(--drilite-navy);
    border-color: var(--drilite-navy);
}

.btn-outline-primary:hover {
    background-color: var(--drilite-navy-soft);
    color: var(--drilite-navy-hover);
    border-color: var(--drilite-navy-hover);
}

/* Forms */
.form-control, .form-select {
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: #f8fafc;
}

.form-control:focus, .form-select:focus {
    background-color: #ffffff;
    border-color: var(--drilite-brand-light);
    box-shadow: 0 0 0 0.25rem rgba(245, 158, 11, 0.15);
}

.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: #475569;
    margin-bottom: 0.4rem;
}

/* Tables */
.table {
    margin-bottom: 0;
}

.table > :not(caption) > * > * {
    padding: 1rem 1.25rem;
    border-bottom-color: #f1f5f9;
    vertical-align: middle;
}

.table thead th {
    background-color: #f8fafc;
    color: #64748b;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #e2e8f0;
}

.table tbody tr {
    transition: background-color 0.15s;
}

.table tbody tr:hover {
    background-color: #f8fafc;
}

/* Badges */
.badge {
    padding: 0.4em 0.8em;
    border-radius: 9999px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.bg-success { background-color: var(--drilite-navy-light) !important; }
.bg-warning { background-color: var(--drilite-brand) !important; color: #fff !important; }

/* 'purple' không có sẵn trong Bootstrap — dùng cho vai trò "Sát hạch viên" / trạng thái "Đã liên hệ" */
.bg-purple { background-color: #8b5cf6 !important; color: #fff !important; }
.text-purple { color: #7c3aed !important; }
.border-purple { border-color: #8b5cf6 !important; }
.bg-purple-subtle { background-color: #ede9fe !important; }

/* Status Badges Custom */
.badge-status-valid    { background: #dcfce7; color: #166534; padding: 0.4em 0.8em; border-radius: 9999px; font-weight: 500; font-size: 0.75rem; }
.badge-status-expiring { background: #fef9c3; color: #854d0e; padding: 0.4em 0.8em; border-radius: 9999px; font-weight: 500; font-size: 0.75rem; }
.badge-status-expired  { background: #fee2e2; color: #991b1b; padding: 0.4em 0.8em; border-radius: 9999px; font-weight: 500; font-size: 0.75rem; }

/* KPI Cards */
.kpi-card {
    border-left: none !important;
    position: relative;
    padding: 1.5rem;
}
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 4px;
    border-radius: 1rem 0 0 1rem;
}
.kpi-card.blue::before   { background: linear-gradient(180deg, #60a5fa, #3b82f6); }
.kpi-card.green::before  { background: linear-gradient(180deg, #34d399, #10b981); }
.kpi-card.yellow::before { background: linear-gradient(180deg, #fbbf24, #f59e0b); }
.kpi-card.red::before    { background: linear-gradient(180deg, #f87171, #ef4444); }

.kpi-title {
    color: #64748b;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.kpi-num {
    color: #0f172a;
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
}

/* =========================================
   LAYOUT OVERRIDES (Sidebar & Topbar)
   ========================================= */

/* Sidebar */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--sidebar-bg);
    /* Subtle gradient overlay */
    background-image: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0) 100%);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    color: #fff;
    z-index: 1040;
    /* Nền luôn phủ tối thiểu 1 màn hình + dính cố định khi cuộn trang, không co giãn
       theo chiều cao của accordion đang mở/đóng hay theo nội dung #main bên cạnh
       (#wrapper là flex row nên mặc định align-items:stretch sẽ kéo giãn nền theo
       phần tử cao nhất — bỏ qua bằng align-self, tự quản chiều cao bằng min/max-height). */
    position: sticky;
    top: 0;
    align-self: flex-start;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

#sidebar .brand {
    padding: 1.5rem 1.25rem;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

#sidebar .brand-title {
    color: #fff;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
}
#sidebar .brand-title span.highlight {
    color: var(--drilite-brand);
}

#sidebar .brand-sub {
    color: rgba(255,255,255,0.6);
    font-size: 0.75rem;
    margin-top: 0.2rem;
    font-weight: 500;
}

#sidebar .nav-section {
    color: rgba(255,255,255,0.4);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 1.5rem 1.25rem 0.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

#sidebar .nav-section:hover {
    color: rgba(255,255,255,0.8);
}

#sidebar .nav-section[aria-expanded="true"] .bi-chevron-down {
    transform: rotate(180deg);
}

#sidebar .nav-link {
    color: rgba(255,255,255,0.7);
    padding: 0.6rem 1.25rem;
    border-radius: 0.5rem;
    margin: 0.2rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

#sidebar .nav-link:hover {
    color: #fff;
    background: var(--sidebar-hover);
    transform: translateX(3px);
}

#sidebar .nav-link.active {
    color: var(--sidebar-active-color);
    background: var(--sidebar-active-bg);
    font-weight: 600;
}

#sidebar .nav-link .bi {
    font-size: 1.1rem;
    width: 1.2rem;
    text-align: center;
}

/* Topbar */
#topbar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    padding: 0.75rem 1.5rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.topbar-breadcrumb {
    font-weight: 600;
    color: #334155;
    font-size: 0.95rem;
}

/* Flash Messages Custom */
.flash-wrap .alert {
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    font-weight: 500;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
}

.flash-wrap .alert-success { background-color: #ecfdf5; color: #065f46; border-left: 4px solid #10b981; }
.flash-wrap .alert-danger { background-color: #fef2f2; color: #991b1b; border-left: 4px solid #ef4444; }
.flash-wrap .alert-info { background-color: #eff6ff; color: #1e40af; border-left: 4px solid #3b82f6; }

.flash-wrap .alert .bi { font-size: 1.25rem; }

/* =========================================
   STUDENT LAYOUT SPECIFIC OVERRIDES
   ========================================= */
.student-topbar {
    background: var(--sidebar-bg); color: #fff;
    padding: .75rem 1.25rem; position: sticky; top: 0; z-index: 1040;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    background-image: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0) 100%);
}
.student-topbar .app-name { font-weight: 800; font-size: 1.05rem; letter-spacing: 0.02em; }
.student-bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(226, 232, 240, 0.8); z-index: 1040;
    display: flex; justify-content: space-around; padding: .5rem 0 .7rem;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.03);
}
.student-bottom-nav a {
    display: flex; flex-direction: column; align-items: center;
    font-size: .7rem; color: #64748b; text-decoration: none; gap: .2rem;
    font-weight: 500; transition: color 0.2s;
}
.student-bottom-nav a.active { color: var(--drilite-brand); font-weight: 600; }
.student-bottom-nav a:hover { color: var(--drilite-brand-hover); }
.student-bottom-nav .bi { font-size: 1.3rem; margin-bottom: -2px; }
main.student-main { padding-bottom: 80px; }

/* =========================================
   DESIGN SYSTEM — Page header / filter bar / section card /
   empty state / pagination (Phase 10 — dùng chung toàn Admin)
   ========================================= */

.page-header-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 0.25rem;
    position: relative;
    padding-bottom: 0.5rem;
    display: inline-block;
}
.page-header-title::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    width: 40px; height: 4px;
    background: linear-gradient(90deg, var(--drilite-brand), var(--drilite-navy-light));
    border-radius: 4px;
}
.page-header-subtitle {
    color: #64748b;
    font-size: 0.85rem;
    margin-bottom: 0;
}

/* Filter bar: wrap existing <form class="row g-2 filter-bar"> — chỉ thêm class, không đổi field */
.filter-bar {
    background: #fff;
    border: 1px solid #f1f5f9;
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
}
.filter-bar .form-control,
.filter-bar .form-select { background-color: #fff; }

/* Section card: nhóm field trong form dài (students/form.php, courses/form.php...) */
.section-card .card-header {
    background-color: #f8fafc !important;
    font-weight: 600;
    font-size: 0.9rem;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.section-card .card-header .bi { color: var(--drilite-navy); }

/* Empty state */
.empty-state .bi {
    font-size: 2.25rem;
    color: #cbd5e1;
    display: block;
    margin-bottom: 0.75rem;
}
.empty-state-text { font-weight: 500; color: #64748b; }
.empty-state-subtext { font-size: 0.8rem; color: #94a3b8; margin-top: 0.25rem; }

/* Pagination bar */
.pagination-bar { padding: 0.5rem 0; }

/* Notification badge (Phase 11 — polling dot dùng chung 3 portal) */
.notif-badge-dot {
    position: absolute; top: -2px; right: -2px;
    background: #ef4444; color: #fff; border-radius: 9999px;
    font-size: 0.65rem; line-height: 1; padding: 0.2em 0.4em;
    min-width: 1.1em; text-align: center; font-weight: 700;
}

/* =========================================
   AUTH PAGE OVERRIDES
   ========================================= */
.auth-bg {
    background: linear-gradient(135deg, var(--sidebar-bg) 0%, #1a3258 100%);
    position: relative;
}
.auth-bg::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCI+PGNpcmNsZSBjeD0iMjAiIGN5PSIyMCIgcj0iMSIgZmlsbD0icmdiYSgyNTUsIDI1NSwgMjU1LCAwLjA1KSIvPjwvc3ZnPg==') repeat;
    pointer-events: none;
}

/* =========================================
   CHART COLORS (Phase 12 — validated qua dataviz skill:
   node validate_palette.js — ALL CHECKS PASS, light mode)
   Thứ tự cố định, dùng cho mọi biểu đồ categorical (không đảo thứ tự).
   ========================================= */
:root {
    --chart-1: #059669; /* green  — cũng dùng làm accent chart đơn-chuỗi (doanh thu) */
    --chart-2: #d97706; /* amber  — accent chart đơn-chuỗi (học viên mới) */
    --chart-3: #2563eb; /* blue */
    --chart-4: #dc2626; /* red */
    --chart-5: #7c3aed; /* purple */
    --chart-6: #0891b2; /* cyan */
    --chart-grid: #eef2f7;
    --chart-text-muted: #94a3b8;
}

/* =========================================
   DASHBOARD CHART CARD + TREND BADGE (Phase 12)
   ========================================= */
.chart-card .card-body { padding: 1.1rem 1.25rem; }
.chart-card canvas { max-height: 220px; }

.trend-badge {
    display: inline-flex; align-items: center; gap: 0.2rem;
    font-size: 0.75rem; font-weight: 600; padding: 0.15em 0.5em;
    border-radius: 9999px;
}
.trend-badge.up   { background: #dcfce7; color: #166534; }
.trend-badge.down { background: #fee2e2; color: #991b1b; }
.trend-badge.flat { background: #f1f5f9; color: #64748b; }

/* =========================================
   MESSAGING / CHAT (Phase 12 — nhắn tin riêng 1-1)
   ========================================= */
.avatar-circle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; min-width: 42px;
    border-radius: 50%; font-weight: 700; font-size: 0.9rem;
    background: var(--drilite-navy-soft); color: var(--drilite-navy);
    text-transform: uppercase;
}
.avatar-circle.sm { width: 32px; height: 32px; min-width: 32px; font-size: 0.75rem; }

.conversation-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.85rem 1rem; text-decoration: none; color: inherit;
    border-bottom: 1px solid #f1f5f9; transition: background-color 0.15s;
}
.conversation-item:hover { background: #f8fafc; }
.conversation-item.active { background: var(--drilite-navy-soft); }
.conversation-item .conv-name { font-weight: 600; color: #1e293b; font-size: 0.9rem; }
.conversation-item .conv-preview {
    font-size: 0.8rem; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 100%;
}
.conversation-item.unread .conv-preview,
.conversation-item.unread .conv-name { color: #0f172a; font-weight: 700; }
.conversation-item .conv-time { font-size: 0.7rem; color: #94a3b8; white-space: nowrap; }
.conv-unread-dot {
    width: 9px; height: 9px; border-radius: 50%; background: var(--drilite-brand);
    display: inline-block; flex: none;
}

.chat-thread {
    height: 55vh; min-height: 320px; overflow-y: auto;
    padding: 1rem; background: #f8fafc;
    display: flex; flex-direction: column; gap: 0.5rem;
}
.msg-bubble-row { display: flex; }
.msg-bubble-row.out { justify-content: flex-end; }
.msg-bubble {
    max-width: 72%; padding: 0.55rem 0.85rem; border-radius: 1rem;
    font-size: 0.88rem; line-height: 1.4; word-wrap: break-word;
}
.msg-bubble-row.in .msg-bubble {
    background: #fff; border: 1px solid #e2e8f0; border-bottom-left-radius: 0.25rem;
}
.msg-bubble-row.out .msg-bubble {
    background: var(--drilite-navy); color: #fff; border-bottom-right-radius: 0.25rem;
}
.msg-bubble-time {
    font-size: 0.65rem; margin-top: 0.2rem; opacity: 0.7;
}
.chat-composer {
    border-top: 1px solid #e2e8f0; padding: 0.75rem; background: #fff;
}

/* =========================================
   PROGRESS RING (student dashboard — Phase 12)
   ========================================= */
.progress-ring-wrap { position: relative; width: 110px; height: 110px; margin: 0 auto; }
.progress-ring-label {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
}
.progress-ring-label .pct { font-size: 1.4rem; font-weight: 800; color: #fff; line-height: 1; }
.progress-ring-label .sub { font-size: 0.62rem; color: rgba(255,255,255,0.75); margin-top: 0.15rem; }

/* =========================================
   PERF: defer offscreen rows in long lists
   (notifications, attendance/GPS history — Phase 14)
   Apply only to rows past the initial fold; skip the
   first few items so above-the-fold render isn't delayed.
   ========================================= */
@supports (content-visibility: auto) {
    .cv-row {
        content-visibility: auto;
        contain-intrinsic-size: auto 84px;
    }
}
