/* 小帳簿 — 樣式（對應設計稿 design tokens） */

:root {
  --bg: #EFEAE0;
  --paper: #FFFDF9;
  --surface: #F6F2E9;
  --surface-2: #F8F5EE;
  --surface-3: #F3EFE6;
  --line: #E7E0D3;
  --line-dash: #DED6C6;
  --line-2: #E4DCCC;
  --line-3: #EBE4D6;
  --line-row: #F0EBDF;
  --ink: #1A1713;
  --ink-2: #5A5145;
  --ink-3: #8A8072;
  --ink-4: #A79C8A;
  --ink-5: #C4B9A4;
  --accent: #111111;
  --accent-hover: #332E27;
  --save: #6E6558;
  --other: #E9E2D3;
  --other-2: #C9BFAB;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Noto Sans TC', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  font-family: var(--sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

input, button {
  font-family: inherit;
  color: inherit;
}
input { border: none; background: transparent; }
input:focus { outline: none; }
button { cursor: pointer; border: none; background: none; }

.mono { font-family: var(--mono); }

/* ---------- 版面外框 ---------- */

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 56px);
}

.frame {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(40, 34, 24, .05), 0 24px 48px -28px rgba(40, 34, 24, .35);
  overflow: hidden;
}

/* ---------- 頁首 ---------- */

.head {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: clamp(16px, 1.6vw, 22px) clamp(18px, 2.4vw, 30px);
  border-bottom: 1px dashed var(--line-dash);
}
.head__brand { display: flex; align-items: center; gap: 14px; }
.head__logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); flex: 0 0 auto; }
.head__titles { display: flex; flex-direction: column; gap: 2px; }
.head__title { font-size: 16px; font-weight: 500; letter-spacing: .02em; }
.head__sub { font-size: 12px; color: var(--ink-3); }
.head__right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.month {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface-3); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 3px;
}
.month__btn {
  width: 30px; height: 28px; display: grid; place-items: center;
  border-radius: 7px; font-size: 14px; color: var(--ink-2);
}
.month__btn:hover:not(:disabled) { background: var(--paper); }
.month__btn:disabled { opacity: .3; cursor: default; }
.month__label { font-family: var(--mono); font-size: 13px; padding: 0 8px; min-width: 74px; text-align: center; }

.income {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-3); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 6px 12px 6px 14px;
}
.income__label { font-size: 12px; color: var(--ink-3); white-space: nowrap; flex: 0 0 auto; }
.income__prefix { font-family: var(--mono); font-size: 13px; color: var(--ink-3); white-space: nowrap; flex: 0 0 auto; }
.income__input {
  width: 86px; flex: 0 0 auto; text-align: right;
  font-family: var(--mono); font-size: 15px; font-weight: 500; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line-2); border-radius: 7px; padding: 4px 8px;
}
.income__input:focus { border-color: var(--accent); }

