/* Font */

/* ======================================================================= */

:root {
    /* --- Main Colors (Updated for Modern Minimal) --- */
    --primary-color: #FF6B35; /* ส้ม Modern */
    --primary-hover: #E85A2D;
    --primary-gradient: linear-gradient(135deg, #FF6B35 0%, #FF8E53 100%); /* Gradient นุ่มขึ้น */
    
    /* --- Backgrounds & Text --- */
    --secondary-bg: #F7F9FC;
    --text-dark: #1A202C;
    --text-light: #718096;
    
    /* --- Shadows & Radius --- */
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03); /* Soft Shadow */
    --card-hover-shadow: 0 10px 15px -3px rgba(255, 107, 53, 0.15), 0 4px 6px -2px rgba(255, 107, 53, 0.1);
    --radius: 12px;
}

html, body {
    height: 100%; /* บอกให้ html/body สูงเต็มจอ */
    margin: 0;
}

body {
    font-family: 'Sarabun', sans-serif;
    background-color: var(--secondary-bg);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased; /* ทำให้ตัวหนังสือคมขึ้น */
}

h1, h2, h3, h4, h5, h6, .btn, .brand-text {
    font-family: 'Prompt', sans-serif;
}

/* ======================================================================= */
/* 1. NAVBAR 
/* ======================================================================= */

.navbar-custom {
    background-color: #ffffff;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    padding-top: 0.8rem;
    padding-bottom: 0.8rem;
    z-index: 1030; /* อยู่เหนือ Card */
}

.brand-text {
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -0.5px;
    text-decoration: none;
    line-height: 1.2;
}

.brand-subtitle {
    font-family: 'Sarabun', sans-serif;
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 400;
    margin-left: 12px;
    border-left: 1px solid #e2e8f0;
    padding-left: 12px;
    display: inline-block;
    height: 24px;
    line-height: 24px;
}

/* Menu Buttons (Ghost Style) */
.nav-btn {
    color: var(--text-dark);
    font-family: 'Prompt', sans-serif;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    text-decoration: none;
    margin-left: 0.25rem;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
}

.nav-btn:hover, .nav-btn.active-link {
    color: var(--primary-color);
    background-color: #FFF5F2; /* ส้มจางๆ */
}

.nav-btn.active-link {
    font-weight: 600;
}

/* Primary Action Button on Navbar */
.nav-btn-primary {
    background-color: var(--primary-color);
    color: white !important;
    box-shadow: 0 4px 6px rgba(255, 107, 53, 0.2);
    margin-left: 1rem;
}

.nav-btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 8px rgba(255, 107, 53, 0.3);
}

@media (max-width: 991px) {
    .brand-subtitle { display: block; margin: 4px 0 0 0; border: none; padding: 0; font-size: 0.8rem; height: auto; }
    .nav-btn { display: flex; width: 100%; margin: 5px 0; justify-content: center; }
    .nav-btn-primary { margin-left: 0; }
}

/* ======================================================================= */
/* 2. LAYOUT & CARDS (UPDATED) */
/* ======================================================================= */

.layout-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* ความสูงขั้นต่ำ 100% ของหน้าจอ */
    margin: 0rem 8rem 0rem 8rem;
}
.page-wrapper {
    margin: 0;
}

/* === CARDS === */
.custom-card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid #edf2f7;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
    overflow: hidden; /* เพื่อให้ Header ไม่ล้น */
}

.custom-card:hover {
    /* transform: translateY(-5px); */
    box-shadow: var(--card-hover-shadow);
    border-color: #ffd8cce0;
}

