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

:root {
  --bg: #111318;
  --surface: #1a1d24;
  --surface2: #23272f;
  --surface3: #2e333c;
  --text: #e8e9ec;
  --text-dim: #6b7280;
  --accent: #dca53b;
  --accent-dim: rgba(212, 153, 61, 0.12);
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.10);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.10);
  --blue: #60a5fa;
  --blue-dim: rgba(96, 165, 250, 0.10);
  --yellow: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ===== Bottom Navigation ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  z-index: 100;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: var(--nav-height);
  gap: 3px;
  color: var(--text-dim);
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
  position: relative;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.nav-icon svg {
  width: 22px;
  height: 22px;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ===== Tab Content ===== */
.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

.scroll-tab {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 16px;
}

/* ===== Tab Header ===== */
.tab-header {
  display: flex;
  align-items: center;
  padding: 16px 0 12px;
  flex-shrink: 0;
}

.tab-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.tab-header-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-left: auto;
}

/* ===== Show Indicator (keypad top bar) ===== */
.show-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
}

.show-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.show-indicator-dot.active {
  background: var(--green);
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.5);
}

.show-indicator-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.show-indicator-actions {
  display: flex;
  gap: 6px;
}

.show-indicator-btn {
  background: var(--surface2);
  border: 1px solid var(--surface3);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  min-height: 28px;
  transition: color 0.15s, border-color 0.15s;
}

.show-indicator-btn:active {
  color: var(--text);
  border-color: var(--accent);
}

.show-indicator-btn.end {
  color: var(--red);
  border-color: transparent;
}

.show-indicator-arrow {
  color: var(--text-dim);
  font-size: 18px;
}

/* ===== Status Chips ===== */
.status-chips {
  display: flex;
  gap: 6px;
  padding: 8px 16px 0;
  flex-shrink: 0;
}

.chip {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  text-align: center;
}

.chip-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  display: block;
  line-height: 1;
}

.chip-value {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
  display: block;
  margin-top: 2px;
  line-height: 1.2;
}

.chip.green .chip-value { color: var(--green); }
.chip.red .chip-value { color: var(--red); }
.chip.blue .chip-value { color: var(--blue); }
.chip.yellow .chip-value { color: var(--yellow); }
.chip.negative .chip-value { color: var(--red); }

/* ===== Spendable Bar (tappable) ===== */
.spendable-bar {
  display: flex;
  align-items: center;
  margin: 6px 16px 0;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

.spendable-bar:active { background: var(--surface2); }

.spendable-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.spendable-value {
  margin-left: auto;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--yellow);
}

.spendable-value.negative { color: var(--red); }

.spendable-arrow {
  color: var(--text-dim);
  font-size: 16px;
  margin-left: 6px;
}

/* ===== Amount Input ===== */
.amount-section {
  text-align: center;
  padding: 16px 16px 4px;
  flex-shrink: 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.amount-display {
  font-size: 52px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.amount-display .dollar {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 36px;
  margin-right: 2px;
}

.amount-display .cursor {
  display: inline-block;
  width: 2px;
  height: 40px;
  background: var(--accent);
  margin-left: 2px;
  animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* ===== Note Input ===== */
.note-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 0;
  flex-shrink: 0;
}

.note-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  text-align: center;
}

.note-input:focus { border-color: var(--accent); }
.note-input::placeholder { color: var(--text-dim); }

/* ===== Action Buttons ===== */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 10px 16px;
  flex-shrink: 0;
}

.action-btn {
  border: none;
  border-radius: var(--radius);
  padding: 16px 8px;
  font-size: 17px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: transform 0.1s, opacity 0.1s;
  min-height: 52px;
}

.action-btn:active {
  transform: scale(0.95);
  opacity: 0.85;
}

.action-btn.buy {
  background: var(--red);
  color: white;
}

.action-btn.sell {
  background: var(--green);
  color: #111318;
}

.action-btn.trade {
  background: var(--blue);
  color: #111318;
}

/* ===== Numpad ===== */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px 16px 8px;
  flex-shrink: 0;
}

