/* ============================================================
   AriolaERP — Design System
   Warm minimal ERP, original brand for Ariola Ventures
   ============================================================ */

:root {
  /* Palette — warm cream + ink + terracotta accent */
  --bg: #f6f3ec;
  --bg-2: #efeae0;
  --surface: #ffffff;
  --surface-2: #fbf9f4;
  --ink: #15130f;
  --ink-2: #3a352d;
  --muted: #7a7368;
  --muted-2: #a8a094;
  --border: #e6dfd1;
  --border-2: #d6cdba;
  --accent: #c2542a;       /* terracotta */
  --accent-ink: #ffffff;
  --accent-soft: #f5e3d8;
  --success: #2f7a4a;
  --success-soft: #e1efe5;
  --danger: #b03a2e;
  --danger-soft: #f5dcd8;
  --warn: #b07c1f;
  --warn-soft: #f3e7c9;
  --info: #2c5a8a;
  --info-soft: #dde8f3;

  /* Type */
  --font-sans: "Geist", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-display: "Geist", system-ui, sans-serif;

  /* Sizing */
  --density: 1;
  --row-h: calc(44px * var(--density));
  --pad-card: calc(22px * var(--density));
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;

  /* Shadow */
  --shadow-1: 0 1px 0 rgba(20, 19, 15, 0.04), 0 1px 2px rgba(20, 19, 15, 0.04);
  --shadow-2: 0 2px 4px rgba(20, 19, 15, 0.05), 0 8px 24px rgba(20, 19, 15, 0.06);
  --shadow-pop: 0 10px 40px rgba(20, 19, 15, 0.12);
}

.theme-dark {
  --bg: #14120f;
  --bg-2: #1c1a16;
  --surface: #1f1c18;
  --surface-2: #25221d;
  --ink: #f3efe6;
  --ink-2: #d8d2c4;
  --muted: #948c7e;
  --muted-2: #6b6457;
  --border: #2e2a23;
  --border-2: #3c372e;
  --accent: #e07a4a;
  --accent-ink: #15130f;
  --accent-soft: #3a261c;
  --success: #6bbf8a;
  --success-soft: #1f3127;
  --danger: #e07a6b;
  --danger-soft: #3a221f;
  --warn: #e3b955;
  --warn-soft: #332a14;
  --info: #84b3e3;
  --info-soft: #1b2a3a;
  --shadow-1: 0 1px 0 rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-2: 0 2px 4px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.4);
  --shadow-pop: 0 10px 40px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ===== App shell ===== */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 15px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: -0.02em;
}

.brand-mark.accent { background: var(--accent); color: var(--accent-ink); }

.shop-pill {
  margin-left: 8px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 500;
}

.topbar .grow { flex: 1; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink-2);
}
.icon-btn:hover { background: var(--bg-2); border-color: var(--border); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.dropdown {
  position: absolute;
  top: 44px;
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: var(--shadow-pop);
  z-index: 50;
}
.dropdown button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dropdown button:hover { background: var(--bg-2); }

/* ===== Layout (sidebar + content) ===== */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  transition: width 200ms ease, padding 200ms ease;
}
.sidebar.collapsed { width: 0; padding: 16px 0; overflow: hidden; border-right: 0; }

.nav-section {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 13.5px;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  font-weight: 500;
}
.nav-item:hover { background: var(--bg-2); color: var(--ink); }
.nav-item.active { background: var(--ink); color: var(--bg); }
.theme-dark .nav-item.active { background: var(--accent); color: var(--accent-ink); }

.nav-sub {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 26px;
  margin: 2px 0 6px;
}
.nav-sub .nav-item { padding: 6px 10px; font-size: 13px; font-weight: 400; }
.nav-sub .nav-item.active { background: var(--accent-soft); color: var(--accent); }
.theme-dark .nav-sub .nav-item.active { background: var(--accent-soft); color: var(--accent); }

.nav-caret { margin-left: auto; opacity: 0.5; transition: transform 150ms; }
.nav-caret.open { transform: rotate(90deg); }

/* ===== Content ===== */
.content {
  flex: 1;
  padding: 28px 32px 56px;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}
