/* ============================================
   RSPG Registration System — Core Design System
   Shadcn/UI Inspired (Zinc/Purple Theme)
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* LINE Seed Sans TH */
@font-face {
    font-family: 'LINE Seed Sans TH';
    src: url('../fonts/LINESeedSansTH_W_Th.woff2') format('woff2');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'LINE Seed Sans TH';
    src: url('../fonts/LINESeedSansTH_W_Rg.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'LINE Seed Sans TH';
    src: url('../fonts/LINESeedSansTH_W_Bd.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'LINE Seed Sans TH';
    src: url('../fonts/LINESeedSansTH_W_He.woff2') format('woff2');
    font-weight: 800;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'LINE Seed Sans TH';
    src: url('../fonts/LINESeedSansTH_W_XBd.woff2') format('woff2');
    font-weight: 900;
    font-style: normal;
    font-display: swap;
}

:root {
    /* ── Primary Palette (Violet/Purple Theme) ── */
    --primary: #7c3aed; /* Violet 600 */
    --primary-hover: #6d28d9; /* Violet 700 */
    --primary-light: #f5f3ff; /* Violet 50 */
    --primary-rgb: 124, 58, 237;
    --primary-foreground: #fafafa;

    /* ── Muted / Secondary (Zinc Palette) ── */
    --secondary: #71717a; /* Zinc 500 — ใช้เป็น muted text */
    --secondary-hover: #52525b; /* Zinc 600 */
    --secondary-light: #f4f4f5; /* Zinc 100 — ใช้เป็น muted background */
    --secondary-foreground: #18181b;

    /* ── Status Colors ── */
    --success: #16a34a; /* Green 600 */
    --success-hover: #15803d;
    --success-light: #f0fdf4;
    --info: #0284c7; /* Sky 600 */
    --info-hover: #0369a1;
    --info-light: #f0f9ff;
    --warning: #d97706; /* Amber 600 */
    --warning-hover: #b45309;
    --warning-light: #fffbeb;
    --danger: #dc2626; /* Red 600 */
    --danger-hover: #b91c1c;
    --danger-light: #fef2f2;

    /* ── Shadcn/UI Standard Variable Names (spec-compliant aliases) ── */
    --background: #fafafa;       /* Zinc 50 */
    --foreground: #09090b;       /* Zinc 950 */
    --card: #ffffff;
    --card-foreground: #09090b;
    --muted: #f4f4f5;            /* Zinc 100 */
    --muted-foreground: #71717a; /* Zinc 500 */
    --border: #e4e4e7;           /* Zinc 200 */
    --input: #e4e4e7;
    --ring: #7c3aed;             /* ใช้ project primary */
    --radius: 0.5rem;

    /* ── Project-Specific Aliases (backward compatibility) ── */
    --body-bg: var(--background);
    --card-bg: var(--card);
    --border-color: var(--border);
    --text-primary: #27272a;     /* Zinc 800 */
    --text-heading: var(--foreground);
    --text-muted: var(--muted-foreground);

    /* ── Sidebar ── */
    --sidebar-bg: #ffffff;
    --sidebar-text: #71717a;
    --sidebar-active: #f4f4f5;
    --sidebar-active-text: #09090b;

    /* ── Dimensions ── */
    --sidebar-width: 272px;
    --sidebar-collapsed: 78px;
    --navbar-height: 60px;

    /* ── Geometry ── */
    --border-radius: 0.375rem; /* 6px */
    --border-radius-lg: var(--radius); /* 8px */

    /* ── Flat Shadows (shadcn style) ── */
    --card-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --card-shadow-hover: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    /* ── Transitions ── */
    --transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

/* ============ RESET & BASE ============ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    /* LINE Seed ก่อน — ให้ภาษาไทยตรงกับหน้าลงทะเบียนและคอนฟิก Tailwind (index.html) */
    font-family: 'LINE Seed Sans TH', 'Sarabun', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.875rem; /* 14px Shadcn standard */
    color: var(--text-primary);
    background-color: var(--body-bg);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

/*
 * Controls มักได้ฟอนต์ค่าเริ่มจากเบราว์เซอร์ ไม่สืบทอดจาก body
 * หน้าที่ไม่โหลด Tailwind preflight จึงเห็นปุ่ม/ select คนละฟอนต์กับข้อความ (เช่น ออกจากระบบใน sidebar)
 */
button,
input,
select,
textarea {
    font-family: inherit;
}

a {
    text-decoration: none;
    color: var(--primary);
    transition: var(--transition);
}
a:hover {
    color: var(--primary-hover);
}
/* ปุ่มที่เป็น <a> ตัวอักษรขาว — กัน a:hover ทับเป็นม่วงแล้วตัวอักษรกลืนกับพื้น */
a.tw-text-white:hover,
a.tw-text-white:focus {
    color: #fff;
}

/* ============ LAYOUT ============ */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
    max-width: 100%;
    overflow-x: clip;
}

.layout-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    z-index: 1040;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.layout-page {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    min-width: 0;
    max-width: 100%;
    overflow-x: clip;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.content-wrapper {
    flex: 1;
    padding: 1rem 2rem;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

/* ============ SIDEBAR ============ */
.sidebar-brand {
    display: flex;
    align-items: center;
    height: var(--navbar-height);
    padding: 0 1.5rem;
    gap: 0.75rem;
    /* Removed bottom border, shadcn uses seamless sidebar headers usually, but we keep right border on sidebar itself */
}

.sidebar-brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary-light);
    border: 1px solid color-mix(in srgb, var(--primary) 16%, #ffffff);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-brand-logo {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    object-fit: contain;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    color: var(--text-heading);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand-title {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: 0.01em;
}

.sidebar-brand-sub {
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1;
    color: var(--text-muted);
}

.sidebar-menu {
    list-style: none;
    padding: 0.5rem 0 1rem;
    margin: 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-search-wrap {
    flex-shrink: 0;
    padding: 1rem 1rem 0.75rem;
}

.sidebar-search-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sidebar-search-inner {
    position: relative;
    display: flex;
    align-items: center;
}

.sidebar-search-icon {
    position: absolute;
    left: 0.75rem;
    color: var(--text-muted);
    pointer-events: none;
    font-size: 0.875rem;
    line-height: 1;
}

.sidebar-search-input {
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.75rem 0.5rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text-heading);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.sidebar-search-input::placeholder {
    color: var(--text-muted);
}

.sidebar-search-input:focus {
    outline: none;
    border-color: var(--text-heading);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--text-heading) 12%, transparent);
}

.sidebar-search-empty.is-hidden {
    display: none;
}

.sidebar-search-empty {
    margin: 0.5rem 0 0;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--text-muted);
    text-align: center;
}

.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}
.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.sidebar-menu-header {
    padding: 1rem 1.5rem 0.5rem;
    font-size: 0.75rem; /* ปรับจาก 0.6875rem (11px) → 0.75rem (12px) ตาม rule */
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.sidebar-menu-item {
    margin: 2px 0;
}

.sidebar-menu-link {
    display: flex;
    align-items: center;
    padding: 0.625rem 1.5rem;
    color: var(--sidebar-text);
    font-size: 0.9375rem;
    transition: var(--transition);
    gap: 0.5rem 0.75rem;
    border-radius: 0;
    position: relative;
    line-height: 1.45;
}

.sidebar-menu-link:hover {
    color: var(--text-heading);
    background: rgba(0, 0, 0, 0.03);
}

.sidebar-menu-link.active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active);
    border-radius: var(--border-radius-lg);
    margin: 0 0.75rem;
    padding: 0.625rem 0.75rem;
    font-weight: 500;
}

