:root {
  --bg0: #f3efe6;
  --bg1: #e7f0ef;
  --ink: #1c2422;
  --muted: #5c6b67;
  --accent: #0f6e56;
  --accent-2: #c45c26;
  --panel: rgba(255, 252, 247, 0.92);
  --line: #d5ddd9;
  --shadow: 0 18px 40px rgba(28, 36, 34, 0.08);
  --radius: 14px;
  --font-ui: "Noto Sans TC", "DM Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at 12% 10%, #dff3ee 0%, transparent 42%),
    radial-gradient(circle at 88% 0%, #f7e2d2 0%, transparent 36%),
    linear-gradient(160deg, var(--bg0), var(--bg1));
}

#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(28, 36, 34, 0.08);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(243, 239, 230, 0.85);
}

.brand-mark {
  font-family: "DM Sans", var(--font-ui);
  font-weight: 700;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  display: block;
}
.brand-sub { color: var(--muted); font-size: 0.85rem; }

.sync-indicator {
  margin-left: auto;
  margin-right: 0.75rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.85rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.sync-indicator.online { background: #e8f5f0; border-color: #9dceb8; color: var(--accent); }
.sync-indicator.offline { background: #f8e8e4; border-color: #e2b4b4; color: #a33; }
.sync-indicator.syncing { background: #fff6e8; border-color: #e2c48a; color: #8a5a12; }

.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.tab, button, .primary {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  min-height: 44px;
}
.tab.active, .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.primary:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

main { padding: 1.25rem 1.5rem 2rem; flex: 1; }
.view { display: none; animation: fade 0.25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.billing-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 1rem;
}
.panel {
  background: var(--panel);
  border: 1px solid rgba(28, 36, 34, 0.06);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem 1.25rem;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.panel h3 { margin: 0 0 0.5rem; font-size: 1rem; }

.row { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.row.gap { flex-wrap: wrap; }
.grow { flex: 1; }
input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  min-height: 44px;
}
label { display: grid; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 0.5rem; color: var(--ink); }

.result-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.result-list li {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.result-list li:hover { background: #eef7f4; }
.result-list li:last-child { border-bottom: 0; }
.selected {
  padding: 0.75rem;
  border-radius: 10px;
  background: #e8f5f0;
  margin-bottom: 1.2rem;
  min-height: 44px;
}
.selected.empty { background: #f4f1ea; color: var(--muted); }

.bill-table, .data-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}
.bill-table th, .bill-table td,
.data-table th, .data-table td {
  text-align: left;
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.bill-table input { min-height: 40px; padding: 0.35rem 0.45rem; }

.bill-controls, .payment-box, .form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.form-grid .wide { grid-column: 1 / -1; }

.totals-box {
  background: linear-gradient(135deg, #1c3d35, #0f6e56);
  color: #f7fffb;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}
.totals-box div {
  display: flex;
  justify-content: space-between;
  margin: 0.2rem 0;
}
.totals-box .grand { font-size: 1.25rem; margin-top: 0.45rem; }

.pay-methods {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}
.pay-methods label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--ink);
  grid: none;
}
.split.hidden { display: none; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.status { min-height: 1.4em; color: var(--accent); }
.status.error { color: #a33; }
.muted { color: var(--muted); font-size: 0.95rem; }
pre.invoice-detail {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  max-height: 420px;
  overflow: auto;
}

.invoice-detail {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}
.invoice-detail.hidden { display: none; }
.danger { color: #a33; border-color: #e2b4b4; }

@media (max-width: 960px) {
  .billing-layout { grid-template-columns: 1fr; }
  .bill-controls, .payment-box, .form-grid { grid-template-columns: 1fr 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
}
