:root {
  --bg: oklch(1 0 0);
  --surface: oklch(0.97 0 0);
  --surface-strong: oklch(0.93 0 0);
  --ink: oklch(0.18 0.01 38.6);
  --muted: oklch(0.50 0.01 38.6);
  --line: oklch(0.88 0 0);
  --primary: oklch(0.67 0.217 38.6);
  --primary-hover: oklch(0.61 0.205 38.6);
  --success: oklch(0.53 0.15 153);
  --success-soft: oklch(0.96 0.04 153);
  --warning: oklch(0.67 0.16 75);
  --warning-soft: oklch(0.96 0.05 75);
  --danger: oklch(0.56 0.20 25);
  --danger-soft: oklch(0.96 0.04 25);
  --radius-sm: 8px;
  --radius: 12px;
  --font: "Noto Sans Thai", "Segoe UI", sans-serif;
  --ease: cubic-bezier(.25, 1, .5, 1);
  --duration: 180ms;
  --z-sticky: 20;
  --z-dialog: 50;
  --z-toast: 60;
}

* { box-sizing: border-box; }
html { color-scheme: light; background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink); background: var(--bg); font-family: var(--font); font-size: 1rem; line-height: 1.5; font-kerning: normal; font-optical-sizing: auto; }
button, input, select { font: inherit; }
button { color: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
input, select { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); padding: 0 12px; color: var(--ink); }
input::placeholder { color: oklch(0.46 0 0); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid oklch(0.78 0.14 38.6); outline-offset: 2px; }
label { display: block; margin-bottom: 6px; font-size: .875rem; font-weight: 600; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 1.75rem; line-height: 1.2; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; line-height: 1.3; }
p { color: var(--muted); }
[hidden] { display: none !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; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; transform: translateY(-160%); background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 6px; }
.skip-link:focus { transform: translateY(0); }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon, .nav-icon, .scan-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; background: var(--primary); color: white; font-weight: 800; font-size: 1.25rem; }
.brand-mark.small { width: 36px; height: 36px; font-size: 1rem; }
.brand-mark .icon { width: 24px; height: 24px; stroke-width: 2; }
.button { min-height: 44px; border: 0; border-radius: var(--radius-sm); padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; cursor: pointer; transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease), transform var(--duration) var(--ease); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { background: var(--primary); color: white; }
.button-primary:hover:not(:disabled) { background: var(--primary-hover); }
.button-danger { background: var(--danger); color: white; }
.button-danger:hover:not(:disabled) { background: oklch(0.49 0.18 25); }
a.button { text-decoration: none; }
.button-secondary { background: var(--bg); border: 1px solid var(--line); }
.button-secondary:hover:not(:disabled) { border-color: oklch(0.68 0 0); background: var(--surface); }
.button-wide { width: 100%; }
.icon-button { width: 44px; height: 44px; border: 0; border-radius: var(--radius-sm); background: transparent; display: grid; place-items: center; font-size: 1.35rem; cursor: pointer; }
.icon-button:hover { background: var(--surface-strong); }
.text-button { min-height: 44px; padding: 0; border: 0; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.text-button:hover:not(:disabled) { color: var(--danger); }
.status-dot { width: 9px; height: 9px; display: inline-block; border-radius: 50%; background: var(--muted); }
.status-dot.success { background: var(--success); }
.form-error { min-height: 22px; margin: 4px 0; color: var(--danger); font-size: .875rem; }

.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr); background: var(--surface); }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 14px; border-right: 1px solid var(--line); background: var(--bg); }
.login-brand strong, .login-brand > div > span { display: block; }
.login-brand strong { font-size: 1.45rem; }
.login-brand > div > span { color: var(--muted); }
.login-panel { width: min(420px, calc(100% - 48px)); margin: auto; background: var(--bg); padding: 36px; border-radius: var(--radius); box-shadow: 0 4px 8px oklch(0.2 0 0 / .07); }
.login-panel h1 { font-size: 2rem; }
.login-panel > p:first-of-type { margin-bottom: 28px; }
.login-panel input { margin-bottom: 16px; }
.connection-state { margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: .875rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 226px minmax(0, 1fr); background: var(--surface); }
.sidebar { position: sticky; top: 0; height: 100vh; z-index: var(--z-sticky); display: flex; flex-direction: column; background: oklch(0.15 0.01 38.6); color: white; padding: 18px 12px; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; }
.sidebar-brand strong, .sidebar-brand > div > span { display: block; }
.sidebar-brand > div > span { color: oklch(0.72 0 0); font-size: .75rem; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item { min-height: 46px; width: 100%; display: flex; align-items: center; gap: 12px; border: 0; border-radius: var(--radius-sm); padding: 0 12px; background: transparent; color: oklch(0.78 0 0); text-align: left; cursor: pointer; }
.nav-item:hover { color: white; background: oklch(0.23 0.01 38.6); }
.nav-item.active { color: white; background: var(--primary); }
.nav-icon { width: 21px; height: 21px; flex: 0 0 21px; }
.sidebar-user { margin-top: auto; padding: 14px 6px 0; border-top: 1px solid oklch(1 0 0 / .13); display: grid; grid-template-columns: 38px minmax(0, 1fr) 44px; gap: 10px; align-items: center; }
.sidebar-user .avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: oklch(1 0 0 / .12); font-weight: 700; }
.sidebar-user strong, .sidebar-user span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sidebar-user span { color: oklch(0.68 0 0); font-size: .75rem; }
.sidebar-user .icon-button { color: white; }
.mobile-header, .bottom-nav { display: none; }

