:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0f172a;
  --accent: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 14px 40px rgba(15, 23, 42, .09);
  --radius: 20px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { overscroll-behavior-y: contain; }
button, input { font: inherit; }
button { cursor: pointer; }
.app-shell { width: 100%; max-width: 760px; margin: 0 auto; min-height: 100dvh; padding: max(18px, env(safe-area-inset-top)) 16px calc(118px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 4px; font-size: 11px; font-weight: 800; letter-spacing: .12em; color: var(--accent); }
h1 { margin: 0; font-size: 28px; line-height: 1.08; letter-spacing: -.03em; }
h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
h3 { margin: 0 0 8px; font-size: 17px; }
p { margin: 0; }
.muted { margin-top: 5px; font-size: 14px; color: var(--muted); }
.hidden { display: none !important; }
.icon-btn, .text-btn, .close-btn { border: 0; background: transparent; color: var(--accent); font-weight: 750; }
.icon-btn { background: #e8efff; padding: 9px 12px; border-radius: 12px; }
.screen { display: none; }
.screen.active { display: block; }
.hero-card, .mini-card, .settings-card, .history-card, .week-row, .rule-card { background: var(--surface); border: 1px solid rgba(226,232,240,.95); box-shadow: var(--shadow); }
.hero-card { border-radius: 24px; padding: 20px; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.label { display: block; color: var(--muted); font-weight: 650; font-size: 13px; margin-bottom: 6px; }
.hero-value { font-size: clamp(28px, 8vw, 40px); font-weight: 850; letter-spacing: -.045em; }
.hero-total { font-size: .52em; color: var(--muted); font-weight: 700; }
.badge { flex: 0 0 auto; padding: 8px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.badge.good { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.bad { background: #fee2e2; color: #991b1b; }
.progress { height: 8px; background: #e9eef5; border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress.large { height: 11px; margin-top: 18px; }
.progress-fill { width: 0%; height: 100%; border-radius: inherit; background: var(--green); transition: width .25s ease, background-color .25s ease; }
.section-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 24px 2px 12px; }
.section-title-row.top-space { margin-top: 8px; }
.hint { color: var(--muted); font-size: 12px; }
.category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini-card { border-radius: 18px; padding: 16px; }
.mini-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 750; }
.mini-head strong { font-size: 12px; color: var(--muted); }
.mini-value { margin-top: 10px; font-size: 18px; font-weight: 850; letter-spacing: -.025em; }
.mini-value > span:last-child { font-size: 12px; color: var(--muted); font-weight: 700; }
.mini-foot { margin-top: 10px; color: var(--muted); font-size: 12px; }
.weeks-list { display: grid; gap: 9px; }
.week-row { border-radius: 16px; padding: 14px; display: grid; grid-template-columns: 1.25fr 1fr auto; gap: 10px; align-items: center; }
.week-name { font-weight: 800; font-size: 14px; }
.week-period { color: var(--muted); font-size: 11px; margin-top: 3px; }
.week-ratio { font-weight: 800; text-align: right; font-size: 14px; }
.week-percent { min-width: 48px; text-align: center; padding: 6px 7px; border-radius: 999px; font-size: 11px; font-weight: 850; background: #dcfce7; color: #166534; }
.week-percent.warn { background: #fef3c7; color: #92400e; }
.week-percent.bad { background: #fee2e2; color: #991b1b; }
.rule-card { margin-top: 14px; border-radius: 16px; padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; }
.rule-card strong { font-size: 13px; }
.rule-card p { margin-top: 3px; font-size: 12px; color: var(--muted); line-height: 1.35; }
.rule-dot { width: 9px; height: 9px; margin-top: 4px; border-radius: 99px; background: var(--accent); flex: 0 0 auto; }
.fab { position: fixed; left: 50%; bottom: calc(74px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; border: 0; background: var(--primary); color: white; border-radius: 999px; padding: 14px 20px; font-weight: 850; font-size: 15px; box-shadow: 0 14px 32px rgba(15,23,42,.28); display: flex; align-items: center; gap: 8px; }
.fab span { font-size: 21px; line-height: 1; }
.bottom-nav { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: min(760px, 100%); height: calc(66px + env(safe-area-inset-bottom)); padding: 7px 10px calc(7px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.94); backdrop-filter: blur(18px); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(3,1fr); z-index: 15; }
.nav-item { border: 0; background: transparent; color: var(--muted); border-radius: 14px; font-size: 11px; font-weight: 750; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.nav-item.active { color: var(--text); background: #eef2f7; }
.nav-icon { font-size: 20px; line-height: 1; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.44); opacity: 0; visibility: hidden; transition: .2s ease; display: flex; align-items: flex-end; }
.sheet-backdrop.open { opacity: 1; visibility: visible; }
.sheet { width: 100%; max-width: 760px; margin: 0 auto; background: white; border-radius: 26px 26px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .24s ease; box-shadow: 0 -24px 80px rgba(15,23,42,.22); }
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-grabber { width: 42px; height: 5px; background: #d3dbe6; border-radius: 999px; margin: 2px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.close-btn { font-size: 30px; line-height: 1; color: var(--muted); padding: 0 3px; }
.field-label { display: block; margin: 16px 0 7px; font-size: 12px; color: var(--muted); font-weight: 800; }
.money-input { height: 50px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); display: flex; align-items: center; padding: 0 14px; gap: 8px; }
.money-input.huge { height: 68px; }
.money-input span { font-weight: 800; color: var(--muted); }
.money-input input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; font-size: 19px; font-weight: 850; color: var(--text); }
.money-input.huge input { font-size: 30px; }
.type-selector { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.type-btn { border: 1px solid var(--line); background: white; border-radius: 13px; padding: 13px 6px; font-weight: 800; color: var(--muted); }
.type-btn.selected { border-color: var(--primary); background: var(--primary); color: white; }
.date-input { width: 100%; height: 50px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 14px; padding: 0 14px; color: var(--text); font-weight: 750; }
.warning-text { margin-top: 7px; color: var(--amber); font-size: 12px; line-height: 1.4; }
.primary-btn, .secondary-btn { border: 0; border-radius: 14px; font-weight: 850; }
.primary-btn { background: var(--primary); color: white; padding: 14px 18px; }
.primary-btn.big { margin-top: 22px; padding: 16px; font-size: 16px; }
.full { width: 100%; }
.secondary-btn { background: #eef2f7; color: var(--text); padding: 12px 14px; display: inline-flex; align-items: center; justify-content: center; }
.settings-card { border-radius: 20px; padding: 18px; margin-bottom: 14px; }
.settings-note { color: var(--muted); font-size: 12px; line-height: 1.45; margin-top: 8px; }
.static-row { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 14px; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.file-label input { display: none; }
.history-list { display: grid; gap: 10px; }
.history-card { border-radius: 18px; padding: 15px; }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.history-head strong { font-size: 15px; }
.history-amount { font-weight: 850; }
.history-period { color: var(--muted); font-size: 11px; margin-top: 3px; }
.history-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.transaction-list { margin-top: 12px; border-top: 1px solid var(--line); }
.transaction-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.transaction-row:last-child { border-bottom: 0; }
.transaction-date { color: var(--muted); font-size: 11px; margin-top: 2px; }
.delete-btn { border: 0; background: #fff1f2; color: #be123c; border-radius: 10px; padding: 7px 9px; font-weight: 850; }
.empty-state { background: white; border: 1px dashed #cbd5e1; border-radius: 18px; padding: 28px 18px; text-align: center; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: calc(138px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px); opacity: 0; visibility: hidden; z-index: 100; background: #0f172a; color: white; padding: 11px 15px; border-radius: 12px; font-size: 13px; font-weight: 750; transition: .2s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
@media (max-width: 560px) {
  .category-grid { grid-template-columns: 1fr; }
  .hero-top { flex-direction: column; }
  .badge { align-self: flex-start; }
  .week-row { grid-template-columns: 1fr auto; }
  .week-percent { grid-column: 2; grid-row: 1 / span 2; }
  .week-ratio { text-align: left; }
}
@media (display-mode: standalone) {
  .install-only { display: none !important; }
}

/* Cloud sync / auth */
.cloud-chip { display:inline-flex; align-items:center; gap:6px; margin-top:8px; padding:6px 9px; border-radius:999px; background:#e8efff; color:#36537d; font-size:11px; font-weight:800; }
.cloud-chip::before { content:""; width:7px; height:7px; border-radius:50%; background:#22c55e; }
.cloud-chip.offline::before { background:#f59e0b; }
.cloud-chip.error::before { background:#ef4444; }
.auth-gate { position:fixed; inset:0; z-index:200; background:linear-gradient(180deg,#eef4fb 0%,#f8fafc 100%); display:flex; align-items:center; justify-content:center; padding:24px; }
.auth-gate.hidden { display:none; }
.auth-card { width:min(420px,100%); background:white; border:1px solid var(--line); border-radius:26px; box-shadow:0 24px 70px rgba(15,23,42,.14); padding:24px; }
.auth-logo { width:52px; height:52px; border-radius:16px; display:grid; place-items:center; background:var(--primary); color:white; font-size:24px; font-weight:900; margin-bottom:18px; }
.auth-card h2 { font-size:24px; }
.auth-copy { color:var(--muted); margin-top:8px; font-size:14px; line-height:1.45; }
.pin-input { width:100%; margin-top:20px; height:60px; border:1px solid var(--line); border-radius:16px; background:var(--surface-2); text-align:center; letter-spacing:.35em; font-size:26px; font-weight:850; outline:none; }
.pin-input:focus { border-color:var(--primary); box-shadow:0 0 0 3px rgba(37,99,235,.12); }
.auth-error { color:#b91c1c; font-size:12px; min-height:18px; margin-top:8px; }
.auth-card .primary-btn { margin-top:8px; }
.cloud-card-row { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.cloud-card-row strong { display:block; }
.cloud-card-row .settings-note { margin-top:4px; }
.status-pill { flex:0 0 auto; border-radius:999px; padding:7px 9px; background:#dcfce7; color:#166534; font-size:11px; font-weight:850; }
.logout-btn { margin-top:14px; color:#be123c; background:#fff1f2; }
.syncing .cloud-chip::before { animation:pulse-dot 1s infinite; }
@keyframes pulse-dot { 50% { opacity:.25; } }

/* iPhone Shortcut setup */
.shortcut-generate-btn { margin-top: 14px; }
.shortcut-setup { margin-top: 14px; padding-top: 2px; }
.copy-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.plain-input { width: 100%; min-width: 0; height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); color: var(--text); padding: 0 12px; font-size: 13px; outline: 0; }
.plain-input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; }
