/* ============ MoneyTrack — mobile-first ============ */

:root {
  --bg: #eef2f4;
  --card: #ffffff;
  --text: #17242b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0e7a5f;
  --primary-soft: #e2f3ed;
  --in: #0a8f4d;
  --in-soft: #e3f6ec;
  --out: #d64545;
  --out-soft: #fdeaea;
  --transfer: #7c5cd6;
  --transfer-soft: #efeafd;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --shadow: 0 1px 2px rgba(16, 40, 33, 0.06), 0 4px 16px rgba(16, 40, 33, 0.07);
  --radius: 16px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e161a;
    --card: #16232a;
    --text: #e6edf1;
    --muted: #8ba1ae;
    --border: #24343d;
    --primary: #2fbf95;
    --primary-soft: #14342b;
    --in: #34d399;
    --in-soft: #10331f;
    --out: #f07070;
    --out-soft: #3a1717;
    --transfer: #a58cf0;
    --transfer-soft: #221a38;
    --warn: #f0a34a;
    --warn-soft: #33240f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

.app { max-width: 520px; margin: 0 auto; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); min-height: 100%; }
.app.no-tabs { padding-bottom: 24px; }

.hidden { display: none !important; }

/* ---------- header ---------- */
.header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.header h1 { font-size: 19px; font-weight: 750; letter-spacing: -0.02em; flex: 1; }
.header .sub { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; flex: none;
}
.iconbtn:active { transform: scale(0.94); }
.iconbtn svg { width: 19px; height: 19px; }

/* ---------- cards & sections ---------- */
.wrap { padding: 4px 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 4px 2px -6px;
  display: flex; align-items: center; justify-content: space-between;
}
.section-title .link { color: var(--primary); font-weight: 650; text-transform: none; letter-spacing: 0; font-size: 13px; cursor: pointer; background: none; border: none; }

