/* =========================================================
   PharmaPOS — ระบบขายหน้าร้านร้านยา
   โทนสี: ฟ้า (sky) + เหลือง (sun) · มินิมอล อ่านง่าย
   ========================================================= */

:root {
    --sky-50: #F0F8FF;
    --sky-100: #DDEFFD;
    --sky-200: #BADFFA;
    --sky-300: #88C8F4;
    --sky-400: #4FAEEE;
    --sky-500: #2A9DF4;
    --sky-600: #1479C9;
    --sky-700: #0F62A6;
    --sky-800: #0C4F86;

    --sun-50: #FFFBEB;
    --sun-100: #FFF4C6;
    --sun-200: #FFE994;
    --sun-300: #FFDD5E;
    --sun-400: #FFD233;
    --sun-500: #F5BF00;
    --sun-600: #D9A400;
    --sun-800: #7A5C00;

    --ink: #1B2433;
    --ink-2: #394456;
    --muted: #5F6A7C;
    --line: #E3E9F0;
    --line-2: #EEF2F7;
    --bg: #F4F8FC;
    --card: #FFFFFF;

    --green: #15803D;
    --green-bg: #E6F6EC;
    --red: #C62828;
    --red-bg: #FDECEC;
    --orange: #B45309;
    --orange-bg: #FFF1E0;
    --purple: #6D28D9;
    --purple-bg: #F1EAFE;
    --teal: #0F766E;
    --teal-bg: #E3F5F2;
    --gray: #4B5563;
    --gray-bg: #EEF1F5;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 6px rgba(16, 24, 40, .05);
    --shadow-lg: 0 18px 50px rgba(16, 24, 40, .18);
    --font: 'Sarabun', 'Leelawadee UI', 'Leelawadee', 'Noto Sans Thai', 'Tahoma', system-ui, sans-serif;
    --sidebar-w: 236px;
    --sidebar-w-mini: 72px;
    --topbar-h: 60px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15.5px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--sky-600); text-decoration: none; }
a:hover { color: var(--sky-700); text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; font-weight: 700; color: var(--ink); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
small, .small { font-size: .86em; }
code, kbd {
    font-family: ui-monospace, Consolas, monospace;
    font-size: .88em;
    background: var(--gray-bg);
    padding: 1px 6px;
    border-radius: 6px;
}
kbd { border: 1px solid var(--line); border-bottom-width: 2px; background: #fff; color: var(--ink-2); }
.btn-primary kbd, .btn-danger kbd, .btn-success kbd { background: rgba(255, 255, 255, .2); border-color: rgba(255, 255, 255, .35); color: #fff; }
.btn-accent kbd { background: rgba(255, 255, 255, .55); border-color: rgba(0, 0, 0, .12); color: var(--ink); }
.ic { flex-shrink: 0; vertical-align: middle; }
.num, .tnum { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: #fff;
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: width .2s ease, transform .2s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 18px 16px;
    color: var(--ink);
    text-decoration: none !important;
    border-bottom: 1px solid var(--line-2);
}
.brand-logo {
    width: 40px; height: 40px;
    border-radius: 12px;
    background: var(--sun-400);
    color: var(--sky-700);
    display: grid; place-items: center;
    flex-shrink: 0;
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .06);
}
.brand-logo .ic { stroke-width: 3; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.brand-text small { color: var(--muted); font-size: .8rem; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--ink-2);
    font-weight: 500;
    text-decoration: none !important;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--sky-50); color: var(--sky-700); }
.nav-item.active {
    background: var(--sky-100);
    color: var(--sky-800);
    font-weight: 700;
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: -10px; top: 8px; bottom: 8px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--sun-400);
}
.nav-highlight { background: var(--sun-100); color: var(--sun-800); }
.nav-highlight:hover { background: var(--sun-200); color: var(--ink); }
.nav-highlight.active { background: var(--sun-300); color: var(--ink); }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; }
.nav-badge {
    min-width: 22px; height: 22px;
    padding: 0 7px;
    border-radius: 11px;
    background: var(--red);
    color: #fff;
    font-size: .75rem;
    font-weight: 700;
    display: grid; place-items: center;
}
.nav-sep { height: 1px; background: var(--line-2); margin: 8px 4px; }

.sidebar-foot { padding: 10px; border-top: 1px solid var(--line-2); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px 10px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--sky-100); color: var(--sky-700);
    display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-meta strong { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--muted); font-size: .78rem; }
.nav-logout { color: var(--muted); }
.nav-logout:hover { background: var(--red-bg); color: var(--red); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; transition: margin .2s ease; }

