/* ==========================================================================
   Tempahan Patin — styles.css
   Vanilla, tiada dependency, mobile-first, sedia untuk cetak.
   ========================================================================== */

:root {
  --bg: #f6f2ec;
  --surface: #fffdfa;
  --surface-2: #f1eae0;
  --ink: #1c1917;
  --muted: #62564a;
  --line: #e6ddd2;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fdece3;
  --ok: #15803d;      --ok-soft: #e7f6ec;
  --warn: #b45309;    --warn-soft: #fdf1e0;
  --bad: #b91c1c;     --bad-soft: #fdecec;
  --info: #1d4ed8;    --info-soft: #e8eefc;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(28,25,23,.06), 0 10px 26px -16px rgba(28,25,23,.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html[data-theme="dark"] {
  --bg: #16130f;
  --surface: #1f1b16;
  --surface-2: #272118;
  --ink: #f5efe6;
  --muted: #c0b4a6;
  --line: #3a3128;
  --accent: #f97316;
  --accent-ink: #1c1917;
  --accent-soft: #3a2413;
  --ok: #4ade80;      --ok-soft: #14301f;
  --warn: #fbbf24;    --warn-soft: #3a2c11;
  --bad: #f87171;     --bad-soft: #3a1b1b;
  --info: #93b4fd;    --info-soft: #1c2545;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 28px -18px rgba(0,0,0,.9);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(96px + var(--safe-b));
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- app bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { border-radius: 9px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 16px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text span { font-size: 12px; }
.appbar-actions { display: flex; gap: 6px; flex: none; }

.icon-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  width: 38px; height: 38px; border-radius: 11px; font-size: 15px; cursor: pointer;
  display: inline-grid; place-items: center; transition: transform .08s, background .15s;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn:active { transform: scale(.94); }

.tabs {
  max-width: 1100px; margin: 0 auto; display: flex; gap: 4px;
  padding: 0 8px 8px; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
/* Isyarat boleh-skrol: bar tab lebih lebar drpd skrin telefon — beri fade tepi. */
@media (max-width: 560px) {
  .tabs {
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 26px), transparent 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 26px), transparent 100%);
  }
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; border: 0; background: transparent; color: var(--muted);
  padding: 8px 12px; border-radius: 10px; font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; white-space: nowrap;
}
.tab.is-active { background: var(--accent-soft); color: var(--accent); }

/* ---------- layout ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 14px 14px 78px; }
.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  margin-bottom: 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.grow { flex: 1 1 160px; }
.field > span { font-size: 11.5px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px; min-width: 0; width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { resize: vertical; min-height: 64px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); padding-bottom: 8px; }
.check input { width: auto; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 4px; }
.toolbar-actions { display: flex; gap: 6px; margin-left: auto; padding-bottom: 4px; }

.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 14px; font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.btn.danger:hover { background: var(--bad-soft); }

/* ---------- banner ---------- */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--info-soft); border: 1px solid color-mix(in srgb, var(--info) 25%, transparent);
  color: var(--ink); border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
}
.banner-icon { font-size: 18px; }
.banner-body { flex: 1; }
.banner-body strong { display: block; font-size: 13.5px; }
.banner-body p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

