:root {
  color-scheme: light;
  --bg: #f3f1ec;
  --ink: #17211f;
  --muted: #6d746f;
  --line: #ded7ca;
  --panel: #ffffff;
  --panel-warm: #fffdfa;
  --accent: #0e7669;
  --accent-dark: #0a554d;
  --jade: #0f8b72;
  --indigo: #365486;
  --plum: #704264;
  --gold: #b7791f;
  --rose: #b5485b;
  --danger: #b42318;
  --soft: #edf7f3;
  --soft-blue: #eef3fb;
  --soft-plum: #f7eef5;
  --paid: #e7f6e9;
  --unpaid: #fff2df;
  --shadow: 0 18px 50px rgba(38, 32, 24, .11);
  --shadow-soft: 0 10px 24px rgba(38, 32, 24, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(14, 118, 105, .14), rgba(183, 121, 31, .08) 310px, transparent 620px),
    linear-gradient(90deg, rgba(54, 84, 134, .08), transparent 44%, rgba(112, 66, 100, .07)),
    var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar,
.panel-title,
.line-title,
.order-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--plum);
  font-size: .78rem;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 4rem);
  letter-spacing: 0;
  line-height: .95;
  color: #15201e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .72);
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

h3 {
  margin: 0;
  font-size: .96rem;
}

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

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: rgba(255, 253, 250, .92);
  color: var(--ink);
  border: 1px solid rgba(222, 215, 202, .86);
  box-shadow: var(--shadow-soft);
  font-size: 1.25rem;
}

.icon-btn.danger {
  color: var(--danger);
}

.workflow,
.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  gap: 14px;
  align-items: start;
}

.workflow.single {
  grid-template-columns: 1fr;
}

.main-grid {
  grid-template-columns: minmax(320px, .72fr) minmax(0, 1.28fr);
  margin-top: 14px;
}

.panel {
  background: rgba(255, 253, 250, .94);
  border: 1px solid rgba(222, 215, 202, .9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(10px);
}

.upload-panel {
  background:
    linear-gradient(135deg, rgba(14, 118, 105, .1), rgba(54, 84, 134, .08)),
    var(--panel-warm);
}

.confirm-panel {
  border-top: 4px solid var(--gold);
}

.summary-panel {
  border-top: 4px solid var(--plum);
}

.orders-panel {
  border-top: 4px solid var(--accent);
}

.panel-title {
  margin-bottom: 14px;
}

.panel-title span {
  color: #7b6140;
  font-size: .88rem;
  white-space: nowrap;
  font-weight: 760;
}

.confirm-panel {
  margin-top: 14px;
}

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

.upload-form {
  display: grid;
  gap: 10px;
}

.file-drop {
  display: grid;
  gap: 6px;
  min-height: 118px;
  align-content: center;
  justify-items: center;
  border: 1px dashed rgba(14, 118, 105, .45);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .76), rgba(238, 243, 251, .9)),
    #fbfcfa;
  color: var(--muted);
  text-align: center;
  padding: 18px;
  cursor: pointer;
}

.file-drop strong {
  color: var(--accent-dark);
}

.file-drop input {
  max-width: 260px;
  min-height: auto;
  padding: 0;
  border: 0;
}

.order-fields,
.draft-row {
  display: grid;
  grid-template-columns: 1.2fr .8fr repeat(3, minmax(92px, .45fr));
  gap: 10px;
  align-items: start;
}

.draft-row {
  grid-template-columns: minmax(150px, 1fr) 96px minmax(220px, 1fr) 34px;
  border: 1px solid rgba(222, 215, 202, .92);
  border-radius: 8px;
  padding: 10px;
  background: linear-gradient(180deg, #fff, #fffdfa);
}

label span,
.sharer-cell > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #d8cfbf;
  border-radius: 8px;
  background: #fffefc;
  color: var(--ink);
  padding: 7px 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 118, 105, .14), 0 1px 0 rgba(255, 255, 255, .9) inset;
}

form button,
.full-btn,
.small-btn,
.secondary-btn {
  min-height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #0a5f76);
  color: white;
  padding: 0 14px;
  font-weight: 820;
}

.full-btn {
  width: 100%;
}

.small-btn,
.secondary-btn {
  width: auto;
  min-height: 36px;
}

.secondary-btn {
  background: #f8f4ed;
  color: var(--ink);
  border: 1px solid var(--line);
}

.confirm-actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  margin-top: 12px;
}

.person-picker {
  display: grid;
  gap: 6px;
}

.person-add-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.person-add-row .small-btn {
  min-height: 38px;
}

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

.person-tab {
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid #d8cfbf;
  background: #fffdfa;
  color: var(--ink);
  padding: 6px 12px;
  font-weight: 820;
}

