/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --accent: #5BB3E4;
  --accent-light: #0D1E2E;
  --bg: #000000;
  --card: #0D1B2A;
  --text: #F2F2F7;
  --text-secondary: #8E8E9A;
  --separator: #1E2E3E;
  --destructive: #FF453A;
  --success: #30D158;
  --radius-card: 12px;
  --radius-btn: 10px;
  --radius-input: 10px;
  --header-height: 56px;
  --max-width: 480px;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
}

/* ── View Transitions ─────────────────────────────────────────────────────── */
@view-transition { navigation: auto; }
::view-transition { background-color: var(--bg); }

@keyframes vt-slide-in-from-right  { from { transform: translateX(100%); } }
@keyframes vt-slide-out-to-left    { to   { transform: translateX(-30%); opacity: 0; } }
@keyframes vt-slide-in-from-left   { from { transform: translateX(-30%); opacity: 0; } }
@keyframes vt-slide-out-to-right   { to   { transform: translateX(100%); } }

::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

:root[data-nav-direction="forward"]::view-transition-old(root)  { animation: 300ms cubic-bezier(0.25,0.46,0.45,0.94) both vt-slide-out-to-left; }
:root[data-nav-direction="forward"]::view-transition-new(root)  { animation: 300ms cubic-bezier(0.25,0.46,0.45,0.94) both vt-slide-in-from-right; }
:root[data-nav-direction="backward"]::view-transition-old(root) { animation: 300ms cubic-bezier(0.25,0.46,0.45,0.94) both vt-slide-out-to-right; }
:root[data-nav-direction="backward"]::view-transition-new(root) { animation: 300ms cubic-bezier(0.25,0.46,0.45,0.94) both vt-slide-in-from-left; }

@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in  { from { opacity: 0; } }

:root[data-nav-direction="replace"]::view-transition-old(root) { animation: 150ms ease-out both vt-fade-out; }
:root[data-nav-direction="replace"]::view-transition-new(root) { animation: 150ms ease-out both vt-fade-in; }

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; background-color: var(--bg); }
body {
  font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.page-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

#edge-swipe-zone {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: 24px;
  z-index: 9999;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.page-content {
  padding: 16px;
  padding-top: calc(var(--header-height) + env(safe-area-inset-top) + 16px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-width);
  height: calc(var(--header-height) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  background: #000000;
  border-bottom: 1px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 8px;
  padding-right: 8px;
  z-index: 100;
}

.header-btn {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-btn);
  padding: 0 8px;
  -webkit-tap-highlight-color: transparent;
}
.header-btn:active { background: var(--separator); }

.header-title {
  position: absolute;
  top: calc(env(safe-area-inset-top) + var(--header-height) / 2);
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 120px);
}

