/* ============ Cashflow กค Liquid Glass ============ */
* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
:root {
  --accent:#ff3b5c; --accent-soft:rgba(255,59,92,.16);
  --income:#34d17b; --expense:#ff5f6d;
  --radius:22px;
  --font:-apple-system,BlinkMacSystemFont,'SF Pro Text','Helvetica Neue',Helvetica,Arial,sans-serif;
}
html[data-theme="dark"] {
  --bg:#0b0b10; --text:#f5f5f7; --text-dim:#9a9aa5;
  --glass-bg:rgba(255,255,255,.07); --glass-bg-strong:rgba(22,22,28,.82);
  --glass-border:rgba(255,255,255,.13); --glass-hi:rgba(255,255,255,.14);
  --field-bg:rgba(255,255,255,.06); --row-hover:rgba(255,255,255,.05);
  --shadow:0 18px 50px rgba(0,0,0,.55);
  color-scheme:dark;
}
html[data-theme="light"] {
  --bg:#eef0f6; --text:#15151a; --text-dim:#6a6a75;
  --glass-bg:rgba(255,255,255,.55); --glass-bg-strong:rgba(255,255,255,.88);
  --glass-border:rgba(20,20,40,.1); --glass-hi:rgba(255,255,255,.7);
  --field-bg:rgba(20,20,40,.05); --row-hover:rgba(20,20,40,.04);
  --shadow:0 18px 50px rgba(40,40,80,.18);
  color-scheme:light;
}
html,body { min-height:100%; }
body {
  font-family:var(--font); background:var(--bg); color:var(--text);
  -webkit-font-smoothing:antialiased; transition:background .35s;
}
.hidden { display:none !important; }