/* ไอคอนหลักด้านซ้าย (เช่น ไคล์บอร์ด) — จับกลางแนวกับข้อความ */
.sidebar-menu-link > i:first-of-type {
    font-size: 1.25rem;
    width: 1.5rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex-shrink: 0;
}

/* ข้อความเมนู — ขึ้นบรรทัดใหม่ได้ ไม่ดันล้น sidebar (ยกเว้นป้ายตัวเลข) */
.sidebar-menu-link > span:not(.sidebar-menu-badge) {
    flex: 1;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* ตัวเลขแจ้งเตือนเมนู (เช่น คำขอแก้ไขรออนุมัติ) — วงกลม */
.sidebar-menu-link .sidebar-menu-badge {
    flex: 0 0 auto;
    flex-shrink: 0;
    margin-left: auto;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.375rem;
    height: 1.375rem;
    min-width: 1.375rem;
    max-width: 1.375rem;
    min-height: 1.375rem;
    max-height: 1.375rem;
    padding: 0;
    border-radius: 50%;
    aspect-ratio: 1 / 1;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1;
    background: #fef3c7;
    color: #b45309;
}

.sidebar-menu-link .sidebar-menu-badge.sidebar-menu-badge--wide {
    width: 1.5rem;
    height: 1.5rem;
    min-width: 1.5rem;
    max-width: 1.5rem;
    min-height: 1.5rem;
    max-height: 1.5rem;
    font-size: 0.625rem;
}

.sidebar-menu-link .sidebar-menu-badge.is-hidden {
    display: none;
}

.sidebar-menu-link.active .sidebar-menu-badge:not(.is-hidden) {
    background: rgba(9, 9, 11, 0.12);
    color: var(--sidebar-active-text);
}

/* ไอคอนสถานะ “ส่งแล้ว” ด้านขวา (ข้อมูลที่ส่ง) */
.sidebar-menu-link .sidebar-link-done {
    flex-shrink: 0;
    width: auto !important;
    min-width: 1em;
    font-size: 0.8125rem !important;
    margin-left: auto;
    color: var(--primary);
    line-height: 1;
    align-self: center;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--sidebar-bg);
}