.page-head .sub {
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 4px;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--pad-card);
  box-shadow: var(--shadow-1);
}
.card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}
.card-h h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-value {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.025em;
  margin-top: 8px;
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
}
.kpi-value .unit { font-size: 14px; color: var(--muted); margin-left: 4px; font-weight: 500; }
.kpi-delta {
  margin-top: 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}
.kpi-delta .up { color: var(--success); font-weight: 600; }
.kpi-delta .down { color: var(--danger); font-weight: 600; }
.kpi.accent {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.kpi.accent .kpi-label, .kpi.accent .kpi-delta { color: rgba(255,255,255,0.7); }
.kpi.accent .kpi-value .unit { color: rgba(255,255,255,0.6); }
.theme-dark .kpi.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.theme-dark .kpi.accent .kpi-label, .theme-dark .kpi.accent .kpi-delta { color: rgba(0,0,0,0.6); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  height: 36px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
  transition: background 120ms, border-color 120ms;
}
.btn:hover { background: var(--bg-2); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { background: #000; }
.theme-dark .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.accent:hover { filter: brightness(0.95); }
.btn.success { background: var(--success); color: #fff; border-color: var(--success); }
.btn.success:hover { filter: brightness(0.95); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.lg { height: 44px; padding: 0 20px; font-size: 14px; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
}
.field label .req { color: var(--danger); margin-left: 2px; }
.input, .select, textarea.input {
  height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
  width: 100%;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.mono { font-family: var(--font-mono); letter-spacing: 0.02em; }
.input::placeholder { color: var(--muted-2); }

.input-wrap { position: relative; }
.input-wrap .input { padding-left: 36px; }
.input-wrap .lead {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  display: flex;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

/* ===== Table ===== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.tbl th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.tbl td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.row:hover td { background: var(--bg-2); }
.tbl td.mono, .tbl th.mono { font-family: var(--font-mono); font-size: 12.5px; letter-spacing: 0.01em; }
.tbl td .imei { color: var(--ink-2); }
.tbl td .imei .last { color: var(--accent); font-weight: 600; }

/* table toolbar */
.tbl-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.tbl-toolbar .grow { flex: 1; min-width: 200px; }

/* pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.pagination .pages { display: flex; align-items: center; gap: 4px; }
.pagination .page-btn {
  min-width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  font-size: 12.5px;
}
.pagination .page-btn:hover { background: var(--bg-2); }
.pagination .page-btn.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.theme-dark .pagination .page-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pagination .page-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--bg-2); color: var(--muted); border-color: var(--border); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ===== Modal / drawer ===== */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(20, 19, 15, 0.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  box-shadow: var(--shadow-pop);
}
.modal.lg { max-width: 760px; }
.modal-h {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-h h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-b { padding: 22px 24px; }
.modal-f {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface-2);
}

/* edit drawer (green for shop edit customer) */
.modal.edit-customer {
  background: linear-gradient(180deg, #2f7a4a 0%, #246039 100%);
  color: #fff;
  border-color: #1f5230;
}
.modal.edit-customer .modal-h { border-color: rgba(255,255,255,0.15); }
.modal.edit-customer .modal-f { background: rgba(0,0,0,0.15); border-color: rgba(255,255,255,0.15); }
.modal.edit-customer .field label { color: rgba(255,255,255,0.85); }
.modal.edit-customer .input {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.25);
  color: #fff;
}
.modal.edit-customer .input::placeholder { color: rgba(255,255,255,0.5); }
.modal.edit-customer .input:focus { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,0.15); }

/* toast */
.toast-host { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  animation: tin 200ms ease-out;
}
.toast.success { background: var(--success); color: #fff; }
.toast.danger { background: var(--danger); color: #fff; }
@keyframes tin { from { transform: translateY(-8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ===== Dashboard charts (simple bars) ===== */
.spark {
  display: flex;
  align-items: end;
  gap: 4px;
  height: 80px;
}
.spark .bar {
  flex: 1;
  background: var(--accent-soft);
  border-radius: 4px 4px 0 0;
  position: relative;
}
.spark .bar.hi { background: var(--accent); }

/* allocation transfer split */
.transfer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: stretch;
}
.transfer .col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.transfer .col h4 { margin: 0 0 10px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.transfer .arrow { display: grid; place-items: center; color: var(--muted); }

.chip-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.chip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.chip-row.selected { border-color: var(--accent); background: var(--accent-soft); }
.chip-row .grow { flex: 1; }
.chip-row .mono { font-family: var(--font-mono); color: var(--muted); font-size: 11.5px; }
.chip-row button.x {
  background: transparent;
  border: 0;
  color: var(--muted);
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: grid;
  place-items: center;
}
.chip-row button.x:hover { background: var(--bg-2); color: var(--danger); }

/* ===== Receipt (thermal style) ===== */
.receipt-host {
  position: fixed;
  inset: 0;
  background: rgba(20,19,15,0.6);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px;
  overflow: auto;
}
.receipt {
  width: 380px;
  background: #fffdf8;
  color: #14110d;
  padding: 28px 26px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  border-radius: 4px;
  position: relative;
}
.receipt::before, .receipt::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 14px;
  background:
    radial-gradient(circle at 7px 0, #fffdf8 7px, transparent 7.5px) 0 0/14px 14px repeat-x;
}
.receipt::before { top: -14px; background: radial-gradient(circle at 7px 14px, #fffdf8 7px, transparent 7.5px) 0 0/14px 14px repeat-x; }
.receipt::after { bottom: -14px; }

.receipt h2 {
  text-align: center;
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.04em;
  font-weight: 700;
}
.receipt .biz { text-align: center; font-size: 11.5px; }
.receipt .biz strong { display: block; font-family: var(--font-display); font-size: 13px; letter-spacing: 0.08em; margin: 10px 0 4px; font-weight: 600; }
.receipt .divider { border-top: 1px dashed #14110d; margin: 12px 0; }
.receipt .rl { display: flex; justify-content: space-between; gap: 12px; }
.receipt .rl .k { color: #555; }
.receipt .rl .v { font-weight: 600; text-align: right; word-break: break-all; }
.receipt .totals .rl { font-size: 14px; }
.receipt .totals .grand .v { font-size: 16px; }
.receipt .foot { text-align: center; margin-top: 10px; font-size: 11px; font-style: italic; color: #444; }

/* ===== Sidebar — drawer mode on tablet, overlay on mobile ===== */
.sidebar-backdrop {
  position: fixed;
  inset: 56px 0 0 0;
  background: rgba(20, 19, 15, 0.4);
  backdrop-filter: blur(2px);
  z-index: 39;
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 56px;
    z-index: 40;
    box-shadow: var(--shadow-pop);
    height: calc(100vh - 56px);
    width: 260px;
    transform: translateX(0);
    transition: transform 220ms ease, width 220ms ease;
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
    width: 260px;
    padding: 16px 12px;
    border-right: 1px solid var(--border);
  }
  .sidebar-backdrop.show { display: block; }
}

/* ===== Mobile responsive ===== */
@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 8px; height: 52px; }
  .sidebar, .sidebar-backdrop { top: 52px; height: calc(100vh - 52px); }
  .sidebar-backdrop { inset: 52px 0 0 0; }
  .topbar .brand span { display: none; }
  .topbar .shop-pill {
    display: inline-block;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-left: 4px;
    font-size: 11px;
  }

  .content { padding: 16px 14px 80px; }

  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
  }
  .page-head h1 { font-size: 22px; }
  .page-head .sub { font-size: 12.5px; }
  .page-head .row-flex { gap: 8px; flex-wrap: wrap; }
  .page-head .row-flex .btn { flex: 1; min-width: 0; }
  .page-head .input-wrap { flex: 1; }

  /* KPIs: 2-up on phones */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .kpi { padding: 14px 14px; }
  .kpi-value { font-size: 24px; }
  .kpi-label { font-size: 10.5px; }
  .kpi-delta { font-size: 11px; }

  /* Cards & sections */
  .card { padding: 16px 14px; border-radius: 12px; }
  .card-h { margin-bottom: 10px; }
  .card-h h2 { font-size: 14px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 12px; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Tables — convert to card-stack on mobile */
  .table-wrap { border-radius: 12px; }
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr {
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
    background: var(--surface);
  }
  .tbl tr:nth-child(even) { background: var(--surface-2); }
  .tbl tr:last-child { border-bottom: 0; }
  .tbl tr.row:hover td { background: transparent; }
  .tbl td {
    padding: 4px 0;
    border-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
    font-size: 13px;
  }
  .tbl td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
    text-align: left;
    flex-shrink: 0;
  }
  .tbl td[colspan] { display: block; text-align: center; }
  .tbl td[colspan]::before { display: none; }

  /* Toolbar + pagination */
  .tbl-toolbar { padding: 12px 14px; gap: 8px; }
  .pagination { flex-direction: column; gap: 10px; align-items: stretch; padding: 12px 14px; }
  .pagination .pages { justify-content: center; }

  /* Transfer (allocation) stacks vertically */
  .transfer { grid-template-columns: 1fr; }
  .transfer .arrow { transform: rotate(90deg); padding: 4px; }

  /* Scan card stacks */
  .scan-card { flex-direction: column; align-items: stretch; gap: 14px; padding: 16px; }
  .scan-card form { grid-template-columns: 1fr !important; }

  /* Receipt list — keep mobile card layout but show date+model prominent */
  .receipt-host { padding: 16px; }
  .receipt { width: 100%; max-width: 360px; padding: 22px 20px; }

  /* Modal full-bleed-ish */
  .modal-bg { padding: 12px; align-items: flex-start; padding-top: 60px; }
  .modal { max-height: calc(100vh - 80px); }
  .modal-b { padding: 18px; }
  .modal-h { padding: 16px 18px; }
  .modal-f { padding: 12px 18px; flex-direction: column-reverse; }
  .modal-f .btn { width: 100%; }

  /* Login stacks */
  .login { grid-template-columns: 1fr; }
  .login .left { padding: 28px 24px; min-height: 200px; }
  .login .left .quote { font-size: 17px; }
  .login .right { padding: 28px 24px; }
  .login h1 { font-size: 28px; }

  /* Dropdowns slide from edge */
  .dropdown { right: 8px; }

  /* Pagination buttons compact */
  .pagination .page-btn { min-width: 28px; height: 28px; font-size: 12px; }
}

/* Hide last-cell action menus from overflowing */
@media (max-width: 720px) {
  .dropdown { position: fixed; top: auto; bottom: auto; right: 12px; max-width: calc(100vw - 24px); }
}

/* ===== Phone-preview frame (Tweaks "Phone preview") ===== */
body.phone-preview {
  background: #15130f !important;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 0;
}
body.phone-preview #root {
  width: 390px;
  max-width: 100%;
  height: 844px;
  max-height: calc(100vh - 40px);
  background: var(--bg);
  border-radius: 44px;
  overflow: hidden;
  position: relative;
  box-shadow:
    0 0 0 12px #2a2620,
    0 0 0 14px #4a4138,
    0 30px 60px rgba(0,0,0,0.5);
  isolation: isolate;
}
body.phone-preview #root::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 28px;
  background: #0a0907;
  border-radius: 0 0 18px 18px;
  z-index: 100;
}
body.phone-preview .app {
  min-height: 100%;
  height: 100%;
  overflow-y: auto;
  /* simulate mobile-narrow break inside the frame */
}
body.phone-preview .topbar { padding: 0 12px; gap: 8px; height: 52px; padding-top: 8px; }
body.phone-preview .topbar .brand span { display: none; }
body.phone-preview .sidebar {
  position: fixed;
  left: 0;
  top: 52px;
  z-index: 40;
  box-shadow: var(--shadow-pop);
  height: calc(100% - 52px);
  width: 240px;
  transition: transform 220ms ease;
}
body.phone-preview .sidebar.collapsed { transform: translateX(-100%); width: 240px; padding: 16px 12px; }
body.phone-preview .content { padding: 14px 14px 60px; }
body.phone-preview .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
body.phone-preview .kpi-value { font-size: 22px; }
body.phone-preview .grid-2, body.phone-preview .grid-3 { grid-template-columns: 1fr; gap: 12px; }
body.phone-preview .form-grid { grid-template-columns: 1fr; gap: 12px; }
body.phone-preview .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
body.phone-preview .page-head h1 { font-size: 22px; }
body.phone-preview .transfer { grid-template-columns: 1fr; }
body.phone-preview .transfer .arrow { transform: rotate(90deg); }
body.phone-preview .scan-card { flex-direction: column; align-items: stretch; }
body.phone-preview .scan-card form { grid-template-columns: 1fr !important; }
body.phone-preview .tbl thead { display: none; }
body.phone-preview .tbl, body.phone-preview .tbl tbody, body.phone-preview .tbl tr, body.phone-preview .tbl td { display: block; width: 100%; }
body.phone-preview .tbl tr { border-bottom: 1px solid var(--border); padding: 12px 14px; background: var(--surface); }
body.phone-preview .tbl tr:nth-child(even) { background: var(--surface-2); }
body.phone-preview .tbl td { padding: 4px 0; border-bottom: 0; display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
body.phone-preview .tbl td::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  text-align: left;
}
body.phone-preview .login { grid-template-columns: 1fr; }
body.phone-preview .login .left { padding: 24px; min-height: 180px; }
body.phone-preview .login .right { padding: 24px; }
body.phone-preview .receipt-host { padding: 16px; }
body.phone-preview .receipt { width: 100%; max-width: 320px; }
body.phone-preview .modal-bg { padding: 12px; padding-top: 70px; }

/* When in phone preview, all overlays clip inside the frame */
body.phone-preview .sidebar,
body.phone-preview .sidebar-backdrop,
body.phone-preview .modal-bg,
body.phone-preview .receipt-host,
body.phone-preview .toast-host {
  position: absolute;
}
body.phone-preview .toast-host { top: 60px; right: 12px; }

/* The Tweaks panel itself should stay outside the frame */
body.phone-preview .twk-panel { right: 16px; bottom: 16px; position: fixed; }

/* density variations */
.density-compact { --density: 0.85; }
.density-cozy    { --density: 1; }
.density-comfy   { --density: 1.15; }

.density-compact .tbl td { padding: 9px 14px; }
.density-comfy .tbl td { padding: 16px 18px; }

/* misc */
.muted { color: var(--muted); }
.row-flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.col-flex { display: flex; flex-direction: column; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* loading-style stripes for placeholder phone visual */
.phone-shape {
  width: 180px;
  height: 220px;
  background:
    repeating-linear-gradient(135deg,
      var(--bg-2) 0 12px,
      var(--bg) 12px 24px);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
}

/* scanner card */
.scan-card {
  background: var(--surface);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  gap: 22px;
  align-items: center;
}
.scan-card .pulse {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); }
  50% { box-shadow: 0 0 0 10px rgba(194,84,42,0.0); }
}
.scan-card input.input { font-family: var(--font-mono); font-size: 16px; letter-spacing: 0.04em; height: 48px; }

/* login */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 900px) { .login { grid-template-columns: 1fr; } }
.login .left {
  background: var(--ink);
  color: var(--bg);
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login .left::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(800px 400px at 80% 100%, rgba(194,84,42,0.35), transparent 60%),
    radial-gradient(600px 300px at 0% 0%, rgba(255,255,255,0.04), transparent 60%);
}
.login .left .top, .login .left .bot { position: relative; z-index: 1; }
.login .right {
  display: grid;
  place-items: center;
  padding: 48px;
}
.login form {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login h1 { font-size: 36px; line-height: 1.05; letter-spacing: -0.03em; margin: 0 0 12px; }
.login .quote {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.3;
  letter-spacing: -0.02em;
  max-width: 420px;
}
.login .tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--font-mono);
}

/* segmented role switch on login */
.seg {
  display: flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.seg button {
  flex: 1;
  height: 34px;
  border: 0;
  background: transparent;
  border-radius: 7px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
}
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