.main-content { min-width: 0; height: 100vh; overflow: auto; padding: 30px; }
.page { display: none; width: min(1480px, 100%); margin: 0 auto; }
.page.active { display: block; }
.page-header, .pos-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-header p { margin-bottom: 0; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.loading-region:empty::before { content: ""; display: block; height: 160px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-strong) 37%, var(--surface) 63%); background-size: 400% 100%; animation: skeleton 1.4s ease infinite; }
@keyframes skeleton { to { background-position: -100% 0; } }

.metric-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.metric { min-width: 0; padding: 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span, .summary-label { display: block; color: var(--muted); font-size: .875rem; }
.metric strong { display: block; margin-top: 6px; font-size: 1.55rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.metric strong.positive { color: var(--success); }
.dashboard-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .6fr); gap: 18px; }
.panel, .table-panel { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel { padding: 20px; }
.panel h2 { margin-bottom: 16px; }
.attention-list, .seller-list { display: grid; gap: 12px; }
.attention-row, .seller-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; gap: 12px; border-bottom: 1px solid var(--line); }
.attention-row:last-child, .seller-row:last-child { border-bottom: 0; }
.status-count { min-width: 36px; height: 28px; display: grid; place-items: center; border-radius: 999px; font-weight: 700; }
.status-count.warning { background: var(--warning-soft); color: oklch(0.45 0.13 75); }
.status-count.danger { background: var(--danger-soft); color: var(--danger); }
.dashboard-table { grid-column: 1 / -1; }
.best-seller-panel { min-width: 0; }
.best-seller-heading { min-height: 44px; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.best-seller-heading h2 { margin-bottom: 2px; }
.best-seller-heading p { margin-bottom: 0; font-size: .8rem; }
.best-seller-actions { display: flex; align-items: center; gap: 8px; }
.seller-periods { display: flex; padding: 3px; border-radius: 9px; background: var(--surface); }
.seller-period { min-height: 34px; border: 0; border-radius: 7px; padding: 0 10px; background: transparent; color: var(--muted); font-size: .78rem; font-weight: 600; cursor: pointer; }
.seller-period:hover { color: var(--ink); }
.seller-period.active { background: var(--bg); color: var(--ink); box-shadow: 0 1px 4px oklch(0.2 0 0 / .1); }
.seller-arrows { display: flex; gap: 4px; }
.seller-arrows .icon-button { width: 36px; height: 36px; border: 1px solid var(--line); }
.seller-arrows .icon-button:disabled { opacity: .35; cursor: not-allowed; }
.best-seller-viewport { --seller-visible: 4; width: 100%; max-width: 100%; overflow-x: auto; overflow-y: hidden; overscroll-behavior-inline: contain; scrollbar-width: none; scroll-snap-type: x mandatory; touch-action: pan-x pan-y; }
.best-seller-viewport::-webkit-scrollbar { display: none; }
.best-seller-track { display: flex; gap: 12px; width: 100%; }
.best-seller-card { position: relative; flex: 0 0 calc((100% - 36px) / 4); min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 8px; scroll-snap-align: start; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg); color: var(--ink); text-align: left; cursor: pointer; transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease), transform var(--duration) var(--ease); }
.best-seller-card:hover { border-color: oklch(0.72 0.07 38.6); background: oklch(0.992 0.006 38.6); }
.best-seller-card:active { transform: translateY(1px); }
.best-seller-card.top-ranked { border-color: oklch(0.82 0.08 38.6); }
.seller-rank { position: absolute; top: 16px; left: 16px; z-index: 1; min-width: 28px; height: 28px; display: grid; place-items: center; border-radius: 999px; background: var(--ink); color: white; font-size: .75rem; font-weight: 800; }
.top-ranked .seller-rank { background: var(--primary); }
.best-seller-image { grid-column: 1 / -1; height: 86px; display: grid; place-items: center; overflow: hidden; border-radius: 8px; background: var(--surface); color: var(--muted); }
.best-seller-image img { width: 100%; height: 100%; object-fit: cover; }
.best-seller-image-fallback { display: grid; place-items: center; }
.best-seller-image-fallback .icon { width: 28px; height: 28px; }
.best-seller-name { grid-column: 1 / -1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .88rem; font-weight: 700; }
.best-seller-sold { color: var(--muted); font-size: .75rem; }
.best-seller-sold strong { color: var(--ink); font-size: 1rem; font-variant-numeric: tabular-nums; }
.best-seller-detail { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .72rem; }
.best-seller-detail strong { color: var(--ink); font-size: .78rem; font-variant-numeric: tabular-nums; }
.best-seller-stock { justify-self: end; align-self: center; color: var(--success); font-size: .7rem; font-weight: 700; }
.best-seller-stock.low { color: var(--danger); }
.best-seller-empty { min-height: 208px; display: grid; place-content: center; gap: 4px; text-align: center; color: var(--muted); }
.best-seller-empty strong { color: var(--ink); }
.best-seller-empty span { font-size: .85rem; }
.seller-carousel-skeleton { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.seller-carousel-skeleton span { height: 202px; border-radius: 10px; background: linear-gradient(90deg, var(--surface) 25%, var(--surface-strong) 37%, var(--surface) 63%); background-size: 400% 100%; animation: skeleton 1.4s ease infinite; }
.dashboard-metric-skeleton span { width: 55%; height: 12px; border-radius: 5px; background: var(--surface-strong); }
.dashboard-metric-skeleton strong { width: 42%; height: 24px; border-radius: 6px; background: var(--surface-strong); }
.dashboard-side-skeleton h2, .dashboard-side-skeleton span { display: block; height: 18px; margin-bottom: 18px; border-radius: 5px; background: var(--surface-strong); }
.dashboard-side-skeleton h2 { width: 60%; }
.dashboard-load-error { min-height: 260px; display: grid; place-content: center; justify-items: center; gap: 8px; text-align: center; }
.dashboard-load-error span { color: var(--muted); }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th { color: var(--muted); background: var(--surface); font-size: .75rem; font-weight: 600; text-align: left; }
.data-table th, .data-table td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: oklch(0.985 0 0); }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.muted { color: var(--muted); }
.status-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; border-radius: 999px; padding: 2px 9px; font-size: .75rem; font-weight: 700; }
.status-chip.success { background: var(--success-soft); color: oklch(0.42 0.13 153); }
.status-chip.warning { background: var(--warning-soft); color: oklch(0.45 0.13 75); }
.status-chip.danger { background: var(--danger-soft); color: var(--danger); }
.status-chip.muted { background: var(--surface-strong); color: var(--muted); }

