*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --bg: #f5f0ff;
  --surface: #fdfaff;
  --surface-strong: #ffffff;
  --ink: #28163d;
  --muted: #786a92;
  --line: #e4d8f6;
  --brand: #6b21a8;
  --brand-strong: #581c87;
  --brand-soft: #f3e8ff;
  --accent: #8b5cf6;
  --danger: #c03272;
  --danger-soft: #fbe7f2;
  --success: #7c3aed;
  --shadow: 0 12px 28px rgba(76, 33, 117, 0.08);
  --shadow-raised: 0 18px 36px rgba(89, 28, 135, 0.18);
  --radius: 18px;
  --radius-sm: 13px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --font: "Avenir Next", "Trebuchet MS", sans-serif;
}

html {
  min-height: 100%;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(139, 92, 246, 0.14), transparent 26%),
    radial-gradient(circle at top right, rgba(107, 33, 168, 0.12), transparent 24%),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 56%, #eee6ff 100%);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior-y: none;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button,
a {
  touch-action: manipulation;
}

a {
  color: inherit;
}

h1,
h2,
p {
  margin-top: 0;
}

.app-shell {
  min-height: 100vh;
}

.app-main {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 1rem 1rem calc(5.4rem + var(--safe-bottom));
}

.app-main-order {
  width: 100%;
  max-width: none;
  padding: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.9rem;
  padding: calc(0.8rem + var(--safe-top)) max(1rem, var(--safe-right)) 0.8rem max(1rem, var(--safe-left));
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid rgba(138, 102, 188, 0.18);
  backdrop-filter: blur(16px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.78rem;
  min-width: 0;
  flex: 1 1 220px;
}

.brand-mark {
  display: block;
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-copy {
  display: grid;
  min-width: 0;
  gap: 0.14rem;
}

.brand-name {
  color: var(--brand);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-actions,
.order-actions,
.row-actions,
.settings-actions,
.header-button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.topbar-actions {
  justify-content: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  padding: 0.68rem 1rem;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  transition: transform 120ms ease, background 120ms ease, color 120ms ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-strong);
}

.btn-ghost {
  background: rgba(107, 33, 168, 0.08);
  color: var(--brand);
}

.btn-ghost:hover,
.btn-ghost.is-active {
  background: rgba(107, 33, 168, 0.16);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

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

.btn-block {
  width: 100%;
}

.btn-lg {
  min-height: 54px;
  font-size: 1rem;
}

.btn-sm {
  min-height: 38px;
  padding: 0.5rem 0.78rem;
  font-size: 0.84rem;
}

.badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  border-radius: 999px;
  padding: 0.28rem 0.58rem;
  font-size: 0.75rem;
  font-weight: 800;
}

.badge {
  background: rgba(107, 33, 168, 0.09);
  color: var(--brand);
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 36px;
  margin-bottom: 0.9rem;
  padding: 0.45rem 0.58rem;
}

.status-online {
  background: rgba(107, 33, 168, 0.12);
  color: var(--success);
}

.status-offline {
  background: rgba(139, 92, 246, 0.14);
  color: var(--accent);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-copy,
.status-note,
.subtle-copy,
.editor-row span,
.order-meta-line {
  color: var(--muted);
  font-size: 0.88rem;
}

.page-stack {
  display: grid;
  gap: 0.9rem;
}

.section-card,
.hero-card,
.card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(138, 102, 188, 0.14);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section-card,
.hero-card {
  padding: 1rem;
}

.hero-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.9rem;
}

.hero-card h1,
.section-head h1,
.section-head h2 {
  margin-bottom: 0;
}

.hero-card p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}

.list-stack {
  display: grid;
  gap: 0.68rem;
}

.empty-state {
  padding: 1rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.order-card {
  overflow: hidden;
}

.order-card-main {
  display: flex;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.9rem;
  text-decoration: none;
}

.order-card-main:active {
  background: var(--brand-soft);
}

.order-card-closed {
  opacity: 0.76;
}

.order-id {
  font-size: 1.02rem;
  font-weight: 800;
}

.order-summary {
  display: grid;
  gap: 0.14rem;
  justify-items: end;
  font-size: 0.87rem;
}

.order-actions {
  padding: 0 0.9rem 0.9rem;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.82rem;
}

.field-wide {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 0.38rem;
}

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

.field input,
.field select,
.field textarea,
.inline-form input,
.inline-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-strong);
  padding: 0.78rem 0.84rem;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
}

.inline-form-wide {
  grid-template-columns: 1.1fr 1.2fr 0.7fr auto;
}

.stack-form {
  display: grid;
  gap: 0.9rem;
}

.file-label {
  position: relative;
  overflow: hidden;
}

.file-label input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Order-taking workspace */
.order-screen {
  min-height: 100dvh;
  padding: 0 0 calc(6rem + var(--safe-bottom));
  background: #f7f2ff;
}

