/* ============================================
   Bootstrap 5 Orange Theme Extensions
   ============================================ */

*, *::before, *::after {
    font-family: 'Sarabun', system-ui, sans-serif;
}

.flatpickr-calendar { z-index: 99999 !important; }
.flatpickr-input[readonly] { background-color: inherit; }
.flatpickr-input.form-control { background-color: #fff; }

:root {
    --orange-50:  #fff7ed;
    --orange-100: #ffedd5;
    --orange-200: #fed7aa;
    --orange-300: #fdba74;
    --orange-500: #f97316;
    --orange-600: #ea580c;
}

.is-paid-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-radius: 10px;
    border: 2px solid #e5e7eb;
    background: #f9fafb;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    color: #9ca3af;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    user-select: none;
    width: 100%;
    min-height: 38px;
    margin-bottom: 0;
}

.is-paid-card-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: border-color 0.15s, background 0.15s;
}

.is-paid-card.is-paid-on {
    border-color: var(--orange-500);
    background: var(--orange-50);
    color: var(--orange-600);
}

.is-paid-card.is-paid-on .is-paid-card-icon {
    border-color: var(--orange-500);
    background: var(--orange-500);
}

.is-paid-card.is-paid-on .is-paid-card-icon::after {
    content: '';
    display: block;
    width: 5px;
    height: 9px;
    border-right: 2px solid white;
    border-bottom: 2px solid white;
    transform: rotate(45deg) translate(-1px, -1px);
}

.form-check-input.form-switch-orange:checked {
    background-color: var(--orange-500);
    border-color: var(--orange-500);
}
.form-check-input.form-switch-orange:focus {
    box-shadow: 0 0 0 0.25rem rgba(249, 115, 22, 0.25);
    border-color: var(--orange-300);
}

.btn-orange {
    background-color: var(--orange-500);
    border-color: var(--orange-500);
    color: #fff;
}
.btn-orange:hover,
.btn-orange:focus,
.btn-orange:active {
    background-color: var(--orange-600);
    border-color: var(--orange-600);
    color: #fff;
}
.btn-outline-orange {
    color: var(--orange-500);
    border-color: var(--orange-500);
    background: transparent;
}
.btn-outline-orange:hover {
    background-color: var(--orange-500);
    border-color: var(--orange-500);
    color: #fff;
}
.btn-outline-emerald {
    color: #059669;
    border-color: #a7f3d0;
    background: #fff;
}
.btn-outline-emerald:hover {
    background-color: #ecfdf5;
    color: #059669;
}

.text-orange       { color: var(--orange-500) !important; }
.text-orange-light { color: var(--orange-300) !important; }
.bg-orange         { background-color: var(--orange-500) !important; }
.bg-orange-soft    { background-color: var(--orange-50)  !important; }
.border-orange     { border-color: var(--orange-500) !important; }

