:root {
  --bg: #fff8ef;
  --panel: #fffdf8;
  --soft: #f4e6d4;
  --line: #ead7bd;
  --text: #27221e;
  --muted: #786a5d;
  --accent: #243355;
  --accent-dark: #17213a;
  --ok: #16803c;
  --danger: #b42318;
  --shadow: 0 10px 24px rgba(58, 40, 24, 0.08);
  color-scheme: light;
}

body.dark {
  --bg: #191614;
  --panel: #24201d;
  --soft: #342b24;
  --line: #4b3f35;
  --text: #fff8ef;
  --muted: #c8b6a3;
  --accent: #7f94c8;
  --accent-dark: #b3c3ec;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  touch-action: pan-y;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
  min-height: 42px;
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button:hover { filter: brightness(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.app-shell {
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  display: grid;
  grid-template-columns: 230px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  color: var(--accent);
  font-size: 24px;
  font-weight: 950;
  letter-spacing: 0;
  line-height: 1.1;
  margin: 0 8px 18px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  text-align: left;
  background: transparent;
  color: var(--muted);
}

.nav button.active {
  background: var(--accent);
  color: white;
}

.main {
  min-width: 0;
  padding: 22px;
  padding-bottom: 90px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 36px);
}

.header-clock {
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  font-size: 24px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.subtle { color: var(--muted); }

.grid {
  display: grid;
  gap: 14px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric {
  font-size: 26px;
  font-weight: 850;
  margin-top: 4px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 20px 0 10px;
}

.section-title h2 {
  margin: 0;
  font-size: 19px;
}

.tabs, .quick-row, .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tabs button.active, .quick-row button.active {
  background: var(--text);
  color: var(--bg);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 10px;
}

.product-button {
  min-height: 95px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: left;
}

.product-button.active {
  outline: 3px solid color-mix(in srgb, var(--accent) 70%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
}

.product-name {
  display: block;
  font-weight: 800;
  margin-bottom: 10px;
}

.product-price {
  color: var(--accent-dark);
  font-weight: 800;
}

.sale-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  max-height: none;
  background: #fff;
  overflow: visible;
}

body.dark .sale-panel {
  background: var(--panel);
}

.order-lines, .order-items {
  display: grid;
  gap: 8px;
}

.order-lines {
  overflow: visible;
  min-height: 0;
  max-height: none;
  padding: 0;
  background: #fff;
}

body.dark .order-lines {
  background: var(--panel);
}

.checkout-panel {
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.order-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

body.dark .order-line {
  background: var(--panel);
}

.line-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.line-controls button {
  min-width: 36px;
  min-height: 36px;
  padding: 6px 8px;
}

.order-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 18px;
}

.order-total strong {
  font-size: 24px;
}

.order-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.staff-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.staff-card {
  display: grid;
  gap: 14px;
}

.staff-card h2 {
  margin: 0;
}

.staff-role {
  display: inline-flex;
  width: fit-content;
  margin-top: 6px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 5px 8px;
  font-weight: 850;
}

.role-button-row, .role-choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.role-button-row button.active {
  background: var(--accent);
  color: white;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  border-radius: 8px;
  background: var(--soft);
  padding: 8px 10px;
  font-weight: 750;
}

.check-pill input {
  width: auto;
  min-height: auto;
}

.staff-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
}

.staff-meta span {
  color: var(--muted);
}

.staff-meta strong {
  text-align: right;
}

.order-card {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
  min-height: 330px;
}

.done-order {
  opacity: 0.72;
}

.order-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.order-card h2 {
  margin: 0;
  font-size: 20px;
}

.order-card .primary {
  min-height: 64px;
}

.timer {
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 24px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.timer-green {
  background: #16803c;
  color: white;
}

.timer-yellow {
  background: #d99a18;
  color: white;
}

.timer-red {
  background: #c2412d;
  color: white;
}

.pos-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.primary {
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.pay-button {
  background: #16803c;
  color: white;
  font-weight: 850;
}

.pay-choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.split-button {
  font-weight: 850;
}

.card-button {
  background: #f97316;
  color: white;
  font-weight: 850;
}

.danger {
  background: #fee4df;
  color: var(--danger);
}

.ok {
  color: var(--ok);
  font-weight: 800;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  min-height: 42px;
  padding: 9px 10px;
  font-size: 16px;
}

#payment-received {
  font-size: 24px;
  font-weight: 850;
  text-align: center;
}

textarea {
  resize: vertical;
}

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

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
}

tr:last-child td { border-bottom: 0; }

.inline-input {
  max-width: 120px;
}

.line-detail {
  color: var(--accent-dark);
  font-size: 13px;
  margin-top: 4px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
}

.icon-button svg, .custom-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 12, 0.24);
  z-index: 30;
}

.customize-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  display: grid;
  gap: 14px;
  max-height: min(78vh, 640px);
  overflow: auto;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -18px 50px rgba(37, 28, 20, 0.18);
}

