/* =====================================================
   KRP SCHOOL SYSTEM — Yellow × Blue School Theme
   โมดูลสารบรรณอิเล็กทรอนิกส์ [PREMIUM DESIGNS & MICRO-INTERACTIONS]
   ===================================================== */

:root {
    /* ── Core Palette ── */
    --blue:         #1a56db;
    --blue-dark:    #1139a4;
    --blue-light:   #3b82f6;
    --blue-soft:    #eff6ff;
    --blue-mid:     #dbeafe;

    --yellow:       #f59e0b;
    --yellow-dark:  #d97706;
    --yellow-light: #fcd34d;
    --yellow-soft:  #fffbeb;
    --yellow-mid:   #fef3c7;

    --red:          #dc2626;
    --red-soft:     #fef2f2;
    --green:        #16a34a;
    --green-soft:   #f0fdf4;
    --orange:       #ea580c;

    /* ── Backgrounds ── */
    --bg-main:      #f4f7fe;
    --bg-surface:   #ffffff;
    --bg-card:      #ffffff;
    --bg-sidebar:   #1139a4;

    /* ── Text Shades ── */
    --text-1:       #0f172a; /* ส่วนหัวข้อเข้มเด่น */
    --text-2:       #475569; /* เนื้อหาข้อความปกติ */
    --text-3:       #64748b; /* คำอธิบายย่อยประกอบ */
    --text-light:   #94a3b8;

    /* ── Typography Scale ── */
    --lh-base:      1.6;
    --lh-heading:   1.3;

    /* ── Borders & Enhanced Shadows ── */
    --border:       #e2e8f0;
    --border-blue:  #bfdbfe;
    --shadow-sm:    0 1px 2px rgba(26,86,219,.05);
    --shadow-card:  0 4px 20px rgba(26,86,219,.04), 0 2px 6px rgba(26,86,219,.04);
    --shadow-hover: 0 12px 30px rgba(17,57,164,.12);
    
    --radius:       16px;
    --radius-sm:    10px;
    --transition:   .25s cubic-bezier(.4, 0, .2, 1);
    --bounce:       .4s cubic-bezier(.34, 1.56, .64, 1);
}

/* ── Custom Scrollbar (ลูกเล่นคู่สีประจำโรงเรียน) ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--blue-soft); }
::-webkit-scrollbar-thumb { background: var(--blue-light); border-radius: 999px; border: 2px solid var(--blue-soft); }
::-webkit-scrollbar-thumb:hover { background: var(--yellow); }

/* ── Reset & General Typography Setup ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    background: var(--bg-main);
    font-family: 'Noto Sans Thai', sans-serif;
    color: var(--text-2);
    line-height: var(--lh-base);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    min-height: 100vh;
}

.wrapper { display: flex; min-height: 100vh; position: relative; z-index: 1; }

/* ── Sidebar System Upgrade ── */
.sidebar {
    width: 265px; background: var(--bg-sidebar); flex-shrink: 0; z-index: 1040;
    display: flex; flex-direction: column; transition: var(--transition); position: relative;
    box-shadow: 5px 0 25px rgba(17,57,164,.2);
}
.sidebar::before {
    content: ""; position: absolute; top: 0; left: 0; right: 0; height: 5px;
    background: linear-gradient(90deg, var(--yellow), var(--yellow-light), var(--yellow));
}
.logo-title { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 14px; }
.logo-icon {
    width: 42px; height: 42px; background: var(--yellow); border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; color: var(--blue-dark); flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(245,158,11,.4); transition: var(--bounce);
}
.logo-title:hover .logo-icon { transform: rotate(-10deg) scale(1.1); }

.sidebar-section-title {
    font-size: .72rem; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,.35);
    margin: 18px 0 6px 16px; font-weight: 800;
}
.menu-list { padding: 4px 12px 20px; flex: 1; }
.menu-link {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-bottom: 4px;
    border-radius: var(--radius-sm); color: rgba(255,255,255,.85); text-decoration: none;
    font-weight: 600; font-size: .94rem; transition: var(--transition); cursor: pointer; min-height: 46px;
}
.menu-link i { width: 22px; text-align: center; font-size: 1rem; color: rgba(255,255,255,.5); transition: var(--transition); }