/* ---------- kpis ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.kpi .kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.kpi .kpi-value { font-size: 21px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi.ok .kpi-value { color: var(--ok); }
.kpi.bad .kpi-value { color: var(--bad); }
.kpi.accent .kpi-value { color: var(--accent); }

/* ---------- order cards ---------- */
.order-list { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .order-list { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1080px) { .order-list { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 9px;
}
.order-head { display: flex; align-items: center; gap: 8px; }
.order-no {
  font-size: 11.5px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 7px; padding: 2px 7px; font-variant-numeric: tabular-nums;
}
.order-name { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 3px 9px; white-space: nowrap;
  border: 1px solid transparent;
}
.badge.s-baru   { background: var(--info-soft); color: var(--info); }
.badge.s-sedang { background: var(--warn-soft); color: var(--warn); }
.badge.s-siap   { background: var(--ok-soft);   color: var(--ok); }
.badge.s-dihantar { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.badge.paid     { background: var(--ok-soft); color: var(--ok); }
.badge.unpaid   { background: var(--bad-soft); color: var(--bad); }

.order-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.order-lines li { display: flex; align-items: center; gap: 7px; font-size: 13.5px; }
.order-lines .code {
  font-weight: 700; font-size: 11px; color: var(--accent); background: var(--accent-soft);
  border-radius: 5px; padding: 1px 5px; flex: none;
}
.order-lines .qty { font-weight: 700; font-variant-numeric: tabular-nums; }
.order-lines .price { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }

.order-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--muted); }
.order-meta .tag { background: var(--surface-2); border-radius: 6px; padding: 2px 7px; }
.order-remark { margin: 0; font-size: 12.5px; color: var(--muted); font-style: italic; }

.order-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-top: 1px dashed var(--line); padding-top: 9px;
}
.order-foot .total { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.order-foot .bal { font-size: 12px; font-weight: 700; }
.order-foot .bal.unpaid { color: var(--bad); }
.order-foot .bal.paid { color: var(--ok); }

.order-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.order-actions button {
  flex: 1 1 auto; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: 8px; padding: 7px 8px; font: inherit; font-size: 12px;
  font-weight: 600; cursor: pointer;
}
.order-actions button:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.order-actions button.danger:hover { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

/* ---------- board ---------- */
.board { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 800px) { .board { grid-template-columns: repeat(4, 1fr); align-items: start; } }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.col-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.col-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.col-count { font-size: 12px; font-weight: 700; color: var(--muted); background: var(--surface); border-radius: 999px; padding: 1px 8px; }
.col-list { display: flex; flex-direction: column; gap: 8px; }
.mini {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 10px; font-size: 13px; display: flex; flex-direction: column; gap: 5px;
}
.mini-top { display: flex; align-items: center; gap: 6px; }
.mini-name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-total { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; }
.mini-actions { display: flex; gap: 5px; }
.mini-actions button {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 7px;
  padding: 4px 8px; font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer; color: var(--ink);
}
.mini-actions button:hover { border-color: var(--accent); color: var(--accent); }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 22px 10px; }
.col .empty { padding: 10px; font-size: 12px; }

/* ---------- panels / report ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 10px; font-size: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.panel-head h3 { margin: 0; }
.hint { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); }
.hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.report-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .report-grid { grid-template-columns: 1fr 1fr; } .panel.wide { grid-column: 1 / -1; } }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 13px; }
.bar-label { display: flex; align-items: center; gap: 6px; }
.bar-track { grid-column: 1 / -1; height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.bar-val { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); }

table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple th, table.simple td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
table.simple th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.simple td.num, table.simple th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.simple tbody tr:last-child td { border-bottom: 0; }

/* ---------- forms ---------- */
.form-grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.editor { display: flex; flex-direction: column; gap: 8px; }
.edit-row {
  display: grid; gap: 8px; align-items: end; padding: 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  grid-template-columns: 1fr 1fr;
}
@media (min-width: 700px) {
  .edit-row.items  { grid-template-columns: 72px 1fr 1fr 110px auto; }
  .edit-row.addons { grid-template-columns: 1fr 1fr auto; }
}
.edit-row .field > span { font-size: 10.5px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.qty-row { display: flex; align-items: center; gap: 8px; }
.qty-row input[type="number"] { width: 84px; text-align: center; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 0; }
.stepper button {
  width: 34px; height: 38px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink); font-size: 17px; font-weight: 700; cursor: pointer;
}
.stepper button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.stepper button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.stepper input { border-radius: 0; border-left: 0; border-right: 0; text-align: center; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 90; background: rgba(20,16,12,.55);
  display: grid; place-items: center; padding: 0; animation: fade .15s ease;
}
@media (min-width: 720px) { .modal-back { padding: 24px; } }
.modal {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 100dvh;
  border-radius: 0; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.6);
}
@media (min-width: 720px) { .modal { border-radius: var(--radius); max-height: 88dvh; } }
.modal-head {
  display: flex; align-items: center; gap: 10px; padding: 13px 14px;
  border-bottom: 1px solid var(--line); flex: none;
}
.modal-head h2 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 14px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.modal-foot {
  display: flex; gap: 8px; padding: 12px 14px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line); background: var(--surface); flex: none;
}
.modal-foot .btn { flex: 1; }
.sec-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 2px 0 -4px; }
.item-grid { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .item-grid { grid-template-columns: 1fr 1fr; } }
.item-pick {
  display: flex; align-items: center; gap: 10px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px;
}
.item-pick .ip-name { flex: 1; font-size: 13.5px; font-weight: 600; }
.item-pick .ip-price { font-size: 12px; color: var(--muted); }
.addon-row { display: grid; gap: 8px; grid-template-columns: 1fr 1fr auto; align-items: end; }
.totals {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 12px; display: flex; flex-direction: column; gap: 5px; font-size: 13.5px;
}
.totals .tline { display: flex; justify-content: space-between; }
.totals .tline.big { font-size: 17px; font-weight: 700; border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 2px; }
.totals .tline.bal { color: var(--bad); font-weight: 700; }
.totals .tline.bal.ok { color: var(--ok); }

/* ---------- fab ---------- */
.fab {
  position: fixed; right: 14px; bottom: calc(16px + var(--safe-b)); z-index: 60;
  width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--surface);
  cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-size: 26px; line-height: 1;
  box-shadow: 0 10px 26px -8px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: transform .1s;
}
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(.95); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + var(--safe-b)); transform: translate(-50%, 14px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 120; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- print ---------- */
.print-area { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  .appbar, main, .fab, .toast, #modal-root { display: none !important; }
  .print-area { display: block; padding: 0 6mm; }
  .print-area h1 { font-size: 18pt; margin: 0 0 2mm; }
  .print-area h2 { font-size: 13pt; margin: 5mm 0 1mm; }
  .print-area .p-meta { font-size: 10pt; margin-bottom: 3mm; }
  .print-area table { width: 100%; border-collapse: collapse; font-size: 10pt; }
  .print-area th, .print-area td { border: 1px solid #999; padding: 1.5mm 2mm; text-align: left; }
  .print-area td.num, .print-area th.num { text-align: right; }
  .print-area .p-total { margin-top: 3mm; font-size: 12pt; font-weight: bold; text-align: right; }
  .print-area .p-foot { margin-top: 6mm; font-size: 9pt; color: #444; }
  .print-area .slip { border: 1px dashed #999; padding: 4mm; margin-bottom: 6mm; }
  @page { margin: 10mm; }
}