.card-header-modern {
    background: white;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title-modern {
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--text-dark);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ======================================================================= */
/* 3. BUTTONS & ACTIONS (UPDATED COLORS) */
/* ======================================================================= */

/* Switch */
.policy-switch-container {
    background-color: white;
    padding: 0.5rem;
    border-radius: 50rem;
    box-shadow: var(--card-shadow);
    display: inline-flex;
    gap: 5px;
}

.btn-switch {
    border: none;
    background: transparent;
    color: var(--text-light);
    padding: 0.6rem 1.5rem;
    border-radius: 50rem;
    font-weight: 500;
    transition: all 0.3s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-switch:hover {
    color: var(--primary-color);
    background-color: #fff0e6; /* ส้มจางๆ */
}

.btn-switch.active {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 94, 98, 0.3);
    pointer-events: none;
    cursor: default;
}

/* Buttons General */
.btn-action-primary {
    background: var(--primary-gradient);
    border: none;
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-weight: 500;
    box-shadow: 0 4px 10px rgba(255, 94, 98, 0.2);
    transition: all 0.3s;
}
.btn-action-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    color: white;
}

/* ======================================================================= */
/* 4. TABLES & BADGES */
/* ======================================================================= */

.table-modern {
    width: 100%;
    margin-bottom: 0;
    vertical-align: middle;
}

.table-modern thead th {
    background-color: #f8f9fa;
    border-bottom: none;
    color: var(--text-light);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    padding: 1rem;
    letter-spacing: 0.5px;
}

.table-modern tbody td {
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
    color: var(--text-dark);
    font-size: 0.95rem;
}

.table-modern tbody tr:last-child td {
    border-bottom: none;
}

.table-modern tbody tr:hover {
    background-color: #fffcf9; /* สีส้มอ่อนมากๆ ตอนชี้ */
}

/* Badges สไตล์ใหม่ */
.badge-modern {
    padding: 0.5em 0.8em;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 0.3px;
}
.badge-car {
    background-color: #e3f2fd;
    color: #1976d2;
}
.badge-life {
    background-color: #e8f5e9;
    color: #2e7d32;
}
.badge-policy {
    background-color: #fffde2;
    color: #ccb314;
}
.badge-file {
    background-color: #fff3e0;
    color: #ef6c00;
}

.action-group .btn-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    transition: 0.2s;
    background: #f1f2f6;
    border: none;
    margin-right: 5px;
}
.action-group .btn-icon:hover {
    background: var(--primary-color);
    color: white;
}
.action-group .btn-icon.delete:hover {
    background: #ff4757;
}

/* === สำหรับสี TEXT === */
.theme-color {
    background: #ff6f47;
    -webkit-background-clip: text;
    color: transparent;
}

/* === สีหลัก === */
.main-color {
    background: rgb(255, 117, 75);
}

/* === ปุ่มกับพื้นหลังปุ่มกรองข้อมูลตาราง === */
.nav-tabs {
    background-color: #f8f9fa;
    padding: 1rem 1rem 0 1rem;
    border-bottom: 2px solid rgb(236, 236, 236);
    border-radius: 0.5rem 0.5rem 0rem 0rem;
    /* display: inline-flex; */
    gap: 5px;
}
.nav-tabs .nav-link:hover {
    color: var(--primary-color);
    background-color: #fff0e6; /* ส้มจางๆ */
}
.nav-tabs .nav-link {
    border: none;
    background: transparent;
    color: var(--text-light);
    padding: 0.6rem 1.5rem;
    border-radius: 0.5rem 0.5rem 0rem 0rem;
    font-weight: 500;
    transition: all 0.3s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
.nav-tabs .nav-link.active {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 94, 98, 0.3);
    margin-bottom: 0.1px;
}

