/* AI0506 Ledger — styles.css */

:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --card-2: #f0f0f2;
  --text: #1d1d1f;
  --muted: #86868b;
  --border: rgba(0, 0, 0, 0.08);
  --primary: #0a84ff;
  --primary-soft: rgba(10, 132, 255, 0.12);
  --expense: #ff3b30;
  --income: #34c759;
  --danger: #ff3b30;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --tabbar-h: 60px;
  --topbar-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989d;
    --border: rgba(255, 255, 255, 0.12);
    --primary: #0a84ff;
    --primary-soft: rgba(10, 132, 255, 0.22);
    --expense: #ff453a;
    --income: #30d158;
    --danger: #ff453a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.5;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; white-space: nowrap; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, #34c759, #0a84ff); }
.topbar-title { flex: 1; text-align: center; color: var(--muted); font-size: 14px; }
.icon-btn { font-size: 20px; width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.icon-btn:active { background: var(--card-2); }

/* ---------- Main view ---------- */
.view {
  padding: calc(var(--topbar-h) + 12px) 16px calc(var(--tabbar-h) + 24px + var(--safe-bottom));
  max-width: 640px; margin: 0 auto; min-height: 100%;
}

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; align-items: stretch;
  background: var(--card); border-top: 1px solid var(--border);
  z-index: 20;
  max-width: 640px; margin: 0 auto;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px;
}
.tab.active { color: var(--primary); }
.tab-ico { font-size: 20px; line-height: 1; }
.tab-label { font-size: 11px; }
.tab-add { position: relative; }
.tab-ico-add {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 300; line-height: 1;
  margin-top: -18px; box-shadow: 0 4px 12px rgba(10, 132, 255, 0.4);
}
.tab-ico-add:active { transform: scale(0.95); }

/* ---------- Auth screen ---------- */
.auth-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px; z-index: 50;
}
.login-card {
  width: 100%; max-width: 340px; background: var(--card); border-radius: 20px;
  padding: 32px 24px; box-shadow: var(--shadow); text-align: center;
}
.login-mark { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card-2); margin-bottom: 12px; text-align: center;
}
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- Loading screen ---------- */
.loading-screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: var(--bg); z-index: 60; color: var(--muted);
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }

.hero {
  background: linear-gradient(135deg, #0a84ff, #5e5ce6);
  color: #fff; border-radius: 20px; padding: 22px 20px; box-shadow: var(--shadow);
}
.hero .hero-label { font-size: 13px; opacity: 0.9; }
.hero .hero-amount { font-size: 40px; font-weight: 700; letter-spacing: -0.5px; margin: 2px 0 8px; }
.hero .hero-sub { display: flex; gap: 20px; font-size: 13px; opacity: 0.95; }
.hero .hero-sub b { font-weight: 600; }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 10px; }
.month-nav .month-title { font-size: 16px; font-weight: 600; }
.month-nav button { width: 34px; height: 34px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 18px; color: var(--primary); }
.month-nav button:active { background: var(--card-2); }

.section-title { font-size: 13px; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; }

/* ---------- Transaction list ---------- */
.tx-group { margin-bottom: 16px; }
.tx-day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px; margin-bottom: 6px; }
.tx-day-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.tx-day-total { font-size: 13px; color: var(--muted); }

.tx-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }
.tx-cat-dot { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0; color: #fff; }
.tx-main { flex: 1; min-width: 0; }
.tx-cat-name { font-size: 15px; font-weight: 500; }
.tx-note { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-right { text-align: right; }
.tx-amount { font-size: 16px; font-weight: 600; }
.tx-amount.expense { color: var(--expense); }
.tx-amount.income { color: var(--income); }
.tx-src { font-size: 11px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }
.empty .empty-ico { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--primary); color: #fff; border-radius: 12px; padding: 12px 18px;
  font-weight: 600; font-size: 15px;
}
.btn-primary:active { opacity: 0.85; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--card-2); color: var(--text); border-radius: 12px; padding: 12px 18px; font-weight: 600; }
.btn-ghost:active { opacity: 0.8; }
.btn-danger { background: rgba(255, 59, 48, 0.12); color: var(--danger); border-radius: 12px; padding: 12px 18px; font-weight: 600; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn-primary, .btn-row .btn-ghost, .btn-row .btn-danger { flex: 1; text-align: center; }

/* ---------- Segmented control ---------- */
.seg { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.seg button.active.income { color: var(--income); }
.seg button.active.expense { color: var(--expense); }

/* ---------- Category chips ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.cat-chip {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px;
  border-radius: 12px; background: var(--card-2);
}
.cat-chip .chip-dot { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; color: #fff; }
.cat-chip .chip-name { font-size: 12px; color: var(--text); }
.cat-chip.selected { outline: 2px solid var(--primary); background: var(--primary-soft); }

/* ---------- Summary ---------- */
.stat-row { display: flex; gap: 12px; margin-bottom: 12px; }
.stat-card { flex: 1; background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat-card .stat-label { font-size: 12px; color: var(--muted); }
.stat-card .stat-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat-card.expense .stat-value { color: var(--expense); }
.stat-card.income .stat-value { color: var(--income); }

.donut-wrap { display: flex; align-items: center; gap: 20px; padding: 6px 0; }
.donut { flex-shrink: 0; }
.legend { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.legend-name { flex: 1; }
.legend-val { font-weight: 600; }
.legend-pct { color: var(--muted); font-size: 12px; width: 44px; text-align: right; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 8px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; background: var(--primary); min-height: 2px; }
.bar.income { background: var(--income); }
.bar-label { font-size: 9px; color: var(--muted); }

/* ---------- List rows (categories/subscriptions/vouchers) ---------- */
.list-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row .row-main { flex: 1; min-width: 0; }
.list-row .row-title { font-size: 15px; font-weight: 500; }
.list-row .row-sub { font-size: 12px; color: var(--muted); }
.row-actions { display: flex; gap: 4px; }
.row-btn { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--muted); }
.row-btn:active { background: var(--card-2); }
.row-btn.danger { color: var(--danger); }

.child-row { padding-left: 48px; }
.sub-badge { font-size: 11px; background: var(--primary-soft); color: var(--primary); padding: 1px 8px; border-radius: 999px; }

/* ---------- Menu ---------- */
.menu-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 16px; }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 15px 16px; border-bottom: 1px solid var(--border); width: 100%; text-align: left; font-size: 15px; }
.menu-item:last-child { border-bottom: none; }
.menu-item .menu-ico { font-size: 18px; }
.menu-item .menu-arrow { margin-left: auto; color: var(--muted); }
.menu-item.danger { color: var(--danger); }

/* ---------- Modal ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 560px) { .scrim { align-items: center; } }
.modal {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 20px 20px calc(20px + var(--safe-bottom));
  max-height: 88vh; overflow-y: auto;
}
@media (min-width: 560px) { .modal { border-radius: 20px; } }
.sheet-grab { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 16px; }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal .field { margin-bottom: 14px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card-2);
}
.modal .amount-input { font-size: 32px; font-weight: 700; text-align: center; padding: 14px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .modal-actions > button { flex: 1; }
.cat-picker { display: flex; flex-direction: column; gap: 10px; }
.cat-picker .back-chip { align-self: flex-start; font-size: 13px; color: var(--primary); padding: 4px 10px; border-radius: 8px; background: var(--primary-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px + var(--safe-bottom));
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 80;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: 84vw;
}
.toast.show { opacity: 1; }

@media (min-width: 560px) {
  .toast { bottom: 32px; }
}