.menu-link:hover { color: #fff; background: rgba(255,255,255,.08); }
.menu-link:hover i { transform: translateX(3px); color: var(--yellow-light); }
.menu-link.active { background: var(--yellow); color: var(--blue-dark); font-weight: 800; box-shadow: 0 4px 15px rgba(245,158,11,.35); }
.menu-link.active i { color: var(--blue-dark); }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: .75rem; color: rgba(255,255,255,.4); text-align: center; font-weight: 500; }

/* ── Workspace Header Layout ── */
.main-content { flex: 1; padding: 32px 40px; min-width: 0; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; padding-bottom: 24px; border-bottom: 1px solid var(--border-blue); }
.page-header h1 { font-size: 1.75rem; font-weight: 900; color: var(--blue-dark); margin: 0; letter-spacing: -.5px; line-height: var(--lh-heading); }
.page-header p { margin: 0; color: var(--text-3); font-size: .9rem; font-weight: 500; }

/* ── Modern Cards UI ── */
.modern-card { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); padding: 24px; margin-bottom: 24px; transition: var(--transition); box-shadow: var(--shadow-card); position: relative; }
.card-section-title { font-size: 1.1rem; font-weight: 800; color: var(--blue-dark); margin: 0; display: flex; align-items: center; }

/* ── Stat Card Micro-interactions (สวยสะดุดตาขึ้น) ── */
.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg-card); border-radius: var(--radius); padding: 22px 18px; border: 1px solid var(--border); transition: all var(--bounce); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; width: 60px; height: 60px; background: rgba(255,255,255,.08); border-radius: 50%; top: -10px; right: -10px; transition: var(--transition); }
.stat-card:hover { transform: translateY(-6px); box-shadow: var(--shadow-hover); border-color: var(--blue-light); }
.stat-card:hover::after { transform: scale(2.5); }

.stat-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.stat-label { font-size: .8rem; color: var(--text-3); font-weight: 700; letter-spacing: .2px; }
.stat-icon { font-size: 1.35rem; transition: var(--bounce); }
.stat-card:hover .stat-icon { transform: scale(1.25) rotate(8deg); }

.stat-num { font-size: 2.2rem; font-weight: 900; color: var(--text-1); line-height: 1.1; margin-top: 12px; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }

