:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #eeece5;
  --ink: #1d211f;
  --muted: #6d746f;
  --line: #dedbd2;
  --accent: #1d5f4b;
  --accent-2: #dcebe5;
  --danger: #b13c35;
  --danger-bg: #f8e7e5;
  --warn: #8a5b14;
  --warn-bg: #f7edd9;
  --ok: #23684f;
  --shadow: 0 10px 30px rgba(25, 35, 30, .08);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--ink); color: #fff; font-weight: 800;
  box-shadow: var(--shadow);
}
.brand-title { font-size: 17px; font-weight: 750; letter-spacing: -.02em; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.icon-btn {
  border: 1px solid var(--line); background: rgba(255,255,255,.75); color: var(--ink);
  width: 40px; height: 40px; border-radius: 13px; cursor: pointer;
}

.hero-copy { margin: 8px 2px 16px; }
.hero-copy h1 { margin: 0; font-size: clamp(25px, 7vw, 34px); line-height: 1.08; letter-spacing: -.04em; }
.hero-copy p { margin: 8px 0 0; color: var(--muted); line-height: 1.45; }

.card {
  background: var(--surface);
  border: 1px solid rgba(29,33,31,.07);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.balance-card { padding: 20px; margin-bottom: 14px; overflow: hidden; position: relative; }
.balance-card.primary { padding: 24px; }
.balance-card::after {
  content: ""; position: absolute; width: 170px; height: 170px; border-radius: 50%;
  right: -90px; top: -90px; background: var(--accent-2); opacity: .8; pointer-events: none;
}
.balance-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: relative; z-index: 1; }
.person { font-weight: 760; font-size: 17px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 6px 9px; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--muted);
}
.pill.good { background: var(--accent-2); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.balance-label { color: var(--muted); font-size: 12px; margin-top: 18px; position: relative; z-index: 1; }
.balance-amount { font-size: clamp(38px, 12vw, 54px); line-height: 1; font-weight: 830; letter-spacing: -.05em; margin-top: 5px; position: relative; z-index: 1; }
.balance-card:not(.primary) .balance-amount { font-size: 38px; }
.carry-note { color: var(--muted); font-size: 12px; margin-top: 7px; position: relative; z-index: 1; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; position: relative; z-index: 1; }
.stat { min-width: 0; }
.stat-label { color: var(--muted); font-size: 11px; }
.stat-value { font-weight: 760; margin-top: 3px; font-size: 14px; white-space: nowrap; }

.progress-wrap { margin-top: 16px; position: relative; z-index: 1; }
.progress-track { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--accent); min-width: 0; }
.progress-meta { display:flex; justify-content:space-between; gap:10px; margin-top:7px; font-size:11px; color:var(--muted); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; position: relative; z-index: 1; }
.btn {
  border: 0; border-radius: 14px; min-height: 48px; padding: 12px 16px;
  font-weight: 760; cursor: pointer; transition: transform .08s ease, opacity .08s ease;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.soft { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.small { min-height: 38px; padding: 8px 12px; border-radius: 11px; font-size: 13px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.section { margin-top: 24px; }
.section-title { display:flex; align-items:center; justify-content:space-between; gap:12px; margin: 0 2px 10px; }
.section-title h2 { margin:0; font-size:16px; letter-spacing:-.02em; }
.section-title span { color: var(--muted); font-size: 12px; }

.notice {
  padding: 14px 16px; border-radius: 15px; margin-bottom: 14px;
  background: var(--warn-bg); color: #6e4a13; font-size: 13px; line-height: 1.45;
}
.notice strong { color: inherit; }

.attention-card, .job-card, .history-card, .setting-card {
  padding: 16px; margin-bottom: 10px;
}
.job-top, .history-top { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.job-title { font-weight: 760; line-height: 1.25; }
.job-money { font-weight: 820; white-space: nowrap; }
.job-detail { margin-top: 7px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.job-meta { display:flex; flex-wrap:wrap; gap:7px; margin-top:10px; color:var(--muted); font-size:11px; }
.job-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:14px; }

.empty { padding: 28px 18px; text-align:center; color:var(--muted); border:1px dashed var(--line); border-radius:18px; }
.empty strong { color:var(--ink); display:block; margin-bottom:5px; }

.bottom-nav {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: max(10px, env(safe-area-inset-bottom));
  width: min(calc(100% - 20px), 730px); display:grid; grid-template-columns: repeat(4,1fr);
  padding: 7px; background: rgba(255,255,255,.92); border:1px solid rgba(29,33,31,.09);
  border-radius: 20px; box-shadow: 0 14px 40px rgba(25,35,30,.16); backdrop-filter: blur(18px);
}
.nav-btn { border:0; background:transparent; min-height:50px; border-radius:14px; color:var(--muted); font-size:11px; font-weight:700; cursor:pointer; position:relative; }
.nav-btn .nav-icon { display:block; font-size:19px; line-height:1; margin-bottom:4px; }
.nav-btn.active { color:var(--ink); background:var(--surface-2); }
.badge {
  position:absolute; top:4px; left:calc(50% + 7px); min-width:18px; height:18px; padding:0 5px;
  display:grid; place-items:center; background:var(--danger); color:#fff; border-radius:999px; font-size:10px;
}

.login-wrap { min-height: calc(100vh - 60px); display:grid; align-content:center; max-width:520px; margin:0 auto; }
.login-logo { width:62px; height:62px; border-radius:20px; display:grid; place-items:center; background:var(--ink); color:#fff; font-size:27px; font-weight:850; box-shadow:var(--shadow); margin-bottom:18px; }
.login-wrap h1 { margin:0; font-size:34px; letter-spacing:-.045em; }
.login-wrap > p { color:var(--muted); line-height:1.5; margin:9px 0 22px; }
.people-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.person-btn { text-align:left; border:1px solid rgba(29,33,31,.07); background:var(--surface); border-radius:18px; padding:17px; box-shadow:var(--shadow); cursor:pointer; }
.avatar { width:42px; height:42px; border-radius:14px; display:grid; place-items:center; background:var(--surface-2); font-weight:820; margin-bottom:12px; }
.person-name { font-weight:800; font-size:16px; }
.person-role { color:var(--muted); font-size:12px; margin-top:2px; text-transform:capitalize; }

.sheet-backdrop { position:fixed; z-index:90; inset:0; background:rgba(20,25,22,.38); display:flex; align-items:flex-end; justify-content:center; padding-top:40px; }
.sheet { width:min(100%,720px); max-height:92vh; overflow:auto; background:var(--surface); border-radius:24px 24px 0 0; padding:12px 18px calc(22px + env(safe-area-inset-bottom)); box-shadow:0 -12px 50px rgba(0,0,0,.18); }
.sheet-handle { width:42px; height:5px; background:var(--line); border-radius:99px; margin:0 auto 14px; }
.sheet-head { display:flex; justify-content:space-between; gap:12px; align-items:center; margin-bottom:16px; }
.sheet-head h3 { margin:0; font-size:20px; letter-spacing:-.03em; }
.close-btn { border:0; background:var(--surface-2); width:34px; height:34px; border-radius:11px; cursor:pointer; }

.form-row { margin-bottom:14px; }
.form-row label { display:block; font-size:12px; color:var(--muted); font-weight:700; margin:0 0 7px 2px; }
.input, .select, .textarea {
  width:100%; border:1px solid var(--line); background:#fff; color:var(--ink); border-radius:14px; padding:13px 14px; outline:none;
}
.input:focus, .select:focus, .textarea:focus { border-color:var(--accent); box-shadow:0 0 0 3px rgba(29,95,75,.09); }
.input.money { font-size:28px; font-weight:800; letter-spacing:-.03em; }
.textarea { resize:vertical; min-height:88px; }
.chips { display:flex; flex-wrap:wrap; gap:8px; }
.chip { border:1px solid var(--line); background:#fff; color:var(--ink); border-radius:999px; padding:9px 12px; font-size:13px; font-weight:700; cursor:pointer; }
.chip.active { background:var(--ink); border-color:var(--ink); color:#fff; }
.form-error { background:var(--danger-bg); color:var(--danger); padding:10px 12px; border-radius:12px; margin-bottom:12px; font-size:13px; }
.helper { color:var(--muted); font-size:12px; line-height:1.45; margin-top:6px; }

.pin-entry-wrap { max-width:320px; margin:0 auto 14px; }
.pin-entry { text-align:center; font-size:18px; font-weight:750; letter-spacing:.08em; }
.pin-display { display:flex; gap:8px; justify-content:center; margin:18px 0 16px; }
.pin-dot { width:13px; height:13px; border-radius:50%; background:var(--line); }
.pin-dot.filled { background:var(--ink); }
.pin-pad { display:grid; grid-template-columns:repeat(3,1fr); gap:9px; max-width:320px; margin:0 auto; }
.pin-key { border:0; background:var(--surface-2); border-radius:15px; min-height:58px; font-size:20px; font-weight:750; cursor:pointer; }
.pin-key.blank { background:transparent; }

.history-amount { font-weight:820; white-space:nowrap; }
.history-amount.negative { color:var(--danger); }
.history-amount.positive { color:var(--ok); }
.history-main { font-weight:720; }
.history-sub { color:var(--muted); font-size:12px; margin-top:4px; }
.history-card.reversed { opacity:.48; }
.history-card.reversed .history-main { text-decoration:line-through; }
.filter-row { display:flex; gap:8px; overflow:auto; padding-bottom:3px; margin-bottom:12px; }

.settings-grid { display:grid; gap:10px; }
.setting-card h3 { margin:0 0 5px; font-size:15px; }
.setting-card p { margin:0; color:var(--muted); font-size:12px; line-height:1.45; }
.setting-actions { margin-top:13px; display:flex; gap:8px; flex-wrap:wrap; }

.toast { position:fixed; z-index:120; left:50%; transform:translateX(-50%); bottom:calc(92px + env(safe-area-inset-bottom)); width:min(calc(100% - 32px),520px); background:var(--ink); color:#fff; border-radius:14px; padding:12px 14px; box-shadow:var(--shadow); text-align:center; font-size:13px; }

.loading { min-height:70vh; display:grid; place-items:center; color:var(--muted); }
.spinner { width:28px; height:28px; border:3px solid var(--line); border-top-color:var(--ink); border-radius:50%; animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

@media (min-width: 680px) {
  .app-shell { padding-left:22px; padding-right:22px; }
  .kids-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
  .kids-grid .balance-card { margin-bottom:0; }
  .people-grid { grid-template-columns:repeat(4,1fr); }
  .stat-row { gap:16px; }
  .sheet { border-radius:24px; margin-bottom:16px; }
  .sheet-backdrop { align-items:center; padding:20px; }
}