/* === Modern Modal Styles === */
.modal-content {
    border: none;
    border-radius: 16px; /* โค้งมน */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.modal-header {
    border-bottom: 1px solid #f0f0f0;
    padding: 1.5rem;
}

.modal-title {
    font-weight: 600;
    color: #2d3436;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-body {
    padding: 2rem;
}

.modal-footer {
    border-top: none;
    padding: 1.5rem;
    background-color: #fafafa; /* พื้นหลังส่วนท้ายจางๆ */
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;
}

/* === PIN Input Styling === */
.pin-input-group input {
    font-size: 2.5rem;
    letter-spacing: 1rem;
    font-weight: 700;
    color: #FF5E62; /* สีส้ม */
    border: 2px solid #eee;
    border-radius: 12px;
    padding: 1rem;
    background-color: #fdfdfd;
    transition: all 0.3s;
}

.pin-input-group input:focus {
    border-color: #FF9966;
    box-shadow: 0 0 0 4px rgba(255, 153, 102, 0.2);
    outline: none;
}

/* === File Card Styling === */
.file-card {
    border: 1px solid #eee;
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    height: 100%;
    background: white;
}

.file-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.08);
    border-color: #FF9966;
}

.file-preview-area {
    height: 160px;
    background-color: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.file-icon-placeholder {
    font-size: 4rem;
    color: #cbd5e0;
}

/* === Buttons === */
.btn-modern-primary {
    background: linear-gradient(135deg, #FF9966 0%, #FF5E62 100%);
    border: none;
    color: white;
    padding: 0.6rem 1.5rem;
    border-radius: 50rem; /* Pill shape */
    font-weight: 500;
    box-shadow: 0 4px 10px rgba(255, 94, 98, 0.3);
    transition: 0.3s;
}
.btn-modern-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    color: white;
}

.btn-modern-secondary {
    background: white;
    border: 1px solid #e0e0e0;
    color: #636e72;
    padding: 0.6rem 1.5rem;
    border-radius: 50rem;
    font-weight: 500;
    transition: 0.3s;
}
.btn-modern-secondary:hover {
    background: #f1f2f6;
    color: #2d3436;
}

/* === Footer === */
.footer-modern {
    background-color: #ffffff;
    border-top: 1px solid #eee;
    padding: 2rem 0;
    margin-top: auto; /* ดัน Footer ไปล่างสุดเสมอ */
    color: #636e72;
    font-size: 0.9rem;
}

.footer-brand {
    font-weight: 700;
    color: #2d3436;
    font-size: 1.1rem;
}

.footer-brand span {
    color: #FF5E62; /* สีส้มธีม */
}

/* === Buttons === */
/* === 1. ปุ่มหลัก: ตกลง / บันทึก (Primary Action) === */
/* ใช้ Gradient ส้มที่เป็นธีมหลัก เพื่อให้เด่นที่สุดในหน้า */
.btn-theme-save {
    background: linear-gradient(135deg, #FF9966 0%, #FF5E62 100%);
    border: none;
    color: white;
    border-radius: 50rem; /* ทรงแคปซูล */
    padding: 0.6rem 2rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(255, 94, 98, 0.3); /* เงาสีส้มฟุ้งๆ */
    transition: all 0.3s ease;
}

.btn-theme-save:hover {
    transform: translateY(-2px); /* ลอยขึ้นเล็กน้อย */
    box-shadow: 0 8px 20px rgba(255, 94, 98, 0.4);
    color: white;
}

/* === 2. ปุ่มรอง: ย้อนกลับ / ยกเลิก (Secondary Action) === */
/* ใช้สีเทาอ่อน เพื่อไม่ให้แย่งความเด่น แต่ยังกดง่าย */
.btn-theme-back {
    background-color: #e2e2e2;
    color: #434a4c;
    border: 1px solid transparent;
    border-radius: 50rem;
    padding: 0.6rem 2rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-theme-back:hover {
    background-color: #e4e5e9;
    color: #2d3436;
    transform: translateY(-1px);
}

/* === 3. ปุ่มแก้ไข (Edit) === */
/* ใช้สีเหลืองอำพัน/ส้มอ่อน เพื่อสื่อถึงการเปลี่ยนแปลง แต่ไม่รุนแรง */
.btn-theme-edit {
    background-color: #FFF8E1; /* พื้นหลังเหลืองจางๆ */
    color: #FFB300; /* ตัวหนังสือสีเหลืองเข้ม */
    border: 1px solid #FFE082;
    border-radius: 12px; /* โค้งน้อยกว่าปุ่มหลัก */
    padding: 0.4rem 1rem;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-theme-edit:hover {
    background-color: #FFB300;
    color: white;
    box-shadow: 0 4px 10px rgba(255, 179, 0, 0.2);
}

/* === 4. ปุ่มลบ (Delete) === */
/* ใช้สีแดง แต่เป็นแดงนุ่มๆ (Soft Red) */
.btn-theme-delete {
    background-color: #FFEBEE; /* พื้นหลังแดงจางๆ */
    color: #EF5350; /* ตัวหนังสือสีแดง */
    border: 1px solid #FFCDD2;
    border-radius: 12px;
    padding: 0.4rem 1rem;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-theme-delete:hover {
    background-color: #EF5350;
    color: white;
    box-shadow: 0 4px 10px rgba(239, 83, 80, 0.2);
}

/* === 5. ปุ่มดูข้อมูล (View) === */
/* ใช้สีฟ้า/เทาเข้ม เพื่อสื่อถึงข้อมูล (Information) */
.btn-theme-view {
    background-color: white;
    color: #636e72;
    border: 1px solid #dfe6e9;
    border-radius: 12px;
    padding: 0.4rem 1rem;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-theme-view:hover {
    border-color: #FF5E62; /* Hover แล้วขอบเป็นสีธีม */
    color: #FF5E62;
    background-color: #fff;
}

/* === 6. ปุ่มดูข้อมูลพิมพ์ (Print) === */
/* ใช้สีฟ้า/เทาเข้ม เพื่อสื่อถึงข้อมูล (Information) */
.btn-theme-print {
    background-color: #e6f9ff;
    color: #28bdf4;
    border: 1px solid #dfe6e9;
    border-radius: 12px;
    padding: 0.4rem 1rem;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-theme-print:hover { /* Hover แล้วขอบเป็นสีธีม */
    color: #ffffff;
    background-color: #2ac6ff;
}

/* สำหรับ form */
.search-card {
    background: white;
    border: 1px solid #eee;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    overflow: hidden;
    transition: all 0.3s;
}
.search-card:hover {
    box-shadow: 0 8px 25px rgba(0,0,0,0.06);
    border-color: #ffe0b2;
}
.search-header {
    background: white;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e9e9e9;
    color: #000000;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 2. Policy Type Switch: ปุ่มเลือกประเภทแบบแคปซูล */
.type-selector-container {
    background-color: #f1f2f6;
    padding: 5px;
    border-radius: 50rem;
    display: inline-flex;
    position: relative;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
}
.type-selector-label {
    padding: 0.6rem 2rem;
    border-radius: 50rem;
    cursor: pointer;
    font-weight: 500;
    color: #636e72;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0; /* แก้ bug bootstrap label margin */
}
.type-selector-label:hover {
    color: #FF5E62;
}

/* ซ่อน Radio Button ตัวจริง */
.btn-check:checked + .type-selector-label {
    background: linear-gradient(135deg, #FF9966 0%, #FF5E62 100%);
    color: white;
    box-shadow: 0 4px 10px rgba(255, 94, 98, 0.3);
}

/* 3. Section Title: หัวข้อแต่ละส่วน */
.section-title {
    position: relative;
    padding-left: 15px;
    font-weight: 700;
    color: #2d3436;
}
.section-title::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 20px;
    background: linear-gradient(to bottom, #FF9966, #FF5E62);
    border-radius: 2px;
}

/* === Dashboard Custom CSS === */  
/* 1. Stat Card (การ์ดตัวเลข) */
.stat-card {
    background: white;
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid #f0f0f0;
    height: 100%; /* ให้การ์ดสูงเต็มพื้นที่ column */
    position: relative;
    overflow: hidden;
}
.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.08);
    border-color: #ffe0b2;
}
.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

/* สีไอคอน */
.bg-icon-orange { background: #FFF3E0; color: #FF9966; }
.bg-icon-blue { background: #E3F2FD; color: #2196F3; }
.bg-icon-green { background: #E8F5E9; color: #4CAF50; }
.bg-icon-red { background: #FFEBEE; color: #EF5350; }

/* ตัวเลข */
.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #2d3436;
    line-height: 1.2;
}
.stat-label {
    color: #636e72;
    font-size: 0.9rem;
    font-weight: 500;
}

/* 2. Chart Card */
.chart-card {
    background: white;
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    height: 100%; /* ให้การ์ดสูงเท่ากันใน Row เดียวกัน */
    display: flex;
    flex-direction: column;
}

/* [!] เพิ่ม class นี้เพื่อคุมความสูงของกราฟ */
.chart-container {
    position: relative;
    width: 100%;
    flex-grow: 1; /* ให้ขยายเต็มพื้นที่ที่เหลือในการ์ด */
    min-height: 300px; /* กำหนดความสูงขั้นต่ำ */
}

/* 3. Welcome Section */
.welcome-banner {
    background: linear-gradient(135deg, #FF9966 0%, #FF5E62 100%);
    border-radius: 16px;
    padding: 2rem;
    color: white;
    margin-bottom: 2rem;
    box-shadow: 0 10px 30px rgba(255, 94, 98, 0.3);
    position: relative;
    overflow: hidden;
}
.welcome-banner h2 { font-weight: 700; }
.welcome-banner::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 300px;
    height: 300px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
}

/* Data Table Yajra */
.dataTables_length_custom {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

.dataTables_length_custom .dataTables_length .form-select {
    width: 50px;
}

.dataTables_paginate_custom {
    display: flex;
    justify-content: flex-end;
    padding: 0 !important;
    margin-bottom: 1rem;
}

.dataTables_paginate_custom .dataTables_paginate .paginate_button {
    margin: 0;
    padding: 0;
}

.dataTables_paginate_custom .pagination .page-item .page-link {
    color: #000;
    margin: -1px;
}

.dataTables_paginate_custom .pagination .page-item.active .page-link {
    background-color: var(--primary-color);
    border-color: #FF5E62;
    color: #fff !important;
    box-shadow: 0 4px 6px rgba(255, 107, 53, 0.2);
}
.dataTables_paginate_custom .pagination .page-link:hover {
    background-color: #e0e0e0;
    color: #000;
}

.dataTables_filter {
    display: none !important;
}

/* Preloader คลุมทั้งหน้า */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

/* ซ่อนเมื่อโหลดเสร็จ */
#preloader.hidden {
    opacity: 0;
    visibility: hidden;
}

/* กล่อง loader + ข้อความ */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Loader วงกลม */
.loader {
    border: 8px solid #f3f3f3;
    border-top: 8px solid var(--primary-color);
    border-radius: 50%;
    width: 100px;
    height: 100px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px; /* ระยะห่างจากข้อความ */
}

/* ข้อความใต้ loader */
.loader-text {
    font-size: 16px;
    color: #555555;
    font-weight: 500;
}

/* Animation หมุน */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ปรับสไตล์ของ Processing Loader */
.dataTables_processing {
    margin: 0 !important;
    background-color: rgba(255, 255, 255, 0.9) !important;
    color: #000000 !important;
    border: none !important;
}

/* form ต่างๆ */
.form-select {
    border-radius: 12px;
    padding: 0.4rem 1rem;
    border: 1px solid #eee;
    background-color: #fcfcfc;
}
.form-select:focus {
    border-color: #FF9966;
    box-shadow: 0 0 0 4px rgba(255, 153, 102, 0.1);
    background-color: white;
}
.form-control {
    border-radius: 12px;
    padding: 0.4rem 1rem;
    border: 1px solid #eee;
    background-color: #fcfcfc;
}
.form-control:focus {
    border-color: #FF9966;
    box-shadow: 0 0 0 4px rgba(255, 153, 102, 0.1);
    background-color: white;
}