.sidebar-scroll-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.25rem 0.75rem 0.5rem;
    border-top: 1px dashed var(--border-color);
}

.sidebar-footer-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem;
    background: rgba(0, 0, 0, 0.03);
    border: none;
    border-radius: var(--border-radius-lg);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9375rem;
}
.sidebar-footer-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--danger);
}

/* ============ NAVBAR ============ */
.layout-navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    /* Removed heavy shadow for shadcn flat look */
}

.navbar-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

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

.navbar-page-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-heading);
    margin: 0;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.375rem 0.75rem;
    border-radius: var(--border-radius-lg);
    transition: var(--transition);
}
.navbar-user:hover {
    background: var(--body-bg);
}

.navbar-user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.navbar-user-info {
    line-height: 1.3;
}
.navbar-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-heading);
}

.navbar-user-name--org {
    max-width: 240px;
}
.navbar-user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ============ CARDS ============ */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    transition: var(--transition);
}
.card:hover {
    box-shadow: var(--card-shadow-hover);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-heading);
    margin: 0;
    letter-spacing: -0.015em;
}

.card-body {
    padding: 1.25rem;
}

/* Stats Cards */
.stats-card {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    padding: 1.25rem;
    background: var(--card-bg);
    transition: var(--transition);
}
.stats-card:hover {
    box-shadow: var(--card-shadow-hover);
}

.stats-card-icon {
    width: 46px;
    height: 46px;
    border-radius: var(--border-radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.375rem;
}

.stats-card-icon.bg-primary-light {
    background: var(--primary-light);
    color: var(--primary);
}
.stats-card-icon.bg-success-light {
    background: var(--success-light);
    color: var(--success-hover);
}
.stats-card-icon.bg-warning-light {
    background: var(--warning-light);
    color: var(--warning-hover);
}
.stats-card-icon.bg-danger-light {
    background: var(--danger-light);
    color: var(--danger-hover);
}
.stats-card-icon.bg-info-light {
    background: var(--info-light);
    color: var(--info-hover);
}

.stats-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-heading);
    line-height: 1;
}

.stats-card-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ============ FORMS ============ */
.form-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-heading);
    margin-bottom: 0.375rem;
}

.form-control,
.form-select {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.4375rem 0.875rem;
    font-size: 0.9375rem;
    color: var(--text-primary);
    transition: var(--transition);
    background-color: #fff;
}
.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--primary-rgb), 0.16);
}

/* ── Select2-style native dropdown ──────────────────────── */
.form-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath fill='%236c757d' d='M6 7L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.85rem center;
    background-size: 10px 6px;
    padding-right: 2.25rem;
    cursor: pointer;
    line-height: 1.5;
}
.form-select:hover {
    border-color: #adb5bd;
}
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--primary-rgb), 0.16);
    outline: 0;
}

/* ===== GLOBAL SELECT2 THEME (Purple) ===== */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    border: 1px solid var(--input);
    border-radius: var(--radius);
    background: var(--card);
    transition: var(--transition);
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--primary-rgb), 0.16);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary);
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted);
}