/* ── Flash Messages ───────────────────────────────────────────────────────── */
.flash-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash { padding: 12px 16px; border-radius: var(--radius-card); font-size: 14px; font-weight: 500; }
.flash.success { background: #0A2A18; color: #30D158; }
.flash.error   { background: #2A0A08; color: #FF453A; }
.flash.info    { background: var(--accent-light); color: #5BB3E4; }

/* ── Card Typography ──────────────────────────────────────────────────────── */
.card-title   { font-size: 18px; font-weight: 600; color: var(--text); }
.card-normal  { font-size: 16px; color: var(--text); }
.card-small   { font-size: 12px; color: var(--text-secondary); }
.card-heading { font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-btn);
  font-size: 16px;
  font-weight: 600;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.btn:active { opacity: 0.8; transform: scale(0.98); }
.btn-primary   { background: var(--card); color: #fff; border: 1.5px solid var(--accent); }
.btn-secondary { background: var(--card); color: #fff; border: 1.5px solid var(--separator); }
.btn-ghost     { background: none; color: var(--text); padding: 0 8px; min-height: 36px; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: 8px; }
.btn-sm-destructive {
  min-height: 36px;
  padding: 0 14px;
  font-size: 14px;
  border-radius: 8px;
  background: none;
  color: var(--destructive);
  border: 1.5px solid var(--destructive);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.btn-sm-destructive:active { background: #2A0A08; }
.btn-full { width: 100%; }
.btn-group { display: flex; gap: 10px; margin-top: 16px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.form-group { margin-bottom: 18px; }
.form-group:last-child { margin-bottom: 0; }
.form-label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; color: var(--text-secondary); }
.form-input {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus { border-color: var(--accent); background: #0D1B2A; }
select.form-input { appearance: auto; -webkit-appearance: auto; }

.date-with-today { display: flex; gap: 8px; align-items: center; }
.date-with-today .form-input { flex: 1; }

/* ── Search & Filter Toolbar ──────────────────────────────────────────────── */
.toolbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

.search-row { position: relative; }
.search-input {
  width: 100%;
  height: 44px;
  padding: 0 16px 0 40px;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238E8E9A' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}
.search-input:focus { border-color: var(--accent); }

.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-date { flex: 1; }
.filter-sep { color: var(--text-secondary); font-size: 14px; flex-shrink: 0; }

.sort-select {
  flex: 1;
  height: 44px;
  padding: 0 12px;
  background: var(--card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  font-size: 14px;
  color: var(--text);
  outline: none;
  appearance: auto;
}

.type-filter-wrap {
  position: relative;
  flex: 1;
}

.type-filter-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
  text-align: left;
}

.type-filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  margin-left: 2px;
}

.type-filter-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.type-filter-chevron {
  flex-shrink: 0;
  opacity: 0.5;
}

.type-filter-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-md);
  z-index: 200;
  overflow: hidden;
}

.type-filter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.type-filter-item:active {
  background: var(--separator);
}

.type-filter-check {
  width: 16px;
  flex-shrink: 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

.type-filter-divider {
  height: 1px;
  background: var(--separator);
  margin: 2px 0;
}

.order-toggle-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  background: var(--card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.order-toggle-btn:active { background: var(--separator); color: var(--text); }
.order-toggle-btn[data-order="asc"] .icon-desc { display: none; }
.order-toggle-btn[data-order="desc"] .icon-asc { display: none; }

.clear-filters {
  font-size: 13px;
  color: var(--accent);
  text-align: right;
  display: block;
}

/* ── Tag Chips ────────────────────────────────────────────────────────────── */
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--separator);
  color: var(--text-secondary);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.tag-chip.selected { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.tag-chip--display { cursor: default; }
.tag-chip:active:not(.tag-chip--display) { opacity: 0.75; }

.tag-add-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.tag-add-row .form-input { flex: 1; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 36px; font-weight: 800; color: var(--text); letter-spacing: -1px; }
.login-logo p  { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }

/* ── Home User Cards ──────────────────────────────────────────────────────── */
.home-user-list { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }

.home-user-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--accent);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.2s, background 0.2s, transform 0.2s;
}
.home-user-card:active { box-shadow: var(--shadow-md); background: var(--bg); transform: scale(0.98); transition: none; }

.home-user-info { display: flex; flex-direction: column; gap: 4px; }
.home-user-name { font-size: 24px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; }
.home-user-balance { font-size: 18px; font-weight: 600; }

/* ── Amount Colors ────────────────────────────────────────────────────────── */
.amount-positive { color: var(--success); }
.amount-negative { color: var(--destructive); }

/* ── Balance Card ─────────────────────────────────────────────────────────── */
.balance-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.balance-amount { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }

/* ── Transaction List ─────────────────────────────────────────────────────── */
.txn-list { display: flex; flex-direction: column; gap: 8px; }

.txn-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--separator);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.2s, background 0.2s, transform 0.2s;
}
.txn-card:active { box-shadow: var(--shadow-md); background: var(--bg); transform: scale(0.98); transition: none; }

.txn-left { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.txn-desc { font-size: 15px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-meta { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 5px; }
.txn-recurring-badge { font-size: 11px; color: var(--accent); }
.txn-tags { margin-top: 4px; }
.txn-amount { font-size: 16px; font-weight: 600; flex-shrink: 0; padding-top: 2px; }

.load-more-sentinel { display: flex; justify-content: center; padding: 20px 0; }
.load-more-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--separator);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: load-more-spin 0.7s linear infinite;
}
@keyframes load-more-spin { to { transform: rotate(360deg); } }

/* ── Recurring Section ────────────────────────────────────────────────────── */
.recurring-list { display: flex; flex-direction: column; gap: 8px; }

.recurring-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--separator);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.2s, background 0.2s, transform 0.2s;
}
.recurring-card:active { box-shadow: var(--shadow-md); background: var(--bg); transform: scale(0.98); transition: none; }

.recurring-left { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }

/* ── Header Actions ───────────────────────────────────────────────────────── */
.header-actions { display: flex; align-items: center; gap: 2px; }

/* ── Amount Type Toggle ───────────────────────────────────────────────────── */
.type-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: var(--radius-btn);
  padding: 3px;
  gap: 3px;
  margin-bottom: 10px;
}
.type-btn {
  flex: 1;
  min-height: 38px;
  background: none;
  border: none;
  border-radius: calc(var(--radius-btn) - 2px);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.type-btn.active { background: var(--card); }
.type-btn[data-type="credit"].active { color: var(--success); }
.type-btn[data-type="debit"].active  { color: var(--destructive); }

.amount-row { display: flex; flex-direction: column; }

/* ── Recurring Note ───────────────────────────────────────────────────────── */
.recurring-note {
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 4px;
}

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
  font-size: 15px;
}

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.section-gap { margin-top: 24px; }
