:root {
  --navy: #1a2a4a;
  --navy-deep: #0f1c34;
  --navy-card: #21345a;
  --gold: #c9a961;
  --gold-soft: #e3c98a;
  --white: #ffffff;
  --muted: #9fb0cc;
  --green: #4caf7d;
  --line: #34466e;
  --danger: #e07a7a;
}

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

body {
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: radial-gradient(circle at 20% 0%, #253a63 0%, var(--navy) 35%, var(--navy-deep) 100%);
  color: var(--white);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 560px; margin: 0 auto; padding: 16px 16px 96px; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 16px;
}
header .brand { display: flex; align-items: center; gap: 10px; }
header .star { color: var(--gold); font-size: 22px; }
header h1 { font-size: 18px; margin: 0; letter-spacing: 1px; font-weight: 600; }
header .sub { font-size: 11px; color: var(--muted); }
header a.nav {
  color: var(--gold); text-decoration: none; font-size: 13px;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
}

.card {
  background: rgba(33, 52, 90, 0.6);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
  backdrop-filter: blur(6px);
}

.controls { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row label { font-size: 14px; color: var(--muted); }

select, input[type="text"], input[type="number"], input[type="date"] {
  background: var(--navy-deep);
  color: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 15px;
  font-family: inherit;
}
select { min-width: 110px; }

/* 拆分開關 */
.switch { position: relative; display: inline-block; width: 52px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--navy-deep); border: 1px solid var(--line);
  border-radius: 999px; transition: 0.2s;
}
.slider::before {
  content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px;
  background: var(--muted); border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: rgba(201,169,97,0.25); border-color: var(--gold); }
.switch input:checked + .slider::before { transform: translateX(22px); background: var(--gold); }

.capture-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; width: 100%; padding: 28px; border-radius: 16px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-soft) 100%);
  color: var(--navy-deep); font-size: 18px; font-weight: 700; border: none;
  cursor: pointer; box-shadow: 0 6px 18px rgba(201,169,97,0.25);
}
.capture-btn .icon { font-size: 30px; }
.capture-btn:active { transform: scale(0.99); }
input[type="file"] { display: none; }

.hint { font-size: 12px; color: var(--muted); text-align: center; margin-top: 10px; line-height: 1.6; }

.preview img { width: 100%; border-radius: 12px; border: 1px solid var(--line); }

.status { text-align: center; color: var(--gold-soft); padding: 18px; font-size: 15px; }
.spinner {
  width: 22px; height: 22px; border: 3px solid var(--line);
  border-top-color: var(--gold); border-radius: 50%;
  display: inline-block; vertical-align: middle; margin-right: 8px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.meta-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 11px; color: var(--muted); }
.field input, .field select { width: 100%; }

.rate-line { font-size: 13px; color: var(--gold-soft); margin-top: 8px; }
.rate-line input { width: 90px; padding: 4px 8px; font-size: 13px; }

.item {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  margin-bottom: 10px; background: rgba(15,28,52,0.5);
}
.item .top { display: flex; gap: 8px; margin-bottom: 8px; }
.item .top input.name { flex: 1; }
.item .top input.amt { width: 92px; text-align: right; }
.item .bottom { display: flex; gap: 8px; align-items: center; }
.item .bottom select { flex: 1; }

/* 帳本切換（公司/生活） */
.ledger-toggle { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ledger-toggle button {
  border: none; background: var(--navy-deep); color: var(--muted);
  padding: 9px 14px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.ledger-toggle button.active.company { background: rgba(80,130,220,0.3); color: #cfe0ff; }
.ledger-toggle button.active.life { background: rgba(76,175,125,0.3); color: #c6f0d8; }

.item .twd { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: right; }
.item .del { color: var(--danger); font-size: 12px; background: none; border: none; cursor: pointer; }

.total {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 4px; font-size: 15px;
}
.total b { font-size: 22px; color: var(--gold); }

.save-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--navy-deep) 70%, transparent);
}
.save-bar .inner { max-width: 560px; margin: 0 auto; }
.btn-primary {
  width: 100%; padding: 15px; border-radius: 12px; border: none;
  background: var(--gold); color: var(--navy-deep); font-size: 17px; font-weight: 700;
  cursor: pointer;
}
.btn-primary:disabled { opacity: 0.5; }
.btn-ghost {
  width: 100%; padding: 12px; border-radius: 12px; margin-top: 8px;
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  font-size: 14px; cursor: pointer;
}

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--navy-card); border: 1px solid var(--gold);
  color: var(--white); padding: 12px 20px; border-radius: 12px; font-size: 14px;
  opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 10;
  max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; }
.hidden { display: none !important; }

/* 統計頁 */
.chart-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
canvas { max-width: 100%; }
.legend { width: 100%; }
.legend .li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; border-bottom: 1px solid var(--line); }
.legend .dot { width: 12px; height: 12px; border-radius: 3px; }
.legend .amt { margin-left: auto; color: var(--gold-soft); }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs button {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--navy-deep); color: var(--muted); font-size: 14px; cursor: pointer; font-family: inherit;
}
.tabs button.active { background: rgba(201,169,97,0.2); border-color: var(--gold); color: var(--gold-soft); }
