:root {
  --bg: #0b0d10;
  --surface: #151920;
  --surface-soft: #1e242e;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #28303d;
  --accent: #f59e0b;
  --accent-soft: rgba(245, 158, 11, 0.16);
  --accent-text: #fbbf24;
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.16);
  --red: #f87171;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-x: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: max(36px, env(safe-area-inset-bottom));
}

button, input, select {
  font-family: inherit;
  touch-action: manipulation;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 13, 16, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  font-size: 26px;
  line-height: 1;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.sync-status.offline .sync-dot {
  background: var(--red);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.nickname-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

/* Main Navigation */
.main-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.main-nav-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  gap: 4px;
}

.nav-tab {
  flex: 1;
  max-width: 240px;
  border: none;
  background: transparent;
  padding: 13px 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.nav-tab.active {
  color: var(--accent-text);
  border-bottom-color: var(--accent);
}

.nav-badge {
  background: var(--accent);
  color: #111827;
  font-size: 11px;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 20px;
}

.nav-badge.muted-badge {
  background: var(--surface-soft);
  color: var(--text-muted);
}

/* Main Container */
.main-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* Shop Selector */
.shop-selector {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

@media (max-width: 640px) {
  .shop-selector {
    grid-template-columns: repeat(2, 1fr);
  }
}

.shop-card {
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: border-color 0.15s, background 0.15s;
}

.shop-logo-wrap {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  padding: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.shop-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.sheet-shop-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-text);
  background: var(--accent-soft);
  padding: 3px 10px 3px 5px;
  border-radius: 999px;
  margin-bottom: 6px;
}

.sheet-shop-logo {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  padding: 1px;
  object-fit: contain;
}

.shop-card:hover {
  border-color: #3f4b5e;
}

.shop-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.shop-card-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.shop-card.active .shop-card-name {
  color: var(--accent-text);
}

/* Nearest Branch Bar */
.nearest-branch-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.branch-info {
  font-size: 13.5px;
  color: var(--text);
}

.branch-addr {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-left: 6px;
}

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

.branch-phone-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.branch-delivery-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--green-soft);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.4);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12.5px;
  font-weight: 700;
}

/* Search */
.menu-toolbar {
  margin-bottom: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-box input[type="search"] {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  font-size: 16px;
  background: transparent;
  color: var(--text);
}

.search-box input[type="search"]::placeholder {
  color: var(--text-muted);
}

/* Category Bar */
.category-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
  scrollbar-width: none;
}

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

.cat-chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.cat-chip:hover {
  border-color: var(--accent);
  color: var(--accent-text);
}

/* Menu Grid */
.menu-category-block {
  margin-bottom: 22px;
}

.menu-category-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 800;
  color: var(--accent-text);
}

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

@media (max-width: 640px) {
  .menu-grid {
    grid-template-columns: 1fr;
  }
}

.drink-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.drink-card:hover {
  border-color: var(--accent);
  background: #1b2029;
}

.drink-name {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text);
}

.drink-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.drink-prices {
  display: flex;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

.price-pill {
  background: var(--surface-soft);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text);
}

.price-pill span {
  color: var(--text-muted);
  font-size: 11px;
  margin-right: 2px;
}

.add-mini-btn {
  background: var(--accent);
  color: #111827;
  border: none;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
}

/* Orders View */
.orders-header-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.orders-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.order-item-time {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.day-merged-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.day-merged-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.day-merged-date {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent-text);
}

.day-merged-total {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}

.day-merged-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.day-merged-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

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

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.history-card summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.history-card summary::-webkit-details-marker {
  display: none;
}

.locked-tag {
  display: inline-block;
  background: var(--surface-soft);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 6px;
}

.history-items {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 13.5px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.history-item-line:last-child {
  border-bottom: none;
}

.stat-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.stat-value {
  font-size: 20px;
  font-weight: 900;
  color: var(--text);
}

.stat-value.accent {
  color: var(--accent-text);
}

.stat-value.green {
  color: var(--green);
  font-size: 16px;
}

.orders-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented-control {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 10px;
  gap: 4px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface-soft);
  color: var(--text);
}