.topbar {
    position: sticky; top: 0; z-index: 30;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 24px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 1.18rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: .9rem; }
.topbar-date { display: inline-flex; align-items: center; gap: 6px; }
.topbar-clock {
    font-variant-numeric: tabular-nums;
    font-weight: 700; color: var(--sky-700);
    background: var(--sky-50);
    padding: 4px 10px; border-radius: 8px;
}
.topbar .topbar-menu { display: none; }

.content { padding: 22px 24px 40px; flex: 1; }

/* POS mode: ย่อเมนูข้างเหลือแต่ไอคอน */
body.pos-mode .sidebar { width: var(--sidebar-w-mini); }
body.pos-mode .main { margin-left: var(--sidebar-w-mini); }
body.pos-mode .brand { padding: 14px 16px; justify-content: center; }
body.pos-mode .brand-text,
body.pos-mode .nav-label,
body.pos-mode .user-meta { display: none; }
body.pos-mode .nav-item { justify-content: center; padding: 11px; }
body.pos-mode .nav-badge { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; font-size: .68rem; padding: 0 5px; }
body.pos-mode .user-chip { justify-content: center; padding: 6px 0 10px; }
body.pos-mode .content { padding: 16px; }

/* ---------- Page header ---------- */
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h2 { margin: 0; font-size: 1.35rem; }
.page-head > div:first-child { flex: 1 1 420px; min-width: 0; }
.page-head .sub { color: var(--muted); margin: 2px 0 0; font-size: .92rem; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line-2);
}
.card-head h3 { margin: 0; font-size: 1.04rem; display: flex; align-items: center; gap: 8px; }
.card-head .ic { color: var(--sky-600); }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line-2); background: #FBFCFE; border-radius: 0 0 var(--radius) var(--radius); }
.card + .card { margin-top: 18px; }
.grid > .card + .card { margin-top: 0; }
.card-accent { border-top: 4px solid var(--sun-400); }
.card-sky { background: var(--sky-50); border-color: var(--sky-100); }
.card-sun { background: var(--sun-50); border-color: var(--sun-200); }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.span-2 { grid-column: span 2; }
.stack > * + * { margin-top: 18px; }