.order-toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.62rem;
  min-height: calc(58px + var(--safe-top));
  padding: calc(0.48rem + var(--safe-top)) max(0.72rem, var(--safe-right)) 0.48rem max(0.72rem, var(--safe-left));
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: #fff;
  box-shadow: 0 8px 24px rgba(88, 28, 135, 0.24);
}

.order-toolbar-btn,
.order-toolbar-action,
.cart-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 800;
}

.order-toolbar-btn {
  width: 42px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 1.22rem;
}

.order-toolbar-title {
  display: grid;
  min-width: 0;
  gap: 0.04rem;
}

.order-toolbar-title strong {
  font-size: 1rem;
}

.order-toolbar-title span {
  overflow: hidden;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.71rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-toolbar-action {
  min-width: 62px;
  padding: 0.48rem 0.7rem;
  background: #fff;
  color: var(--brand);
  font-size: 0.8rem;
}

.order-toolbar-action.is-reopen {
  color: var(--accent);
}

.order-context {
  position: sticky;
  top: calc(58px + var(--safe-top));
  z-index: 24;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.58rem;
  padding: 0.56rem max(0.72rem, var(--safe-right)) 0.56rem max(0.72rem, var(--safe-left));
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.order-table-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.52rem;
}

.order-table-field span {
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.order-table-field input,
.order-notes textarea {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  padding: 0.62rem 0.66rem;
  font-size: 0.9rem;
}

.order-notes {
  position: relative;
}

.order-notes summary {
  display: flex;
  align-items: center;
  min-height: 40px;
  border-radius: 999px;
  padding: 0 0.72rem;
  background: var(--brand-soft);
  color: var(--brand);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
  list-style: none;
}

.order-notes summary::-webkit-details-marker {
  display: none;
}

.order-notes textarea {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 35;
  width: min(82vw, 360px);
  min-height: 112px;
  box-shadow: var(--shadow-raised);
}

.order-menu {
  padding: 0;
}

.category-tabs {
  position: sticky;
  top: calc(98px + var(--safe-top));
  z-index: 22;
  display: flex;
  gap: 0.46rem;
  overflow-x: auto;
  margin: 0;
  padding: 0.56rem max(0.72rem, var(--safe-right)) 0.6rem max(0.72rem, var(--safe-left));
  background: rgba(247, 242, 255, 0.96);
  border-bottom: 1px solid rgba(138, 102, 188, 0.16);
  scrollbar-width: none;
  backdrop-filter: blur(14px);
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.category-tab {
  flex: 0 0 auto;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 0.62rem 0.78rem;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.category-tab.is-active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.62rem;
  padding: 0.72rem max(0.72rem, var(--safe-right)) 0.9rem max(0.72rem, var(--safe-left));
}

.menu-tile {
  position: relative;
  display: grid;
  align-content: space-between;
  gap: 0.4rem;
  min-height: 86px;
  overflow: hidden;
  border: 1px solid rgba(107, 33, 168, 0.14);
  border-radius: 15px;
  background: var(--surface-strong);
  padding: 0.78rem 0.72rem;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: border 140ms ease, box-shadow 140ms ease, transform 100ms ease;
}

.menu-tile:active {
  transform: scale(0.96);
}

.menu-tile.is-selected {
  border: 2px solid var(--accent);
  padding: calc(0.78rem - 1px) calc(0.72rem - 1px);
  background: linear-gradient(145deg, #ffffff, #f5eeff);
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.14);
}

.menu-tile-name {
  max-width: calc(100% - 1.6rem);
  font-size: 0.89rem;
  font-weight: 700;
  line-height: 1.16;
}

.menu-tile strong {
  color: var(--brand);
  font-size: 0.86rem;
}

.menu-tile-quantity {
  position: absolute;
  top: 0.46rem;
  right: 0.46rem;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.5);
  background: var(--accent);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 900;
  transition: opacity 130ms ease, transform 130ms ease;
}

.menu-tile-quantity.is-visible {
  opacity: 1;
  transform: scale(1);
}

.menu-tile-added {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(0.88);
  background: rgba(107, 33, 168, 0.94);
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
  pointer-events: none;
}

.menu-tile.just-added .menu-tile-added {
  animation: tile-added 560ms ease;
}

.order-cart-bar {
  position: fixed;
  right: max(0.72rem, var(--safe-right));
  bottom: calc(0.72rem + var(--safe-bottom));
  left: max(0.72rem, var(--safe-left));
  z-index: 32;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.72rem;
  min-height: 68px;
  border: 1px solid rgba(107, 33, 168, 0.24);
  border-radius: 17px;
  background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
  padding: 0.68rem 0.78rem;
  color: #fff;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow-raised);
  transition: transform 140ms ease;
}

.order-cart-bar.just-updated {
  animation: cart-bump 440ms ease;
}

.cart-icon {
  display: grid;
  min-width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.cart-summary {
  display: grid;
  min-width: 0;
  gap: 0.06rem;
}

.cart-summary small {
  overflow: hidden;
  color: rgba(255, 255, 255, 0.72);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cart-total {
  white-space: nowrap;
}

.order-cart-backdrop {
  position: fixed;
  inset: 0;
  z-index: 44;
  opacity: 0;
  visibility: hidden;
  background: rgba(40, 22, 61, 0.46);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.order-cart-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 45;
  max-height: min(78dvh, 720px);
  overflow: hidden;
  transform: translateY(105%);
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: 0 -18px 44px rgba(63, 28, 102, 0.2);
  transition: transform 210ms ease;
}

.is-cart-open .order-cart-backdrop {
  opacity: 1;
  visibility: visible;
}

.is-cart-open .order-cart-sheet {
  transform: translateY(0);
}

.cart-sheet-handle {
  width: 42px;
  height: 4px;
  margin: 0.52rem auto 0.2rem;
  border-radius: 999px;
  background: var(--line);
}

.cart-sheet-header,
.cart-sheet-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.72rem 1rem;
}

.cart-sheet-header {
  border-bottom: 1px solid var(--line);
}

.cart-sheet-header span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.cart-sheet-header h2 {
  margin: 0.06rem 0 0;
  font-size: 1.18rem;
}

.cart-close-btn {
  width: 42px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 1.32rem;
}

.cart-sheet-items {
  max-height: calc(min(78dvh, 720px) - 142px);
  overflow-y: auto;
  padding: 0.16rem 1rem;
  overscroll-behavior: contain;
}

.cart-sheet-footer {
  min-height: calc(62px + var(--safe-bottom));
  padding-bottom: calc(0.72rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
  color: var(--brand);
  font-size: 1.08rem;
}

.cart-empty {
  margin: 0.8rem 0;
}

.order-item-row,
.editor-row {
  display: grid;
  align-items: center;
  gap: 0.68rem;
  padding: 0.78rem 0;
  border-top: 1px solid rgba(138, 102, 188, 0.12);
}

.order-item-row {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.editor-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.order-item-row:first-child,
.editor-row:first-child {
  border-top: 0;
}

.order-item-copy {
  display: grid;
  min-width: 0;
  gap: 0.18rem;
}

.order-item-copy strong {
  overflow: hidden;
  font-size: 0.9rem;
  line-height: 1.12;
  text-overflow: ellipsis;
}

.order-item-copy span {
  color: var(--muted);
  font-size: 0.76rem;
}

.qty-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.46rem;
  justify-content: center;
}

.qty-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 900;
}

.qty-btn:active {
  transform: scale(0.9);
}

.order-item-total {
  color: var(--brand);
  font-size: 0.84rem;
  white-space: nowrap;
}

.remove-item-btn {
  grid-column: 2 / -1;
  justify-self: end;
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 800;
}

.full-width {
  grid-column: 1 / -1;
}

.toast {
  position: fixed;
  right: 0.9rem;
  bottom: calc(5.8rem + var(--safe-bottom));
  left: 0.9rem;
  z-index: 70;
  max-width: 520px;
  margin: 0 auto;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(16px);
  background: linear-gradient(135deg, var(--brand-strong) 0%, var(--brand) 100%);
  padding: 0.76rem 0.92rem;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  text-align: center;
  transition: opacity 150ms ease, transform 150ms ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes tile-added {
  0% {
    opacity: 0;
    transform: scale(0.88);
  }
  24%,
  62% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.05);
  }
}

@keyframes cart-bump {
  0%,
  100% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.025);
  }
}