.orders-tool-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.person-group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.person-group-card.is-me {
  border-color: var(--accent);
}

.person-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.person-name {
  font-size: 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
}

.me-badge {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
}

.person-subtotal {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent-text);
}

.order-item-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.order-item-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.order-item-info {
  flex: 1;
  min-width: 0;
}

.order-item-title {
  font-size: 15px;
  font-weight: 800;
}

.tag-shop {
  background: var(--surface-soft);
  color: #d1d5db;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  margin-right: 4px;
}

.order-item-specs {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.order-item-note {
  font-size: 12px;
  color: var(--accent-text);
  margin-top: 3px;
}

.order-item-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.order-item-price {
  font-size: 15px;
  font-weight: 800;
}

.item-mini-actions {
  display: flex;
  gap: 6px;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.chip-btn.paid {
  background: var(--green-soft);
  border-color: rgba(34, 197, 94, 0.45);
  color: #4ade80;
}

.chip-btn.danger {
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.4);
}

.merged-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.merged-qty {
  background: var(--accent);
  color: #111827;
  font-size: 16px;
  font-weight: 900;
  padding: 6px 12px;
  border-radius: 12px;
  min-width: 52px;
  text-align: center;
}

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #111827;
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.btn-secondary {
  background: var(--surface-soft);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-danger-outline {
  background: transparent;
  color: var(--red);
  border: 1.5px solid rgba(248, 113, 113, 0.45);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-lg {
  padding: 13px 18px;
  font-size: 16px;
}

.btn-full {
  width: 100%;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-overlay.hidden,
.hidden {
  display: none !important;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-sm {
  padding: 24px 20px;
  max-width: 400px;
}

.modal-emoji {
  font-size: 40px;
  text-align: center;
  margin-bottom: 6px;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}

.modal-subtitle {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.text-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 16px;
  outline: none;
  background: var(--bg);
  color: var(--text);
}

.text-input:focus {
  border-color: var(--accent);
}

.modal-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
}

/* Drink Sheet */
.sheet-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.sheet-shop-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-text);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.sheet-drink-title {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
}

.close-x {
  border: none;
  background: var(--surface-soft);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.sheet-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sheet-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-label {
  font-size: 13.5px;
  font-weight: 800;
}

.muted-inline {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 12px;
}

.option-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.opt-pill {
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}

.opt-pill.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.option-row-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 12px;
}

.eco-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.qty-stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.qty-stepper button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.qty-stepper span {
  font-size: 16px;
  font-weight: 800;
  min-width: 20px;
  text-align: center;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .empty-emoji {
  font-size: 40px;
  margin-bottom: 8px;
}

/* Toast */
.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: #f3f4f6;
  color: #111827;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mobile Responsive Auto-Fit */
@media (max-width: 480px) {
  .header-inner {
    padding: 8px 12px;
  }

  .brand-title {
    font-size: 16px;
  }

  .icon-btn,
  .nickname-pill {
    padding: 5px 10px;
    font-size: 12.5px;
  }

  .nav-tab {
    padding: 11px 6px;
    font-size: 13.5px;
  }

  .main-container {
    padding: 12px;
  }

  .shop-card {
    padding: 9px 10px;
    gap: 8px;
  }

  .shop-logo-wrap {
    width: 30px;
    height: 30px;
  }

  .shop-card-name {
    font-size: 14px;
  }

  .drink-card {
    padding: 11px 12px;
    gap: 8px;
  }

  .drink-name {
    font-size: 14.5px;
  }

  .drink-prices {
    gap: 4px;
    font-size: 12px;
  }

  .price-pill {
    padding: 2px 6px;
  }

  .orders-header-card {
    padding: 12px;
  }

  .stat-value {
    font-size: 18px;
  }

  .orders-actions-row {
    flex-direction: column;
    align-items: stretch;
  }

  .segmented-control {
    width: 100%;
  }

  .seg-btn {
    flex: 1;
    text-align: center;
  }

  .orders-tool-btns {
    width: 100%;
  }

  .orders-tool-btns button {
    flex: 1;
  }

  .modal-overlay {
    padding: 10px;
  }

  .sheet-body {
    padding: 14px 16px;
  }
}