.sync {
  font-size: 11px; color: var(--ink-3); white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
}
.sync__dot { width: 6px; height: 6px; border-radius: 999px; background: var(--ink-4); flex: 0 0 auto; }
.sync--saved .sync__dot { background: #5C8A5C; }
.sync--saving .sync__dot { background: #C6A15B; }
.sync--error .sync__dot { background: #B45A4A; }
.sync--local .sync__dot { background: var(--ink-4); }

.btn-plain {
  padding: 5px 12px; border: 1px solid var(--line-2); border-radius: 8px;
  font-size: 12px; color: var(--ink-2); white-space: nowrap; background: var(--paper);
}
.btn-plain:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Hero ---------- */

.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  border-bottom: 1px dashed var(--line-dash);
}
.hero__col { padding: clamp(20px, 2.4vw, 30px); display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.hero__col + .hero__col { border-left: 1px dashed var(--line-dash); }

.eyebrow { font-size: 13px; color: var(--ink-3); letter-spacing: .04em; }

.bignum { display: flex; align-items: baseline; gap: 8px; }
.bignum__unit { font-family: var(--mono); font-size: 19px; color: var(--ink-3); }
.bignum__val { font-family: var(--mono); font-size: clamp(40px, 4.4vw, 60px); font-weight: 500; letter-spacing: -.02em; line-height: 1; }
.bignum__val.is-neg { color: #B45A4A; }

.bar { height: 10px; border-radius: 999px; background: #E9E2D3; overflow: hidden; display: flex; }
.bar__fill { background: var(--accent); }

.rowbetween { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; color: var(--ink-3); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.card__label { font-size: 12px; color: var(--ink-3); }
.card__big { font-family: var(--mono); font-size: 22px; font-weight: 500; }

.alloc { display: flex; height: 44px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line-2); }
.alloc__seg { display: flex; align-items: center; padding-left: 14px; font-family: var(--mono); font-size: 12px; min-width: 0; overflow: hidden; }
.alloc__seg--fixed { background: var(--accent); color: var(--paper); }
.alloc__seg--save { background: var(--save); color: var(--paper); }
.alloc__seg--other { background: var(--other); color: var(--ink-2); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat { display: flex; flex-direction: column; gap: 6px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.stat__head { display: flex; align-items: center; gap: 8px; }
.stat__dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }
.stat__name { font-size: 12px; color: var(--ink-2); }
.stat__val { font-family: var(--mono); font-size: 24px; font-weight: 500; }
.stat__note { font-size: 11px; color: var(--ink-3); }

/* ---------- 三欄工作區 ---------- */

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.col {
  padding: clamp(20px, 2vw, 26px) clamp(18px, 2.4vw, 30px);
  display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.col + .col { border-left: 1px dashed var(--line-dash); }

.col__head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.col__title { font-size: 14px; font-weight: 500; }
.col__meta { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.col__hint { font-size: 12px; color: var(--ink-3); line-height: 1.6; }

/* 固定支出列 */
.fx { display: flex; flex-direction: column; gap: 2px; }
.fx__row { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line-row); }
.fx__name { flex: 1 1 auto; min-width: 0; font-size: 14px; color: var(--ink); border-radius: 6px; padding: 5px; margin-left: -5px; }
.fx__name:focus { background: var(--surface); }
.fx__day { width: 46px; flex: 0 0 auto; font-family: var(--mono); font-size: 11px; color: var(--ink-4); border-radius: 6px; padding: 5px 4px; }
.fx__day:focus { background: var(--surface); }
.fx__amt { width: 62px; flex: 0 0 auto; text-align: right; font-family: var(--mono); font-size: 14px; color: var(--ink); border-radius: 6px; padding: 5px; }
.fx__amt:focus { background: var(--surface); }

.iconbtn {
  flex: 0 0 auto; width: 28px; height: 28px; display: grid; place-items: center;
  border-radius: 8px; font-size: 15px; color: var(--ink-5);
}
.iconbtn:hover { background: #F1ECE1; color: var(--accent); }

.dashed-btn {
  margin-top: 8px; padding: 9px; border: 1px dashed #D8CFBC; border-radius: 9px;
  text-align: center; font-size: 12px; color: var(--ink-3); width: 100%;
}
.dashed-btn:hover { border-color: var(--accent); color: var(--accent); }

/* 存錢帳戶卡 */
.acc {
  padding: 15px 15px 14px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--paper); display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 1px 2px rgba(40, 34, 24, .04);
}
.acc__top { display: flex; align-items: flex-start; gap: 11px; }
.acc__tag { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 9px; background: #EFEAE0; display: grid; place-items: center; font-size: 13px; color: var(--ink-2); }
.acc__id { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.acc__bank { font-size: 14px; font-weight: 500; line-height: 1.3; }
.acc__meta { font-size: 11px; color: var(--ink-3); }
.acc__right { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.acc__monthly { font-family: var(--mono); font-size: 15px; font-weight: 500; white-space: nowrap; }
.acc__monthly-label { font-size: 10px; color: var(--ink-4); white-space: nowrap; }
.acc__bar { height: 8px; border-radius: 999px; background: #EFEAE0; overflow: hidden; }
.acc__bar > div { height: 100%; background: var(--save); }
.acc__bar--empty { background: var(--surface); border: 1px dashed var(--line-2); }
.acc__foot { display: flex; justify-content: space-between; gap: 10px; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.acc__actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

.field-input {
  width: 100%; font-size: 14px; font-weight: 500; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-3); border-radius: 8px; padding: 7px 8px;
}
.field-input:focus { border-color: var(--accent); }

.acc__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 8px 10px; padding-top: 2px; border-top: 1px dashed var(--line); }
.field { display: flex; flex-direction: column; gap: 3px; }
.field__label { font-size: 10px; color: var(--ink-4); letter-spacing: .04em; }
.field__in { width: 100%; font-size: 12px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line-3); border-radius: 7px; padding: 6px 7px; }
.field__in:focus { border-color: var(--accent); }
.field__in.mono { font-family: var(--mono); font-size: 13px; color: var(--ink); text-align: right; }

/* 其他開銷 */
.quick { display: flex; flex-direction: column; gap: 8px; }
.quick__entry {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px;
  border: 1px solid var(--line-dash); border-radius: 12px; background: var(--surface);
}
.quick__name { flex: 1 1 auto; min-width: 0; font-size: 14px; color: var(--ink); }
.quick__amt { width: 64px; flex: 0 0 auto; text-align: right; font-family: var(--mono); font-size: 14px; color: var(--ink); }
.btn-solid {
  flex: 0 0 auto; white-space: nowrap; padding: 8px 16px;
  background: var(--accent); color: var(--paper); border-radius: 9px; font-size: 13px;
}
.btn-solid:hover { background: var(--accent-hover); }

.tags__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tags__hint { font-size: 12px; color: var(--ink-3); }
.tags__list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: flex; align-items: center; gap: 2px; padding: 5px 6px 5px 12px;
  border: 1px solid var(--line-2); border-radius: 999px; background: var(--paper); color: var(--ink-2);
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.tag__text { font-size: 12px; white-space: nowrap; }
.tag__x { width: 22px; height: 22px; margin-left: 2px; display: grid; place-items: center; border-radius: 999px; font-size: 13px; color: var(--ink-5); }
.tag__x:hover { background: #F1ECE1; color: var(--accent); }
.tag__pad { width: 6px; display: inline-block; }
.btn-outline-dark {
  padding: 5px 11px; border: 1px solid var(--accent); border-radius: 8px;
  font-size: 12px; color: var(--accent); white-space: nowrap; background: var(--paper);
}
.btn-outline-dark:hover { background: var(--accent); color: var(--paper); }

.expenses { display: flex; flex-direction: column; gap: 2px; max-height: 236px; overflow-y: auto; padding-right: 4px; }
.exp { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-row); }
.exp__date { font-family: var(--mono); font-size: 11px; color: var(--ink-4); min-width: 38px; flex: 0 0 auto; }
.exp__name { flex: 1; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp__cat { font-size: 11px; color: var(--ink-3); flex: 0 0 auto; }
.exp__amt { font-family: var(--mono); font-size: 14px; min-width: 54px; text-align: right; flex: 0 0 auto; }
.exp__empty { font-size: 12px; color: var(--ink-4); padding: 16px 0; text-align: center; }

/* ---------- 分類報表 ---------- */

.report { border-top: 1px dashed var(--line-dash); padding: clamp(20px, 2vw, 26px) clamp(18px, 2.4vw, 30px); display: flex; flex-direction: column; gap: 16px; }
.report__head { display: flex; align-items: baseline; gap: 12px; }
.report__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 34px; }
.rep { display: flex; flex-direction: column; gap: 7px; }
.rep__top { display: flex; align-items: baseline; gap: 8px; }
.rep__cat { flex: 1; font-size: 13px; }
.rep__share { font-family: var(--mono); font-size: 11px; color: var(--ink-4); }
.rep__amt { font-family: var(--mono); font-size: 14px; }
.rep__bar { height: 7px; border-radius: 999px; background: #EFEAE0; overflow: hidden; }
.rep__bar > div { height: 100%; }

/* ---------- 登入畫面 ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login {
  width: 100%; max-width: 360px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 1px 2px rgba(40, 34, 24, .05), 0 24px 48px -28px rgba(40, 34, 24, .35);
  padding: 30px 26px; display: flex; flex-direction: column; gap: 16px;
}
.login__brand { display: flex; align-items: center; gap: 12px; }
.login__logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); }
.login__title { font-size: 17px; font-weight: 500; }
.login__sub { font-size: 12px; color: var(--ink-3); margin-top: -6px; }
.login__label { font-size: 12px; color: var(--ink-3); }
.login__input {
  width: 100%; font-size: 14px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-3);
  border-radius: 9px; padding: 10px 12px;
}
.login__input:focus { border-color: var(--accent); }
.login__btn {
  width: 100%; padding: 11px; background: var(--accent); color: var(--paper);
  border-radius: 9px; font-size: 14px; font-weight: 500;
}
.login__btn:hover { background: var(--accent-hover); }
.login__btn:disabled { opacity: .55; cursor: default; }
.login__err { font-size: 12px; color: #B45A4A; }
.login__note { font-size: 11px; color: var(--ink-4); line-height: 1.6; }

/* ---------- 載入中 ---------- */
.loading { min-height: 100vh; display: grid; place-items: center; color: var(--ink-3); font-size: 13px; }

/* ---------- 本機模式提示 ---------- */
.banner {
  margin: 0 auto clamp(12px, 2vw, 20px); max-width: 1240px;
  background: #FBF3E2; border: 1px solid #EAD9B0; border-radius: 12px;
  padding: 10px 16px; font-size: 12px; color: #7A6A45;
}
.banner b { font-weight: 500; }

/* ---------- 手機版（< 900px 單欄） ---------- */

@media (max-width: 900px) {
  .page { padding: 12px; }
  .frame { border-radius: 22px; }
  .head { padding: 14px 18px 16px; }
  .head__right { width: 100%; justify-content: space-between; }
  .hero { grid-template-columns: 1fr; }
  .hero__col + .hero__col { border-left: none; border-top: 1px dashed var(--line-dash); }
  .cols { grid-template-columns: 1fr; }
  .col + .col { border-left: none; border-top: 1px dashed var(--line-dash); }
  .bignum__val { font-size: 46px; }

  /* 其他開銷的快速記帳列，捲動時固定在底部 */
  .col--other { position: relative; }
  .col--other .quick {
    position: sticky; bottom: 0; z-index: 5;
    margin: 0 calc(-1 * clamp(18px, 2.4vw, 30px));
    padding: 12px clamp(18px, 2.4vw, 30px) calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px dashed var(--line-dash);
  }
  .col--other .quick__entry { background: var(--paper); }
  .col--other .tags__list { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .tag { flex: 0 0 auto; }
  .expenses { max-height: none; }
}
