:root {
  color-scheme: light;
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-strong: #fbfaf6;
  --ink: #17211f;
  --muted: #68706c;
  --line: #dedbd1;
  --primary: #147c72;
  --primary-dark: #0f5e56;
  --coral: #c84d3d;
  --amber: #c9921e;
  --nav: #11201c;
  --shadow: 0 10px 30px rgba(34, 40, 38, 0.12);
  --radius: 8px;
  --tap: 48px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 124, 114, 0.16);
}

.app-shell {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 calc(76px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(246, 244, 238, 0.96);
  border-bottom: 1px solid rgba(222, 219, 209, 0.85);
  backdrop-filter: blur(14px);
}

.topbar h1,
.screen-heading h2,
.panel-title h3 {
  margin: 0;
  line-height: 1.15;
}

.topbar h1 {
  font-size: 22px;
}

.eyebrow,
.subtext {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.topbar-actions,
.button-pair,
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill,
.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: 999px;
  background: #e7ede9;
  color: #31554f;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.network-pill.online {
  background: #e7ede9;
  color: #31554f;
}

.network-pill.offline {
  background: #fff3d6;
  color: #755000;
}

.screen-stack {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 14px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

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

.screen-heading h2 {
  font-size: 28px;
}

.primary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  border-radius: var(--radius);
  padding: 10px 15px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px rgba(20, 124, 114, 0.2);
}

.primary-button:active {
  background: var(--primary-dark);
  transform: translateY(1px);
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.danger-button {
  background: #fff0ed;
  color: #9b2f25;
  border: 1px solid #f0b8ae;
}

.compact,
.small {
  min-height: 42px;
}

.small {
  padding: 8px 11px;
  font-size: 14px;
}

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 12px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip {
  min-height: 42px;
  border-radius: 999px;
  background: #e9e4d9;
  color: #4a463d;
  padding: 8px 14px;
  font-weight: 800;
  white-space: nowrap;
}

.chip.active {
  background: var(--nav);
  color: #fff;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.menu-card {
  position: relative;
  display: grid;
  align-content: space-between;
  min-height: 98px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 12px;
  text-align: left;
  box-shadow: var(--shadow);
}

.menu-card:active {
  transform: translateY(1px);
}

.menu-card .category {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.menu-card .name {
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.25;
}

.menu-card .price {
  margin-top: 10px;
  color: var(--primary);
  font-size: 18px;
  font-weight: 900;
}

.menu-card .qty-badge {
  position: absolute;
  right: 8px;
  top: 8px;
  display: none;
  min-width: 28px;
  min-height: 28px;
  border-radius: 999px;
  background: var(--coral);
  color: #fff;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
}

.menu-card.has-qty .qty-badge {
  display: inline-flex;
}

.panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 6px 18px rgba(34, 40, 38, 0.08);
}

.order-panel {
  margin-bottom: 12px;
}

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

.panel-title h3 {
  font-size: 18px;
}

.compact-list,
.checkout-items,
.editor-list,
.history-list {
  display: grid;
  gap: 8px;
}

.compact-line,
.checkout-line,
.editor-line,
.history-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.compact-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
}

.compact-line strong,
.checkout-line strong,
.editor-line strong {
  overflow-wrap: anywhere;
}

.line-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.empty-text {
  display: none;
  margin: 12px 0 0;
  color: var(--muted);
  text-align: center;
}

.empty-text.show,
.empty-text.in-page {
  display: block;
}

.checkout-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px;
}

.qty-control {
  display: grid;
  grid-template-columns: 42px 40px 42px;
  align-items: center;
  justify-items: center;
  gap: 4px;
}

.qty-control button {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--nav);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}

.qty-control .remove-line {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 4px;
  background: #fff0ed;
  color: #9b2f25;
  border: 1px solid #f0b8ae;
  font-size: 13px;
}

.qty-number {
  min-width: 34px;
  text-align: center;
  font-weight: 900;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stepper {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  gap: 6px;
}

.stepper button {
  min-height: var(--tap);
  border-radius: var(--radius);
  background: var(--nav);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.totals-panel {
  background: #fffdfa;
}

.total-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.total-row:last-child {
  border-bottom: 0;
}

.total-row span {
  color: var(--muted);
  font-weight: 800;
}

.total-row strong {
  font-size: 18px;
}

.total-row.grand strong {
  color: var(--primary);
  font-size: 30px;
}

.total-row.per-person {
  padding-top: 12px;
}

.total-row.per-person strong {
  color: var(--coral);
  font-size: 24px;
}

.menu-form {
  display: grid;
  gap: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(0, 1.2fr);
  gap: 10px;
}

.form-actions {
  justify-content: stretch;
}

.form-actions button {
  flex: 1;
}

.backup-panel {
  display: grid;
  gap: 10px;
}

.backup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.file-button {
  cursor: pointer;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.editor-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.editor-actions button {
  min-height: 40px;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 800;
}

.edit-item {
  background: #edf5f2;
  color: #0f5e56;
}

.delete-item,
.delete-history {
  background: #fff0ed;
  color: #9b2f25;
  border: 1px solid #f0b8ae;
}

.category-heading {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.history-card {
  padding: 12px;
}

.history-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}

.history-total {
  color: var(--primary);
  font-size: 22px;
  font-weight: 900;
  text-align: right;
}

.history-items {
  margin: 10px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(17, 32, 28, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(14px);
}

.nav-item {
  min-height: 54px;
  border-radius: var(--radius);
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font-weight: 900;
}

.nav-item.active {
  background: #f6f4ee;
  color: var(--nav);
}

.toast {
  position: fixed;
  right: 14px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 14px;
  z-index: 30;
  display: none;
  border-radius: var(--radius);
  background: var(--nav);
  color: #fff;
  padding: 12px 14px;
  text-align: center;
  font-weight: 800;
  box-shadow: 0 14px 30px rgba(17, 32, 28, 0.24);
}

.toast.show {
  display: block;
}

@media (min-width: 700px) {
  .screen-stack {
    padding: 20px;
  }

  .menu-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .settings-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 390px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar-actions,
  .screen-heading {
    align-items: flex-end;
  }

  .topbar-actions {
    flex-direction: column;
    gap: 6px;
  }

  .screen-heading {
    flex-wrap: wrap;
  }

  .screen-heading > .button-pair {
    width: 100%;
  }

  .screen-heading > .button-pair button {
    flex: 1;
  }

  .settings-grid,
  .field-row,
  .backup-actions {
    grid-template-columns: 1fr;
  }

  .checkout-line,
  .editor-line {
    grid-template-columns: 1fr;
  }

  .qty-control {
    grid-template-columns: 1fr 52px 1fr;
  }

  .qty-control button {
    width: 100%;
  }
}
