/* ── Reset & Variables ─────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f13;
  --bg2: #1a1a22;
  --bg3: #22222e;
  --border: #2e2e3e;
  --text: #f0f0f5;
  --muted: #8888aa;
  --income: #22c55e;
  --expense: #f43f5e;
  --accent: #7c6af7;
  --accent2: #9d8fff;
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}

html {
  height: 100dvh;
  background: var(--bg);
  -webkit-touch-callout: none;
}

body {
  height: 100dvh;
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button,
a,
select,
input,
label {
  touch-action: manipulation;
}

/* ── Layout ────────────────────────────────────────────────── */
#app {
  position: fixed;
  inset: 0;
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
  padding-top: var(--safe-t);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
  overflow: hidden;
}

.view {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 0 16px 24px;
}
.view.active {
  display: flex;
}
.view.fade-in {
  animation: fadeSlideIn 0.22s var(--ease-out) forwards;
}
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Lock Screen ───────────────────────────────────────────── */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
}
.lock-screen.hidden {
  display: none;
}

.lock-content {
  text-align: center;
  padding: 40px 32px;
}
.lock-app-icon {
  font-size: 72px;
  margin-bottom: 20px;
}
.lock-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 48px;
  letter-spacing: -0.5px;
}

.faceid-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 17px;
  font-weight: 600;
  padding: 18px 32px;
  border-radius: var(--radius);
  cursor: pointer;
  width: 100%;
  box-shadow: 0 4px 24px rgba(124, 106, 247, 0.4);
  transition: transform 140ms var(--ease-out);
}
.faceid-btn:active {
  transform: scale(0.97);
}
.faceid-btn svg {
  width: 28px;
  height: 28px;
}

.lock-error {
  margin-top: 20px;
  font-size: 14px;
  color: var(--expense);
  min-height: 20px;
}

/* ── Settings Sheet ────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.sheet-backdrop.hidden {
  display: none;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 850;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(20px + var(--safe-b));
  transform: translateY(0);
  transition: transform 0.32s var(--ease-drawer);
  max-height: 80dvh;
  overflow-y: auto;
}
.bottom-sheet.hidden {
  transform: translateY(100%);
  display: block !important;
  visibility: hidden;
}
.bottom-sheet.slide-up {
  visibility: visible;
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}
.sheet-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 24px;
}

.setting-group {
  margin-bottom: 28px;
}
.setting-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.setting-row:last-child {
  border-bottom: none;
}
.setting-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.setting-btn {
  width: 100%;
  padding: 14px;
  margin-top: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--accent2);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 140ms var(--ease-out);
}
.setting-btn:active {
  transform: scale(0.97);
}

.sheet-close-btn {
  width: 100%;
  padding: 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 8px;
  transition: transform 140ms var(--ease-out);
}
.sheet-close-btn:active {
  transform: scale(0.97);
}

/* iOS-style toggle */
.toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border-radius: 31px;
  transition: background 0.2s ease-out;
  cursor: pointer;
}
.toggle-track::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 27px;
  height: 27px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.22s var(--ease-out);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.toggle input:checked + .toggle-track {
  background: var(--income);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(20px);
}

.inline-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
  outline: none;
}

/* ── Install Banner ────────────────────────────────────────── */
.install-banner {
  position: fixed;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 12px);
  right: calc(var(--safe-r) + 12px);
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 500;
  box-shadow: 0 8px 32px rgba(124, 106, 247, 0.25);
}
.install-banner.hidden {
  display: none;
}
.install-banner-icon {
  font-size: 28px;
  flex-shrink: 0;
}
.install-banner-text {
  flex: 1;
}
.install-banner-text strong {
  display: block;
  font-size: 14px;
}
.install-banner-text span {
  font-size: 12px;
  color: var(--muted);
}
.install-banner-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  padding: 4px 8px;
  cursor: pointer;
}

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 120ms var(--ease-out);
}
.icon-btn:active {
  transform: scale(0.88);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}

.period-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 20px;
  outline: none;
  cursor: pointer;
}