.hero {
  background: linear-gradient(135deg, #0e7a5f, #0b5d49);
  color: #fff; border: none;
}
.hero .label { font-size: 12.5px; opacity: 0.85; font-weight: 550; }
.hero .amount { font-size: 32px; font-weight: 800; letter-spacing: -0.03em; margin: 2px 0 12px; }
.hero .row { display: flex; gap: 8px; }
.hero .pill {
  flex: 1; background: rgba(255, 255, 255, 0.14); border-radius: 12px; padding: 8px 10px;
}
.hero .pill .k { font-size: 11px; opacity: 0.85; display: flex; gap: 4px; align-items: center; }
.hero .pill .v { font-size: 15.5px; font-weight: 750; margin-top: 1px; }

.quick { display: flex; gap: 10px; }
.quick button {
  flex: 1; border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 14px; padding: 11px 6px; font-size: 13px; font-weight: 650;
  display: flex; flex-direction: column; align-items: center; gap: 5px; cursor: pointer;
}
.quick button .ic { width: 34px; height: 34px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.quick button:active { transform: scale(0.96); }
.quick .q-out .ic { background: var(--out-soft); color: var(--out); }
.quick .q-in .ic { background: var(--in-soft); color: var(--in); }
.quick .q-transfer .ic { background: var(--transfer-soft); color: var(--transfer); }

/* ---------- account rows ---------- */
.group { display: flex; flex-direction: column; gap: 10px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px; }
.group-head .t { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.group-head .s { font-size: 13.5px; font-weight: 700; }
.acc-row {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; cursor: pointer;
}
.acc-row:active { background: var(--primary-soft); }
.acc-row .dot { width: 38px; height: 38px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 17px; }
.acc-row .name { flex: 1; min-width: 0; }
.acc-row .name .n { font-weight: 650; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-row .name .k { font-size: 11.5px; color: var(--muted); }
.acc-row .amt { font-weight: 750; font-size: 15px; letter-spacing: -0.01em; }
.acc-row .amt.neg { color: var(--out); }
.badge { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; letter-spacing: 0.02em; }
.badge.ok { background: var(--in-soft); color: var(--in); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--out-soft); color: var(--out); }
.badge.info { background: var(--transfer-soft); color: var(--transfer); }

.empty {
  text-align: center; color: var(--muted); font-size: 13.5px; padding: 26px 16px;
  border: 1.5px dashed var(--border); border-radius: var(--radius);
}
.empty .big { font-size: 30px; margin-bottom: 6px; }

/* ---------- transactions ---------- */
.txn-row { display: flex; align-items: center; gap: 12px; padding: 11px 2px; cursor: pointer; }
.txn-row:active { opacity: 0.7; }
.txn-row .ic {
  width: 40px; height: 40px; border-radius: 13px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.txn-row .ic.out { background: var(--out-soft); }
.txn-row .ic.in { background: var(--in-soft); }
.txn-row .ic.transfer { background: var(--transfer-soft); }
.txn-row .mid { flex: 1; min-width: 0; }
.txn-row .t1 { font-weight: 640; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-row .t2 { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-row .amt { font-weight: 750; font-size: 14.5px; white-space: nowrap; }
.txn-row .amt.in { color: var(--in); }
.txn-row .amt.out { color: var(--out); }
.txn-row .amt.transfer { color: var(--transfer); }
.date-head { font-size: 12px; font-weight: 700; color: var(--muted); margin: 14px 2px 4px; }
.txn-list .card { padding: 4px 14px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 650; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; color: var(--text);
  background: var(--bg); border: 1.5px solid var(--border); border-radius: 12px;
  padding: 12px 13px; outline: none; width: 100%; appearance: none; -webkit-appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.amount-input { display: flex; align-items: baseline; gap: 8px; background: var(--bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 10px 14px; }
.amount-input:focus-within { border-color: var(--primary); }
.amount-input .cur { font-size: 20px; font-weight: 700; color: var(--muted); }
.amount-input input { border: none; background: none; font-size: 28px; font-weight: 800; padding: 2px 0; width: 100%; outline: none; color: var(--text); }
.seg { display: flex; background: var(--bg); border-radius: 13px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; border: none; background: none; color: var(--muted); font: inherit; font-weight: 700; font-size: 13.5px;
  padding: 9px 4px; border-radius: 10px; cursor: pointer;
}
.seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg.seg-type button.active[data-v="out"] { color: var(--out); }
.seg.seg-type button.active[data-v="in"] { color: var(--in); }
.seg.seg-type button.active[data-v="transfer"] { color: var(--transfer); }

.btn {
  font: inherit; font-weight: 700; border: none; border-radius: 13px; padding: 13px 16px;
  background: var(--primary); color: #fff; cursor: pointer; width: 100%; font-size: 15px;
}
.btn:active { transform: scale(0.98); opacity: 0.9; }
.btn[disabled] { opacity: 0.55; }
.btn.ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--out-soft); color: var(--out); }
.btn.sm { width: auto; padding: 8px 13px; font-size: 13px; border-radius: 11px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--text);
  background: var(--bg); border: 1.5px solid var(--border); border-radius: 999px; padding: 8px 13px; cursor: pointer;
}
.chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.palette { display: flex; gap: 9px; flex-wrap: wrap; }
.palette button { width: 34px; height: 34px; border-radius: 11px; border: 2.5px solid transparent; cursor: pointer; }
.palette button.active { border-color: var(--text); transform: scale(1.06); }

.form-error { background: var(--out-soft); color: var(--out); font-size: 13px; font-weight: 600; border-radius: 11px; padding: 10px 13px; margin-bottom: 14px; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 26px; }
.logo svg { width: 72px; height: 72px; border-radius: 20px; }
.logo h1 { font-size: 24px; letter-spacing: -0.02em; }
.logo p { color: var(--muted); font-size: 13.5px; margin-top: -6px; }

/* ---------- sheets ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 20, 16, 0.5);
  display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity 0.18s;
}
.overlay.open { opacity: 1; }
.overlay.center { align-items: center; padding: 24px; }
.sheet {
  background: var(--card); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(24px); transition: transform 0.2s;
}
.overlay.center .sheet { border-radius: 22px; transform: none; max-width: 400px; }
.overlay.open .sheet { transform: none; }
.grabber { width: 40px; height: 4.5px; background: var(--border); border-radius: 99px; margin: 4px auto 12px; }
.sheet h2 { font-size: 17px; font-weight: 750; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.sheet h2 .x { background: var(--bg); border: none; color: var(--muted); width: 30px; height: 30px; border-radius: 99px; font-size: 15px; cursor: pointer; }
.sheet .actions { display: flex; gap: 10px; margin-top: 6px; }

.creds { text-align: center; }
.creds .ok-ic { width: 58px; height: 58px; margin: 4px auto 12px; background: var(--in-soft); color: var(--in); border-radius: 18px; display: flex; align-items: center; justify-content: center; font-size: 27px; }
.creds .cred-box {
  background: var(--bg); border: 1.5px dashed var(--border); border-radius: 14px; padding: 14px; margin: 12px 0 4px;
}
.creds .cred-box .k { font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.creds .cred-box .v { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 19px; font-weight: 700; margin-top: 2px; user-select: all; word-break: break-all; }
.creds .warn { font-size: 12.5px; color: var(--warn); font-weight: 600; margin: 10px 2px 14px; }

/* ---------- stats ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--border); border-radius: 13px; padding: 6px 8px; }
.month-nav button { background: var(--bg); border: none; color: var(--text); width: 34px; height: 34px; border-radius: 10px; font-size: 16px; cursor: pointer; }
.month-nav .m { font-weight: 750; font-size: 15px; }
.stat3 { display: flex; gap: 9px; }
.stat3 .card { flex: 1; padding: 11px 12px; }
.stat3 .k { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat3 .v { font-size: 16.5px; font-weight: 800; margin-top: 2px; letter-spacing: -0.01em; }
.stat3 .v.in { color: var(--in); } .stat3 .v.out { color: var(--out); }
.delta { font-size: 12.5px; font-weight: 650; display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 4px 10px; }
.delta.up { background: var(--out-soft); color: var(--out); }
.delta.down { background: var(--in-soft); color: var(--in); }

.bar-row { margin-bottom: 11px; }
.bar-row .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar-row .top .n { font-weight: 620; }
.bar-row .top .v { font-weight: 700; color: var(--muted); }
.bar-row .track { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 99px; background: var(--primary); }
.bar-row .fill.out { background: var(--out); }
.bar-row .fill.in { background: var(--in); }

.donut-flex { display: flex; align-items: center; gap: 16px; }
.donut-flex svg { flex: none; }
.legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.legend .li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend .li .sw { width: 10px; height: 10px; border-radius: 4px; flex: none; }
.legend .li .n { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.legend .li .p { color: var(--muted); font-weight: 600; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  max-width: 520px; margin: 0 auto;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}
.tabbar .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10.5px; font-weight: 650; color: var(--muted); cursor: pointer; background: none; border: none; font-family: inherit;
}
.tabbar .tab svg { width: 22px; height: 22px; }
.tabbar .tab.active { color: var(--primary); }
.tabbar .tab:active { opacity: 0.7; }
.tabbar .fab-slot { flex: 1; display: flex; align-items: center; justify-content: center; }
.tabbar .fab {
  width: 52px; height: 52px; border-radius: 18px; border: none; cursor: pointer;
  background: var(--primary); color: #fff; font-size: 26px; font-weight: 500;
  box-shadow: 0 6px 18px rgba(14, 122, 95, 0.45); margin-bottom: 14px;
  display: flex; align-items: center; justify-content: center;
}
.tabbar .fab:active { transform: scale(0.94); }

/* ---------- misc ---------- */
.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom, 0px)); left: 50%;
  transform: translateX(-50%) translateY(8px); z-index: 90;
  background: #1d2b33; color: #fff; font-size: 13.5px; font-weight: 600;
  padding: 11px 18px; border-radius: 13px; opacity: 0; transition: all 0.2s; pointer-events: none;
  max-width: 86vw; text-align: center; box-shadow: var(--shadow);
}
.toast.err { background: var(--out); }
.toast.show { opacity: 1; transform: translateX(-50%); }
body.no-tabs .toast { bottom: 24px; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters .field { margin-bottom: 0; }
.filters select, .filters input { padding: 9px 11px; font-size: 13.5px; border-radius: 10px; }
.filters .span2 { grid-column: span 2; }

.load-more { background: var(--bg); border: 1px solid var(--border); color: var(--text); font: inherit; font-weight: 650; font-size: 13.5px; padding: 11px; border-radius: 12px; cursor: pointer; width: 100%; }

.list-actions { display: flex; flex-direction: column; }
.list-actions button {
  font: inherit; text-align: left; background: none; border: none; color: var(--text);
  padding: 13px 4px; font-size: 14.5px; font-weight: 600; cursor: pointer;
  border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center;
}
.list-actions button:last-child { border-bottom: none; }
.list-actions button.danger { color: var(--out); }

.search-box { position: relative; }
.search-box input { padding-left: 34px; }
.search-box::before { content: "🔍"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: 0.6; }

.count-note { font-size: 12px; color: var(--muted); text-align: center; }

@media (min-width: 560px) {
  body { background: linear-gradient(160deg, #dfe7ea, #eef2f4); }
  .app, .tabbar { box-shadow: 0 0 0 1px var(--border); }
  @media (prefers-color-scheme: dark) {
    body { background: #080d10; }
  }
}