.select2-dropdown {
    border: 1px solid rgba(var(--primary-rgb), 0.35);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid var(--input);
    border-radius: var(--radius);
    padding: 6px 10px;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.12);
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: var(--primary-light) !important;
    color: var(--primary-hover) !important;
}

.select2-container--default .select2-results__option[aria-selected=true] {
    background: rgba(var(--primary-rgb), 0.12) !important;
    color: var(--primary-hover) !important;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: var(--primary) !important;
    color: var(--primary-foreground) !important;
}

.select2-container--default .select2-results__option--selected {
    background-color: rgba(var(--primary-rgb), 0.16) !important;
    color: var(--primary-hover) !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background: var(--primary-light);
    border: 1px solid rgba(var(--primary-rgb), 0.25);
    color: var(--primary-hover);
    border-radius: 9999px;
}

.select2-container--open {
    z-index: 9999;
}

.form-control::placeholder {
    color: var(--text-muted);
}

/* ============ BUTTONS ============ */
.btn {
    font-weight: 500;
    transition: var(--transition);
}

.btn-primary {
    background: var(--text-heading);
    border-color: var(--text-heading);
    color: #fff;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}
.btn-primary:hover,
.btn-primary:focus {
    background: rgba(9, 9, 11, 0.9); /* Zinc 950 at 90% */
    border-color: transparent;
    color: #fff;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.btn-outline-primary {
    color: var(--text-heading);
    border-color: var(--border-color);
    background: transparent;
}
.btn-outline-primary:hover {
    background: var(--secondary-light);
    color: var(--text-heading);
    border-color: var(--border-color);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
}
.btn-success:hover {
    background: var(--success-hover);
    border-color: var(--success-hover);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.btn-warning {
    background: var(--warning);
    border-color: var(--warning);
    color: #fff;
}
.btn-warning:hover {
    background: var(--warning-hover);
    border-color: var(--warning-hover);
    color: #fff;
}

.btn-label-primary { background: var(--primary-light); color: var(--primary); border: none; }
.btn-label-primary:hover { background: var(--primary); color: #fff; }

.btn-label-success { background: var(--success-light); color: var(--success-hover); border: none; }
.btn-label-success:hover { background: var(--success); color: #fff; }

.btn-label-warning { background: var(--warning-light); color: var(--warning-hover); border: none; }
.btn-label-warning:hover { background: var(--warning); color: #fff; }

.btn-label-danger { background: var(--danger-light); color: var(--danger-hover); border: none; }
.btn-label-danger:hover { background: var(--danger); color: #fff; }

.btn-label-info { background: var(--info-light); color: var(--info-hover); border: none; }
.btn-label-info:hover { background: var(--info); color: #fff; }

/* Ghost icon button — borderless minimal action button (shadcn style) */
.btn-ghost-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: var(--border-radius);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}
.btn-ghost-icon:hover {
    background: var(--secondary-light);
    color: var(--text-heading);
}

/* ===== Icon Button (shadcn/ui inspired) =====
   ใช้สำหรับปุ่มไอคอนล้วน เช่น ลบ/ปิด/แก้ไข ให้กดง่ายบนมือถือ (>=44px) */
.icon-btn {
    min-width: 44px;
    min-height: 44px;
    border-radius: 10px;
    border: 0;
    background: transparent;
    color: var(--muted-foreground);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    box-shadow: none;
    transition: var(--transition);
}
.icon-btn i,
.icon-btn .bi,
.icon-btn .bx {
    font-size: 1.1rem;
    font-weight: 700;
}
.icon-btn:hover {
    background: var(--muted);
    color: var(--foreground);
}
.icon-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--ring);
}
.icon-btn--destructive:hover {
    background: rgba(239, 68, 68, 0.10);
    color: rgb(220, 38, 38);
}

/* ============ BADGES ============ */
.badge-status {
    padding: 0.4em 0.85em;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 9999px; /* Pill shape */
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.badge-pending {
    background: var(--warning-light);
    color: #b37800;
}
.badge-approved {
    background: var(--success-light);
    color: #4da828;
}
.badge-rejected {
    background: var(--danger-light);
    color: #cc3216;
}
.badge-draft {
    background: var(--secondary-light);
    color: var(--secondary);
}
.badge-free {
    background: var(--success-light);
    color: #4da828;
}
.badge-paid {
    background: var(--warning-light);
    color: #b37800;
}

/* bg-label Utilities (New Shadcn/Sneat Style) */
.bg-label-primary { background-color: var(--primary-light) !important; color: var(--primary) !important; }
.bg-label-success { background-color: var(--success-light) !important; color: var(--success-hover) !important; }
.bg-label-warning { background-color: var(--warning-light) !important; color: var(--warning-hover) !important; }
.bg-label-danger  { background-color: var(--danger-light) !important; color: var(--danger-hover) !important; }
.bg-label-info    { background-color: var(--info-light) !important; color: var(--info-hover) !important; }
.bg-label-secondary { background-color: var(--secondary-light) !important; color: var(--secondary-hover) !important; }

/* Status Badge - height matched to buttons (38px) */
.status-badge {
    height: 38px;
    padding: 0 1.15rem;
    display: inline-flex;
    align-items: center;
    border-radius: var(--border-radius-lg);
    font-size: 0.8125rem;
    font-weight: 600;
    transition: none;
    cursor: default;
    border: 1px solid transparent;
}
.status-badge.bg-label-primary { border-color: rgba(var(--primary-rgb), 0.15) !important; }
.status-badge.bg-label-success { border-color: rgba(22, 163, 74, 0.15) !important; }

/* ============ TABLES ============ */
.table {
    color: var(--text-primary);
    font-size: 0.9375rem;
    margin-bottom: 0;
}

/* ============ DATATABLES OVERRIDES ============ */
/* These use maximum-specificity selectors to beat dataTables.bootstrap5.min.css */
.dataTables_wrapper table.dataTable > thead > tr > th,
.dataTables_wrapper table.dataTable > thead > tr > td,
.dataTables_wrapper .table > thead > tr > th {
    font-weight: 500 !important;
    color: var(--text-muted) !important;
    font-size: 0.875rem !important;
    padding: 1rem !important;
    border-bottom: 1px solid var(--border-color) !important;
    border-top: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    box-shadow: none !important;
    text-transform: none !important;
    letter-spacing: normal !important;
}
.dataTables_wrapper table.dataTable > tbody > tr > td,
.dataTables_wrapper table.dataTable > tbody > tr > th,
.dataTables_wrapper .table > tbody > tr > td {
    padding: 1rem !important;
    vertical-align: middle !important;
    border-bottom: 1px solid var(--border-color) !important;
    border-top: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
}
.dataTables_wrapper table.dataTable > tbody > tr:hover > td,
.dataTables_wrapper table.dataTable > tbody > tr:hover > th {
    background-color: var(--secondary-light) !important;
}
.dataTables_wrapper table.dataTable {
    border-collapse: collapse !important;
    border: none !important;
}


/* DataTables override */
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.25rem 2rem 0.25rem 0.5rem; 
    font-size: 0.875rem;
    background-color: #fff;
}
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}
.dataTables_wrapper .dataTables_length select:focus,
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--text-heading);
    outline: none;
    box-shadow: 0 0 0 1px var(--text-heading);
}

/* DataTables Pagination Override (Shadcn Style) */
.dataTables_wrapper .dataTables_paginate .pagination {
    gap: 0.25rem;
    margin-bottom: 0;
}
.dataTables_wrapper .dataTables_paginate .page-item .page-link {
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    color: var(--text-primary);
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    background-color: transparent;
    transition: var(--transition);
}
.dataTables_wrapper .dataTables_paginate .page-item.active .page-link {
    background-color: var(--text-heading);
    color: #fff;
    border-color: var(--text-heading);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}
.dataTables_wrapper .dataTables_paginate .page-item:not(.active) .page-link:hover {
    background-color: var(--secondary-light);
    border-color: var(--border-color);
}
.dataTables_wrapper .dataTables_paginate .page-item.disabled .page-link {
    background-color: transparent;
    color: var(--text-muted);
}

/* DataTables Sorting Icons Override */
table.dataTable thead th {
    position: relative;
    cursor: pointer;
}
table.dataTable thead th::before,
table.dataTable thead th::after {
    display: none !important; /* Hide default Bootstrap/DataTables pseudo-elements */
}
table.dataTable thead .sorting,
table.dataTable thead .sorting_asc,
table.dataTable thead .sorting_desc {
    padding-right: 3.25rem !important; /* เว้นระยะหัวข้อสั้น (เช่น ID) กับลูกศร */
}

/* SVG Sorting Backgrounds */
table.dataTable thead .sorting {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23a1acb8' viewBox='0 0 16 16'%3E%3Cpath d='M8 2.5l3.5 4h-7L8 2.5zm0 11l-3.5-4h7L8 13.5z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.7rem center !important;
    background-size: 1rem 1rem !important;
}
table.dataTable thead .sorting_asc {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 2.5l3.5 4h-7L8 2.5z' fill='%23696cff'/%3E%3Cpath d='M8 13.5l-3.5-4h7L8 13.5z' fill='%23a1acb8'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.7rem center !important;
    background-size: 1rem 1rem !important;
}
table.dataTable thead .sorting_desc {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 2.5l3.5 4h-7L8 2.5z' fill='%23a1acb8'/%3E%3Cpath d='M8 13.5l-3.5-4h7L8 13.5z' fill='%23696cff'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.7rem center !important;
    background-size: 1rem 1rem !important;
}

/* ============ TIMELINE ============ */
.timeline {
    position: relative;
    padding-left: 2.5rem;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 0.75rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.timeline-item {
    position: relative;
    padding-bottom: 1.5rem;
}
.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-dot {
    position: absolute;
    left: -1.85rem;
    top: 0.25rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: #fff;
}
.timeline-dot.dot-primary { border-color: var(--primary); background: var(--primary); }
.timeline-dot.dot-success { border-color: var(--success); background: var(--success); }
.timeline-dot.dot-danger { border-color: var(--danger); background: var(--danger); }
.timeline-dot.dot-warning { border-color: var(--warning); background: var(--warning); }

.timeline-content {
    background: var(--body-bg);
    border-radius: var(--border-radius-lg);
    padding: 1rem 1.25rem;
}

.timeline-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-heading);
    margin-bottom: 0.25rem;
}

