/* =====================================================
   KRP SCHOOL SYSTEM — Futuristic Yellow × Blue Edition
   Premium, Hyper-Responsive, Ultra-Modern & Light-Weight UI
   ===================================================== */

:root {
    /* ── Core Palette (Enhanced Contrast) ── */
    --blue:         #1a56db;
    --blue-dark:    #0f2d83;
    --blue-light:   #60a5fa;
    --blue-soft:    #f0f5ff;
    --blue-mid:     #dbeafe;

    --yellow:       #f59e0b;
    --yellow-dark:  #b45309;
    --yellow-light: #fcd34d;
    --yellow-soft:  #fffbeb;
    --yellow-mid:   #fef3c7;

    --red:          #ef4444;
    --red-soft:     #fef2f2;
    --green:        #10b981;
    --green-soft:   #f0fdf4;
    --orange:       #f97316;

    /* ── Backgrounds ── */
    --bg-main:      #f4f7fe;
    --bg-surface:   #ffffff;
    --bg-card:      #ffffff;
    --bg-sidebar:   linear-gradient(180deg, #1139a4 0%, #1a56db 100%);

    /* ── Borders & Optimized Shadows ── */
    --border:       #e2e8f0;
    --border-blue:  rgba(191, 219, 254, 0.6);
    
    /* Soft 3D Layers */
    --shadow-sm:    0 2px 8px rgba(26, 86, 219, 0.04);
    --shadow:       0 10px 30px rgba(26, 86, 219, 0.05);
    --shadow-lg:    0 20px 40px rgba(17, 57, 164, 0.1);
    --shadow-card:  0 4px 16px rgba(26, 86, 219, 0.04);

    /* ── Sizing & Transitions ── */
    --radius:       16px;
    --radius-sm:    10px;
    --trans-fast:   0.2s cubic-bezier(0.25, 1, 0.5, 1);
    --trans-smooth: 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    --bounce:       0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Reset & Base Layout ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html {
    scroll-behavior: smooth;
    text-size-adjust: 100%;
}

body {
    background: var(--bg-main);
    font-family: 'Noto Sans Thai', sans-serif;
    color: #1e293b;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* Tech Dot Grid Pattern */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: radial-gradient(circle, rgba(26, 86, 219, 0.04) 1.2px, transparent 1.2px);
    background-size: 32px 32px;
    pointer-events: none;
    z-index: 0;
}

.wrapper {
    display: flex;
    min-height: 100vh;
    position: relative;
    /* FIX: เอา z-index: 1 ออก เพื่อป้องกันไม่ให้ครอบทับระดับเลเยอร์ของ Sidebar บนมือถือ */
    z-index: auto; 
}

/* ── Sidebar (Premium Modern Look) ── */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    flex-shrink: 0;
    z-index: 1060; /* FIX: ต้องอยู่บนสุดเสมอตอนเปิดเมนูมือถือ (เดิม 1040 เท่ากับ overlay ทำให้ซ้อนไม่แน่นอน) */
    display: flex;
    flex-direction: column;
    transition: var(--trans-smooth);
    position: relative;
    box-shadow: 6px 0 30px rgba(15, 45, 131, 0.15);
}

.sidebar::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--yellow), var(--yellow-light), var(--blue-light));
}

.logo-title {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--yellow) 0%, #d97706 100%);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem; color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
    transition: var(--bounce);
}
.sidebar:hover .logo-icon {
    transform: rotate(8deg) scale(1.05);
}

.logo-title span {
    font-size: 0.95rem;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: 0.3px;
    line-height: 1.3;
}

.menu-list {
    padding: 12px 10px;
    flex: 1;
}

.menu-link {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 16px; margin-bottom: 5px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.88);
    text-decoration: none;
    font-weight: 600; font-size: 0.92rem;
    transition: var(--trans-smooth);
    position: relative;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent !important;
}
.menu-link i {
    width: 20px; text-align: center;
    font-size: 1rem; flex-shrink: 0;
    transition: var(--bounce);
}

@media (hover: hover) {
    .menu-link:hover {
        color: #ffffff;
        background: rgba(255, 255, 255, 0.06);
        transform: translateX(4px);
    }
    .menu-link:hover i {
        color: var(--yellow-light);
        transform: scale(1.1);
    }
}

.menu-link:active {
    background: var(--yellow) !important;
    color: #fff !important;
}