/* คู่สีกราฟิกขอบการ์ดสถิติ */
.stat-card.card-total { border-left: 4px solid var(--blue); }
.stat-card.card-act { border-left: 4px solid #7c3aed; }
.stat-card.card-meet { border-left: 4px solid var(--green); }
.stat-card.card-vehicle { border-left: 4px solid var(--yellow); }
.stat-card.card-trip { border-left: 4px solid #0891b2; }
.stat-card.card-repair { border-left: 4px solid var(--red); }

.stat-card.card-total .stat-icon { color: var(--blue); }
.stat-card.card-act .stat-icon { color: #7c3aed; }
.stat-card.card-meet .stat-icon { color: var(--green); }
.stat-card.card-vehicle .stat-icon { color: var(--yellow-dark); }
.stat-card.card-trip .stat-icon { color: #0891b2; }
.stat-card.card-repair .stat-icon { color: var(--red); }

/* ── Typography-optimized List Tables ── */
.list-table { border-collapse: separate; border-spacing: 0; width: 100%; }
.list-table th { background: #f8faff; color: var(--blue-dark); font-weight: 800; padding: 14px 18px; font-size: .82rem; text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--border-blue); }
.list-table td { padding: 16px 18px; vertical-align: middle; border-bottom: 1px solid #edf2f7; color: var(--text-2); font-size: .92rem; }
.list-table tbody tr { transition: var(--transition); }
.list-table tbody tr:hover td { background: var(--blue-soft); }

.date-badge { background: #fff; border: 1px solid var(--border-blue); padding: 4px 10px; border-radius: 8px; font-size: .82rem; text-align: center; color: var(--blue-dark); box-shadow: var(--shadow-sm); }

/* ── Enhanced Badges & Animations ── */
.badge { font-weight: 700; padding: 6px 12px; border-radius: 8px; font-size: .76rem; letter-spacing: .3px; }
.bg-primary { background: #eff6ff!important; color: var(--blue)!important; border: 1px solid var(--blue-mid)!important; }
.bg-success { background: var(--green-soft)!important; color: #166534!important; border: 1px solid #bbf7d0!important; }
.bg-warning { background: var(--yellow-soft)!important; color: var(--yellow-dark)!important; border: 1px solid var(--yellow-mid)!important; }
.bg-danger { background: var(--red-soft)!important; color: var(--red)!important; border: 1px solid #fecaca!important; }

/* เอฟเฟกต์ไฟกะพริบสำหรับหนังสือด่วนที่สุด */
.animate-pulse { animation: pulseAnim 1.8s infinite ease-in-out; }
@keyframes pulseAnim { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.6; transform: scale(0.97); } }

/* ── Filter Engine Style ── */
.filter-section { background: #fff; border-radius: var(--radius); padding: 24px; margin-bottom: 24px; border: 1px solid var(--border-blue); box-shadow: var(--shadow-sm); position: relative; }
.filter-label { font-size: .8rem; font-weight: 800; color: var(--blue-dark); margin-bottom: 8px; display: block; letter-spacing: .5px; }

/* ── Form Element Elements ── */
.form-label { font-weight: 700; color: var(--text-1); margin-bottom: 8px; font-size: .86rem; }
.form-control, .form-select { background: #f8fafc; border: 1.5px solid #cbd5e1; border-radius: var(--radius-sm); padding: 12px 16px; color: var(--text-1); transition: var(--transition); font-size: .94rem; }
.form-control:focus, .form-select:focus { background: #fff; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(26,86,219,.15); outline: none; }

/* ── Premium Buttons ── */
.btn-primary { background: linear-gradient(135deg, var(--blue), var(--blue-dark)); border: none; border-radius: 999px; padding: 12px 28px; font-weight: 700; color: #fff; transition: all var(--bounce); box-shadow: 0 4px 15px rgba(26,86,219,.35); font-size: .92rem; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(26,86,219,.45); filter: brightness(1.1); color: #fff; }
.btn-outline-secondary { background: #fff; border: 1.5px solid var(--border-blue); border-radius: 999px; color: var(--text-2); font-size: .9rem; padding: 11px 26px; font-weight: 600; transition: var(--transition); }
.btn-outline-secondary:hover { background: var(--blue-soft); color: var(--blue); border-color: var(--blue); }

/* ปุ่มลิงก์เปิดดู PDF ทะเบียน */
.btn-action-pdf { background: var(--red-soft); color: var(--red); border: 1px solid #fecaca; padding: 6px 14px; border-radius: 8px; font-size: .82rem; font-weight: 700; text-decoration: none; transition: var(--transition); display: inline-flex; align-items: center; gap: 6px; }
.btn-action-pdf:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Visual Workflow Tracker ── */
.workflow-tracker-box { background: #f8fafc; border: 1px dashed var(--border-blue); }
.w-step-item { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid #e2e8f0; transition: var(--transition); font-size: .86rem; font-weight: 600; padding: 10px 14px; }
.step-dot { font-size: .9rem; flex-shrink: 0; }
.w-step-item.active-wf { background: var(--blue-soft) !important; border-color: var(--blue-light) !important; color: var(--blue-dark) !important; font-weight: 700; box-shadow: var(--shadow-sm); }
.w-step-item.completed-wf { background: var(--green-soft) !important; border-color: var(--green) !important; color: #166534 !important; }
.routing-box { background: var(--yellow-soft); border: 1px solid var(--yellow-light); }

/* ── Mobile Layout & Floating Button (FAB) ── */
.mobile-topbar {
    display: none; background: var(--bg-sidebar); border-bottom: 3px solid var(--yellow);
    padding: 14px 20px; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 1030; box-shadow: 0 4px 15px rgba(17,57,164,.15);
}
.mobile-topbar .brand { font-size: 1rem; font-weight: 800; color: #fff; display: flex; align-items: center; gap: 10px; }
.mobile-topbar .menu-btn { background: rgba(255,255,255,.15); border: none; color: #fff; width: 38px; height: 38px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.6); backdrop-filter: blur(4px); z-index: 1035; }
.sidebar-overlay.show { display: block; }

/* ปุ่มลอยโมบายล์ (FAB) */
.mobile-fab {
    display: none; position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px;
    background: linear-gradient(135deg, var(--yellow), var(--yellow-dark)); color: var(--blue-dark);
    border: none; border-radius: 50%; justify-content: center; align-items: center;
    font-size: 1.5rem; box-shadow: 0 8px 25px rgba(245,158,11,.5); z-index: 1020; transition: var(--bounce);
}
.mobile-fab:active { transform: scale(0.9) rotate(90deg); }

/* ── FontAwesome Animation Hovers ── */
.fa-bounce-hover:hover { animation: fa-bounce 1s infinite linear; }
.fa-spin-hover:hover { animation: fa-spin 2s infinite linear; }

/* ── Responsive View Matrix ── */
@media (max-width: 1199.98px) {
    .stat-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
}

@media (max-width: 991.98px) {
    .wrapper { display: block; }
    .sidebar { position: fixed !important; top: 0; left: -280px; width: 265px; height: 100vh; overflow-y: auto; z-index: 1050; transition: left .3s cubic-bezier(.4,0,.2,1); }
    .sidebar.show { left: 0 !important; }
    .mobile-topbar { display: flex; }
    .mobile-fab { display: flex; } /* เปิดใช้งานปุ่มลอยเพิ่มงานบนมือถือ */
    .main-content { padding: 20px; }
    .page-header { margin-bottom: 20px; padding-bottom: 16px; }
}

@media (max-width: 767.98px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .list-table thead { display: none; }
    
    /* แปลงร่างแถวตารางให้กลายเป็นการ์ดข้อความสวยงามบนสมาร์ตโฟน */
    .list-table tbody tr {
        display: block; background: #fff; border: 1px solid var(--border-blue);
        border-radius: var(--radius); margin-bottom: 16px; padding: 20px;
        box-shadow: var(--shadow-sm); transition: var(--transition);
    }
    .list-table tbody tr:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }
    .list-table tbody td { display: block; padding: 6px 0; border: none; }
    
    .list-table tbody td:first-child { border-bottom: 1px dashed var(--border-blue); padding-bottom: 12px; margin-bottom: 10px; }
    
    /* จัดวางเลย์เอาต์ข้อความหัวข้อเรื่องภายในมือถือให้เด่นชัด */
    .mobile-card-label { font-size: 0.75rem; font-weight: 800; color: var(--text-3); text-transform: uppercase; margin-bottom: 2px; display: block; }
}
/* 🔒 [เพิ่มใหม่] หน้าจอเข้าสู่ระบบ (Login Overlay) */
.login-overlay {
    position: fixed; inset: 0; z-index: 10000;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.login-box {
    background: #fff; border-radius: 20px; padding: 36px 32px;
    width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.user-badge-footer {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; font-size: 0.78rem; color: rgba(255,255,255,0.85);
}
.user-badge-footer button {
    background: transparent; border: 1px solid rgba(255,255,255,0.3); color: #fff;
    border-radius: 8px; padding: 4px 10px; font-size: 0.72rem; cursor: pointer;
}
.user-badge-footer button:hover { background: rgba(255,255,255,0.15); }

/* 🆕 [เพิ่มใหม่] ไฮไลต์แถวที่เลยกำหนดเสร็จแล้วยังไม่ปิดงาน */
tr.row-overdue {
    background: #fef2f2 !important;
    box-shadow: inset 3px 0 0 #ef4444;
}
tr.row-overdue:hover {
    background: #fee2e2 !important;
}