.person-tab.active {
  background: linear-gradient(135deg, var(--accent), #0a5f76);
  border-color: transparent;
  color: #fff;
}

.chips,
.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
}

.chips {
  margin-top: 12px;
}

.chip,
.check-pill {
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid #d8cfbf;
  background: #fffdfa;
  color: var(--ink);
  padding: 6px 10px;
  font-weight: 760;
}

.chip::after {
  content: " ×";
  color: var(--rose);
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.check-pill input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
  padding: 0;
}

.line-title {
  margin: 18px 0 10px;
}

.items-hidden {
  display: none;
}

.draft-list,
.orders-list,
.totals,
.payment-list,
.detail-list {
  display: grid;
  gap: 8px;
}

.debt-row,
.order-card,
.detail-row {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(222, 215, 202, .92);
  border-radius: 8px;
  padding: 10px;
}

.debt-row,
.detail-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.debt-row {
  background: linear-gradient(135deg, var(--soft-plum), var(--soft-blue));
  border-left: 4px solid var(--plum);
  grid-template-columns: 1fr auto;
  align-items: stretch;
}

.debt-main,
.debt-side {
  display: grid;
  gap: 6px;
}

.debt-main {
  align-content: space-between;
}

.debt-side {
  justify-items: end;
  align-content: space-between;
  text-align: right;
}

.order-card {
  background: linear-gradient(180deg, #fff, #fffdfa);
  box-shadow: var(--shadow-soft);
}

.order-card.order-highlight {
  outline: 3px solid rgba(183, 121, 31, .38);
  outline-offset: 2px;
}

.meal-meta,
small {
  display: block;
  color: var(--muted);
  font-size: .86rem;
  margin-top: 3px;
}

.debt-links {
  display: inline;
}

.debt-link {
  background: transparent;
  color: var(--indigo);
  padding: 0;
  font-weight: 820;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  color: var(--accent-dark);
}

.remove-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #fff0f2;
  color: var(--rose);
  font-size: 1.2rem;
}

.paid-toggle {
  min-height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--unpaid), #fff8ef);
  color: #7a4211;
  border: 1px solid #f3c285;
  padding: 7px 9px;
  text-align: left;
  font-weight: 780;
}

.paid-toggle.paid {
  background: linear-gradient(135deg, var(--paid), #f5fbf6);
  color: #17612c;
  border-color: #acd9b8;
}

details {
  border-top: 0;
  padding-top: 0;
}

summary {
  cursor: pointer;
  color: var(--indigo);
  font-weight: 820;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  list-style-position: outside;
  min-height: 36px;
}

.order-summary-side {
  color: #7b4211;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.order-editor {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.readable-details {
  display: grid;
  gap: 2px;
  border: 1px solid rgba(222, 215, 202, .72);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 253, 250, .72);
}

.edit-details {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.edit-details.compact {
  border-top: 0;
  padding-top: 0;
}

.edit-details > summary {
  color: var(--accent-dark);
  font-size: .92rem;
}

.detail-list {
  margin-top: 10px;
}

.detail-row {
  padding: 8px 0;
  border-width: 0 0 1px;
  border-radius: 0;
}

.detail-row.total {
  border-bottom: 0;
  font-weight: 850;
}

.editable-detail-row input,
.editable-detail-row select {
  max-width: 180px;
  justify-self: end;
}

.inline-controls,
.item-side {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.compact-btn {
  min-height: 34px;
  padding: 0 10px;
}

.inline-paid {
  min-height: 30px;
  padding: 4px 8px;
  font-size: .86rem;
  white-space: nowrap;
}

.clickable-detail {
  cursor: pointer;
  border-radius: 8px;
  padding: 9px 10px;
}

.clickable-detail:hover,
.clickable-detail.active {
  background: var(--soft-blue);
  border-bottom-color: transparent;
}

.inline-edit-row {
  margin: 4px 0;
  background: var(--soft-blue);
}

.empty {
  display: none;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed #d2c6b1;
  border-radius: 8px;
  background: #fffdfa;
}

.empty.visible {
  display: grid;
}

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

@media (max-width: 980px) {
  .workflow,
  .main-grid,
  .order-fields,
  .draft-row {
    grid-template-columns: 1fr;
  }

  .remove-btn {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
  }

  .confirm-actions,
  .person-add-row,
  .debt-row,
  .detail-row {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .top-actions,
  .workflow,
  .confirm-panel,
  .paid-toggle,
  .secondary-btn {
    display: none;
  }

  .app-shell {
    width: 100%;
  }

  .panel {
    box-shadow: none;
  }
}