.customize-sheet.sheet-enter {
  animation: sheet-rise 160ms ease-out;
}

@keyframes sheet-rise {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  justify-self: center;
  width: 56px;
  height: 5px;
  border-radius: 99px;
  background: var(--line);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.sheet-head h2 {
  margin: 0;
}

.custom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.split-list {
  display: grid;
  gap: 10px;
}

.split-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}

@media (max-width: 720px) {
  .split-line {
    grid-template-columns: 1fr;
  }
}

.custom-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 78px;
  text-align: left;
  background: var(--soft);
  overflow: hidden;
}

.custom-chip.active {
  background: var(--accent);
  color: white;
}

.custom-chip small {
  display: block;
  margin-top: 3px;
  color: inherit;
  opacity: 0.78;
}

.custom-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: color-mix(in srgb, white 55%, transparent);
}

.chip-qty {
  display: grid;
  grid-template-rows: 28px 24px 28px;
  justify-items: center;
  align-items: center;
  gap: 2px;
  align-self: stretch;
}

.chip-qty span {
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 28px;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  font-weight: 850;
}

.chip-qty strong {
  display: grid;
  place-items: center;
  min-width: 24px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.settings-cards {
  margin-top: 14px;
}

.sync-status {
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--ok) 12%, var(--panel));
  color: var(--ok);
  font-weight: 850;
}

.sync-state {
  padding: 12px;
  border-radius: 8px;
  background: #fee4df;
  color: var(--danger);
  font-weight: 900;
}

.sync-state.sync-on {
  background: color-mix(in srgb, var(--ok) 15%, var(--panel));
  color: var(--ok);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.success-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
  box-shadow: 0 18px 50px rgba(37, 28, 20, 0.18);
  text-align: center;
}

.success-check {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #16803c;
  color: white;
  font-size: 46px;
  font-weight: 950;
}

.payment-method-label {
  margin: -6px 0 0;
  color: var(--muted);
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.receipt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.receipt-card {
  display: grid;
  gap: 12px;
}

.receipt-head, .receipt-total, .receipt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.receipt-head h2 {
  margin: 0;
}

.receipt-method {
  display: inline-flex;
  width: fit-content;
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.receipt-items {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.bottom-nav {
  display: none;
}

.chart {
  display: grid;
  gap: 8px;
}

.bar {
  display: grid;
  grid-template-columns: 130px 1fr 80px;
  gap: 8px;
  align-items: center;
}

.bar-track {
  height: 16px;
  border-radius: 99px;
  background: var(--soft);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 190px minmax(0, 1fr);
  }
  .pos-layout {
    grid-template-columns: minmax(0, 1fr) minmax(310px, 360px);
  }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main {
    padding: 14px 12px calc(190px + env(safe-area-inset-bottom));
  }
  .pos-layout { grid-template-columns: 1fr; }
  .sale-panel {
    min-height: 0;
    max-height: none;
    overflow: visible;
  }
  .order-lines {
    min-height: 0;
    max-height: none;
  }
  .bottom-nav {
    position: fixed;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
    z-index: 10;
  }
  .bottom-nav button {
    min-height: 54px;
    padding: 4px;
    font-size: 11px;
  }
  .bottom-nav button.active {
    background: var(--accent);
    color: white;
  }
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .bar {
    grid-template-columns: 92px 1fr 70px;
  }
}

@media print {
  .sidebar, .bottom-nav, .topbar button, .no-print { display: none !important; }
  .main { padding: 0; }
  body { background: white; color: black; }
  .card, .table-wrap { box-shadow: none; border-color: #bbb; }
}
