:root {
  --bg: #f6f7f2;
  --ink: #20252c;
  --muted: #68707a;
  --line: #dfe3dc;
  --panel: #ffffff;
  --panel-soft: #fbfcf8;
  --green: #00a88f;
  --coral: #f45d48;
  --amber: #f4b942;
  --blue: #3f7ee8;
  --graphite: #343a42;
  --danger: #c93232;
  --shadow: 0 14px 42px rgba(32, 37, 44, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.35;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
svg { width: 1.2rem; height: 1.2rem; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }

.app-shell {
  width: min(100%, 540px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}
.profile-picker label,
.cash-input span,
.admin-grid label,
.muted-label {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}
.profile-picker select,
.cash-input input,
.admin-grid input,
.admin-grid select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}
.profile-picker select { min-width: 0; font-weight: 800; }
.status-stack { display: flex; align-items: center; gap: 8px; }
.status-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid #cdd7cf;
  border-radius: 999px;
  background: #eef7f0;
  color: #245d35;
  font-size: 0.76rem;
  font-weight: 900;
  white-space: nowrap;
}
.status-pill.pending { background: #fff8e5; color: #7d5a00; border-color: #f2dfaa; }
.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  display: inline-grid;
  place-items: center;
}

.seller-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.total-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 108px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.total-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
}
#grandTotal {
  display: block;
  font-size: clamp(2.7rem, 16vw, 4.45rem);
  line-height: 0.92;
  margin-top: 2px;
}
.total-side {
  min-width: 112px;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-align: right;
}
.total-side b { display: block; color: var(--ink); font-size: 1.08rem; }
.total-side .balance-due,
.total-side .balance-due b { color: var(--danger); }
.clear-sale-button,
.clear-cash-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-weight: 950;
  line-height: 1;
}
.clear-sale-button {
  width: auto;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 0.68rem;
  text-transform: uppercase;
}
.clear-sale-button:hover,
.clear-cash-button:hover { color: var(--danger); border-color: #efc5c5; background: #fff5f5; }
.cash-input-wrap { display: block; }
.cash-input-wrap input { padding-right: 12px; }
.clear-cash-button {
  width: 46px;
  height: 46px;
  min-width: 46px;
  min-height: 46px;
  align-self: end;
  font-size: 1.05rem;
}

.item-grid {
  flex: 1 1 auto;
  min-height: 300px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 128px;
  gap: 10px;
}
.item-tile {
  position: relative;
  min-height: 0;
  height: 128px;
}
.item-button {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 8px;
  padding: 14px 12px 12px 14px;
  color: #fff;
  box-shadow: 0 10px 24px rgba(32, 37, 44, 0.18);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
  overflow: hidden;
}
.item-button::after {
  content: "";
  position: absolute;
  inset: auto -26px -36px auto;
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: rgba(255,255,255,0.14);
}
.item-button span { position: relative; z-index: 1; }
.item-label {
  display: block;
  width: 100%;
  padding-right: 78px;
  font-size: clamp(1.06rem, 4.45vw, 1.38rem);
  line-height: 1.16;
  font-weight: 900;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}
.item-tile.has-qty .item-label { width: 100%; }
.item-price { font-size: clamp(1.42rem, 6.6vw, 2rem); font-weight: 950; line-height: 1; }
.tile-stepper {
  position: absolute;
  top: 10px;
  right: 8px;
  z-index: 3;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 18px rgba(32, 37, 44, 0.18);
}
.item-tile.has-qty .tile-stepper { display: flex; }
.item-qty {
  min-width: 26px;
  height: 30px;
  color: var(--ink);
  display: grid;
  place-items: center;
  font-weight: 950;
}
.item-tile:nth-child(5n+1) .item-button { background: var(--green); }
.item-tile:nth-child(5n+2) .item-button { background: var(--coral); }
.item-tile:nth-child(5n+3) .item-button { background: var(--amber); color: #231d08; }
.item-tile:nth-child(5n+4) .item-button { background: var(--blue); }
.item-tile:nth-child(5n+5) .item-button { background: var(--graphite); }
.tile-minus {
  width: 34px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  line-height: 1;
  font-weight: 950;
}

.receipt-drawer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.drawer-summary {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 0;
  background: var(--panel);
  color: var(--ink);
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  font-weight: 900;
}
.receipt-details { display: none; padding: 0 12px 10px; }
.receipt-drawer.open .receipt-details { display: block; }
.receipt-drawer.open .drawer-summary svg { transform: rotate(180deg); }
.receipt-lines {
  display: grid;
  gap: 2px;
  padding-top: 2px;
}
.receipt-line, .total-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-size: 0.92rem;
}
.receipt-line {
  min-height: 34px;
  padding: 2px 0;
}
.receipt-line .line-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.receipt-line .line-price {
  font-weight: 800;
  text-align: right;
}
.receipt-line b { font-weight: 950; }
.receipt-minus {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  display: grid;
  place-items: center;
  line-height: 1;
  font-weight: 950;
}
.totals-breakdown {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 3px;
}
.total-row { grid-template-columns: 1fr auto; font-weight: 800; color: var(--muted); }
.total-row.strong { color: var(--ink); font-size: 1.05rem; }
.total-row.discount { color: #1b7b53; }

.cash-strip {
  display: grid;
  grid-template-columns: minmax(132px, 0.72fr) 46px minmax(0, 1.28fr);
  gap: 8px;
  align-items: end;
}
.cash-input input { font-size: 1rem; font-weight: 900; }
.quick-cash { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.quick-cash button,
.action-bar button,
.button-row button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
}
.quick-cash button { background: #eef4f2; font-size: 0.92rem; padding-left: 4px; padding-right: 4px; }
.action-bar {
  display: grid;
  grid-template-columns: 1.45fr 0.75fr 0.75fr;
  gap: 8px;
}
.primary-action { background: var(--ink) !important; color: #fff !important; border-color: var(--ink) !important; }
.danger-button { color: var(--danger) !important; border-color: #efc5c5 !important; }
.action-bar button:disabled {
  cursor: default;
  opacity: 1;
}
.action-bar button:disabled:not(.history-off) {
  background: #e5e9df;
  color: #7c867b;
  border-color: #d3dacd;
}
.action-bar .history-off {
  background: #f4eee1;
  color: #8a6500;
  border-color: #ead8ac;
}

.modal {
  width: min(94vw, 460px);
  border: 0;
  border-radius: 12px;
  padding: 0;
  box-shadow: var(--shadow);
}
.wide-modal { width: min(94vw, 760px); max-height: 92dvh; }
.modal::backdrop { background: rgba(22, 25, 29, 0.52); }
.modal-frame { padding: 16px; margin: 0; background: var(--bg); }
.wide-modal .modal-frame { padding-bottom: 0; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.modal-header h2 { margin: 0; font-size: 1.4rem; }
.eyebrow { display: block; color: var(--muted); font-size: 0.72rem; font-weight: 900; text-transform: uppercase; }
.modal-help { color: var(--muted); margin: 0 0 12px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.tab { min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 0 12px; font-weight: 900; }
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tab.tab-dirty::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 7px;
  border-radius: 999px;
  background: var(--amber);
  vertical-align: middle;
}
.tab.active.tab-dirty::after { background: #ffffff; }
.admin-panel { display: none; }
.admin-panel.active { display: grid; gap: 12px; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.admin-grid.one { grid-template-columns: 1fr; }
.toggle-row { min-height: 46px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px; display: flex !important; align-items: center; gap: 8px; color: var(--ink) !important; text-transform: none !important; font-size: 0.92rem !important; }
.editor-card, .admin-list, .history-summary, #jsonPreview { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.editor-card h3 { margin: 0 0 10px; }
.admin-note { margin: 8px 0 0; color: var(--muted); font-size: 0.92rem; font-weight: 800; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.button-row.right { justify-content: flex-end; }
.admin-list { display: grid; gap: 8px; }
.admin-list-row, .history-day, .history-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.admin-list-row:last-child, .history-day:last-child, .history-item:last-child { border-bottom: 0; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.check-grid label { min-height: 42px; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-weight: 800; }
#jsonPreview { min-height: 280px; resize: vertical; font-family: Consolas, Monaco, monospace; font-size: 0.84rem; }
.admin-savebar {
  position: sticky;
  bottom: 0;
  z-index: 4;
  margin: 14px -16px 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(246, 247, 242, 0.96);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
#adminSaveStatus {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}
.admin-dirty #adminSaveStatus { color: #8a6500; }
.pin-input { width: 100%; min-height: 58px; border: 1px solid var(--line); border-radius: 8px; font-size: 1.8rem; text-align: center; letter-spacing: 0; }
.error-text { min-height: 1.2em; color: var(--danger); font-weight: 800; }
.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; font-weight: 900; transition: opacity 160ms ease, transform 160ms ease; z-index: 20; max-width: min(92vw, 420px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 700px) {
  .app-shell { width: min(100%, 1120px); }
  .seller-view { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr); grid-template-rows: auto 1fr auto; }
  .total-card { grid-column: 1 / -1; }
  .item-grid { grid-row: 2 / 4; min-height: 540px; }
  .receipt-drawer { grid-column: 2; grid-row: 2; }
  .receipt-details { display: block; }
  .drawer-summary svg { display: none; }
  .cash-strip, .action-bar { grid-column: 2; }
}

@media (max-width: 699px) {
  .tabs {
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .tab {
    flex: 1 1 calc((100% - 12px) / 3);
    padding: 0 8px;
    font-size: 0.92rem;
  }
  .cash-strip {
    grid-template-columns: minmax(0, 1fr) 46px;
  }
  .quick-cash {
    grid-column: 1 / -1;
  }
  .cash-input input {
    font-size: 1.12rem;
  }
}

@media (max-width: 390px) {
  .app-shell { padding-left: 8px; padding-right: 8px; gap: 8px; }
  .item-grid { gap: 8px; min-height: 286px; grid-auto-rows: 118px; }
  .item-tile { min-height: 0; height: 118px; }
  .item-button { min-height: 0; padding: 12px 10px 10px 12px; }
  .item-label { padding-right: 74px; font-size: clamp(1rem, 4.2vw, 1.26rem); }
  .total-card { min-height: 96px; padding: 12px; }
  .cash-strip { grid-template-columns: minmax(0, 1fr) 42px; }
  .clear-cash-button { width: 42px; min-width: 42px; }
  .admin-grid, .check-grid { grid-template-columns: 1fr; }
}

.item-order-row {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}
.item-order-row.selected .list-pick {
  border-color: var(--ink);
  background: #f1f4ef;
}
.list-pick {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
  font-weight: 900;
}
.list-pick span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.order-buttons {
  display: grid;
  grid-template-columns: repeat(2, 38px);
  gap: 6px;
}
.order-buttons button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  font-weight: 950;
}
.order-buttons button:disabled {
  opacity: 0.35;
}
