/* KCPOS shared styles.
   Building blocks (use these instead of inventing new ones):
     layout   .page-head (h1 + .actions) · .card · .stats > .stat · .toolbar · .tabs > .tab(.active) · .empty
     buttons  .btn + .btn-primary | .btn-danger | .btn-ghost, size .btn-sm
     forms    .form-grid > .field (.field-wide spans the row) · .check · .form-actions
     tables   .table-wrap > table.table · td.num for numbers · .muted
     picker   .picker > input + .picker-results (buttons with .name, or a .note)
     badges   .badge + .badge-ok | .badge-warn | .badge-danger | .badge-muted
*/
:root {
  --brand: #1b7f3b;
  --brand-dark: #14602c;
  --brand-soft: #e6f4ea;
  --accent: #f59e0b;
  --ink: #1f2430;
  --muted: #6b7280;
  --bg: #f3f5f3;
  --card: #ffffff;
  --line: #dfe4df;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --side: #10231a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 35, 26, 0.06), 0 2px 8px rgba(16, 35, 26, 0.05);
  --font: -apple-system, "Segoe UI", "Leelawadee UI", Thonburi, "Noto Sans Thai", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
/* The hidden attribute must win over component rules that set display (grid, flex, ...). */
[hidden] { display: none !important; }
html { font-size: 16px; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.5; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }

/* ---- app shell ---- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--side); color: #dfe9e2; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; color: #fff; font-weight: 700; font-size: 1.15rem; }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.brand:hover { text-decoration: none; }
.shop-name { padding: 0 16px 12px; font-size: 0.8rem; color: #9db5a5; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.branch-switch { padding: 0 12px 12px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.branch-switch select { width: 100%; background: rgba(255, 255, 255, 0.08); color: #fff; border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 6px; padding: 6px 8px; font: inherit; font-size: 0.85rem; }
.nav { padding: 8px; flex: 1; }
.nav-group { margin: 12px 8px 4px; font-size: 0.72rem; letter-spacing: 0.04em; color: #7f9a88; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #dfe9e2; }
.nav a:hover { background: rgba(255, 255, 255, 0.07); text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav a.nav-pos { background: var(--accent); color: #2b1d00; font-weight: 700; justify-content: center; margin-bottom: 4px; }
.nav a.nav-pos:hover { filter: brightness(1.05); }
.side-user { padding: 12px 16px; border-top: 1px solid rgba(255, 255, 255, 0.08); font-size: 0.875rem; }
.side-user form { margin-top: 6px; }
.side-user button { background: none; border: 0; padding: 0; color: #9db5a5; cursor: pointer; font: inherit; }
.side-user button:hover { color: #fff; text-decoration: underline; }
.main { padding: 22px 26px 40px; min-width: 0; }
.btn.menu-toggle { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform 0.18s; }
  body.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35); }
  .main { padding: 14px 14px 32px; }
  .btn.menu-toggle { display: inline-flex; margin-bottom: 10px; }
}

/* ---- page pieces ---- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card > h2 { margin-bottom: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.good .value { color: var(--brand-dark); }
.stat.bad .value { color: var(--danger); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1 1 220px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab { padding: 7px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--ink); font-size: 0.92rem; }
.tab:hover { text-decoration: none; border-color: var(--brand); }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: #b9c4bb; background: #f8faf8; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: #fff; border-color: #e6b3b0; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 0.875rem; }

/* ---- forms ---- */
input[type="text"], input[type="number"], input[type="password"], input[type="email"], input[type="date"], input[type="search"], input[type="tel"], input[type="file"], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #c9d1ca; border-radius: 8px; background: #fff; color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
textarea { min-height: 84px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.field label { display: block; font-weight: 600; font-size: 0.92rem; margin-bottom: 4px; }
.field .help { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }
.field .error, .errorlist { color: var(--danger); font-size: 0.85rem; margin: 3px 0 0; padding: 0; list-style: none; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field-wide { grid-column: 1 / -1; }
.check { display: flex; gap: 9px; align-items: flex-start; }
.check input { width: 18px; height: 18px; margin-top: 3px; flex: none; }
.check-row { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.bundle-box { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.bundle-box .table input { width: 100%; }
.bundle-box .table input.num { text-align: right; }
.bundle-box h2 { margin: 0 0 4px; }
.print-only { display: none; }
.check-row .check { align-items: center; }
.check label { margin: 0; font-weight: 600; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.94rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.82rem; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfa; }
.table td { padding: 10px 12px; border-bottom: 1px solid #edf0ed; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcfa; }
.table .num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fafbfa; }
.row-void td { color: var(--muted); text-decoration: line-through; }
.row-void td.keep { text-decoration: none; }

/* ---- product picker (type-ahead search that adds rows to a document) ---- */
.picker { position: relative; }
.picker-results { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin-top: 4px; max-height: 340px; overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16, 35, 26, 0.18); }
.picker-results button { display: flex; gap: 12px; align-items: baseline; width: 100%; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.picker-results button:last-child { border-bottom: 0; }
.picker-results button:hover, .picker-results button.active { background: var(--brand-soft); }
.picker-results .name { flex: 1; }
.picker-results .note { padding: 12px; color: var(--muted); }

/* ---- bar chart of days (home page, reports) ---- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; align-items: end; height: 170px; }
.week .col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; min-width: 0; }
.week .bar { width: 100%; max-width: 54px; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 3px; }
.week .col.today .bar { background: var(--accent); }
.week .amount { font-size: 0.75rem; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.week .day { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* ---- badges, messages, pagination ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--brand-soft); color: var(--brand-dark); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: #eceeed; color: var(--muted); }
.messages { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 8px; }
.messages li { padding: 10px 14px; border-radius: 8px; background: var(--brand-soft); color: var(--brand-dark); border: 1px solid #bfe0c8; }
.messages li.error { background: var(--danger-soft); color: var(--danger); border-color: #f0c2bf; }
.messages li.warning { background: var(--warn-soft); color: var(--warn); border-color: #f1d9a8; }
.pagination { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 12px; font-size: 0.9rem; }

/* ---- sign-in ---- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #10231a 0%, #1b7f3b 100%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 28px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25); }
.login-card .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-card .logo img { width: 52px; height: 52px; border-radius: 12px; }
.login-card .field { margin-bottom: 12px; }
.login-card .btn { width: 100%; margin-top: 6px; padding: 11px; }

@media print {
  .sidebar, .menu-toggle, .no-print, .messages { display: none !important; }
  .print-only { display: flex !important; }
  .app { display: block; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