.timeline-text {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0;
}

.timeline-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ============ MODALS ============ */
.modal-content {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); /* shadow-lg */
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem 1.5rem;
}

.modal-title {
    font-weight: 600;
    color: var(--text-heading);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
}

/* ============ FILE UPLOAD ============ */
.file-upload-area {
    border: 1px dashed var(--secondary);
    border-radius: var(--border-radius-lg);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
}
.file-upload-area:hover,
.file-upload-area.dragover {
    background: var(--secondary-light);
}

.file-upload-icon {
    font-size: 2.5rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}
.file-upload-text {
    font-size: 0.875rem;
    color: var(--text-primary);
}
.file-upload-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ============ SHADCN TABS ============ */
.shadcn-tabs-list {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--secondary-light);
    padding: 0.25rem;
    border-radius: var(--border-radius-lg);
    gap: 0.25rem;
}

.shadcn-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    border-radius: var(--border-radius);
    padding: 0.375rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.shadcn-tab:hover {
    color: var(--text-heading);
}

.shadcn-tab.active {
    background-color: var(--card-bg);
    color: var(--text-heading);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); /* shadow-sm */
}

/* ============ LOADING ============ */
.page-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.3s;
}
.page-loading.hide {
    opacity: 0;
    pointer-events: none;
}

.spinner-border-custom {
    width: 3rem;
    height: 3rem;
    border-width: 3px;
    color: var(--primary);
}

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}
.empty-state h5 {
    color: var(--text-heading);
    font-weight: 600;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1199.98px) {
    .layout-sidebar {
        transform: translateX(-100%);
    }
    .layout-sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    }
    .layout-page {
        margin-left: 0;
        /* แถบข้างเป็น fixed — ไม่เว้น 272px ซ้ำ; กันล้นแนวนอนบนมือถือ */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        /* ให้คอลัมน์หลักหดได้ในแถว flex — ไม่ใช้ flex-basis อัตโนมัติจากเนื้อหา */
        flex: 1 1 0;
    }
    /*
     * ช่องโหลด sidebar จาก data-include — ห่อ aside อยู่ใน div ที่เป็น flex item
     * aside กว้าง 272px ทำให้ช่องนี้ได้ min-width ~272px คู่กับ layout-page = ล้นแนวนอน
     * ยุบทุก sibling ที่ไม่ใช่ layout-page (รองรับลำดับ DOM / ชนิดโหนดต่างจาก first-of-type)
     */
    .layout-wrapper > *:not(.layout-page) {
        flex: 0 0 0;
        width: 0;
        min-width: 0;
        max-width: 0;
        padding: 0;
        margin: 0;
        border: none;
    }
    .layout-wrapper {
        width: 100%;
        max-width: 100%;
    }
    .navbar-toggle {
        display: block;
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1039;
    }
    .sidebar-overlay.show {
        display: block;
    }
}