.num-btn {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s, background 0.08s;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.num-btn:active {
  transform: scale(0.93);
  background: var(--surface2);
}

.num-btn.wide { font-size: 18px; }
.num-btn.backspace { font-size: 20px; color: var(--text-dim); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* ===== Activity Summary Bar ===== */
.activity-summary {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1px;
  background: var(--surface2);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.activity-summary-item {
  background: var(--surface);
  padding: 12px 8px;
  text-align: center;
}

.activity-summary-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.activity-summary-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.activity-summary-value.positive { color: var(--green); }
.activity-summary-value.negative { color: var(--red); }
.activity-summary-value.trade { color: var(--blue); }

/* ===== Activity Details Row ===== */
.activity-details {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
}

.activity-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.activity-detail-row + .activity-detail-row {
  border-top: 1px solid var(--surface2);
}

.activity-detail-label {
  font-size: 13px;
  color: var(--text-dim);
}

.activity-detail-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ===== Summary Grid ===== */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.summary-item {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}

.summary-item.full-width {
  grid-column: 1 / -1;
}

.summary-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.summary-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.summary-value.positive { color: var(--green); }
.summary-value.negative { color: var(--red); }
.summary-value.trade { color: var(--blue); }

/* ===== Transaction List ===== */
.tx-list { list-style: none; }

.tx-swipe-wrap {
  position: relative;
  overflow: hidden;
}

.tx-swipe-wrap + .tx-swipe-wrap { border-top: 1px solid var(--surface2); }

.tx-delete-zone {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.tx-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
  gap: 10px;
  position: relative;
  background: var(--surface);
  will-change: transform;
}

.tx-list:not(:has(.tx-swipe-wrap)) .tx-item + .tx-item {
  border-top: 1px solid var(--surface2);
}

.tx-badge {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 44px;
  text-align: center;
}

.tx-badge.buy { background: var(--red-dim); color: var(--red); }
.tx-badge.sell { background: var(--green-dim); color: var(--green); }
.tx-badge.trade { background: var(--blue-dim); color: var(--blue); }

.tx-info { flex: 1; min-width: 0; }

.tx-note {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-time {
  font-size: 12px;
  color: var(--text-dim);
}

.tx-amount {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tx-amount.buy { color: var(--red); }
.tx-amount.sell { color: var(--green); }
.tx-amount.trade { color: var(--blue); }

.tx-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 8px;
  cursor: pointer;
  opacity: 0.4;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tx-delete:active { opacity: 1; color: var(--red); }

/* ===== Show List Items ===== */
.show-item {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.1s;
  min-height: 56px;
}

.show-item:active { transform: scale(0.98); }

.show-item-info { flex: 1; min-width: 0; }

.show-item-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.show-item-date {
  font-size: 12px;
  color: var(--text-dim);
}

.show-item-net {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.show-item-net.positive { color: var(--green); }
.show-item-net.negative { color: var(--red); }

.show-item-arrow {
  color: var(--text-dim);
  margin-left: 8px;
  font-size: 18px;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input, .form-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-dim); }

.form-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ===== Buttons ===== */
.btn-primary {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  color: #111318;
  font-family: inherit;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-height: 52px;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:active { opacity: 0.85; transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; }

.btn-danger {
  width: 100%;
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--red);
  font-family: inherit;
  cursor: pointer;
  margin-top: 12px;
  min-height: 48px;
}

.btn-secondary {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--surface3);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  margin-top: 8px;
  min-height: 44px;
  transition: background 0.15s;
}

.btn-secondary:active { background: var(--surface3); }

/* ===== Margin Controls ===== */
.margin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--surface2);
}

.margin-label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

.margin-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.margin-btn {
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.margin-btn:active { background: var(--accent); color: #111318; }

.margin-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--yellow);
  min-width: 40px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ===== Venue Tags ===== */
.venue-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.venue-tag {
  background: var(--surface2);
  border: 1px solid var(--surface3);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  min-height: 36px;
  transition: border-color 0.15s, color 0.15s;
}

.venue-tag.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.venue-tag:active { transform: scale(0.95); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.empty-state-text {
  font-size: 15px;
  line-height: 1.5;
}

/* ===== Stats ===== */
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--surface2);
}

.stat-row:last-child { border-bottom: none; }

.stat-label {
  font-size: 14px;
  color: var(--text-dim);
}

.stat-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

/* ===== Filter Tabs ===== */
.filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-tab {
  background: var(--surface2);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  min-height: 36px;
  transition: background 0.15s, color 0.15s;
}

.filter-tab.active {
  background: var(--accent);
  color: #111318;
}

/* ===== Overlay & Dialog ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.dialog {
  background: var(--surface);
  border-radius: 18px;
  padding: 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  border: 1px solid var(--surface2);
}

.dialog h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.dialog p {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 20px;
  line-height: 1.5;
}

.dialog-buttons {
  display: flex;
  gap: 10px;
}

.dialog-buttons button {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  min-height: 48px;
}

.dialog-cancel {
  background: var(--surface2);
  color: var(--text);
}

.dialog-confirm {
  background: var(--red);
  color: white;
}

/* ===== Toast (top position - doesn't cover nav) ===== */
.toast {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--surface2);
  color: var(--text);
  padding: 14px 24px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  font-size: 14px;
  font-weight: 600;
  z-index: 300;
  text-align: center;
  transform: translateY(-100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border-bottom: 1px solid var(--surface3);
}

.toast.show {
  transform: translateY(0);
}

/* ===== Expense Rows ===== */
.expense-row {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface2);
  gap: 8px;
}

.expense-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
}

.expense-amt {
  font-size: 14px;
  font-weight: 600;
  color: var(--red);
  font-variant-numeric: tabular-nums;
}

.expense-items { margin-top: 8px; }

/* ===== Quick Actions ===== */
.quick-actions {
  display: flex;
  gap: 8px;
}

.quick-actions .btn-secondary {
  margin: 0;
  flex: 1;
}

/* ===== Header Button (used in sub-views) ===== */
.header-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 8px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-btn:active { background: var(--surface2); }

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
