@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --paper: #f6f4ee;
  --panel: #ffffff;
  --ink: #201f1c;
  --ink-soft: #56534a;
  --muted: #8a8577;
  --line: #e3dfd3;
  --green: #1f4d3d;
  --green-dark: #163a2d;
  --green-tint: #e7efe9;
  --amber: #c97a2b;
  --amber-tint: #fbead9;
  --danger: #b23a2e;
  --danger-tint: #f8e4e1;

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(32, 31, 28, 0.06), 0 8px 24px -12px rgba(32, 31, 28, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--ink);
  color: #fff;
}

.topbar .brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.01em;
}

.topbar .brand .tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: #cfc9b8;
  border: 1px solid #4a473e;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topbar nav {
  display: flex;
  gap: 4px;
}

.topbar nav a {
  text-decoration: none;
  color: #cfc9b8;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.topbar nav a:hover { background: #322f28; color: #fff; }
.topbar nav a.active { background: var(--green); color: #fff; }

/* ---------- Layout shells ---------- */

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  gap: 20px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0;
}

.page-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Register screen ---------- */

.register-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}

.category-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.category-tabs button {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 13px;
  border-radius: 999px;
}

.category-tabs button.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.search-row {
  margin-bottom: 14px;
}

.search-row input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--panel);
  font-family: var(--font-body);
}

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

.product-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, border-color 0.1s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 108px;
}

.product-card:hover { transform: translateY(-2px); border-color: var(--green); }
.product-card:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.product-card .name {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
}

.product-card .meta {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.product-card .price {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--green-dark);
}

.product-card .stock {
  font-size: 11px;
  color: var(--muted);
}

.product-card .stock.low { color: var(--amber); font-weight: 600; }

/* ---------- Receipt / cart panel (signature element) ---------- */

.receipt {
  position: sticky;
  top: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 3px;
  padding: 20px 18px 26px;
  clip-path: polygon(
    0% 0%, 100% 0%, 100% 96%,
    95% 100%, 90% 96%, 85% 100%, 80% 96%, 75% 100%, 70% 96%, 65% 100%,
    60% 96%, 55% 100%, 50% 96%, 45% 100%, 40% 96%, 35% 100%, 30% 96%,
    25% 100%, 20% 96%, 15% 100%, 10% 96%, 5% 100%, 0% 96%
  );
}

.receipt-head {
  text-align: center;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.receipt-head .store {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}

.receipt-head .sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.receipt-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.receipt-empty {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

.receipt-line {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.receipt-line .row1 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.receipt-line .row1 .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-line .row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--ink-soft);
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-controls button {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-family: var(--font-mono);
  line-height: 1;
  font-size: 13px;
}

.qty-controls .remove {
  border: none;
  background: none;
  color: var(--danger);
  font-size: 11px;
  margin-left: 4px;
  text-decoration: underline;
}

.receipt-totals {
  border-top: 1px dashed var(--line);
  padding-top: 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.receipt-totals .row {
  display: flex;
  justify-content: space-between;
  color: var(--ink-soft);
}

.receipt-totals .row.total {
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  margin-top: 3px;
}

.pay-row {
  display: flex;
  gap: 6px;
  margin-top: 14px;
}

.pay-row button {
  flex: 1;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
}

.pay-row button.active {
  background: var(--green-tint);
  border-color: var(--green);
  color: var(--green-dark);
}

/* Delivery has 6 options (Free/1/1.25/1.5/1.75/Other) — a 3x2 grid reads
   better here than squeezing them into one flex row. */
#deliveryRow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 14px;
}
#deliveryRow button {
  flex: none;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
}
#deliveryRow button.active {
  background: var(--green-tint);
  border-color: var(--green);
  color: var(--green-dark);
}

.checkout-btn {
  width: 100%;
  margin-top: 12px;
  padding: 13px 0;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
}

.checkout-btn:hover { background: var(--green-dark); }
.checkout-btn:disabled { background: var(--muted); cursor: not-allowed; }

/* ---------- Buttons, generic ---------- */

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 9px 15px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
}

.btn.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.btn.primary:hover { background: var(--green-dark); }

.btn.danger {
  color: var(--danger);
  border-color: var(--danger-tint);
  background: var(--danger-tint);
}

/* ---------- Tables (Inventory / Reports) ---------- */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--paper);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfaf6; }

td.num, th.num { text-align: right; font-family: var(--font-mono); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge.low { background: var(--amber-tint); color: var(--amber); }
.badge.ok { background: var(--green-tint); color: var(--green-dark); }

.row-actions { display: flex; gap: 6px; }
.row-actions button {
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
}
.row-actions .edit { color: var(--green-dark); }
.row-actions .edit:hover { background: var(--green-tint); }
.row-actions .delete { color: var(--danger); }
.row-actions .delete:hover { background: var(--danger-tint); }

/* ---------- Cards / stat blocks (Reports) ---------- */

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

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

.stat-card .label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-card .value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
}

.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.chart-wrap h2 {
  font-family: var(--font-display);
  font-size: 14px;
  margin: 0 0 14px;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 160px;
}

.bars .bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  height: 100%;
}

.bars .bar {
  width: 100%;
  max-width: 34px;
  background: var(--green);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}

.bars .bar-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

/* ---------- Filters row ---------- */

.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.filters input, .filters select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  background: var(--panel);
  font-family: var(--font-body);
}

/* ---------- Date range picker (calendar + presets popover) ---------- */

.date-picker-wrap {
  position: relative;
  display: inline-block;
}

.date-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 60;
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.date-popover-calendar {
  padding: 14px 16px;
  width: 260px;
  border-right: 1px solid var(--line);
}

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13.5px;
}

.cal-header button {
  border: none;
  background: none;
  font-size: 16px;
  line-height: 1;
  color: var(--ink-soft);
  padding: 4px 8px;
  border-radius: 6px;
}
.cal-header button:hover { background: var(--paper); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 4px;
}

.cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  row-gap: 2px;
}

.cal-day {
  border: none;
  background: none;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink);
  padding: 7px 0;
  cursor: pointer;
  position: relative;
}

.cal-day.other-month { color: var(--line); }
.cal-day.in-range { background: var(--green-tint); }
.cal-day.range-start, .cal-day.range-end {
  background: var(--green);
  color: #fff;
  border-radius: 999px;
  font-weight: 600;
}
.cal-day.today:not(.range-start):not(.range-end) {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.date-popover-presets {
  width: 150px;
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.date-popover-presets button {
  text-align: left;
  border: none;
  background: none;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink);
}
.date-popover-presets button:hover { background: var(--paper); }
.date-popover-presets button.active { background: var(--green-tint); color: var(--green-dark); font-weight: 600; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(32, 31, 28, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.modal h2 {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0 0 16px;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.field input, .field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13.5px;
  font-family: var(--font-body);
}

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { background: var(--danger); }

/* ---------- Receipt printout modal ---------- */

.printout {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
}
.printout .center { text-align: center; }
.printout hr { border: none; border-top: 1px dashed var(--line); margin: 10px 0; }
.printout .line { display: flex; justify-content: space-between; }

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
}

.empty-state .icon { font-size: 28px; margin-bottom: 8px; }

@media (max-width: 860px) {
  .register-layout { grid-template-columns: 1fr; }
  .receipt { position: static; }
}