@media (min-width: 700px) {
  .menu-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .order-cart-bar {
    right: max(calc((100vw - 760px) / 2), 1rem);
    left: max(calc((100vw - 760px) / 2), 1rem);
  }

  .order-cart-sheet {
    right: max(calc((100vw - 760px) / 2), 0px);
    left: max(calc((100vw - 760px) / 2), 0px);
  }
}

@media (min-width: 1050px) {
  .menu-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    min-height: calc(64px + var(--safe-top));
    gap: 0.75rem;
    padding-bottom: 0.75rem;
  }

  .topbar-brand {
    flex-basis: 100%;
  }

  .brand-mark {
    width: 54px;
    height: 54px;
  }

  .topbar-actions {
    position: static;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 0.35rem;
    padding: 0;
    background: transparent;
    border-top: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .topbar-actions .btn {
    min-height: 44px;
    padding: 0.46rem 0.24rem;
    border-radius: 12px;
    font-size: 0.74rem;
  }

  .topbar-actions .btn-install {
    display: none;
  }

  .hero-card {
    display: grid;
    align-items: stretch;
  }

  .field-grid,
  .inline-form,
  .inline-form-wide {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 360px) {
  .menu-grid {
    gap: 0.48rem;
    padding-right: 0.55rem;
    padding-left: 0.55rem;
  }

  .menu-tile {
    min-height: 82px;
    padding: 0.66rem 0.6rem;
  }

  .menu-tile.is-selected {
    padding: calc(0.66rem - 1px) calc(0.6rem - 1px);
  }

  .menu-tile-name {
    font-size: 0.82rem;
  }
}
