:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-soft: #eef6f2;
  --ink: #182026;
  --muted: #65717c;
  --line: #dce2e7;
  --line-strong: #c5ced6;
  --brand: #0f8b6d;
  --brand-dark: #09644f;
  --accent: #b85b29;
  --danger: #b63d3d;
  --warning: #9b6b13;
  --shadow: 0 12px 36px rgba(24, 32, 38, 0.08);
  --radius: 8px;
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 250, 0.95);
  backdrop-filter: blur(10px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1180px, calc(100vw - 32px));
  min-height: 72px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  flex: 0 0 auto;
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
}

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

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 12px;
  font-size: 20px;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
}

.layout {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  gap: 24px;
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto 56px;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 96px;
  display: grid;
  gap: 14px;
}

.main {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel,
.modal-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel.subtle {
  background: var(--panel-soft);
  box-shadow: none;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 24px;
  align-items: center;
  width: min(1060px, calc(100vw - 32px));
  min-height: calc(100vh - 92px);
  margin: 0 auto;
  padding: 48px 0;
}

.hero h1 {
  font-size: 44px;
  line-height: 1.08;
  margin-bottom: 16px;
}

.hero p {
  color: var(--muted);
  line-height: 1.7;
}

.hero-visual {
  min-height: 420px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background:
    linear-gradient(120deg, rgba(15, 139, 109, 0.16), transparent 58%),
    linear-gradient(180deg, #ffffff, #eef2f4);
  padding: 20px;
  box-shadow: var(--shadow);
}

.mock-sheet {
  display: grid;
  gap: 12px;
}

.mock-row {
  display: grid;
  grid-template-columns: 1.1fr 0.7fr 0.8fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.mock-row strong {
  font-size: 14px;
}

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

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

.button,
.icon-button,
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--brand);
  color: white;
  font-weight: 700;
  text-decoration: none;
}

.button {
  padding: 0 14px;
}

.button.secondary,
.icon-button.secondary {
  border-color: var(--line-strong);
  background: white;
  color: var(--ink);
}

.button.ghost,
.icon-button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink);
}

.button.danger,
.icon-button.danger {
  background: var(--danger);
  color: white;
}

.button.warning {
  background: var(--warning);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.tabs,
.segmented {
  display: grid;
  gap: 6px;
}

.tab-button {
  justify-content: flex-start;
  width: 100%;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  min-height: 40px;
  padding: 0 12px;
}

.tab-button.active {
  border-color: rgba(15, 139, 109, 0.24);
  background: #e8f4ef;
  color: var(--brand-dark);
}

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

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

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

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 139, 109, 0.13);
}

textarea {
  resize: vertical;
  min-height: 86px;
}

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

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
}

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

.settlement-card,
.settlement-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 16px;
}

.settlement-card span,
.settlement-result span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.settlement-card strong,
.settlement-result strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.2;
}

.settlement-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.settlement-result {
  margin-top: 12px;
  background: var(--panel-soft);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

.money {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.positive {
  color: var(--brand-dark);
}

.negative {
  color: var(--danger);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  border-color: rgba(15, 139, 109, 0.26);
  background: #e8f4ef;
  color: var(--brand-dark);
}

.badge.warn {
  border-color: rgba(155, 107, 19, 0.22);
  background: #fff5dc;
  color: var(--warning);
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

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

.small {
  font-size: 13px;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
}

.receipt-preview {
  display: block;
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 32, 38, 0.38);
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(720px, 100%);
  max-height: min(86vh, 760px);
  overflow: auto;
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  background: var(--ink);
  color: white;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.toast[hidden] {
  display: none;
}

@media (max-width: 920px) {
  .layout,
  .hero {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

  .tab-button {
    justify-content: center;
  }

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

@media (max-width: 640px) {
  .topbar-inner,
  .layout,
  .hero {
    width: min(100vw - 20px, 1180px);
  }

  .topbar-inner {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 0;
  }

  .hero {
    padding: 28px 0;
  }

  .hero h1 {
    font-size: 34px;
  }

  .field-grid,
  .stats-grid,
  .settlement-grid,
  .tabs {
    grid-template-columns: 1fr;
  }

  .panel,
  .modal-panel {
    padding: 14px;
  }

  .actions {
    align-items: stretch;
  }

  .button {
    flex: 1 1 150px;
  }
}
