/* ============================================================
   Home Finance — minimal, flat, lightweight dark theme.
   No web fonts, no glow, no animations, no blur. Runs anywhere.
   ============================================================ */

:root {
  --bg:        #0D1117;
  --bg-deep:   #0A0D12;
  --card:      #161B22;
  --card-2:    #1B222B;
  --border:    #283039;
  --border-soft:#1E252E;

  --text:      #E8EDF2;
  --text-dim:  #9AA5B1;
  --text-faint:#626d7a;

  --accent:    #E8A838;
  --accent-ink:#1A1206;
  --accent-soft:rgba(232,168,56,0.14);
  --accent-line:rgba(232,168,56,0.40);

  --green:     #3FC98A;
  --green-soft:rgba(63,201,138,0.14);
  --red:       #FF6B6B;
  --red-soft:  rgba(255,107,107,0.14);
  --blue:      #5AA0FF;
  --blue-soft: rgba(90,160,255,0.14);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --radius: 14px;
  --radius-sm: 10px;
  --app-max: 540px;
  --nav-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-dim); }
.small { font-size: 0.82rem; }
.req { color: var(--accent); }
::selection { background: var(--accent-soft); }

/* ============================ AUTH (tiny) ============================ */
.auth-screen {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 300px; text-align: center; }
.auth-brand { margin-bottom: 18px; }
.auth-mark, .brand-mark {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  color: var(--accent); font-size: 22px; font-weight: 700;
}
.auth-brand h1 { font-size: 1.35rem; font-weight: 700; margin-top: 12px; letter-spacing: -0.01em; }
.auth-tag { color: var(--text-dim); font-size: 0.85rem; margin-top: 2px; }
.auth-brand h1 + .auth-tag { margin-bottom: 0; }
#auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; text-align: left; }
.auth-hint { font-size: 0.78rem; color: var(--text-faint); min-height: 1em; }
.auth-hint.error { color: var(--red); }
.auth-footer { display: none; }