.text-purple    { color: #7c3aed !important; }
.bg-purple-soft { background-color: #ede9fe !important; }

.link-orange       { color: var(--orange-500); text-decoration: none; }
.link-orange:hover { color: var(--orange-600); }

.badge-orange-soft {
    background-color: var(--orange-50);
    color: var(--orange-600);
}
.badge-emerald-soft {
    background-color: #d1fae5;
    color: #065f46;
}
.badge-rose-soft {
    background-color: #fee2e2;
    color: #9f1239;
}

/* Status colors */
.text-emerald  { color: #059669 !important; }
.text-rose     { color: #e11d48 !important; }
.text-amber    { color: #d97706 !important; }
.text-sky      { color: #0284c7 !important; }
.bg-emerald    { background-color: #059669 !important; }
.bg-sky-500    { background-color: #0ea5e9 !important; }
.bg-amber-500  { background-color: #f59e0b !important; }
.bg-rose-500   { background-color: #f43f5e !important; }
.bg-red-700    { background-color: #b91c1c !important; }

/* ============================================
   Compatibility / Utility Classes
   ============================================ */

.hidden              { display: none !important; }
.opacity-0           { opacity: 0 !important; }
.-translate-y-1      { transform: translateY(-0.25rem) !important; }
.opacity-40          { opacity: 0.4 !important; }
.cursor-not-allowed  { cursor: not-allowed !important; }
.text-xs             { font-size: 0.75rem !important; line-height: 1rem; }
.border-dashed       { border-style: dashed !important; }
.min-w-0             { min-width: 0 !important; }
.object-cover        { object-fit: cover !important; }
.object-contain      { object-fit: contain !important; }
.leading-tight       { line-height: 1.25 !important; }
.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; }

[data-flash-alert] {
    background: #fff !important;
    border-width: 2px !important;
    border-radius: 12px !important;
    box-shadow: 0 16px 48px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.1) !important;
    transition: opacity 0.25s ease, transform 0.25s ease;
    animation: flash-slide-in 0.3s cubic-bezier(.16,1,.3,1);
    min-width: 300px;
}

@keyframes flash-slide-in {
    from { opacity: 0; transform: translateX(1.5rem); }
    to   { opacity: 1; transform: translateX(0); }
}

/* Custom grid utilities (Bootstrap 5 doesn't have CSS Grid cols) */
.grid      { display: grid; }
.grid-2    { grid-template-columns: repeat(2, 1fr); }
.grid-3    { grid-template-columns: repeat(3, 1fr); }
.grid-4    { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

@media (max-width: 767px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
@media (min-width: 768px) and (max-width: 991px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================
   Auth Pages
   ============================================ */

.auth-hero-bg {
    background-image: url("../images/login-bg.jpg");
    background-position: center center;
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
    min-height: 100vh;
}

/* ── Login Page (Industrial Dark Theme) ── */
.auth-login-page {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100vh;
    background-image: url("../images/login-bg.jpg");
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    font-family: inherit;
}

.auth-login-wrap {
    display: flex;
    min-height: 100vh;
}

/* Left hero panel */
.auth-login-hero {
    flex: 1.2;
    position: relative;
    background: transparent;
    background-size: cover;
    background-position: center center;
    display: none;
}
@media (min-width: 992px) {
    .auth-login-hero { display: flex; align-items: flex-end; }
}

.auth-login-hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(0,0,0,.55) 0%,
        rgba(0,0,0,.15) 50%,
        rgba(0,0,0,.7) 100%
    );
}

.auth-login-tagline {
    position: relative;
    z-index: 1;
    padding: 3rem 3rem 3.5rem;
    color: #fff;
}

.auth-login-tagline-badge {
    display: inline-block;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .18em;
    color: #f97316;
    border: 1px solid rgba(249,115,22,.5);
    border-radius: 2px;
    padding: 3px 10px;
    margin-bottom: 1.2rem;
    text-transform: uppercase;
}

.auth-login-tagline h2 {
    font-size: 2.6rem;
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: .75rem;
    text-shadow: 0 2px 12px rgba(0,0,0,.6);
}

.auth-login-tagline p {
    font-size: .9rem;
    color: rgba(255,255,255,.65);
    line-height: 1.7;
    margin: 0;
}

/* Right form panel */
.auth-login-panel {
    flex: 0 0 420px;
    background: rgba(15, 15, 15, 0.55);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    border-left: 1px solid rgba(255,255,255,.08);
}
@media (max-width: 991.98px) {
    .auth-login-panel { flex: 1; }
}

.auth-login-panel-inner {
    width: 100%;
    max-width: 360px;
}

/* Logo area */
.auth-login-logo-wrap {
    width: 52px;
    height: 52px;
    background: rgba(249,115,22,.12);
    border: 1px solid rgba(249,115,22,.3);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 0 18px rgba(249,115,22,.15);
}
.auth-login-logo-wrap img {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.auth-login-brand {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: .01em;
}
.auth-login-brand-sub {
    font-size: .75rem;
    color: rgba(255,255,255,.4);
    margin-top: 1px;
}

/* Headings */
.auth-login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: .35rem;
}
.auth-login-subtitle {
    font-size: .82rem;
    color: rgba(255,255,255,.4);
    margin-bottom: 1.75rem;
}

/* Flash alerts */
.auth-flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.2rem;
    font-size: .85rem;
    transition: opacity .2s, transform .2s;
    cursor: pointer;
}
.auth-flash button {
    background: none;
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0 0 .75rem;
    opacity: .7;
}
.auth-flash-success { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.3); color: #4ade80; }
.auth-flash-success button { color: #4ade80; }
.auth-flash-danger  { background: rgba(239,68,68,.12);  border: 1px solid rgba(239,68,68,.3);  color: #f87171; }
.auth-flash-danger button  { color: #f87171; }

/* Inputs */
.auth-login-label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: rgba(255,255,255,.55);
    letter-spacing: .05em;
    text-transform: uppercase;
    margin-bottom: .45rem;
}

.auth-login-input {
    width: 100%;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 8px;
    padding: .65rem 1rem;
    font-size: .9rem;
    color: #fff;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.auth-login-input::placeholder { color: rgba(255,255,255,.2); }
.auth-login-input:focus {
    border-color: rgba(249,115,22,.6);
    box-shadow: 0 0 0 3px rgba(249,115,22,.12);
    background: #222;
}

/* Remember me */
.auth-login-check {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .82rem;
    color: rgba(255,255,255,.45);
    cursor: pointer;
    user-select: none;
}
.auth-login-check input { accent-color: #f97316; cursor: pointer; }

/* Submit button */
.auth-login-btn {
    width: 100%;
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border: none;
    border-radius: 8px;
    padding: .75rem;
    font-size: .95rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: .03em;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(249,115,22,.35);
    transition: box-shadow .2s, transform .1s;
}
.auth-login-btn:hover {
    box-shadow: 0 6px 24px rgba(249,115,22,.5);
    transform: translateY(-1px);
}
.auth-login-btn:active { transform: translateY(0); }

/* Footer links */
.auth-login-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: .82rem;
    color: rgba(255,255,255,.35);
    margin-bottom: 0;
}
.auth-login-footer a {
    color: #f97316;
    font-weight: 600;
    text-decoration: none;
}
.auth-login-footer a:hover { text-decoration: underline; }

.auth-login-demo {
    text-align: center;
    font-size: .75rem;
    color: rgba(255,255,255,.2);
    margin-top: .6rem;
    margin-bottom: 0;
}

/* Register page */
.auth-register-panel {
    overflow-y: auto;
    align-items: flex-start;
    padding-top: 2.5rem;
    padding-bottom: 2.5rem;
}

.auth-register-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* Modal tabs (salesperson detail) */
.sp-tab {
    background: none; border: none; padding: .65rem 1rem; font-size: .82rem;
    font-weight: 600; color: #64748b; cursor: pointer; display: inline-flex;
    align-items: center; gap: 6px; border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
}
.sp-tab:hover { color: #1e293b; }
.sp-tab-active { color: #f97316 !important; border-bottom-color: #f97316 !important; }

.auth-login-input option {
    background: #1f1f1f;
    color: #fff;
}

/* ============================================
   Progress Bars
   ============================================ */

.progress-fill {
    transition: width 0.2s ease;
    width: 0;
}

/* ============================================
   App Shell
   ============================================ */

.app-body {
    height: 100vh;
    overflow: hidden;
}

.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}


.app-main {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    overflow: hidden;
}

.app-header {
    flex: 0 0 4rem;
    position: relative;
    z-index: 10;
}

.app-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.app-content-inner {
    min-height: 100%;
    min-width: 0;
}

.app-header > div {
    min-width: 0;
}

.app-header h2,
.app-header p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   Metric Cards
   ============================================ */

.metric-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.metric-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
    min-width: 0;
    padding: 20px;
}

.metric-card-body {
    align-items: flex-start;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    min-height: 82px;
    min-width: 0;
}

.metric-icon {
    align-items: center;
    border-radius: 12px;
    display: inline-flex;
    flex: 0 0 48px;
    height: 48px;
    justify-content: center;
    width: 48px;
}

.metric-value {
    font-size: clamp(28px, 2.1vw, 42px);
    font-weight: 800;
    line-height: 1.05;
    margin-top: 10px;
    overflow-wrap: normal;
    white-space: nowrap;
    min-width: 0;
}

.metric-value-long {
    font-size: clamp(23px, 1.75vw, 38px);
    overflow-wrap: normal;
    white-space: nowrap;
    min-width: 0;
}

/* ============================================
   Sidebar — Modern shadcn/ui Style
   ============================================ */

.sidebar {
    background: #1f1a2e;
    border-right: 1px solid #2d2739;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    width: 260px;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: #3d3556 transparent;
}
.sidebar::-webkit-scrollbar {
    width: 4px;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
    background: #3d3556;
    border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
    background: #f97316;
}

.sidebar-header {
    border-bottom: 1px solid #2d2739;
    padding: 16px;
    flex-shrink: 0;
}

.sidebar-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(249, 115, 22, 0.1);
    border-radius: 8px;
    flex-shrink: 0;
}

.sidebar-logo img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.sidebar-branding {
    min-width: 0;
    flex: 1;
}

.sidebar-title {
    font-size: 13px;
    font-weight: 700;
    color: #f5f3f9;
    margin: 0;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.sidebar-subtitle {
    font-size: 11px;
    color: #9b95b0;
    margin: 2px 0 0 0;
    line-height: 1.2;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.sidebar-divider {
    height: 1px;
    background: #2d2739;
    margin: 8px 8px;
}

.sidebar-nav-link {
    align-items: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #b4afc4;
    cursor: pointer;
    display: flex;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    gap: 12px;
    height: 36px;
    padding: 0 12px;
    text-align: left;
    text-decoration: none;
    transition: all 0.15s ease;
    width: 100%;
}

.sidebar-nav-link:hover {
    background: rgba(249, 115, 22, 0.08);
    color: #e8e4f3;
}

.sidebar-nav-link.is-active {
    background: rgba(249, 115, 22, 0.15);
    color: #f97316;
}

.sidebar-nav-link .sidebar-icon {
    height: 18px;
    width: 18px;
    flex-shrink: 0;
    color: currentColor;
}

.sidebar-nav-link .sidebar-label {
    flex: 1;
    min-width: 0;
}

.sidebar-toggle {
    position: relative;
}

.sidebar-toggle .sidebar-chevron {
    margin-left: auto;
    flex-shrink: 0;
    height: 16px;
    width: 16px;
    transition: transform 0.2s ease;
    color: currentColor;
}

.sidebar-toggle.is-open .sidebar-chevron {
    transform: rotate(180deg);
}

.sidebar-submenu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
    padding-left: 0;
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.25s ease;
    opacity: 1;
}

.sidebar-submenu.is-collapsed {
    max-height: 0;
    opacity: 0;
    transition: max-height 0.25s ease, opacity 0.25s ease;
}

.sidebar-submenu-link {
    align-items: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #9b95b0;
    cursor: pointer;
    display: flex;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    gap: 12px;
    min-height: 32px;
    height: auto;
    padding: 6px 12px 6px 36px;
    line-height: 1.4;
    text-align: left;
    text-decoration: none;
    transition: all 0.15s ease;
    width: 100%;
    position: relative;
}

.sidebar-submenu-link::before {
    content: '';
    position: absolute;
    left: 18px;
    width: 4px;
    height: 4px;
    background: #766f8d;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.sidebar-submenu-link:hover {
    background: rgba(249, 115, 22, 0.08);
    color: #d8d4e7;
}

.sidebar-submenu-link:hover::before {
    background: #9b95b0;
    width: 5px;
    height: 5px;
}

.sidebar-submenu-link.is-active {
    background: rgba(249, 115, 22, 0.12);
    color: #f97316;
    font-weight: 600;
}

.sidebar-submenu-link.is-active::before {
    background: #f97316;
    width: 6px;
    height: 6px;
}

/* ── Nested sub-toggle (e.g. รายรับ under Accounting) ─────────────────── */
.sidebar-sub-toggle {
    align-items: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #9b95b0;
    cursor: pointer;
    display: flex;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    gap: 12px;
    height: 32px;
    padding: 0 12px 0 36px;
    text-align: left;
    width: 100%;
    position: relative;
    transition: all 0.15s ease;
}
.sidebar-sub-toggle::before {
    content: '';
    position: absolute;
    left: 18px;
    width: 4px;
    height: 4px;
    background: #766f8d;
    border-radius: 50%;
    transition: all 0.15s ease;
}
.sidebar-sub-toggle .sidebar-chevron {
    margin-left: auto;
    flex-shrink: 0;
    height: 12px;
    width: 12px;
    transition: transform 0.2s ease;
    color: currentColor;
}
.sidebar-sub-toggle.is-open .sidebar-chevron {
    transform: rotate(180deg);
}
.sidebar-sub-toggle:hover {
    background: rgba(249, 115, 22, 0.08);
    color: #d8d4e7;
}
.sidebar-sub-toggle.is-active {
    color: #f97316;
    font-weight: 600;
}

.sidebar-sub-submenu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-left: 10px;
    max-height: 400px;
    overflow: hidden;
    transition: max-height 0.25s ease, opacity 0.25s ease;
    opacity: 1;
}
.sidebar-sub-submenu.is-collapsed {
    max-height: 0;
    opacity: 0;
}

/* ============================================
   DataTables
   ============================================ */

.dark-datatable {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    color: #111827;
    padding: 18px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.dark-datatable h2 {
    color: #111827;
    font-size: 18px;
    font-weight: 800;
}

.dark-datatable p {
    color: #6b7280;
}

.dark-datatable table,
.dark-datatable .datatable-table {
    width: 100%;
    min-width: 860px;
    background: #ffffff;
    border-collapse: collapse;
    color: #111827;
    font-size: 14px;
}

.dark-datatable thead th,
.dark-datatable .datatable-table thead th {
    background: #fed7aa !important;
    color: #111827;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.35;
    padding: 10px 12px !important;
    border: 1px solid #e5e7eb !important;
    white-space: nowrap;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 2;
}

.dark-datatable thead th:first-child,
.dark-datatable .datatable-table thead th:first-child {
    text-align: left;
}

.dark-datatable thead th.text-center,
.dark-datatable .datatable-table thead th.text-center {
    text-align: center !important;
}

.dark-datatable thead th.text-end,
.dark-datatable .datatable-table thead th.text-end {
    text-align: right !important;
}

.dark-datatable tbody td,
.dark-datatable .datatable-table tbody td {
    background: #ffffff;
    color: #374151;
    font-size: 13px;
    line-height: 1.4;
    padding: 8px 12px !important;
    border: 1px solid #e5e7eb !important;
    vertical-align: middle;
    white-space: nowrap;
}

.dark-datatable tbody tr:hover td {
    background: #fff7ed;
}

.dark-datatable tbody tr.expense-group-header td {
    background: #eef2ff;
    cursor: pointer;
}
.dark-datatable tbody tr.expense-group-header:hover td {
    background: #e0e7ff;
}
.dark-datatable tbody tr.expense-group-row td {
    background: #f8f9ff;
}
.dark-datatable tbody tr.expense-group-row:hover td {
    background: #f0f4ff;
}

.dark-datatable .datatable-top,
.dark-datatable .datatable-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    color: #475569;
}

.dark-datatable .datatable-top {
    justify-content: flex-end;
}

.dark-datatable .datatable-bottom {
    margin-top: 18px;
    margin-bottom: 0;
}

.dark-datatable .datatable-dropdown {
    display: none;
}

/* แสดง dropdown จำนวนรายการต่อหน้าเฉพาะตารางที่ติดคลาสนี้ */
.dark-datatable.show-perpage .datatable-top {
    justify-content: space-between;
}
.dark-datatable.show-perpage .datatable-dropdown {
    display: flex;
    align-items: center;
    gap: 8px;
    order: 0;
}

.dark-datatable .datatable-search {
    align-items: center;
    display: flex;
    gap: 12px;
    order: 1;
    position: relative;
}

.dark-datatable .datatable-search::before {
    background-color: #94a3b8;
    content: "";
    display: block;
    height: 20px;
    margin-right: -44px;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21 21-4.34-4.34'/%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3C/svg%3E") center / contain no-repeat;
    pointer-events: none;
    width: 20px;
    z-index: 1;
}

.dark-datatable .datatable-selector,
.dark-datatable .datatable-input,
.dark-datatable tbody input:not([type="hidden"]),
.dark-datatable select {
    background: #ffffff !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    color: #111827 !important;
    font-size: 14px !important;
    height: 42px !important;
    margin: 0 !important;
    outline: none !important;
    padding: 8px 12px !important;
}

.dark-datatable .datatable-selector {
    min-width: 118px;
}

.dark-datatable .datatable-input {
    min-width: 240px !important;
    padding-left: 42px !important;
    width: min(560px, 72vw) !important;
}

.dark-datatable .datatable-info {
    color: #6b7280;
    font-size: 14px;
    font-weight: 600;
}

.dark-datatable .datatable-input:focus,
.dark-datatable tbody input:not([type="hidden"]):focus,
.dark-datatable select:focus {
    border-color: #fb923c !important;
    box-shadow: 0 0 0 3px rgba(251, 146, 60, .18) !important;
}

.dark-datatable .datatable-pagination-list {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.dark-datatable .datatable-pagination a {
    background: #ffffff !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 8px !important;
    color: #111827 !important;
    font-weight: 700;
    height: 38px;
    min-width: 36px;
    padding: 8px 12px !important;
}

.dark-datatable .datatable-pagination .datatable-active a {
    background: #f97316 !important;
    border-color: #f97316 !important;
    color: #ffffff !important;
}

.dark-datatable .datatable-pagination a:hover {
    background: #fff7ed !important;
    border-color: #fb923c !important;
    color: #ea580c !important;
}

.dark-datatable .table-action {
    align-items: center;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #475569;
    display: inline-flex;
    height: 38px;
    justify-content: center;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
    width: 38px;
}

.dark-datatable .table-action-cell {
    text-align: center;
}

.dark-datatable .table-action-cell form,
.dark-datatable .table-action-cell div {
    justify-content: center;
}

.dark-datatable .table-action:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #111827;
}

.dark-datatable .table-action-danger {
    border-color: #fecaca;
    color: #ef4444;
}

.dark-datatable .table-action-danger:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

.dark-datatable .table-action-success {
    border-color: #bbf7d0;
    color: #16a34a;
}

.dark-datatable .table-action-success:hover {
    background: #f0fdf4;
    border-color: #86efac;
    color: #15803d;
}

.dark-datatable tbody input::placeholder {
    color: #9ca3af;
}

.dark-datatable .status-select-active {
    background: #ecfdf5 !important;
    border-color: #a7f3d0 !important;
    color: #047857 !important;
    font-weight: 800;
}

.dark-datatable .status-select-inactive {
    background: #fff1f2 !important;
    border-color: #fecdd3 !important;
    color: #be123c !important;
    font-weight: 800;
}

.dark-datatable .datatable-wrapper {
    max-width: 100%;
}

.dark-datatable .datatable-container {
    max-width: 100%;
    max-height: 62vh;
    overflow-x: auto;
    overflow-y: auto;
}

/* ============================================
   Status Badges
   ============================================ */

.status-unpaid {
    background: #d1fae5;
    color: #047857;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    display: inline-block;
}

.status-overdue {
    background: #fee2e2;
    color: #dc2626;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    display: inline-block;
}

.status-warning {
    background: #fef3c7;
    color: #d97706;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    display: inline-block;
}

.status-pending {
    background: #eff6ff;
    color: #3b82f6;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    display: inline-block;
}

/* ============================================
   Modal Data Tables
   ============================================ */

.modal-table-wrap {
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
}

.modal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.modal-table thead tr {
    background: #1e293b;
}

.modal-table thead th {
    padding: 0.6rem 0.875rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    background: transparent;
    border-bottom: none;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.modal-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.1s;
}

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

.modal-table tbody tr:nth-child(even) {
    background: #f8fafc;
}

.modal-table tbody tr:hover {
    background: #eff6ff !important;
}

.modal-table td {
    padding: 0.65rem 0.875rem;
    vertical-align: middle;
    white-space: nowrap;
}

.modal-table td:first-child {
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 600;
}

/* คอลัมน์ข้อความยาว (เช่น ชื่อลูกค้า) ให้ตัดบรรทัดแทนการดันตารางล้น */
.modal-table td.cell-wrap {
    white-space: normal;
    min-width: 150px;
    max-width: 260px;
    word-break: break-word;
}

#customerRowsModalTable td:first-child {
    color: #1e293b;
    font-size: 0.8125rem;
    font-weight: 600;
}

.modal-table .status-unpaid,
.modal-table .status-overdue,
.modal-table .status-warning,
.modal-table .status-pending {
    padding: 3px 9px;
    font-size: 0.6875rem;
    border-radius: 999px;
}

.modal-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.2em 0.65em;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.5;
}
.modal-pill-danger  { background: #fef2f2; color: #dc2626; }
.modal-pill-success { background: #f0fdf4; color: #16a34a; }
.modal-pill-warning { background: #fffbeb; color: #d97706; }
.modal-pill-muted   { background: #f8fafc; color: #64748b; border: 1px solid #e2e8f0; }

/* ============================================
   Custom App Modals
   ============================================ */

.app-modal {
    position: fixed;
    inset: 0;
    z-index: 1055;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 6, 23, 0.6);
    padding: 1rem;
}

.app-modal.hidden {
    display: none !important;
}

/* ============================================
   Form Controls — Orange Focus
   ============================================ */

.form-control:focus,
.form-select:focus {
    border-color: #f97316;
    box-shadow: 0 0 0 0.2rem rgba(249, 115, 22, 0.18);
}

/* ============================================
   Mobile Sidebar Drawer — Hamburger Toggle
   ============================================ */

.sidebar-overlay {
    background: rgba(0, 0, 0, 0.55);
    bottom: 0;
    left: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    right: 0;
    top: 0;
    transition: opacity 0.25s ease;
    z-index: 299;
}

.sidebar-toggle-btn {
    align-items: center;
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #374151;
    cursor: pointer;
    display: none;
    flex-shrink: 0;
    justify-content: center;
    margin-right: 10px;
    padding: 6px 8px;
    transition: background 0.15s ease;
}

.sidebar-toggle-btn:hover {
    background: #f3f4f6;
}

.sidebar-close-btn {
    align-items: center;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 6px;
    color: #9b95b0;
    cursor: pointer;
    display: none;
    flex-shrink: 0;
    justify-content: center;
    margin-left: auto;
    padding: 5px;
    transition: all 0.15s ease;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #e8e4f3;
}

/* ============================================
   Mobile Bottom Navigation
   ============================================ */

.mobile-bottom-nav {
    background: #211d2d;
    border-top: 1px solid #363047;
    bottom: 0;
    display: none;
    justify-content: space-around;
    left: 0;
    padding: 6px 0 max(6px, env(safe-area-inset-bottom, 0px));
    position: fixed;
    right: 0;
    z-index: 200;
}

.mobile-nav-item {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 10px;
    color: #9b95b0;
    cursor: pointer;
    display: flex;
    flex: 1;
    flex-direction: column;
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    gap: 4px;
    justify-content: center;
    letter-spacing: .01em;
    min-width: 0;
    padding: 6px 4px;
    text-align: center;
    text-decoration: none;
    transition: color 0.15s ease;
}

.mobile-nav-item i {
    color: #766f8d;
    height: 20px;
    transition: color 0.15s ease;
    width: 20px;
}

.mobile-nav-item.is-active,
.mobile-nav-item:hover {
    color: #f97316;
}

.mobile-nav-item.is-active i,
.mobile-nav-item:hover i {
    color: #f97316;
}

/* ============================================
   Responsive Layout
   ============================================ */

@media (max-width: 1280px) {
    .sidebar {
        width: 220px !important;
    }

    .metric-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

@media (max-width: 900px) {
    .app-body,
    .app-shell,
    .app-main {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .app-shell {
        display: block;
    }

    /* Sidebar becomes a fixed drawer — slides in from left */
    .sidebar {
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
        display: flex !important;
        height: 100vh;
        left: 0;
        position: fixed;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        width: 280px !important;
        z-index: 300;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar-toggle-btn,
    .sidebar-close-btn {
        display: flex;
    }

    .app-header {
        flex-wrap: wrap;
        gap: 12px;
        height: auto;
        min-height: 4rem;
        padding: 12px 16px !important;
    }

    .app-header > div:last-child {
        gap: 10px;
        margin-left: auto;
    }

    .app-content {
        overflow: visible;
        padding: 16px !important;
    }

    .dark-datatable {
        padding: 14px;
    }

    .dark-datatable table,
    .dark-datatable .datatable-table {
        min-width: 720px;
    }

    .dark-datatable .datatable-top,
    .dark-datatable .datatable-bottom {
        align-items: stretch;
        flex-direction: column;
    }

    .dark-datatable .datatable-search,
    .dark-datatable .datatable-input {
        min-width: 0 !important;
        width: 100% !important;
    }

    .dark-datatable .datatable-pagination-list {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    [data-flash-alert] {
        left: 16px;
        right: 16px;
        top: 16px;
        max-width: none !important;
    }

    .app-modal > .modal-dialog-custom {
        margin-top: 0;
        width: 100% !important;
    }
}

@media (max-width: 640px) {
    .app-header > div:first-child p {
        display: none;
    }

    .app-header img {
        height: 32px !important;
        width: 32px !important;
    }

    .metric-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .metric-card {
        padding: 16px;
    }

    .metric-card-body {
        min-height: 74px;
    }

    .metric-icon {
        flex-basis: 42px;
        height: 42px;
        width: 42px;
    }

    .metric-value,
    .metric-value-long {
        font-size: clamp(26px, 10vw, 36px);
    }

    .dark-datatable {
        border-radius: 10px;
        margin-left: -4px;
        margin-right: -4px;
        padding: 12px;
    }

    .dark-datatable thead th,
    .dark-datatable .datatable-table thead th,
    .dark-datatable tbody td,
    .dark-datatable .datatable-table tbody td {
        font-size: 13px;
        padding: 12px 10px !important;
    }

    .dark-datatable .table-action {
        height: 34px;
        width: 34px;
    }

    .app-modal > .modal-dialog-custom {
        max-height: calc(100vh - 24px) !important;
    }

    .modal-footer-sticky {
        flex-direction: column-reverse;
        align-items: stretch !important;
    }

    .modal-footer-sticky button {
        justify-content: center;
        width: 100%;
    }
}
