/* ─────────────────────────────────────────────
   ReshiTrip レシ旅 — 日本旅行收據記帳
   JoeOkami 品牌風格：乾淨白底 + 紫色點綴
   ───────────────────────────────────────────── */

:root {
  /* Brand */
  --primary:        #7C3AED;
  --primary-pressed:#6D28D9;
  --charcoal:       #1A1033;
  --link:           #2563EB;

  /* Spectrum (分類色) */
  --c-food:    #E27F2E;
  --c-transit: #2563EB;
  --c-shop:    #EC4899;
  --c-hotel:   #8B5CF6;
  --c-fun:     #4AB897;
  --c-store:   #1AAE39;
  --c-other:   #7A7686;

  /* Surface */
  --canvas:  #FFFFFF;
  --subtle:  #F7F6FA;
  --hairline:#E6E3EE;
  --hairline-strong: #C9C4D6;

  /* Text */
  --ink:      #1A1626;
  --charcoal-t:#2E2A3D;
  --slate:    #5B5768;
  --steel:    #7A7686;
  --stone:    #A4A0AE;

  --radius-card: 14px;
  --radius-btn:  9px;
  --shadow-1: 0 1px 2px rgba(26,16,51,0.04);
  --shadow-2: 0 4px 16px rgba(26,16,51,0.08);
  --font: "Inter", "Noto Sans TC", -apple-system, BlinkMacSystemFont,
          "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--subtle);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding: 20px 16px 40px;
  line-height: 1.5;
}

.app { max-width: 600px; margin: 0 auto; }

