@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:       #D40511;
    --primary-dark:  #A8040D;
    --accent:        #FFCC00;
    --success:       #16A34A;
    --success-bg:    #DCFCE7;
    --danger:        #D40511;
    --danger-bg:     #FEE2E2;
    --warning:       #B45309;
    --warning-bg:    #FEF3C7;
    --gray-50:       #F9FAFB;
    --gray-100:      #F3F4F6;
    --gray-200:      #E5E7EB;
    --gray-300:      #D1D5DB;
    --gray-400:      #9CA3AF;
    --gray-500:      #6B7280;
    --gray-600:      #4B5563;
    --gray-700:      #374151;
    --gray-800:      #111827;
    --radius:        8px;
    --radius-lg:     12px;
    --shadow:        0 1px 3px rgba(0,0,0,.07);
    --shadow-md:     0 4px 12px rgba(0,0,0,.08);
}

body {
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    font-size: 13.5px;
    color: var(--gray-800);
    background: #F4F4F4;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.4rem; font-weight: 800; letter-spacing: -.3px; }
h2 { font-size: 1.1rem; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 700; }

/* ── Card ── */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
    white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-200); }
.btn-success   { background: var(--success); color: #fff; }
.btn-ghost     { background: #fff; color: var(--gray-600); border-color: var(--gray-300); }
.btn-sm        { padding: .25rem .65rem; font-size: .78rem; }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; }
.form-group label { font-weight: 600; font-size: .8rem; color: var(--gray-600); text-transform: uppercase; letter-spacing: .04em; }
.form-group input, .form-group select {
    padding: .5rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .875rem;
    font-family: inherit;
    outline: none;
    background: #fff;
    color: var(--gray-800);
    transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(212,5,17,.1);
}

/* ── Badge ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
}
.badge-done    { background: #DCFCE7; color: #15803D; border: 1px solid #86EFAC; }
.badge-pending { background: #FEF9C3; color: #854D0E; border: 1px solid #FDE047; }
.badge-cancel  { background: #FEE2E2; color: #B91C1C; border: 1px solid #FCA5A5; }
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ── Table ── */
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th, td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid var(--gray-200); }
th {
    background: #FFF9E6;
    font-weight: 700;
    font-size: .73rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    border-bottom: 2px solid var(--gray-200);
}
tr:hover td { background: #FFFBEB !important; }

/* ── Alert ── */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .85rem;
    font-weight: 500;
}
.alert-error   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid #FCA5A5; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #86EFAC; }
.alert-info    { background: #EFF6FF; color: #1E40AF; border: 1px solid #93C5FD; }

/* ── WH progress bar ── */
.wh-bar { display: flex; align-items: center; gap: .4rem; min-width: 110px; }
.wh-bar-track { flex: 1; height: 5px; background: var(--gray-200); border-radius: 99px; overflow: hidden; }
.wh-bar-fill  { height: 5px; border-radius: 99px; transition: width .3s; }
.wh-bar-pct   { font-size: .75rem; font-weight: 700; white-space: nowrap; min-width: 38px; text-align: right; color: var(--gray-600); }

/* ── Status colors ── */
.status-done     { background: #DCFCE7; color: #15803D; }
.status-pending  { background: #EFF6FF; color: #1E40AF; }
.status-waiting  { background: #FEF3C7; color: #92400E; }
.status-partial  { background: #FED7AA; color: #9A3412; }
.status-other    { background: var(--gray-100); color: var(--gray-600); }

/* ── Status icon (tick / cross) ── */
.icon-yes { color: #16A34A; font-size: 1.1rem; }
.icon-no  { color: var(--danger); font-size: 1.1rem; }

/* ── Upload zone ── */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    background: var(--gray-50);
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--primary);
    background: #FEF2F2;
}
.upload-zone input[type=file] { display: none; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 99px; }

.hidden { display: none !important; }

/* ──────────────────────────────────────────────────────────────────────────
   Loading states — top progress bar, skeleton, chart overlay
   ────────────────────────────────────────────────────────────────────────── */

/* Top progress bar — sticky thin DHL red stripe loop (indeterminate) */
.top-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(212, 5, 17, .12);
    z-index: 9999;
    overflow: hidden;
    pointer-events: none;
}
.top-progress-bar {
    position: absolute;
    inset: 0;
    width: 35%;
    background: linear-gradient(90deg, transparent, var(--primary) 50%, transparent);
    animation: top-progress-slide 1.4s linear infinite;
}
@keyframes top-progress-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(385%); }   /* 100 / 0.35 ≈ 285 + travel */
}

/* Skeleton — generic shimmer placeholder for dynamic values */
.skeleton {
    display: inline-block;
    background: linear-gradient(
        90deg,
        var(--gray-200) 0%,
        var(--gray-100) 50%,
        var(--gray-200) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 4px;
    color: transparent !important;
    user-select: none;
    pointer-events: none;
}
/* Width helpers — pick one to avoid layout shift */
.skeleton-w-sm { width: 32px; }
.skeleton-w-md { width: 48px; }
.skeleton-w-lg { width: 64px; }
@keyframes skeleton-shimmer {
    0%   { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* Chart canvas overlay — "Loading chart…" + dots */
.chart-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .55);
    color: var(--gray-500);
    font-size: .9rem;
    font-weight: 600;
    letter-spacing: .02em;
    pointer-events: none;     /* never block clicks on chart canvas */
    z-index: 5;
}
/* Explicit [hidden] override — class selector ชนะ UA default ที่ display:none
   เลยต้องบังคับ hide เองเมื่อ HTML attribute hidden ติด */
.chart-loading-overlay[hidden],
.top-progress[hidden] { display: none !important; }
.chart-loading-overlay .dots::after {
    content: '';
    display: inline-block;
    animation: dots-cycle 1.4s steps(4, end) infinite;
}
@keyframes dots-cycle {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%, 100% { content: '...'; }
}

/* Respect reduced-motion users — freeze animations */
@media (prefers-reduced-motion: reduce) {
    .top-progress-bar,
    .skeleton,
    .chart-loading-overlay .dots::after {
        animation: none;
    }
    .top-progress-bar { width: 100%; opacity: .5; }
}