.pos-page { width: 100%; height: calc(100vh - 60px); }
.pos-page.active { display: flex; flex-direction: column; }
.pos-header { flex: 0 0 auto; margin-bottom: 14px; align-items: center; }
.pos-header > div { display: flex; align-items: center; gap: 14px; }
.pos-header h1 { margin: 0; }
.online-label { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .875rem; }
.cashier-label { color: var(--muted); }
.pos-layout { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 350px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.pos-workspace { min-width: 0; display: flex; flex-direction: column; padding: 18px; }
.search-box { display: flex; align-items: center; gap: 10px; min-height: 48px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); padding: 0 12px; }
.search-box:focus-within { border-color: var(--primary); outline: 3px solid oklch(0.92 0.06 38.6); }
.search-box input { min-width: 0; border: 0; padding: 0; outline: 0; background: transparent; }
.search-box input:focus-visible { outline: 0; }
.scan-box { min-height: 64px; font-size: 1.15rem; }
.scan-icon { width: 25px; height: 25px; flex: 0 0 25px; }
kbd { border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px; color: var(--muted); background: var(--surface); font: 600 .75rem var(--font); }
.search-results { position: fixed; z-index: 30; width: min(620px, calc(100vw - 48px)); max-height: 300px; overflow: auto; margin-top: 70px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 4px 8px oklch(0.2 0 0 / .12); }
.search-result { width: 100%; min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; background: var(--bg); text-align: left; cursor: pointer; }
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: var(--surface); }
.search-result span { display: block; color: var(--muted); font-size: .75rem; }
.cart-table-wrap { min-height: 0; flex: 1; overflow: auto; margin-top: 16px; }
.cart-table th { position: sticky; top: 0; z-index: 1; }
.cart-product strong, .cart-product span { display: block; }
.cart-product span { color: var(--muted); font-size: .75rem; }
.product-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.product-cell > div { min-width: 0; }
.product-thumb { width: 48px; height: 48px; flex: 0 0 48px; display: grid; place-items: center; overflow: hidden; border-radius: 9px; background: var(--surface); color: var(--muted); }
.product-thumb.compact { width: 40px; height: 40px; flex-basis: 40px; }
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-thumb .icon { width: 22px; height: 22px; }
.quantity-control { display: inline-grid; grid-template-columns: 38px 42px 38px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.quantity-control button { min-height: 38px; border: 0; background: var(--bg); cursor: pointer; font-size: 1.1rem; }
.quantity-control button:hover { background: var(--surface); }
.quantity-control span { display: grid; place-items: center; border-inline: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.remove-item { width: 38px; height: 38px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.remove-item:hover { color: var(--danger); background: var(--danger-soft); }
.empty-state { min-height: 240px; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { color: var(--ink); margin-bottom: 5px; }
.cart-footer { min-height: 52px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); }
.checkout-rail { display: flex; flex-direction: column; justify-content: space-between; gap: 22px; border-left: 1px solid var(--line); padding: 24px; background: oklch(0.992 0 0); }
.checkout-total { display: block; margin-top: 7px; font-size: 3rem; line-height: 1.1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.payment-options { display: grid; gap: 10px; }
.payment-option { min-height: 58px; display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 14px; background: var(--bg); font-weight: 600; cursor: pointer; }
.payment-option:hover { border-color: oklch(0.68 0 0); }
.payment-option.selected { border-color: var(--primary); outline: 2px solid oklch(0.92 0.06 38.6); }
.payment-option .icon { width: 24px; height: 24px; }
.checkout-button { width: 100%; min-height: 64px; font-size: 1.1rem; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar .search-box { flex: 1; }
.toolbar select { width: 170px; }
.filter-toolbar input[type="date"] { width: 160px; }
.filter-toolbar .button { flex: 0 0 auto; }
.compact { min-height: 44px; }
.row-action { min-height: 36px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); padding: 0 10px; cursor: pointer; }
.row-action:hover { background: var(--surface); }
.tab-row { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { min-height: 44px; border: 0; border-bottom: 3px solid transparent; padding: 0 16px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.tab.active { border-color: var(--primary); color: var(--ink); }
.settings-form { width: min(660px, 100%); display: grid; gap: 18px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.settings-form .button { justify-self: start; }
.field-help { display: block; margin-top: 6px; color: var(--muted); line-height: 1.5; }
.settings-tools { margin-top: 18px; }
.settings-tools h2, .settings-tools p { margin-bottom: 4px; }
.settings-tools .header-actions { margin-top: 8px; }
.bar-chart { min-height: 220px; display: flex; align-items: end; gap: 12px; padding: 24px 8px 0; border-bottom: 1px solid var(--line); }
.bar-column { min-width: 34px; flex: 1; display: grid; grid-template-rows: 1fr auto; align-items: end; gap: 8px; height: 190px; }
.bar-fill { width: 100%; min-height: 2px; border-radius: 6px 6px 0 0; background: var(--primary); }
.bar-column span { color: var(--muted); font-size: .7rem; text-align: center; }

.dialog { width: min(720px, calc(100% - 32px)); max-height: calc(100vh - 32px); border: 0; border-radius: var(--radius); padding: 0; box-shadow: 0 8px 24px oklch(0.12 0 0 / .18); }
.dialog::backdrop { background: oklch(0.12 0 0 / .54); }
.dialog form { display: grid; gap: 16px; padding: 22px; }
.dialog header { display: flex; justify-content: space-between; gap: 16px; }
.dialog header h2 { margin-bottom: 2px; }
.dialog header p { margin-bottom: 0; font-size: .875rem; }
.dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.small-dialog { width: min(520px, calc(100% - 32px)); }
.wide-dialog { width: min(880px, calc(100% - 32px)); }
.dialog-article { padding: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 22px; }
.sale-detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.sale-detail-header h2 { margin: 2px 0; overflow-wrap: anywhere; }
.sale-detail-header p { margin: 0; }
.eyebrow { color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .04em; }
.sale-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.sale-summary div { padding: 12px; border-radius: var(--radius-sm); background: var(--surface); }
.sale-summary span, .sale-summary strong { display: block; }
.sale-summary span { margin-bottom: 3px; color: var(--muted); font-size: .75rem; }
.sale-detail-section { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.sale-detail-section h3 { margin-bottom: 10px; }
.sale-detail-list { display: grid; gap: 4px; }
.sale-detail-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sale-detail-row:last-child { border-bottom: 0; }
.sale-detail-row > div { min-width: 0; }
.sale-detail-row span { display: block; margin-top: 2px; color: var(--muted); font-size: .8rem; }
.return-items { display: grid; gap: 8px; }
.return-item { display: grid; grid-template-columns: minmax(0, 1fr) 110px; align-items: center; gap: 14px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface); }
.return-item strong, .return-item span { display: block; }
.return-item span { color: var(--muted); font-size: .8rem; }
.sale-status { white-space: nowrap; }
.sale-status.completed { background: var(--success-soft); color: oklch(0.42 0.13 153); }
.sale-status.partially_refunded { background: var(--warning-soft); color: oklch(0.45 0.13 75); }
.sale-status.refunded, .sale-status.cancelled { background: var(--danger-soft); color: var(--danger); }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.check-row { min-height: 44px; display: flex; align-items: center; gap: 10px; }
.check-row input { width: 18px; min-height: 18px; accent-color: var(--primary); }
.product-image-editor { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 16px; align-items: center; padding: 14px; border-radius: var(--radius-sm); background: var(--surface); }
.product-image-preview { width: 104px; aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg); color: var(--muted); }
.product-image-preview .icon { width: 30px; height: 30px; }
.product-image-preview img { width: 100%; height: 100%; object-fit: cover; }
.product-image-copy label span { color: var(--muted); font-weight: 400; }
.product-image-copy small { display: block; margin-top: 6px; color: var(--muted); }
.product-image-copy input[type="file"] { padding: 7px; }
.edit-stock-field { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px; border-radius: var(--radius-sm); background: var(--surface); }
.edit-stock-field > div { min-width: 0; }
.edit-stock-field span, .edit-stock-field small { display: block; color: var(--muted); }
.edit-stock-field strong { display: block; margin: 2px 0; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.edit-stock-field small { line-height: 1.45; }
.edit-stock-field .button { flex: 0 0 auto; }
.payment-dialog { width: min(500px, calc(100% - 32px)); }
.payment-total { display: flex; align-items: end; justify-content: space-between; padding: 16px 0; border-block: 1px solid var(--line); }
.payment-total strong { font-size: 2rem; font-variant-numeric: tabular-nums; }
.change-preview { display: flex; justify-content: space-between; margin-top: 10px; color: var(--muted); }
.change-preview strong { color: var(--success); font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.promptpay-panel { min-height: 320px; display: grid; place-content: center; justify-items: center; gap: 6px; padding: 14px; background: var(--surface); border-radius: var(--radius-sm); text-align: center; }
.promptpay-loading { display: grid; justify-items: center; gap: 12px; color: var(--muted); }
.qr-loading-box { width: 220px; aspect-ratio: 1; border-radius: 8px; background: var(--surface-strong); animation: qr-loading 1.2s ease-in-out infinite alternate; }
.promptpay-qr { display: block; width: min(220px, 68vw); height: auto; padding: 8px; border-radius: 8px; background: white; }
.promptpay-panel > span { color: var(--muted); }
.promptpay-download { min-height: 38px; margin-top: 4px; color: var(--ink); }
.promptpay-error { max-width: 34ch; margin: 0; color: var(--danger); font-weight: 600; text-wrap: pretty; }
@keyframes qr-loading { to { background: oklch(0.88 0 0); } }
.receipt-dialog { width: min(420px, calc(100% - 32px)); padding: 22px; }
.receipt-dialog article { font-size: .875rem; }
.receipt-head { text-align: center; border-bottom: 1px dashed var(--line); padding-bottom: 14px; }
.receipt-head h2 { margin-bottom: 2px; }
.receipt-lines { margin: 14px 0; }
.receipt-line, .receipt-summary { display: flex; justify-content: space-between; gap: 12px; margin: 7px 0; }
.receipt-summary { border-top: 1px dashed var(--line); padding-top: 12px; font-size: 1rem; }
.receipt-dialog footer { display: flex; gap: 8px; margin-top: 18px; }
.receipt-dialog footer .button { flex: 1; }

.toast-region { position: fixed; top: 18px; right: 18px; z-index: var(--z-toast); display: grid; gap: 8px; width: min(360px, calc(100% - 36px)); }
.toast { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--ink); color: white; box-shadow: 0 4px 8px oklch(0.2 0 0 / .18); animation: toast-in var(--duration) var(--ease); }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 196px minmax(0, 1fr); }
  .sidebar { padding-inline: 10px; }
  .nav-item { gap: 9px; padding-inline: 10px; }
  .sidebar-user { grid-template-columns: 34px minmax(0, 1fr) 38px; gap: 7px; padding-inline: 2px; }
  .sidebar-user .avatar { width: 34px; height: 34px; }
  .checkout-rail { padding: 18px; }
  .pos-layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 1120px) and (min-width: 761px) {
  .dashboard-layout { grid-template-columns: 1fr; }
  .dashboard-table { grid-column: auto; }
  .best-seller-viewport { --seller-visible: 2; }
  .best-seller-card { flex-basis: calc((100% - 12px) / 2); }
  .seller-carousel-skeleton { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seller-carousel-skeleton span:nth-child(n+3) { display: none; }
  .best-seller-heading { align-items: stretch; flex-direction: column; }
  .best-seller-actions { justify-content: space-between; }
}

@media (max-width: 760px) {
  body { font-size: 1rem; padding-bottom: max(64px, env(safe-area-inset-bottom)); }
  .login-screen { display: block; padding: 24px 0; background: var(--bg); }
  .login-brand { min-height: 150px; border: 0; }
  .login-panel { box-shadow: none; padding: 20px 24px; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .mobile-header { position: sticky; top: 0; z-index: var(--z-sticky); min-height: 60px; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 14px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
  .main-content { height: auto; min-height: calc(100vh - 124px); overflow: visible; padding: 18px 14px; }
  .bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: var(--z-sticky); min-height: 62px; display: flex; align-items: stretch; padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--line); }
  .bottom-nav button { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--muted); font-size: .75rem; font-weight: 600; }
  .bottom-nav button.active { color: var(--primary); }
  .page-header { align-items: stretch; flex-direction: column; }
  .page-header .button, .header-actions .button { flex: 1; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .metric { padding: 15px; }
  .metric strong { font-size: 1.25rem; }
  .dashboard-layout { grid-template-columns: 1fr; }
  .best-seller-viewport { --seller-visible: 1; }
  .best-seller-card { flex-basis: 100%; }
  .seller-carousel-skeleton { grid-template-columns: 1fr; }
  .seller-carousel-skeleton span:not(:first-child) { display: none; }
  .best-seller-heading { align-items: stretch; flex-direction: column; }
  .best-seller-actions { justify-content: space-between; }
  .seller-period { padding-inline: 8px; }
  .dashboard-table { grid-column: auto; overflow-x: auto; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar select { width: 100%; }
  .filter-toolbar input[type="date"] { width: 100%; }
  .table-panel { overflow-x: auto; }
  .data-table:not(.cart-table) { min-width: 720px; }
  .pos-page { height: auto; }
  .pos-header { display: none; }
  .pos-layout { display: block; border: 0; background: transparent; overflow: visible; }
  .pos-workspace { padding: 0; }
  .scan-box { min-height: 56px; }
  .cart-table-wrap { margin-bottom: 160px; overflow-x: auto; }
  .cart-table { min-width: 620px; }
  .cart-footer { display: none; }
  .checkout-rail { position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 15; display: grid; grid-template-columns: 1fr 150px; align-items: center; gap: 10px; border: 0; border-top: 1px solid var(--line); padding: 10px 14px; background: var(--bg); box-shadow: 0 -2px 6px oklch(0.2 0 0 / .08); }
  .checkout-total { font-size: 1.8rem; }
  .payment-options { display: none; }
  .checkout-button { min-height: 54px; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .product-image-editor { grid-template-columns: 80px minmax(0, 1fr); }
  .product-image-preview { width: 80px; }
  .edit-stock-field { align-items: stretch; flex-direction: column; }
  .edit-stock-field .button { width: 100%; }
  .dialog { max-height: calc(100vh - 16px); }
  .sale-summary { grid-template-columns: 1fr 1fr; }
  .sale-detail-header { gap: 10px; }
  .sale-detail-row { align-items: flex-start; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .button { flex: 1; }
  .return-item { grid-template-columns: 1fr 90px; }
}

@media print {
  body > *:not(#receipt-dialog) { display: none !important; }
  #receipt-dialog { position: static; display: block; width: 80mm; max-height: none; margin: 0; padding: 8mm; box-shadow: none; }
  #receipt-dialog::backdrop, #receipt-dialog footer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