/* ── 頂部 ── */
.topbar { margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-emoji { font-size: 34px; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.brand-jp { font-size: 15px; font-weight: 500; color: var(--primary); margin-left: 2px; }
.tagline { font-size: 13px; color: var(--slate); }

/* ── 分頁 ── */
.tabs {
  display: flex; gap: 6px; padding: 5px;
  background: var(--canvas); border: 1px solid var(--hairline);
  border-radius: var(--radius-card); margin-bottom: 18px;
}
.tab {
  flex: 1; padding: 10px 12px; border: none; border-radius: 10px;
  background: transparent; color: var(--slate);
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .18s, color .18s;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.tab.is-active { background: var(--primary); color: #fff; }
.tab-count {
  min-width: 20px; padding: 1px 7px; border-radius: 999px;
  background: rgba(255,255,255,0.25); font-size: 12px; font-weight: 700;
}
.tab:not(.is-active) .tab-count { background: var(--subtle); color: var(--steel); }

/* ── 視圖切換 ── */
.view { display: none; }
.view.is-active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── 卡片通用 ── */
.card {
  background: var(--canvas); border: 1px solid var(--hairline);
  border-radius: var(--radius-card); box-shadow: var(--shadow-1);
  padding: 18px;
}

/* ── 上傳區 ── */
.dropzone {
  display: block; position: relative;
  border: 2px dashed var(--hairline-strong); border-radius: var(--radius-card);
  background: var(--canvas); cursor: pointer; overflow: hidden;
  transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #FBFAFE; }
.dropzone-inner {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 40px 20px; text-align: center;
}
.dropzone-icon { font-size: 38px; }
.dropzone-title { font-size: 16px; font-weight: 600; color: var(--ink); }
.dropzone-hint { font-size: 13px; color: var(--steel); }
.dropzone-preview { display: block; width: 100%; max-height: 260px; object-fit: contain; background: #000; }

/* ── 辨識狀態 ── */
.status {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  margin-top: 14px; padding: 14px; border-radius: var(--radius-card);
  background: #F3EFFE; color: var(--primary-pressed); font-weight: 600; font-size: 14px;
}
.status.is-error { background: #FDECEC; color: #C0392B; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(124,58,237,0.25); border-top-color: var(--primary);
  animation: spin .7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status.is-error .spinner { display: none; }

/* ── 結果表單 ── */
.receipt-form { margin-top: 14px; }
.form-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.form-head h2 { font-size: 17px; font-weight: 700; }
.badge {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
}
.badge-ai { background: #EDE9FB; color: var(--primary-pressed); }
.badge-manual { background: var(--subtle); color: var(--steel); }

.field-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--slate); }
.field input, .field select {
  height: 42px; padding: 0 12px;
  border: 1px solid var(--hairline-strong); border-radius: var(--radius-btn);
  background: var(--canvas); font-family: var(--font); font-size: 14.5px; color: var(--ink);
  transition: border-color .15s, box-shadow .15s; width: 100%;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.12);
}

/* ── 品項 ── */
.items-block { margin-bottom: 16px; }
.items-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.items-list { display: flex; flex-direction: column; gap: 8px; }
.item-row { display: grid; grid-template-columns: 1fr 0.8fr 80px 32px; gap: 6px; align-items: center; }
.item-row input {
  height: 38px; padding: 0 10px;
  border: 1px solid var(--hairline-strong); border-radius: 8px;
  font-family: var(--font); font-size: 13.5px; width: 100%;
}
.item-row input:focus { outline: none; border-color: var(--primary); }
.item-del {
  width: 32px; height: 32px; border: none; border-radius: 8px;
  background: var(--subtle); color: var(--steel); cursor: pointer; font-size: 13px;
  transition: background .15s, color .15s;
}
.item-del:hover { background: #FDECEC; color: #C0392B; }

/* ── 按鈕 ── */
.btn {
  height: 44px; padding: 0 22px; border: none; border-radius: var(--radius-btn);
  font-family: var(--font); font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-pressed); }
.btn-ghost { background: transparent; color: var(--slate); }
.btn-ghost:hover { background: var(--subtle); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }
.form-actions .btn { min-width: 96px; }

.btn-mini {
  height: 34px; padding: 0 12px; border: 1px solid var(--hairline-strong);
  border-radius: 8px; background: var(--canvas); color: var(--charcoal-t);
  font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-mini:hover { background: var(--subtle); }
.btn-danger { color: #C0392B; }
.btn-danger:hover { background: #FDECEC; border-color: #F0B4B4; }

.manual-link {
  display: block; margin: 16px auto 0; padding: 8px;
  background: none; border: none; color: var(--link);
  font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer;
}
.manual-link:hover { text-decoration: underline; }

/* ── 帳本：總覽 ── */
.summary {
  display: flex; justify-content: space-between; align-items: flex-end;
  background: linear-gradient(135deg, #2E1065, #5B21B6); border: none; color: #fff;
  margin-bottom: 14px;
}
.summary-main { display: flex; flex-direction: column; gap: 2px; }
.summary-label { font-size: 13px; opacity: .8; font-weight: 500; }
.summary-jpy { font-size: 32px; font-weight: 700; letter-spacing: -1px; line-height: 1.1; }
.summary-twd { font-size: 14px; opacity: .85; font-weight: 500; }
.summary-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.rate-row { display: flex; align-items: center; gap: 5px; font-size: 12.5px; opacity: .85; }
.rate-row input {
  width: 62px; height: 30px; padding: 0 8px; text-align: center;
  border: 1px solid rgba(255,255,255,0.3); border-radius: 7px;
  background: rgba(255,255,255,0.12); color: #fff; font-family: var(--font); font-size: 13px;
}
.rate-row input:focus { outline: none; border-color: #fff; }
.summary-count { font-size: 12.5px; opacity: .8; }
.sync-pill {
  font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: rgba(255,255,255,0.15); color: #fff; transition: background .2s;
}
.sync-pill[data-state="ok"]   { background: rgba(74,184,151,0.35); }
.sync-pill[data-state="warn"] { background: rgba(226,127,46,0.4); }
.sync-pill[data-state="syncing"] { background: rgba(255,255,255,0.18); }

/* ── 分類統計 ── */
.breakdown { margin-bottom: 18px; display: flex; flex-direction: column; gap: 11px; }
.breakdown:empty { display: none; }
.bd-row { display: flex; flex-direction: column; gap: 5px; }
.bd-top { display: flex; justify-content: space-between; font-size: 13px; }
.bd-cat { font-weight: 600; color: var(--charcoal-t); }
.bd-amt { color: var(--slate); font-variant-numeric: tabular-nums; }
.bd-bar { height: 7px; border-radius: 999px; background: var(--subtle); overflow: hidden; }
.bd-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }

/* ── 清單 ── */
.ledger-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ledger-head h2 { font-size: 17px; font-weight: 700; }
.ledger-tools { display: flex; gap: 8px; }
.entries { display: flex; flex-direction: column; gap: 10px; }
.empty {
  text-align: center; color: var(--steel); font-size: 14px;
  padding: 40px 20px; background: var(--canvas);
  border: 1px dashed var(--hairline-strong); border-radius: var(--radius-card);
}

.entry {
  background: var(--canvas); border: 1px solid var(--hairline);
  border-radius: var(--radius-card); box-shadow: var(--shadow-1);
  overflow: hidden;
}
.entry-main {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer;
}
.entry-cat-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.entry-info { flex: 1; min-width: 0; }
.entry-store { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-sub { font-size: 12.5px; color: var(--steel); display: flex; gap: 8px; align-items: center; }
.entry-cat-chip {
  font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
}
.entry-pay { font-size: 11.5px; color: var(--steel); }
.entry-amt { text-align: right; flex: none; }
.entry-jpy { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.entry-twd { font-size: 12px; color: var(--steel); }

.entry-detail { display: none; padding: 0 16px 14px 38px; }
.entry.is-open .entry-detail { display: block; }
.entry-items { border-top: 1px solid var(--hairline); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.entry-item { display: flex; justify-content: space-between; font-size: 13px; color: var(--charcoal-t); }
.entry-item-ja { color: var(--stone); font-size: 11.5px; }
.entry-meta-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.entry-tax { font-size: 12px; color: var(--steel); background: var(--subtle); padding: 2px 9px; border-radius: 999px; }
.entry-note { font-size: 12.5px; color: var(--slate); font-style: italic; }
.entry-del {
  margin-left: auto; height: 30px; padding: 0 12px; border: 1px solid var(--hairline-strong);
  border-radius: 8px; background: var(--canvas); color: #C0392B;
  font-family: var(--font); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.entry-del:hover { background: #FDECEC; }

/* ── 頁尾 ── */
.footer {
  margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--hairline);
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  font-size: 12px; color: var(--steel); text-align: center;
}
.footer a { color: var(--link); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ── 手機 ── */
@media (max-width: 460px) {
  .field-grid { grid-template-columns: 1fr; }
  .summary { flex-direction: column; align-items: flex-start; gap: 14px; }
  .summary-meta { align-items: flex-start; }
  .item-row { grid-template-columns: 1fr 70px 30px; }
  .item-row .item-ja { display: none; }
}