/* ---------- Stat tiles ---------- */
.stat {
    position: relative;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 4px;
    min-width: 0;
}
.stat-label { color: var(--muted); font-size: .9rem; display: flex; align-items: baseline; gap: 7px; }
.stat-label > .ic { align-self: center; }
.stat-value { font-size: 1.7rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { font-size: .85rem; color: var(--muted); }
.stat-icon {
    position: absolute; top: 14px; right: 14px;
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center;
    background: var(--sky-50); color: var(--sky-600);
}
.stat-sky { background: linear-gradient(135deg, var(--sky-600), var(--sky-500)); border-color: transparent; }
.stat-sky .stat-label, .stat-sky .stat-sub { color: rgba(255, 255, 255, .85); }
.stat-sky .stat-value { color: #fff; }
.stat-sky .stat-icon { background: rgba(255, 255, 255, .18); color: #fff; }
.stat-sun { background: var(--sun-400); border-color: transparent; }
.stat-sun .stat-label, .stat-sun .stat-sub { color: #5C4500; }
.stat-sun .stat-icon { background: rgba(255, 255, 255, .45); color: var(--sun-800); }
.stat-warn .stat-icon { background: var(--orange-bg); color: var(--orange); }
.stat-danger .stat-icon { background: var(--red-bg); color: var(--red); }
.stat-ok .stat-icon { background: var(--green-bg); color: var(--green); }
a.stat { text-decoration: none !important; color: inherit; transition: transform .12s, box-shadow .12s; }
/* แถวสถิติแบบกะทัดรัด (ใช้บนหน้ารายการ เพื่อให้ตารางข้อมูลขึ้นมาเหนือขอบจอ) */
.stats-compact { gap: 12px; margin-bottom: 14px; }
.stats-compact .stat { padding: 10px 14px; gap: 2px; }
.stats-compact .stat-label { font-size: .84rem; }
.stats-compact .stat-value { font-size: 1.28rem; }
.stats-compact .stat-sub { font-size: .8rem; }
.stats-compact .stat-icon { width: 30px; height: 30px; top: 10px; right: 10px; border-radius: 9px; }
.stats-compact .stat-icon .ic { width: 16px; height: 16px; }
/* คำใบ้วันที่ พ.ศ. ใต้ช่องวันที่ (สร้างโดย app.js) */
.date-be { font-size: .8rem; color: var(--muted); }
/* คำใบ้ที่มีสีสถานะ (ชนะกฎ .field .hint) */
.field .hint.text-red, .field .hint.text-danger, .hint.text-red, .hint.text-danger { color: var(--red); }
.field .hint.text-orange, .hint.text-orange { color: var(--orange); }
.field .hint.text-green, .field .hint.text-success, .hint.text-green, .hint.text-success { color: var(--green); }
.field .hint.text-sky, .hint.text-sky { color: var(--sky-700); }
a.stat:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(16, 24, 40, .08); }
.up { color: var(--green); }
.down { color: var(--red); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 10px;
    font: inherit; font-weight: 600; font-size: .95rem;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none !important;
    white-space: nowrap;
    user-select: none;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--sky-200); outline-offset: 1px; }
.btn[disabled], .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--sky-600); color: #fff; }
.btn-primary:hover { background: var(--sky-700); color: #fff; }
.btn-accent { background: var(--sun-400); color: var(--ink); }
.btn-accent:hover { background: var(--sun-500); color: var(--ink); }
.btn-outline { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-outline:hover { border-color: var(--sky-300); color: var(--sky-700); background: var(--sky-50); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--gray-bg); color: var(--ink); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #A61E1E; color: #fff; }
.btn-danger-outline { background: #fff; color: var(--red); border-color: #F3C5C5; }
.btn-danger-outline:hover { background: var(--red-bg); color: var(--red); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #126B33; color: #fff; }
.btn-sm { min-height: 32px; padding: 5px 11px; font-size: .86rem; border-radius: 8px; }
.btn-lg { min-height: 50px; padding: 12px 22px; font-size: 1.08rem; border-radius: 12px; }
.btn-xl { min-height: 64px; padding: 14px 26px; font-size: 1.3rem; border-radius: 14px; }
.btn-block { display: flex; width: 100%; }
.btn-icon {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px; padding: 0;
    border: 1px solid transparent; border-radius: 9px;
    background: transparent; color: var(--ink-2); cursor: pointer;
}
.btn-icon:hover { background: var(--gray-bg); color: var(--ink); }
.btn-icon.danger:hover { background: var(--red-bg); color: var(--red); }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 600; font-size: .92rem; color: var(--ink-2); }
.field .hint, .hint { font-size: .82rem; color: var(--muted); }
.req::after { content: ' *'; color: var(--red); }

.input, .select, .textarea,
.field input[type=text], .field input[type=number], .field input[type=date], .field input[type=datetime-local],
.field input[type=email], .field input[type=tel], .field input[type=password], .field input[type=search],
.field input[type=file], .field select, .field textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid #D5DDE7;
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: .98rem;
    transition: border-color .15s, box-shadow .15s;
}
.field textarea, .textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus,
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--sky-500);
    box-shadow: 0 0 0 3px var(--sky-100);
}
.input-lg { min-height: 52px !important; font-size: 1.12rem !important; }
.input[readonly], .field input[readonly] { background: var(--line-2); }
.input-group { display: flex; align-items: stretch; }
.input-group > .input, .input-group > input { border-radius: 10px 0 0 10px; flex: 1; min-width: 0; }
.input-group > .btn { border-radius: 0 10px 10px 0; }
.input-icon { position: relative; }
.input-icon > .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > input, .input-icon > .input,
.field .input-icon > input, .field .input-icon > .input { padding-left: 38px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--sky-600); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.is-invalid { border-color: var(--red) !important; }
.field-error { color: var(--red); font-size: .84rem; }

/* แถบตัวกรอง */
.filters {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
    margin-bottom: 14px;
}
.filters .field { min-width: 130px; }
.filters .field.grow { flex: 1; min-width: 190px; }
.filters .input, .filters select, .filters input { min-height: 40px; }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: 11px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line-2); }
.table thead th {
    background: #F7FAFD;
    color: var(--muted);
    font-weight: 700; font-size: .84rem;
    white-space: nowrap;
    position: sticky; top: 0;
}
.table tbody tr:hover { background: #FAFCFF; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table .actions { text-align: right; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }
.table tfoot td { font-weight: 700; background: #F7FAFD; border-top: 2px solid var(--line); }
.table .text-right { text-align: right; }
.table .text-center { text-align: center; }
.table .text-left { text-align: left; }
.table-sm th, .table-sm td { padding: 7px 10px; font-size: .9rem; }
.row-muted td { color: var(--muted); }
.row-void td { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(198, 40, 40, .5); }
.row-warn { background: #FFFBF2; }
.row-danger { background: #FFF6F6; }
.cell-title { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: .83rem; color: var(--muted); }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .8rem; font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
    background: var(--gray-bg); color: var(--gray);
}
.badge-blue { background: var(--sky-100); color: var(--sky-800); }
.badge-yellow { background: var(--sun-100); color: var(--sun-800); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-teal { background: var(--teal-bg); color: var(--teal); }
.badge-gray { background: var(--gray-bg); color: var(--gray); }
.badge-solid-red { background: var(--red); color: #fff; }
.expiry-ok { color: var(--ink-2); }

/* ---------- Alerts ---------- */
.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px;
    border-radius: 11px;
    border: 1px solid transparent;
    margin-bottom: 14px;
    font-size: .95rem;
}
.alert > div { flex: 1; }
.alert .ic { margin-top: 2px; }
.alert-info { background: var(--sky-50); border-color: var(--sky-100); color: var(--sky-800); }
.alert-success { background: var(--green-bg); border-color: #C7EBD3; color: #14532D; }
.alert-warning { background: var(--sun-50); border-color: var(--sun-200); color: var(--sun-800); }
.alert-danger { background: var(--red-bg); border-color: #F6CACA; color: #8B1A1A; }
.alert-close { border: 0; background: transparent; font-size: 1.3rem; line-height: 1; cursor: pointer; color: inherit; opacity: .6; padding: 0 4px; }
.alert-close:hover { opacity: 1; }

/* ---------- Tabs ---------- */
.tabs {
    display: flex; gap: 4px; flex-wrap: wrap;
    border-bottom: 1px solid var(--line);
    margin-bottom: 18px;
}
.tab {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 10px 12px;
    white-space: nowrap;
    color: var(--muted);
    font-weight: 600;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    text-decoration: none !important;
    border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--sky-700); background: var(--sky-50); }
.tab.active { color: var(--sky-800); border-bottom-color: var(--sun-400); }

/* segmented control */
.segmented { display: inline-flex; background: var(--gray-bg); border-radius: 11px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.segmented button, .segmented a, .segmented label {
    border: 0; background: transparent; padding: 7px 14px; border-radius: 8px;
    font: inherit; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer;
    text-decoration: none !important;
}
.segmented .active, .segmented input:checked + span { background: #fff; color: var(--sky-700); box-shadow: var(--shadow); }
.segmented label { padding: 0; }
.segmented label span { display: block; padding: 7px 14px; border-radius: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }

/* ---------- Modal (<dialog class="modal">) ---------- */
dialog.modal {
    border: 0; padding: 0;
    border-radius: 16px;
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100vh - 40px);
    box-shadow: var(--shadow-lg);
    color: var(--ink);
}
dialog.modal::backdrop { background: rgba(15, 30, 55, .45); backdrop-filter: blur(2px); }
dialog.modal.modal-sm { width: min(420px, calc(100vw - 32px)); }
dialog.modal.modal-lg { width: min(820px, calc(100vw - 32px)); }
dialog.modal.modal-xl { width: min(1100px, calc(100vw - 32px)); }
.modal-box { display: flex; flex-direction: column; max-height: calc(100vh - 40px); margin: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-head h3 { margin: 0; font-size: 1.12rem; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line-2); background: #FBFCFE; }
.confirm-icon { width: 54px; height: 54px; border-radius: 50%; background: var(--sun-100); color: var(--sun-800); display: grid; place-items: center; margin: 0 auto 12px; }
#app-confirm .modal-body { text-align: center; font-size: 1.02rem; }

/* ---------- Toast ---------- */
.toast-container { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 1000; pointer-events: none; }
.toast {
    pointer-events: none; /* ข้อความแจ้งเตือนไม่บังการคลิกปุ่มที่อยู่ด้านหลัง */
    display: flex; align-items: center; gap: 10px;
    min-width: 260px; max-width: 420px;
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--ink); color: #fff;
    box-shadow: var(--shadow-lg);
    font-weight: 500;
    animation: toast-in .2s ease;
}
.toast.success { background: #166534; }
.toast.error { background: #B91C1C; }
.toast.warning { background: var(--sun-400); color: var(--ink); }
.toast.hide { opacity: 0; transform: translateY(8px); transition: all .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 14px 0 0; }
.pagination .page {
    min-width: 36px; height: 36px; padding: 0 10px;
    display: inline-grid; place-items: center;
    border-radius: 9px; border: 1px solid var(--line);
    background: #fff; color: var(--ink-2); font-weight: 600;
    text-decoration: none !important;
}
.pagination .page:hover { border-color: var(--sky-300); color: var(--sky-700); }
.pagination .page.active { background: var(--sky-600); border-color: var(--sky-600); color: #fff; }
.pagination .page.disabled { opacity: .4; }
.pagination .page.gap { border: 0; background: transparent; }
.pagination .page-info { margin-left: auto; color: var(--muted); font-size: .88rem; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty > .ic { color: var(--sky-300); margin-bottom: 8px; }
.empty p { margin-bottom: 12px; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line-2); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: .9rem; }
.dl dd { margin: 0; font-weight: 500; word-break: break-word; }

/* ---------- Simple charts ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 200px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; min-width: 0; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar { width: 70%; max-width: 44px; border-radius: 8px 8px 3px 3px; background: var(--sky-300); min-height: 3px; transition: height .3s; position: relative; }
.bar.today { background: var(--sun-400); }
.bar:hover { background: var(--sky-500); }
.bar.today:hover { background: var(--sun-500); }
.bar-label { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.bar-value { font-size: .72rem; color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.progress { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--sky-500); border-radius: 99px; }
.progress.sun > span { background: var(--sun-400); }

/* ---------- Utilities ---------- */
.muted { color: var(--muted); }
.text-sky { color: var(--sky-700); }
.text-red, .text-danger { color: var(--red); }
.text-green, .text-success { color: var(--green); }
.text-orange { color: var(--orange); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-bold, .bold { font-weight: 700; }
.big { font-size: 1.25rem; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.items-center { align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-0 { margin-top: 0 !important; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0 !important; } .mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.w-full { width: 100%; }
.hidden, [hidden] { display: none !important; }
.nowrap { white-space: nowrap; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill-note { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--sun-100); color: var(--sun-800); font-size: .82rem; }
.divider { height: 1px; background: var(--line-2); margin: 14px 0; }
.kbd-hint { font-size: .8rem; color: var(--muted); }

/* dropdown (autocomplete) */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px);
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-height: 360px; overflow-y: auto; z-index: 50;
    padding: 4px;
}
.dropdown-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; cursor: pointer; }
.dropdown-item:hover, .dropdown-item.active { background: var(--sky-50); }
.dropdown-empty { padding: 12px; color: var(--muted); text-align: center; }

/* ---------- Login / setup ---------- */
body.auth-page {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 12% 18%, var(--sun-200) 0, transparent 38%),
        radial-gradient(circle at 88% 82%, var(--sky-200) 0, transparent 42%),
        var(--sky-50);
}
.auth-card { width: min(440px, 100%); background: #fff; border-radius: 20px; box-shadow: var(--shadow-lg); padding: 32px; }
.auth-card.wide { width: min(620px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.auth-brand .brand-logo { width: 52px; height: 52px; border-radius: 15px; }
.auth-brand h1 { font-size: 1.35rem; margin: 0; }
.auth-brand p { margin: 0; color: var(--muted); font-size: .92rem; }
.auth-card > .field + .field { margin-top: 14px; }
.auth-foot { text-align: center; margin-top: 16px; color: var(--muted); font-size: .85rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
    .grid-main-side, .grid-3 { grid-template-columns: minmax(0, 1fr); }
    .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 30, 55, .35); z-index: 35; }
    .main, body.pos-mode .main { margin-left: 0; }
    body.pos-mode .brand-text, body.pos-mode .nav-label, body.pos-mode .user-meta { display: flex; }
    body.pos-mode .nav-item { justify-content: flex-start; padding: 10px 12px; }
    body.pos-mode .nav-badge { position: static; min-width: 22px; height: 22px; font-size: .75rem; padding: 0 7px; }
    body.pos-mode .user-chip { justify-content: flex-start; padding: 6px 8px 10px; }
    .topbar .topbar-menu { display: inline-grid; }
    .topbar { padding: 0 14px; }
    .topbar-date { display: none; }
    .content { padding: 16px 14px 32px; }
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
    .grid-4 { grid-template-columns: minmax(0, 1fr); }
    .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
    .dl { grid-template-columns: 1fr; gap: 2px; }
    .dl dd { margin-bottom: 8px; }
    .stat-value { font-size: 1.45rem; }
}

/* ---------- Print ---------- */
@media print {
    body { background: #fff; font-size: 12pt; }
    .sidebar, .topbar, .no-print, .page-actions, .filters, .pagination, .tabs, .toast-container, .flash { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    .card { box-shadow: none; border: 0; }
    .table th, .table td { padding: 5px 6px; }
    .table-wrap { overflow: visible !important; }
    .table thead th { position: static; }
    .table { font-size: 9pt; }
    a { color: inherit; text-decoration: none; }
}