/* ============================ APP SHELL ============================ */
.app {
  max-width: var(--app-max);
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
}
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px;
  padding-top: calc(13px + env(safe-area-inset-top, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 9px;
  background: transparent; border: 1px solid transparent; color: var(--text-dim); cursor: pointer;
}
.icon-btn:hover { background: var(--card); color: var(--text); }

.views { padding: 18px 16px; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 26px 2px 14px; gap: 12px;
}
.section-head:first-child { margin-top: 4px; }
.section-head h2 { font-weight: 700; font-size: 1.08rem; letter-spacing: -0.01em; }

/* ============================ HERO ============================ */
.hero {
  text-align: center;
  padding: 24px 18px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
}
.hero-label { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.68rem; color: var(--accent); font-weight: 700; }
.hero-amount { font-size: clamp(2.3rem, 11vw, 3rem); font-weight: 700; letter-spacing: -0.02em; margin: 8px 0 6px; line-height: 1; }
.hero-delta { font-size: 0.84rem; color: var(--text-dim); display: flex; gap: 7px; justify-content: center; align-items: center; flex-wrap: wrap; }
.delta-chip { font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600; padding: 2px 8px; border-radius: 16px; }
.delta-chip.up { color: var(--green); background: var(--green-soft); }
.delta-chip.down { color: var(--red); background: var(--red-soft); }
.delta-chip.flat { color: var(--text-dim); background: var(--bg-deep); }

/* ============================ CARDS ============================ */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stack > * + * { margin-top: 10px; }

.acct-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.acct-card {
  position: relative; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 13px 12px; overflow: hidden;
}
.acct-card .swatch { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.acct-card .acct-name { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 5px; padding-left: 5px; display: flex; align-items: center; gap: 6px; }
.acct-card .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.acct-card .acct-bal { font-family: var(--font-mono); font-size: 1.12rem; font-weight: 600; padding-left: 5px; letter-spacing: -0.01em; }

.acct-row { display: flex; align-items: flex-start; gap: 12px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 15px; }
.acct-row .swatch-dot { width: 11px; height: 11px; border-radius: 4px; flex: none; margin-top: 4px; }
.acct-row .meta { flex: 1; min-width: 0; }
.acct-row .name-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.acct-row .name { font-weight: 600; font-size: 0.95rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-row .bal { font-family: var(--font-mono); font-weight: 600; font-size: 1.02rem; flex: none; }
.acct-row .sub { color: var(--text-faint); font-size: 0.74rem; font-family: var(--font-mono); margin-top: 2px; }
.acct-row .acct-actions { display: flex; gap: 6px; margin-top: 11px; }

/* ============================ TRANSACTIONS ============================ */
.txn-list { display: flex; flex-direction: column; }
.txn { display: flex; align-items: center; gap: 11px; padding: 11px 2px; border-bottom: 1px solid var(--border-soft); cursor: pointer; }
.txn:hover { background: var(--card); }
.txn:last-child { border-bottom: none; }
.txn-ico { width: 34px; height: 34px; border-radius: 9px; flex: none; display: grid; place-items: center; font-size: 15px; }
.txn-ico.expense { background: var(--red-soft); color: var(--red); }
.txn-ico.income { background: var(--green-soft); color: var(--green); }
.txn-ico.transfer { background: var(--blue-soft); color: var(--blue); }
.txn-ico.adjustment { background: var(--accent-soft); color: var(--accent); }
.txn-body { flex: 1; min-width: 0; }
.txn-top { display: flex; align-items: baseline; gap: 7px; }
.txn-dir { font-weight: 600; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-desc { color: var(--text-dim); font-size: 0.79rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-meta { display: flex; align-items: center; gap: 7px; margin-top: 2px; }
.txn-time { color: var(--text-faint); font-size: 0.71rem; font-family: var(--font-mono); }
.cat-tag { font-size: 0.67rem; font-weight: 600; padding: 1px 7px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.txn-amt { font-family: var(--font-mono); font-weight: 600; font-size: 0.95rem; white-space: nowrap; }
.txn-amt.neg { color: var(--red); }
.txn-amt.pos { color: var(--green); }
.txn-amt.neutral { color: var(--text); }
.txn .del { opacity: 0.4; color: var(--text-faint); background: none; border: none; cursor: pointer; font-size: 15px; padding: 4px; flex: none; }
.txn .del:hover { opacity: 1; color: var(--red); }

/* ============================ SEGMENTED (recent filter) ============================ */
.segmented { display: flex; gap: 3px; padding: 3px; background: var(--bg-deep); border: 1px solid var(--border-soft); border-radius: 11px; }
.seg { flex: 1; border: none; background: transparent; cursor: pointer; color: var(--text-dim); font-family: var(--font-ui); font-weight: 600; font-size: 0.74rem; padding: 6px 8px; border-radius: 8px; white-space: nowrap; }
.seg:hover { color: var(--text); }
.seg.active { background: var(--card-2); color: var(--accent); }

/* ============================ FORMS ============================ */
.form, .flow-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 9px; }
.field-label { font-size: 0.8rem; color: var(--text-dim); font-weight: 600; }
.field-row { display: flex; gap: 10px; }
.field-row.tight { gap: 8px; }
.field-row > .field { flex: 1; }

.input {
  width: 100%; background: var(--bg-deep); border: 1px solid var(--border); color: var(--text);
  font-family: var(--font-ui); font-size: 16px; padding: 13px 14px; border-radius: 10px; outline: none;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { border-color: var(--accent-line); }
.input.mono { font-family: var(--font-mono); }
.textarea { resize: vertical; min-height: 46px; line-height: 1.45; }
.select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239AA5B1' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}
input[type="date"], input[type="time"], input[type="datetime-local"] { color-scheme: dark; }

/* ============================ FROM → TO (log) ============================ */
.flow-form { padding: 22px 18px; }
#log-fields { display: flex; flex-direction: column; gap: 18px; }
.flow-row { display: flex; align-items: center; gap: 14px; }
.flow-tag { width: 46px; flex: none; font-size: 0.82rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.flow-select { flex: 1; }
.flow-arrow { text-align: center; color: var(--text-faint); font-size: 1rem; line-height: 1; margin: -6px 0; }
.amount-wrap { display: flex; align-items: center; gap: 8px; background: var(--bg-deep); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-top: 2px; }
.amount-cur { font-size: 1.5rem; color: var(--text-dim); }
.amount-input { flex: 1; width: 100%; background: none; border: none; outline: none; color: var(--text); font-size: 1.7rem; font-weight: 700; }
.amount-input::placeholder { color: var(--text-faint); }

#log-out-fields { display: flex; flex-direction: column; gap: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip { padding: 9px 15px; border-radius: 18px; background: var(--bg-deep); border: 1px solid var(--border); color: var(--text-dim); font-family: var(--font-ui); font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.chip:hover { color: var(--text); border-color: var(--text-faint); }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.add { border-style: dashed; }
.new-cat { margin-top: 12px; }

#cat-filter { margin-bottom: 14px; }
.cat-custom { display: flex; flex-direction: column; gap: 10px; margin: -4px 0 16px; }

/* ============================ BUTTONS ============================ */
.btn {
  font-family: var(--font-ui); font-weight: 600; font-size: 0.92rem;
  border-radius: 10px; padding: 12px 18px; cursor: pointer;
  border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.05); }
.btn-ghost { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--card-2); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-block { width: 100%; }
.btn-lg { padding: 16px; font-size: 1rem; }
.btn-sm { padding: 8px 12px; font-size: 0.82rem; border-radius: 9px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* ============================ TIME MACHINE ============================ */
.timemachine { display: flex; flex-direction: column; gap: 12px; }
.tm-controls { display: flex; gap: 10px; }
.tm-controls .input { flex: 1; }
.tm-result:empty { display: none; }
.tm-result { display: flex; flex-direction: column; border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 2px; }
.tm-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border-soft); }
.tm-row:last-child { border-bottom: none; }
.tm-row .nm { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.tm-row .nm .dot { width: 8px; height: 8px; border-radius: 50%; }
.tm-row .vl { font-family: var(--font-mono); font-weight: 600; }
.tm-row.total { margin-top: 5px; padding-top: 11px; border-top: 1px solid var(--border); border-bottom: none; }
.tm-row.total .nm { font-weight: 700; }
.tm-row.total .vl { color: var(--accent); font-size: 1.02rem; }
.tm-when { text-align: center; color: var(--text-faint); font-size: 0.75rem; font-family: var(--font-mono); margin-bottom: 4px; }

/* ============================ CATEGORIES ============================ */
.cat-item { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.cat-head { display: flex; align-items: center; gap: 12px; padding: 13px 14px; cursor: pointer; }
.cat-head:hover { background: var(--card-2); }
.cat-rank { font-family: var(--font-mono); color: var(--text-faint); font-size: 0.82rem; width: 22px; }
.cat-info { flex: 1; min-width: 0; }
.cat-name { font-weight: 600; font-size: 0.93rem; }
.cat-sub { color: var(--text-faint); font-size: 0.74rem; }
.cat-totals { text-align: right; }
.cat-total { font-family: var(--font-mono); font-weight: 600; font-size: 1rem; }
.cat-month { font-family: var(--font-mono); color: var(--text-dim); font-size: 0.71rem; }
.cat-chev { color: var(--text-faint); flex: none; }
.cat-item.open .cat-chev { transform: rotate(180deg); }
.cat-bar { height: 3px; background: var(--accent); opacity: 0.55; }
.cat-txns { display: none; background: var(--bg-deep); }
.cat-item.open .cat-txns { display: block; }
.cat-txns-inner { padding: 4px 14px 8px; }
.cat-txn { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border-soft); font-size: 0.83rem; cursor: pointer; }
.cat-txn:last-child { border-bottom: none; }
.cat-txn .l { min-width: 0; }
.cat-txn .l .d { color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-txn .l .t { color: var(--text-faint); font-size: 0.71rem; font-family: var(--font-mono); }
.cat-txn .r { font-family: var(--font-mono); white-space: nowrap; }

/* ============================ EXPORT MODAL ============================ */
.export-opts { display: flex; flex-direction: column; gap: 8px; }
.export-custom { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 14px; margin-top: 12px; }
.manage-row { display: flex; gap: 8px; align-items: center; }
.manage-row .input { flex: 1; min-width: 0; }
.manage-add { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.manage-add .input { flex: 1; min-width: 0; }

/* ============================ EMPTY STATES ============================ */
.empty { text-align: center; padding: 34px 20px; color: var(--text-faint); }
.empty .ttl { font-size: 1.05rem; font-weight: 700; color: var(--text-dim); margin-bottom: 5px; }
.empty .sub { font-size: 0.85rem; }

/* ============================ TAB BAR ============================ */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--app-max); z-index: 40;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: none; cursor: pointer; color: var(--text-faint); padding: 9px 4px 8px; font-family: var(--font-ui); font-size: 0.65rem; font-weight: 600; position: relative; }
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }
.tab.active::before { content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 24px; height: 2px; background: var(--accent); }

/* ============================ MODAL ============================ */
.modal-root { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; background: rgba(5,7,10,0.7); }
.modal { width: 100%; max-width: var(--app-max); background: var(--card); border: 1px solid var(--border); border-bottom: none; border-radius: 18px 18px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom, 0px)); max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
/* Full-page modal (used for tall, scrollable sheets like txn detail & manage categories) */
.modal-full { align-self: stretch; height: 100dvh; max-height: none; border-radius: 0; border: none; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.modal-full .modal-grab { display: none; }
.modal-grab { width: 38px; height: 4px; border-radius: 4px; background: var(--border); margin: 8px auto 14px; }
.modal h3 { font-weight: 700; font-size: 1.18rem; margin-bottom: 3px; }
.modal .modal-sub { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.modal-head h3 { margin-bottom: 0; }
.modal-x { background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 8px; line-height: 1; }
.modal-x:hover { color: var(--text); background: var(--card-2); }
.modal-edit { display: flex; flex-direction: column; gap: 16px; }
.txn-amount { font-family: var(--font-mono); font-size: 1.7rem; font-weight: 700; margin: 4px 0 16px; }
.txn-amount.neg { color: var(--red); }
.txn-amount.pos { color: var(--green); }
.txn-amount.neutral { color: var(--text); }
.txn-detail { display: flex; flex-direction: column; margin-bottom: 18px; }
.detail-row { display: flex; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--border-soft); }
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text-dim); font-size: 0.86rem; flex: none; }
.detail-value { font-weight: 600; text-align: right; }
@media (min-width: 560px) { .modal-root { align-items: center; } .modal { border-radius: 18px; border-bottom: 1px solid var(--border); } }

/* ============================ TOASTS ============================ */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 14px); z-index: 80; display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: var(--app-max); padding: 0 16px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: var(--card-2); border: 1px solid var(--border); border-radius: 11px; padding: 11px 14px; font-size: 0.87rem; font-weight: 500; }
.toast .tdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.toast.success .tdot { background: var(--green); }
.toast.error .tdot { background: var(--red); }
.toast.info .tdot { background: var(--accent); }