.menu-link.active {
    background: linear-gradient(90deg, var(--yellow) 0%, #ea580c 100%);
    color: #ffffff;
    font-weight: 700;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}
.menu-link.active i { color: #ffffff; }

/* Shimmer Light Effect */
.menu-link.active::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.15) 50%, transparent 100%);
    background-size: 200% 100%;
    animation: cyber-shimmer 3.5s infinite linear;
    clip-path: inset(0 round var(--radius-sm));
}
@keyframes cyber-shimmer {
    0% { background-position: 150% center; }
    100% { background-position: -150% center; }
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.35);
    text-align: center;
}

/* ── Mobile Topbar ── */
.mobile-topbar {
    display: none;
    background: #0f2d83;
    border-bottom: 3px solid var(--yellow);
    padding: 12px 18px;
    align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 1050; /* FIX: เดิม 1030 ต่ำกว่า overlay (1040) ทำให้ฉากมืดวางทับปุ่ม 3 ขีด กดยาก/รู้สึกจอดรอป */
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.mobile-topbar .brand {
    font-size: 0.95rem; font-weight: 800; color: #fff;
    display: flex; align-items: center; gap: 10px;
}
.mobile-topbar .menu-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff; width: 44px; height: 44px; border-radius: 8px;
    font-size: 1.15rem;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: var(--trans-fast);
    -webkit-tap-highlight-color: transparent;
}
.mobile-topbar .menu-btn:active { background: rgba(255, 255, 255, 0.25); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.32);
    /* LINE In-App Browser บน iOS จัด compositing layer ของ backdrop-filter
       ผิดลำดับและนำฉากมืดไปทับ Sidebar แม้ z-index สูงกว่า จึงใช้สีโปร่งแทน */
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    z-index: 1040;
}
.sidebar-overlay.show { display: block; }

/* ── Main Content Area ── */
.main-content {
    flex: 1;
    padding: clamp(16px, 2.5vw, 35px);
    min-width: 0;
}

/* ── Page Header ── */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 26px; flex-wrap: wrap; gap: 14px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(26, 86, 219, 0.12);
}
.page-header h1 {
    font-size: clamp(1.35rem, 2.2vw, 1.65rem);
    font-weight: 900; color: var(--blue-dark);
    letter-spacing: -0.3px; margin-bottom: 4px;
}
.page-header p { color: #64748b; font-size: 0.88rem; font-weight: 500; }

/* ── Premium Clean Cards ── */
.modern-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: clamp(18px, 2.5vw, 26px);
    margin-bottom: 22px;
    position: relative;
    box-shadow: var(--shadow-card), var(--shadow);
}
.modern-card::before {
    content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3.5px;
    background: linear-gradient(90deg, var(--blue), var(--yellow));
    border-radius: var(--radius) var(--radius) 0 0;
}

/* ── Stat Grid ── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card {
    background: #ffffff;
    border-radius: var(--radius);
    padding: 18px 14px;
    border: 1px solid rgba(26, 86, 219, 0.06);
    position: relative; overflow: hidden;
    transition: var(--bounce);
    box-shadow: var(--shadow-sm);
}
.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.stat-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px; }
.stat-card.card-total::before   { background: linear-gradient(90deg, var(--blue), var(--blue-light)); }
.stat-card.card-act::before     { background: linear-gradient(90deg, #8b5cf6, #c084fc); }
.stat-card.card-meet::before    { background: linear-gradient(90deg, var(--green), #34d399); }
.stat-card.card-vehicle::before { background: linear-gradient(90deg, var(--yellow), var(--yellow-light)); }
.stat-card.card-trip::before    { background: linear-gradient(90deg, #06b6d4, #22d3ee); }
.stat-card.card-repair::before  { background: linear-gradient(90deg, var(--red), #f87171); }

.stat-card .stat-icon {
    font-size: 1.4rem; margin-bottom: 10px; display: inline-flex;
    padding: 8px; border-radius: 10px; background: #f8fafc;
}
.stat-card.card-total .stat-icon   { color: var(--blue); }
.stat-card.card-act .stat-icon     { color: #8b5cf6; }
.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: #06b6d4; }
.stat-card.card-repair .stat-icon  { color: var(--red); }

.stat-card .stat-num {
    font-size: 2rem; font-weight: 900; color: #0f172a;
    line-height: 1.1; margin-bottom: 4px; letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}
.stat-card .stat-label { font-size: 0.8rem; color: #64748b; font-weight: 700; }

/* ── Forms ── */
.form-label {
    font-weight: 700; color: #475569; margin-bottom: 6px;
    font-size: 0.8rem; letter-spacing: 0.3px; text-transform: uppercase;
}
.form-control, .form-select {
    background: #f8fafc; border: 1.5px solid #e2e8f0;
    border-radius: var(--radius-sm); padding: 11px 14px;
    color: #0f172a; font-family: inherit; font-size: 0.92rem;
    transition: var(--trans-fast);
}
.form-control:focus, .form-select:focus {
    background: #fff; border-color: var(--blue);
    box-shadow: 0 0 0 3.5px rgba(26, 86, 219, 0.1); outline: none;
}