/* ── Balance Card ──────────────────────────────────────────── */
.balance-card {
  background: linear-gradient(135deg, #2d1f6e 0%, #1a1a40 60%, #0f0f20 100%);
  border: 1px solid #3d2fa0;
  border-radius: var(--radius);
  padding: 24px 20px 20px;
  margin-bottom: 24px;
}
.balance-label {
  font-size: 13px;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  margin-bottom: 6px;
}
.balance-amount {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -1.5px;
  margin-bottom: 20px;
  line-height: 1;
}
.balance-amount.positive {
  color: var(--income);
}
.balance-amount.negative {
  color: var(--expense);
}

.balance-row {
  display: flex;
  gap: 12px;
}
.balance-stat {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.stat-icon {
  font-size: 18px;
  font-weight: 700;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.balance-stat.income .stat-icon {
  background: rgba(34, 197, 94, 0.2);
  color: var(--income);
}
.balance-stat.expense .stat-icon {
  background: rgba(244, 63, 94, 0.2);
  color: var(--expense);
}
.stat-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.stat-value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}
.balance-stat.income .stat-value {
  color: var(--income);
}
.balance-stat.expense .stat-value {
  color: var(--expense);
}

/* ── Section Title ─────────────────────────────────────────── */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}

/* ── Category List ─────────────────────────────────────────── */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cat-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: catIn 0.25s var(--ease-out) both;
}
.cat-item:nth-child(1) {
  animation-delay: 0ms;
}
.cat-item:nth-child(2) {
  animation-delay: 40ms;
}
.cat-item:nth-child(3) {
  animation-delay: 80ms;
}
.cat-item:nth-child(4) {
  animation-delay: 120ms;
}
.cat-item:nth-child(5) {
  animation-delay: 160ms;
}
.cat-item:nth-child(6) {
  animation-delay: 200ms;
}
@keyframes catIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.cat-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.cat-info {
  flex: 1;
}
.cat-name {
  font-size: 14px;
  font-weight: 600;
}
.cat-type {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.cat-amount {
  font-size: 16px;
  font-weight: 700;
}
.cat-item.income .cat-amount {
  color: var(--income);
}
.cat-item.expense .cat-amount {
  color: var(--expense);
}

/* ── Filter Bar ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar {
  display: none;
}
.filter-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.15s ease-out,
    border-color 0.15s ease-out,
    color 0.15s ease-out,
    transform 120ms var(--ease-out);
}
.filter-btn:active {
  transform: scale(0.95);
}
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Transactions ──────────────────────────────────────────── */
.tx-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tx-group-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 8px 0 4px;
}
.tx-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: transform 130ms var(--ease-out);
}
.tx-item:active {
  transform: scale(0.98);
}
.tx-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.tx-info {
  flex: 1;
  min-width: 0;
}
.tx-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}
.tx-right {
  text-align: right;
  flex-shrink: 0;
}
.tx-amount {
  font-size: 17px;
  font-weight: 700;
}
.tx-item.income .tx-amount {
  color: var(--income);
}
.tx-item.expense .tx-amount {
  color: var(--expense);
}
.tx-delete {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 72px;
  background: var(--expense);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transform: translateX(100%);
  transition: transform 0.2s var(--ease-out);
}
.tx-item.swipe-open .tx-delete {
  transform: translateX(0);
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.empty-state p {
  font-size: 15px;
}

/* ── Add Form ──────────────────────────────────────────────── */
.type-toggle {
  display: flex;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
}
.type-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition:
    background 0.18s ease-out,
    color 0.18s ease-out,
    transform 120ms var(--ease-out);
}
.type-btn:active {
  transform: scale(0.96);
}
.type-btn.active {
  background: var(--bg3);
  color: var(--text);
}
.type-btn[data-type="income"].active {
  color: var(--income);
}
.type-btn[data-type="expense"].active {
  color: var(--expense);
}

.add-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
}

.amount-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  transition: border-color 0.15s;
}
.amount-input-wrap:focus-within {
  border-color: var(--accent);
}
.currency-symbol {
  font-size: 20px;
  font-weight: 700;
  color: var(--muted);
  margin-right: 8px;
}

input,
select {
  background: var(--bg2);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-size: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
input:focus,
select:focus {
  border-color: var(--accent);
}
input::placeholder {
  color: var(--muted);
}

#f-amount {
  background: transparent;
  border: none;
  padding: 14px 0;
  font-size: 28px;
  font-weight: 700;
  flex: 1;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238888aa' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
  cursor: pointer;
}
select option {
  background: var(--bg3);
}

.submit-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 17px;
  font-weight: 700;
  padding: 18px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 8px;
  transition: transform 140ms var(--ease-out);
}
.submit-btn:active {
  transform: scale(0.97);
}

/* ── Bottom Nav ────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
  background: rgba(15, 15, 19, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 24px;
  transition: color 0.15s;
  flex: 1;
  -webkit-touch-callout: none;
}
.nav-btn svg {
  width: 24px;
  height: 24px;
}
.nav-btn.active {
  color: var(--accent2);
}
.nav-btn span {
  font-size: 10px;
}

.add-btn-circle {
  width: 52px;
  height: 52px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(124, 106, 247, 0.5);
  transition:
    transform 140ms var(--ease-out),
    box-shadow 140ms ease-out;
}
.nav-btn:active .add-btn-circle {
  transform: scale(0.92);
  box-shadow: 0 2px 10px rgba(124, 106, 247, 0.3);
}
.add-btn-circle svg {
  width: 26px;
  height: 26px;
  color: #fff;
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  left: 16px;
  right: 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  text-align: center;
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.22s ease-out,
    transform 0.22s var(--ease-out);
  pointer-events: none;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success {
  border-color: var(--income);
  color: var(--income);
}
.toast.error {
  border-color: var(--expense);
  color: var(--expense);
}

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .view.fade-in,
  .cat-item {
    animation: none;
    opacity: 1;
    transform: none;
  }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
