:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #65758b;
  --line: #d9e0e8;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--brand);
}

button.primary,
button.active,
.segmented button.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

button.danger {
  color: var(--danger);
  border-color: #fecaca;
}

input,
select,
textarea {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  min-width: 0;
}

textarea {
  resize: vertical;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #e7f5f2, #f7efe4);
}

.login-panel {
  width: min(380px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  display: grid;
  gap: 16px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 26px;
}

.login-panel label {
  display: grid;
  gap: 6px;
}

.error-text {
  margin: 0;
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}

.sidebar {
  background: #14213d;
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar h1 {
  margin: 0;
  font-size: 22px;
}

.sidebar p {
  color: #cbd5e1;
  margin: 8px 0 0;
}

.sidebar-logout {
  width: 100%;
  margin-top: 12px;
  color: #dbeafe;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.25);
}

.sidebar-logout:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.nav-btn {
  color: #dbeafe;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.15);
  text-align: left;
}

.sub-nav-btn {
  margin-left: 16px;
  padding-left: 16px;
  font-size: 14px;
  color: #bfdbfe;
}

.nav-btn.active {
  background: #0f766e;
  color: #fff;
}

.nav-btn.parent-active {
  background: rgba(15, 118, 110, 0.28);
  color: #fff;
}

main {
  padding: 22px;
  overflow-x: hidden;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-head h2 {
  margin: 0;
  font-size: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.panel h3 {
  margin: 0 0 12px;
  font-size: 17px;
}

.delivery-toolbar {
  display: grid;
  grid-template-columns: 180px repeat(3, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

.delivery-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.delivery-status-new {
  background: #fef3c7;
  color: #92400e;
}

.delivery-status-accepted,
.delivery-status-preparing {
  background: #dbeafe;
  color: #1d4ed8;
}

.delivery-status-delivering {
  background: #dcfce7;
  color: #166534;
}

.delivery-status-completed {
  background: #e0f2fe;
  color: #0369a1;
}

.delivery-status-cancelled {
  background: #fee2e2;
  color: #991b1b;
}

.delivery-status-ready {
  background: #dcfce7;
  color: #166534;
}

.delivery-status-out_of_stock {
  background: #fee2e2;
  color: #991b1b;
}

.delivery-status-refunding {
  background: #fef3c7;
  color: #92400e;
}

.delivery-status-refunded {
  background: #e0f2fe;
  color: #0369a1;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 28px 8px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.two-column,
.cashier-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 0.9fr);
  gap: 16px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented.full-width {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
}

.segmented.compact button {
  padding: 8px 14px;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

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

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

.product-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 8px;
  position: relative;
}

.product-card.half-price-product {
  border-color: #f59e0b;
  background: #fff7ed;
  box-shadow: inset 0 0 0 1px #fed7aa;
}

.product-card.half-price-product strong {
  color: #92400e;
}

.product-card.bbq-product {
  border-color: #16a34a;
  background: #f0fdf4;
  box-shadow: inset 0 0 0 1px #bbf7d0;
}

.product-card.bbq-product strong {
  color: #166534;
}

.promo-badge {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #f59e0b;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.category-badge {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #16a34a;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.product-card strong {
  font-size: 16px;
}

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

.product-card input {
  width: 100%;
}

.custom-product-box {
  margin-top: 12px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 0.5fr 0.7fr auto;
  gap: 8px;
  align-items: end;
}

.custom-product-box > div {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.custom-product-box strong {
  color: var(--text);
  font-size: 15px;
}

.quantity-cell {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.quantity-cell span {
  color: var(--muted);
  font-size: 13px;
}

.cart-section-row td {
  padding: 8px 10px;
  border-bottom: 0;
  font-weight: 700;
}

.cart-section-row td > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cart-section-row.beer-section td {
  background: #e0f2fe;
  color: #075985;
}

.cart-section-row.bbq-section td {
  background: #ffedd5;
  color: #9a3412;
}

.cart-item-row.beer-item {
  background: #f0f9ff;
}

.cart-item-row.bbq-item {
  background: #fff7ed;
}

.cart-category-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.cart-category-badge.beer-badge {
  background: #bae6fd;
  color: #075985;
}

.cart-category-badge.bbq-badge {
  background: #fed7aa;
  color: #9a3412;
}

.member-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.member-box select,
.member-box .muted,
.member-box .balance-preview {
  grid-column: 1 / -1;
}

.balance-preview {
  padding: 9px 10px;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  background: #f0fdf4;
  color: #166534;
  font-size: 13px;
  font-weight: 700;
}

.balance-preview.warning {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

.table-selector {
  display: grid;
  grid-template-columns: minmax(180px, 0.6fr) minmax(0, 1fr);
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
}

.table-selector label,
.table-config label,
.order-remark-box {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.order-remark-box {
  margin-bottom: 12px;
}

.table-config {
  max-width: 460px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.table-create {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px auto;
  gap: 10px;
  align-items: end;
}

.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.table-order-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.table-order-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 8px;
  text-align: left;
  min-height: 156px;
}

.table-order-card:hover:not(:disabled) {
  border-color: var(--brand);
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.12);
}

.table-order-card:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.table-order-card strong {
  font-size: 18px;
}

.table-order-card .status-pill {
  justify-self: start;
}

.table-order-card .table-order-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
}

.table-order-remark {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.table-order-card.occupied {
  border-color: #f59e0b;
  background: #fff7ed;
}

.table-order-card.free {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.table-order-card.disabled {
  background: #f8fafc;
}

#tableOrderDialog {
  width: min(1280px, calc(100vw - 32px));
}

.dialog-body.table-order-dialog {
  width: 100%;
  max-height: calc(100vh - 30px);
  overflow: auto;
}

.table-order-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.table-order-head h3 {
  margin: 0 0 4px;
}

.table-order-workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(460px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.table-order-workspace > section {
  min-width: 0;
}

.table-order-dialog .product-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.table-order-dialog .custom-product-box {
  grid-template-columns: minmax(160px, 1fr) 90px 82px 112px auto;
}

.table-order-dialog table {
  table-layout: fixed;
}

.table-order-dialog th,
.table-order-dialog td {
  word-break: break-word;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.free {
  background: #dcfce7;
  color: #166534;
}

.status-pill.occupied {
  background: #fed7aa;
  color: #92400e;
}

.status-pill.disabled {
  background: #e2e8f0;
  color: #475569;
}

.pending-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  background: #fff7ed;
  color: #92400e;
  font-size: 14px;
  font-weight: 700;
}

.pending-context button {
  background: #fff;
}

.muted {
  color: var(--muted);
}

.checkout-box {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

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

.pending-orders {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

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

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

.discount-options label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.discount-options label select,
.discount-options label input {
  color: var(--text);
}

.check-option {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

.check-option input {
  min-height: auto;
  width: 16px;
  height: 16px;
}

.promotion-hint {
  background: #fff7ed;
  color: var(--accent);
  border: 1px solid #fed7aa;
  border-radius: 6px;
  padding: 10px;
}

.amount-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
}

.amount-line.total {
  font-size: 22px;
}

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

.category-payable-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 700;
}

.category-payable-line.beer-total {
  background: #e0f2fe;
  color: #075985;
}

.category-payable-line.bbq-total {
  background: #ffedd5;
  color: #9a3412;
}

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

.employee-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.finance-filter label,
.order-filter label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.order-summary-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.order-filter {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) repeat(4, minmax(120px, 1fr)) auto auto;
  gap: 10px;
  align-items: end;
}

.bbq-order-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  font-size: 12px;
  font-weight: 700;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 14px;
}

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

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

.expense-form input[readonly] {
  background: #f8fafc;
  color: var(--muted);
}

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

.order-edit-head label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.order-edit-member {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.3fr);
  gap: 8px;
}

.order-edit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.wide-dialog input,
.wide-dialog select {
  width: 100%;
}

.receipt-template-editor {
  width: 100%;
  min-height: 460px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.5;
}

.receipt-preview-dialog {
  width: min(520px, calc(100vw - 32px));
}

.receipt-preview-paper {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.receipt-preview-paper h3 {
  text-align: center;
}

.receipt-preview-paper p {
  margin: 6px 0;
}

.receipt-preview-total {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.receipt-preview-total p {
  display: flex;
  justify-content: space-between;
}

.receipt-preview-total .total {
  font-size: 20px;
}

.receipt-preview-warning {
  color: var(--danger);
  font-weight: 700;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.settings-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.settings-grid input[readonly] {
  background: #f8fafc;
  color: var(--muted);
}

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

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

button.danger {
  color: var(--danger);
  border-color: #fecaca;
}

button.danger:hover {
  background: #fef2f2;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #111827;
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.dialog-body {
  width: 360px;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.wide-dialog {
  width: min(860px, calc(100vw - 32px));
}

.dialog-body h3,
.dialog-body p {
  margin: 0;
}

.custom-recharge {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.custom-recharge label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.custom-recharge .amount-line {
  grid-column: 1 / -1;
}

.dialog-body menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0;
  margin: 0;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 52vh;
  overflow: auto;
}

.history-row {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafcff;
  line-height: 1.6;
}

@media (max-width: 1100px) {
  .metric-grid,
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-column,
  .cashier-grid {
    grid-template-columns: 1fr;
  }

  .table-order-workspace {
    grid-template-columns: 1fr;
  }

  .table-order-dialog .custom-product-box {
    grid-template-columns: 1fr 110px;
  }

  .table-order-dialog .custom-product-box > div,
  .table-order-dialog .custom-product-box button {
    grid-column: 1 / -1;
  }

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

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  main {
    padding: 14px;
  }

  .metric-grid,
  .product-grid,
  .form-row,
  .custom-product-box,
  .table-selector,
  .table-config,
  .table-create,
  .order-summary-grid,
  .order-filter {
    grid-template-columns: 1fr;
  }

  .category-payable-grid,
  .checkout-options,
  .discount-options {
    grid-template-columns: 1fr;
  }

  .pager {
    justify-content: stretch;
  }
}