/* ── Buttons ── */
.btn-primary {
    background: linear-gradient(135deg, var(--blue) 0%, #1d4ed8 100%);
    border: none; border-radius: 999px; padding: 11px 26px;
    font-weight: 700; color: #fff; transition: var(--bounce);
    box-shadow: 0 4px 12px rgba(26, 86, 219, 0.25); font-size: 0.9rem;
    cursor: pointer;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(26, 86, 219, 0.35); }

/* ── Tables & List UI ── */
.table-responsive { transform: translateZ(0); }
.list-table { border-collapse: separate; border-spacing: 0; width: 100%; }
.list-table th {
    background: #f8fafc; color: var(--blue-dark); font-weight: 800;
    padding: 14px 16px; font-size: 0.78rem; text-transform: uppercase;
    letter-spacing: 0.5px; border-bottom: 2px solid #e2e8f0;
}
.list-table td {
    padding: 14px 16px; vertical-align: middle; border-bottom: 1px solid #f1f5f9;
    color: #334155; font-size: 0.9rem; transition: var(--trans-fast);
}
.list-table tbody tr:hover td { background: rgba(26, 86, 219, 0.02); }

/* ── Badges ── */
.badge {
    font-weight: 700; padding: 5px 12px; border-radius: 6px;
    font-size: 0.75rem; display: inline-flex; align-items: center; gap: 4px;
}
.bg-primary, .bg-กิจกรรม { background: #eff6ff!important; color: var(--blue)!important; border: 1px solid var(--blue-mid)!important; }
.bg-success, .bg-ประชุม { background: var(--green-soft)!important; color: #065f46!important; border: 1px solid #a7f3d0!important; }
.bg-warning, .bg-จองรถ { background: var(--yellow-soft)!important; color: var(--yellow-dark)!important; border: 1px solid var(--yellow-mid)!important; }
.bg-danger, .bg-แจ้งซ่อม { background: var(--red-soft)!important; color: var(--red)!important; border: 1px solid #fecaca!important; }

/* ── Action Buttons ── */
.td-action {
    display: flex; align-items: center; gap: 8px; justify-content: flex-start;
}
.btn-view-detail {
    background: #fff; color: var(--blue); border: 1.5px solid var(--blue-mid);
    border-radius: 8px; padding: 6px 14px; font-size: 0.82rem; font-weight: 700;
    cursor: pointer; transition: var(--bounce); display: inline-flex; align-items: center; gap: 4px;
}
.btn-view-detail:hover { background: var(--blue); color: #fff; transform: translateY(-1px); }

/* 🗑️ ปุ่มถังขยะเวอร์ชันพรีเมียม (Merged & Optimized) */
.btn-delete-dash {
    background: rgba(239, 68, 68, 0.08) !important;
    color: #ef4444 !important;
    border: 1px solid rgba(239, 68, 68, 0.2) !important;
    padding: 7px 12px !important;
    border-radius: 8px !important;
    font-size: 0.88rem !important;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
    text-decoration: none;
}
.btn-delete-dash:hover {
    background: #ef4444 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4) !important;
    border-color: #ef4444 !important;
    transform: scale(1.05) translateY(-2px);
}
.btn-delete-dash:hover i, .btn-delete-dash:hover svg {
    animation: trash-shake 0.2s ease-in-out infinite alternate;
}
@keyframes trash-shake {
    0% { transform: rotate(-6deg); }
    100% { transform: rotate(6deg); }
}

/* ── Calendar Table ── */
.calendar-table { min-width: 780px; border-collapse: separate; border-spacing: 5px; }
.calendar-table th { padding: 12px!important; font-weight: 800; color: var(--blue-dark); text-align: center; }
.calendar-table td {
    height: 125px; vertical-align: top; padding: 10px!important;
    background: #fff; border: 1px solid var(--border-blue);
    border-radius: var(--radius-sm); width: 14.28%; transition: var(--trans-smooth);
    box-shadow: var(--shadow-sm);
}
.calendar-table td:hover { background: var(--blue-soft); border-color: var(--blue); transform: translateY(-2px); }
.day-num { font-weight: 800; color: #475569; font-size: 0.88rem; display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; border-radius: 50%; }
.today-mark { border: 2px solid var(--blue)!important; }
.today-mark .day-num { background: var(--blue); color: #fff; }

.event-badge {
    font-size: 11px; padding: 4px 8px; border-radius: 5px; margin-bottom: 3px;
    font-weight: 700; display: block; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;
    transition: var(--trans-fast);
}
.event-badge:hover { transform: translateX(3px); }

/* ── Vehicle Platform ── */
.vehicle-card {
    background: #fff; border: 1px solid var(--border-blue);
    border-radius: var(--radius); overflow: hidden; transition: var(--bounce); box-shadow: var(--shadow-sm);
}
.vehicle-card:hover { transform: translateY(-6px); border-color: var(--blue); box-shadow: var(--shadow-lg); }
.vehicle-img-wrap { height: 180px; overflow: hidden; }
.vehicle-img-wrap img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; }
.vehicle-card:hover .vehicle-img-wrap img { transform: scale(1.06); }

/* ── Intelligent Light-Weight Animations ── */
@keyframes hyperFadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.modern-card, .stat-card, .vehicle-card, .filter-section {
    will-change: transform, opacity;
    animation: hyperFadeUp 0.4s cubic-bezier(0.215, 0.610, 0.355, 1) both;
}
.stat-card:nth-child(1) { animation-delay: 0.03s; }
.stat-card:nth-child(2) { animation-delay: 0.06s; }
.stat-card:nth-child(3) { animation-delay: 0.09s; }
.stat-card:nth-child(4) { animation-delay: 0.12s; }
.stat-card:nth-child(5) { animation-delay: 0.15s; }
.stat-card:nth-child(6) { animation-delay: 0.18s; }

/* ── Perfect Responsive Engine ── */
@media (max-width: 1200px) {
    .stat-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
}

@media (max-width: 991.98px) {
    .wrapper { display: block; }
    .sidebar {
        position: fixed !important; top: 0; left: -280px;
        width: 260px; height: 100vh; height: 100dvh; overflow-y: auto;
        z-index: 1080 !important;
        isolation: isolate;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    .sidebar.show { left: 0 !important; box-shadow: 12px 0 40px rgba(15, 23, 42, 0.25); }
    .mobile-topbar { display: flex; z-index: 1070; }
    /* จำกัดฉากมืดให้อยู่เฉพาะพื้นที่เนื้อหาด้านขวาเท่านั้น
       ต่อให้ WebView ของ LINE วาง layer ผิด ฉากก็ไม่สามารถครอบ Sidebar ได้ */
    .sidebar-overlay {
        top: 0;
        right: 0;
        bottom: 0;
        left: 260px;
        z-index: 1060;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
    .main-content { padding: 16px; }
}

@media (max-width: 767.98px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    
    /* แปลงตารางเป็นการ์ดบนมือถือ */
    .list-table thead { display: none; }
    .list-table tbody tr {
        display: flex; flex-direction: column;
        background: #fff; border: 1px solid #e2e8f0;
        border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px;
        box-shadow: var(--shadow-sm);
    }
    .list-table tbody td {
        display: flex; flex-direction: column; padding: 6px 0; border: none; text-align: left;
    }
    .list-table tbody td::before {
        content: attr(data-label);
        font-weight: 800; font-size: 0.72rem; color: var(--blue-dark);
        text-transform: uppercase; margin-bottom: 2px;
    }
    .list-table tbody td:first-child { border-bottom: 1px solid #f1f5f9; padding-bottom: 8px; margin-bottom: 4px; }
    .td-action { flex-direction: row !important; gap: 8px; margin-top: 6px; justify-content: center; align-items: center; }
    .td-action button, .td-action a { flex: 1; }
}

@media (max-width: 480px) {
    /* FIX: เปลี่ยนจาก repeat(3, 1fr) เป็น repeat(2, 1fr) เพื่อป้องกันตัวหนังสือการ์ดสถิติล้นและซ้อนทับกันบนมือถือจอเล็ก */
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; } 
    .stat-card { padding: 12px 8px; }
    .stat-card .stat-icon { font-size: 1.1rem; padding: 6px; margin-bottom: 6px; }
    .stat-card .stat-num { font-size: 1.4rem; }
    .stat-card .stat-label { font-size: 0.68rem; }
}