.bg-orbs { position:fixed; inset:0; z-index:-1; overflow:hidden; }
.orb { position:absolute; border-radius:50%; filter:blur(90px); opacity:.5; }
html[data-theme="light"] .orb { opacity:.35; }
.o1 { width:52vmax; height:52vmax; top:-22vmax; right:-18vmax; background:radial-gradient(circle,#ff3b5c44,transparent 65%); }
.o2 { width:46vmax; height:46vmax; bottom:-20vmax; left:-16vmax; background:radial-gradient(circle,#34d17b33,transparent 65%); }
.o3 { width:40vmax; height:40vmax; top:32%; left:52%; background:radial-gradient(circle,#4da3ff2e,transparent 65%); }

.glass {
  background:var(--glass-bg);
  backdrop-filter:blur(26px) saturate(180%);
  -webkit-backdrop-filter:blur(26px) saturate(180%);
  border:1px solid var(--glass-border);
  border-radius:var(--radius);
  box-shadow:inset 0 1px 0 var(--glass-hi), var(--shadow);
}
.glass-bar {
  background:var(--glass-bg-strong);
  backdrop-filter:blur(30px) saturate(190%);
  -webkit-backdrop-filter:blur(30px) saturate(190%);
  border-bottom:1px solid var(--glass-border);
}

/* ---------- Auth ---------- */
.auth-wrap { min-height:100dvh; display:flex; align-items:center; justify-content:center; padding:24px; }
.auth-card { width:100%; max-width:400px; padding:34px 28px; text-align:center; }
.brand-mark {
  width:64px; height:64px; margin:0 auto 14px; border-radius:18px;
  display:flex; align-items:center; justify-content:center;
  font-size:32px; font-weight:700; color:#fff;
  background:linear-gradient(135deg,#ff3b5c,#c81e3e);
  box-shadow:0 8px 24px rgba(255,59,92,.35), inset 0 1px 0 rgba(255,255,255,.35);
}
.brand-mark.small { width:34px; height:34px; border-radius:10px; font-size:18px; margin:0; }
.eyebrow { font-size:11px; letter-spacing:.32em; color:var(--text-dim); margin-bottom:10px; }
.auth-title { font-size:27px; font-weight:700; letter-spacing:-.02em; margin-bottom:8px; }
.auth-sub { font-size:14px; color:var(--text-dim); margin-bottom:24px; line-height:1.45; }
.field { display:block; text-align:left; margin-bottom:14px; }
.field span { display:block; font-size:12px; color:var(--text-dim); margin-bottom:6px; letter-spacing:.04em; }
.field input, .field select {
  width:100%; padding:13px 14px; font-size:16px; font-family:var(--font);
  color:var(--text); background:var(--field-bg);
  border:1px solid var(--glass-border); border-radius:14px; outline:none;
  transition:border-color .2s, box-shadow .2s;
}
.field input:focus, .field select:focus { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }
.form-error { color:var(--expense); font-size:13px; margin:4px 0 10px; }
.btn-primary {
  width:100%; padding:14px; margin-top:6px; font-size:16px; font-weight:600; font-family:var(--font);
  color:#fff; background:linear-gradient(135deg,#ff3b5c,#d62443);
  border:none; border-radius:16px; cursor:pointer;
  box-shadow:0 8px 22px rgba(255,59,92,.35), inset 0 1px 0 rgba(255,255,255,.3);
  transition:transform .15s, opacity .2s;
}
.btn-primary:active { transform:scale(.98); }
.btn-primary:disabled { opacity:.55; }
.btn-ghost {
  padding:8px 14px; font-size:13px; font-weight:500; font-family:var(--font);
  color:var(--text); background:var(--field-bg);
  border:1px solid var(--glass-border); border-radius:12px; cursor:pointer;
  transition:background .2s;
}
.btn-ghost:hover { background:var(--row-hover); }
.btn-ghost.danger { color:var(--expense); }

/* ---------- Header ---------- */
.app-header {
  position:sticky; top:0; z-index:40;
  display:flex; align-items:center; gap:12px;
  padding:12px 16px calc(12px + env(safe-area-inset-top,0px)); padding-top:calc(12px + env(safe-area-inset-top,0px));
}
.brand-mini { display:flex; align-items:center; gap:9px; }
.brand-word { font-size:12px; letter-spacing:.28em; color:var(--text-dim); font-weight:600; }
.household-name {
  flex:1; min-width:0; text-align:left; font-size:19px; font-weight:700; letter-spacing:-.01em;
  color:var(--text); background:none; border:none; font-family:var(--font); cursor:pointer;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.header-actions { display:flex; gap:8px; }
.icon-btn {
  width:38px; height:38px; border-radius:50%; flex:none;
  display:flex; align-items:center; justify-content:center;
  background:var(--field-bg); border:1px solid var(--glass-border);
  color:var(--text); cursor:pointer; transition:background .2s;
}
.icon-btn:hover { background:var(--row-hover); }
.icon-btn svg { width:19px; height:19px; }

/* ---------- Main ---------- */
.app-main { max-width:1160px; margin:0 auto; padding:18px 16px calc(48px + env(safe-area-inset-bottom,0px)); }

.summary-row { display:grid; grid-template-columns:1fr; gap:12px; }
.sum-card { padding:18px 20px; }
.sum-label { font-size:11px; letter-spacing:.22em; color:var(--text-dim); font-weight:600; }
.sum-period { opacity:.7; }
.sum-number {
  font-size:clamp(30px,8vw,44px); font-weight:700; letter-spacing:-.02em;
  font-variant-numeric:tabular-nums; margin:6px 0 10px;
}
.sum-card.expense .sum-number { color:var(--expense); }
.sum-card.income .sum-number { color:var(--income); }
.sum-card.flow.positive .sum-number { color:var(--income); }
.sum-card.flow.negative .sum-number { color:var(--expense); }
.sum-persons { display:flex; flex-direction:column; gap:4px; }
.sum-person { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--text-dim); }
.sum-person .dot { width:8px; height:8px; border-radius:50%; flex:none; }
.sum-person .val { margin-left:auto; font-variant-numeric:tabular-nums; color:var(--text); }

.controls-row { display:flex; gap:10px; margin:18px 0 12px; flex-wrap:wrap; }
.seg { display:inline-flex; padding:4px; border-radius:16px; box-shadow:none; }
.seg-btn {
  padding:8px 16px; font-size:14px; font-weight:500; font-family:var(--font);
  color:var(--text-dim); background:none; border:none; border-radius:12px; cursor:pointer;
  transition:background .2s, color .2s;
}
.seg-btn.active { background:var(--glass-hi); color:var(--text); box-shadow:0 2px 8px rgba(0,0,0,.18); }
.seg.small .seg-btn { padding:7px 13px; font-size:13px; }

.person-filter { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:18px; }
.chip {
  display:inline-flex; align-items:center; gap:7px;
  padding:7px 14px; font-size:13px; font-weight:500; font-family:var(--font);
  color:var(--text-dim); background:var(--field-bg);
  border:1px solid var(--glass-border); border-radius:999px; cursor:pointer;
  transition:all .2s;
}
.chip .dot { width:9px; height:9px; border-radius:50%; }
.chip.active { color:var(--text); background:var(--accent-soft); border-color:var(--accent); }

/* ---------- Sections & categories ---------- */
.section-head { display:flex; align-items:center; justify-content:space-between; margin:26px 2px 12px; }
.section-title { font-size:23px; font-weight:700; letter-spacing:-.02em; }
.expense-title { color:var(--expense); }
.income-title { color:var(--income); }
.cat-stack { display:flex; flex-direction:column; gap:12px; }

.cat-card { overflow:visible; }
.cat-head {
  display:flex; align-items:center; gap:12px; width:100%;
  padding:15px 16px; background:none; border:none; cursor:pointer;
  font-family:var(--font); color:var(--text); text-align:left;
}
.cat-chevron { width:18px; height:18px; color:var(--text-dim); transition:transform .25s; flex:none; }
.cat-card.open .cat-chevron { transform:rotate(90deg); }
.cat-emoji {
  width:40px; height:40px; border-radius:12px; flex:none;
  display:flex; align-items:center; justify-content:center; font-size:20px;
  background:var(--field-bg); border:1px solid var(--glass-border);
}
.cat-name { font-size:16px; font-weight:600; flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cat-count {
  font-size:12px; color:var(--text-dim); background:var(--field-bg);
  padding:3px 9px; border-radius:999px; flex:none; font-variant-numeric:tabular-nums;
}
.cat-sum { font-size:17px; font-weight:700; font-variant-numeric:tabular-nums; flex:none; }
.cat-sum.expense { color:var(--expense); }
.cat-sum.income { color:var(--income); }
.cat-menu-btn { flex:none; }

.cat-body { display:none; padding:0 10px 10px; }
.cat-card.open .cat-body { display:block; }

/* ---------- Entries ---------- */
.entry {
  display:grid;
  grid-template-columns:minmax(0,1.6fr) auto auto auto auto 34px;
  align-items:center; gap:10px;
  padding:10px 8px; border-radius:14px;
  transition:background .2s;
}
.entry:hover { background:var(--row-hover); }
.entry .drag-handle { display:none; width:22px; color:var(--text-dim); cursor:grab; touch-action:none; }
.entry.incomplete { background:rgba(255,176,32,.07); box-shadow:inset 2px 0 0 rgba(255,176,32,.55); }
.entry.flag-check { background:rgba(255,176,32,.1); box-shadow:inset 2px 0 0 #ffb020; }
.entry.flag-cancel { background:rgba(255,95,109,.1); box-shadow:inset 2px 0 0 var(--expense); }
.entry-name {
  min-width:0; width:100%; box-sizing:border-box; font-size:15px; background:transparent; border:none; outline:none;
  color:var(--text); font-family:var(--font); padding:6px 4px; border-radius:8px;
}
.entry-name:focus { background:var(--field-bg); }
.entry-name::placeholder { color:var(--text-dim); }
.entry-flag-chip { display:block; font-size:11px; margin-top:1px; }
.entry.flag-check .entry-flag-chip { color:#ffb020; }
.entry.flag-cancel .entry-flag-chip { color:var(--expense); }
.entry.incomplete .entry-flag-chip { color:#ffb020; }
.person-pill {
  display:inline-flex; align-items:center; gap:6px;
  padding:5px 10px; font-size:12.5px; font-family:var(--font);
  background:var(--field-bg); border:1px solid var(--glass-border); border-radius:999px;
  color:var(--text); cursor:pointer; white-space:nowrap;
}
.person-pill .dot { width:8px; height:8px; border-radius:50%; flex:none; }
select.entry-rhythm {
  padding:6px 8px; font-size:12.5px; font-family:var(--font);
  background:var(--field-bg); border:1px solid var(--glass-border);
  border-radius:10px; color:var(--text); cursor:pointer;
}
.entry-amount {
  width:96px; text-align:right; font-variant-numeric:tabular-nums;
  padding:7px 9px; font-size:14.5px; font-family:var(--font);
  background:var(--field-bg); border:1px solid var(--glass-border); border-radius:10px;
  color:var(--text); outline:none;
}
.entry-amount:focus { border-color:var(--accent); }
.entry-yearly { font-size:13px; color:var(--text-dim); font-variant-numeric:tabular-nums; white-space:nowrap; }
.entry-menu-btn {
  width:30px; height:30px; border-radius:50%; border:none; cursor:pointer;
  background:transparent; color:var(--text-dim); display:flex; align-items:center; justify-content:center;
}
.entry-menu-btn:hover { background:var(--row-hover); color:var(--text); }
.entry-menu-btn svg { width:17px; height:17px; }

.add-entry {
  display:flex; align-items:center; justify-content:center; gap:6px;
  width:calc(100% - 8px); margin:6px 4px 4px; padding:10px;
  font-size:13.5px; font-weight:500; font-family:var(--font);
  color:var(--text-dim); background:none;
  border:1px dashed var(--glass-border); border-radius:12px; cursor:pointer;
  transition:color .2s, border-color .2s;
}
.add-entry:hover { color:var(--text); border-color:var(--text-dim); }

/* reorder modes */
.cat-card.reorder-entries .entry { grid-template-columns:22px minmax(0,1.6fr) auto auto auto 34px; }
.cat-card.reorder-entries .entry .drag-handle { display:flex; }
.cat-card.reorder-entries .entry-yearly { display:none; }
.cat-card.reorder-entries .entry input,
.cat-card.reorder-entries .entry select,
.cat-card.reorder-entries .entry .person-pill { pointer-events:none; opacity:.65; }
.dragging { opacity:.45; }
.drag-over { box-shadow:inset 0 2px 0 var(--accent) !important; }

/* ---------- Settings sheet ---------- */
.overlay { position:fixed; inset:0; background:rgba(0,0,0,.45); backdrop-filter:blur(4px); z-index:60; }
.sheet {
  position:fixed; z-index:70;
  left:0; right:0; bottom:0; top:auto;
  max-height:88dvh; border-radius:26px 26px 0 0;
  background:var(--glass-bg-strong);
  display:flex; flex-direction:column;
  animation:slideUp .3s cubic-bezier(.2,.9,.3,1);
}
@keyframes slideUp { from { transform:translateY(40px); opacity:0; } to { transform:none; opacity:1; } }
.sheet-head { display:flex; align-items:center; justify-content:space-between; padding:18px 20px 8px; }
.sheet-body { overflow-y:auto; padding:0 20px calc(24px + env(safe-area-inset-bottom,0px)); }
.sheet-group { margin-bottom:26px; }
.sheet-group h3 { font-size:16px; font-weight:650; margin-bottom:12px; }
.hint { font-size:12.5px; color:var(--text-dim); margin-bottom:10px; }
.mini-label { font-size:11px; letter-spacing:.2em; font-weight:600; margin:12px 0 8px; }
.field.inline { display:flex; align-items:center; gap:12px; }
.field.inline span { margin:0; width:52px; flex:none; }

.person-row { display:flex; align-items:center; gap:10px; padding:8px 0; }
.person-row input[type="color"] {
  width:34px; height:34px; border:none; border-radius:50%; padding:0;
  background:none; cursor:pointer; flex:none;
}
.person-row input[type="color"]::-webkit-color-swatch-wrapper { padding:0; }
.person-row input[type="color"]::-webkit-color-swatch { border:2px solid var(--glass-border); border-radius:50%; }
.person-row .p-name {
  flex:1; min-width:0; font-size:15px; padding:8px 10px;
  background:var(--field-bg); border:1px solid var(--glass-border); border-radius:10px;
  color:var(--text); font-family:var(--font); outline:none;
}
.person-row .kid-tag, .person-row .shared-tag { font-size:11px; color:var(--text-dim); flex:none; }

.sort-list { display:flex; flex-direction:column; gap:6px; }
.sort-item {
  display:flex; align-items:center; gap:10px;
  padding:10px 12px; border-radius:12px;
  background:var(--field-bg); border:1px solid var(--glass-border);
  font-size:14px;
}
.sort-item .drag-handle { color:var(--text-dim); cursor:grab; touch-action:none; display:flex; }
.sort-item .s-emoji { width:22px; text-align:center; }
.sort-item .s-name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* ---------- Popover menu ---------- */
.menu-pop {
  position:fixed; z-index:80; min-width:210px; padding:6px;
  border-radius:16px; background:var(--glass-bg-strong);
}
.menu-item {
  display:flex; align-items:center; gap:10px; width:100%;
  padding:11px 12px; border:none; background:none; cursor:pointer;
  font-size:14.5px; font-family:var(--font); color:var(--text);
  border-radius:11px; text-align:left; transition:background .15s;
}
.menu-item:hover { background:var(--row-hover); }
.menu-item svg { width:17px; height:17px; flex:none; color:var(--text-dim); }
.menu-item.danger { color:var(--expense); }
.menu-item.danger svg { color:var(--expense); }
.menu-item.active-flag { background:var(--accent-soft); }
.menu-sep { height:1px; background:var(--glass-border); margin:5px 8px; }

/* ---------- Toast ---------- */
.toast {
  position:fixed; left:50%; bottom:calc(24px + env(safe-area-inset-bottom,0px)); transform:translateX(-50%);
  z-index:90; padding:12px 20px; border-radius:999px;
  background:var(--glass-bg-strong); backdrop-filter:blur(20px);
  border:1px solid var(--glass-border); box-shadow:var(--shadow);
  font-size:14px; animation:slideUp .25s;
}

.foot-note { text-align:center; font-size:12px; color:var(--text-dim); margin-top:34px; }

/* ---------- Responsive ---------- */
@media (min-width:760px) {
  .summary-row { grid-template-columns:1fr 1fr 1fr; }
  #category-lists.tab-overview { display:grid; grid-template-columns:1fr 1fr; gap:0 28px; align-items:start; }
  .sheet { left:auto; right:24px; top:24px; bottom:24px; width:420px; max-height:none; border-radius:26px; }
  .entry { grid-template-columns:minmax(0,1.8fr) auto auto auto auto 34px; }
  .entry-yearly { min-width:88px; text-align:right; }
}
@media (max-width:430px) {
  .entry { grid-template-columns:minmax(0,1.5fr) auto auto 34px; grid-row-gap:4px; }
  .entry .person-pill { grid-column:1; grid-row:2; justify-self:start; }
  .entry .drag-handle { display:none !important; }
  .cat-card.reorder-entries .entry { grid-template-columns:22px minmax(0,1.5fr) auto 34px; }
  .cat-card.reorder-entries .entry .drag-handle { display:flex !important; grid-row:1/3; }
  .entry-amount { width:82px; }
  .entry-yearly { display:none; }
}

/* two-column overview: wrap entry controls to a second line */
#category-lists.tab-overview .entry { grid-template-columns:minmax(0,1fr) auto auto 34px; grid-row-gap:4px; }
#category-lists.tab-overview .entry .person-pill { grid-column:1; grid-row:2; justify-self:start; }
#category-lists.tab-overview .entry .entry-yearly { display:none; }
@media (min-width:760px) {
  #category-lists.tab-overview .entry { grid-template-columns:minmax(0,1fr) auto auto 34px; }
}

/* mobile: entry name gets full row, controls wrap below */
@media (max-width:430px) {
  #category-lists .entry { grid-template-columns:minmax(0,1fr) auto 34px !important; grid-row-gap:8px; }
  #category-lists .entry > div:nth-child(2) { grid-column:1 / -1; grid-row:1; }
  #category-lists .entry .entry-rhythm { grid-column:1; grid-row:2; justify-self:start; }
  #category-lists .entry .entry-amount { grid-column:2; grid-row:2; width:90px; }
  #category-lists .entry .entry-menu-btn { grid-column:3; grid-row:2; }
  #category-lists .entry .person-pill { grid-column:1; grid-row:3; }
}
@media (max-width:430px) {
  #category-lists.tab-overview .entry .entry-rhythm { grid-column:1; grid-row:2; justify-self:start; }
  #category-lists.tab-overview .entry .entry-amount { grid-column:2; grid-row:2; width:90px; }
  #category-lists.tab-overview .entry .entry-menu-btn { grid-column:3; grid-row:2; }
  #category-lists.tab-overview .entry .person-pill { grid-column:1; grid-row:3; }
}