@media (max-width: 575.98px) {
    .content-wrapper {
        padding: 1rem;
    }
    .stats-card-value {
        font-size: 1.375rem;
    }
}

/* ============ ANIMATIONS ============ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.cursor-default { cursor: default !important; }
.pointer-events-none { pointer-events: none !important; }
.text-pink { color: #db2777; }
/* ============ MASCOT & ANIMATIONS ============ */
@keyframes float {
    0% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(1deg); }
    100% { transform: translateY(0px) rotate(0deg); }
}

.mascot-sidebar-container {
    animation: float 5s ease-in-out infinite;
}

@media (max-height: 860px) {
    .mascot-sidebar-container {
        display: none !important;
    }
}

.preview-anim {
    animation: fadeIn 0.4s ease-out forwards;
}

/* fadeIn นิยามแล้วในส่วน ANIMATIONS ด้านบน — ไม่ต้องนิยามซ้ำ */

/* ===== Utilities แทน Bootstrap บางคลาส (หน้าที่ไม่โหลด Bootstrap เช่น view_data) ===== */
.display-lg-only {
    display: none !important;
}

@media (min-width: 992px) {
    .display-lg-only {
        display: block !important;
    }
}

.display-sm-up {
    display: none !important;
}

@media (min-width: 576px) {
    .display-sm-up {
        display: block !important;
    }
}

.u-text-center {
    text-align: center;
}

.u-px-3 {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.u-mt-4 {
    margin-top: 1.5rem;
}

.u-text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Skeleton Loading (shimmer) — ใช้ได้ทั้งระบบ ===== */
:root {
    --skeleton-base: rgba(24, 24, 27, 0.08);
    --skeleton-highlight: rgba(24, 24, 27, 0.14);
}

@keyframes skel-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skel {
    display: block;
    border-radius: 10px;
    background: linear-gradient(
        90deg,
        var(--skeleton-base) 25%,
        var(--skeleton-highlight) 37%,
        var(--skeleton-base) 63%
    );
    background-size: 400% 100%;
    animation: skel-shimmer 1.2s ease-in-out infinite;
}

.skel-text {
    height: 0.9rem;
    border-radius: 999px;
}

.skel-sm { height: 0.75rem; }
.skel-md { height: 1rem; }
.skel-lg { height: 1.25rem; }

.skel-w-20 { width: 20%; }
.skel-w-40 { width: 40%; }
.skel-w-60 { width: 60%; }
.skel-w-80 { width: 80%; }
.skel-w-full { width: 100%; }

/* แถบ skeleton ทั่วทั้งระบบ (แสดงเมื่อมี API call) */
.global-skel-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9998;
    height: 3px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

body[data-api-loading="1"] .global-skel-bar {
    opacity: 1;
}

.global-skel-bar::before {
    content: '';
    display: block;
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, rgba(124,58,237,0.15), rgba(124,58,237,0.65), rgba(124,58,237,0.15));
    background-size: 200% 100%;
    animation: skel-shimmer 1.1s ease-in-out infinite;
}

/* Skeleton สำหรับ input/select ในฟอร์ม (แสดงระหว่างโหลดค่าเริ่มต้น) */
.skel-input {
    color: transparent !important;
    caret-color: transparent !important;
    background: linear-gradient(
        90deg,
        var(--skeleton-base) 25%,
        var(--skeleton-highlight) 37%,
        var(--skeleton-base) 63%
    ) !important;
    background-size: 400% 100% !important;
    animation: skel-shimmer 1.2s ease-in-out infinite;
    border-color: var(--border, #e4e4e7) !important;
}

.skel-input::placeholder {
    color: transparent !important;
}
