:root {
  --bg-body: #0b0f19;
  --bg-card: #151c2c;
  --bg-card-hover: #1c263b;
  --bg-subtle: #1e293b;
  --bg-input: #0f172a;
  --border-color: #27354f;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-blue: #0284c7;
  --accent-blue-hover: #0369a1;
  --accent-green: #10b981;
  --accent-green-bg: #064e3b;
  --accent-red: #ef4444;
  --accent-red-bg: #7f1d1d;
  --accent-amber: #f59e0b;
  --accent-amber-bg: #78350f;
  --radius-card: 14px;
  --radius-btn: 10px;
  --touch-min: 44px;
}

[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-subtle: #e2e8f0;
  --bg-input: #f8fafc;
  --border-color: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --accent-blue: #0284c7;
  --accent-blue-hover: #0369a1;
  --accent-green: #059669;
  --accent-green-bg: #d1fae5;
  --accent-red: #dc2626;
  --accent-red-bg: #fee2e2;
  --accent-amber: #d97706;
  --accent-amber-bg: #fef3c7;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.45;
  min-height: 100vh;
  padding: 0 0 calc(var(--touch-min) + 20px) 0;
  user-select: none;
}

/* Peep Mode Blur */
.peep-active .peep-blur {
  filter: blur(8px);
  transition: filter 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 14px;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 12px 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 14px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #ffffff;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-btn);
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.96);
}

/* Net Worth Banner */
.net-worth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.net-worth-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.net-worth-amount {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.8px;
  color: var(--text-main);
  margin-bottom: 10px;
}

.net-worth-breakdown {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.breakdown-val {
  font-weight: 600;
  color: var(--text-main);
  margin-left: 4px;
}

/* Badge Styles */
.badge-green {
  background: var(--accent-green-bg);
  color: var(--accent-green);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.badge-red {
  background: var(--accent-red-bg);
  color: var(--accent-red);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.badge-amber {
  background: var(--accent-amber-bg);
  color: var(--accent-amber);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

/* Section Cards */
.card-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  padding: 14px;
  margin-bottom: 14px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Card 1: Pending Actions Banner */
.pending-banner {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(245, 158, 11, 0.05));
  border: 1px solid var(--accent-amber);
  border-radius: var(--radius-card);
  padding: 14px;
  margin-bottom: 14px;
}

.pending-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.pending-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-btn);
  padding: 10px 12px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pending-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.inline-align-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-input {
  flex: 1;
  min-height: var(--touch-min);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-btn);
  padding: 0 10px;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
}

.btn-primary {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  background: var(--accent-blue);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-btn);
  font-weight: 700;
  font-size: 14px;
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s ease;
}

.btn-primary:active {
  opacity: 0.85;
}

.btn-success {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  background: var(--accent-green);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-btn);
  font-weight: 700;
  font-size: 14px;
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-outline {
  min-height: var(--touch-min);
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-btn);
  padding: 0 12px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Card 2: Four Envelopes Grid */
.envelopes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.envelope-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-btn);
  padding: 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.envelope-card:active {
  background: var(--bg-card-hover);
  border-color: var(--accent-blue);
}

.envelope-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.envelope-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.envelope-target {
  font-size: 11px;
  color: var(--text-dim);
}

.envelope-bal {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 4px;
}

/* Card 3: Sparplan Portfolio */
.portfolio-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.portfolio-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-btn);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.portfolio-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ticker-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.ticker-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.portfolio-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px dashed var(--border-color);
  padding-top: 6px;
}

.pos-val {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-main);
}

/* Bottom Sheet Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.active {
  display: flex;
}

.bottom-sheet {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 18px 16px 28px 16px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-color);
  margin: 0 auto 14px auto;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-title {
  font-size: 17px;
  font-weight: 700;
}

.sheet-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 16px;
  padding-bottom: 4px;
}

.tab-btn {
  min-height: 38px;
  padding: 0 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--accent-blue);
  color: #ffffff;
  border-color: var(--accent-blue);
}

.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-input, .form-select {
  width: 100%;
  min-height: var(--touch-min);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-btn);
  padding: 0 12px;
  color: var(--text-main);
  font-size: 15px;
  font-weight: 600;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-btn);
  padding: 12px 16px;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Fullscreen Auth Gate */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-body);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 3000;
}

.auth-overlay.active {
  display: flex;
}

.auth-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.auth-header {
  text-align: center;
  margin-bottom: 20px;
}

.auth-title {
  font-size: 20px;
  font-weight: 800;
  margin-top: 10px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.auth-error {
  background: var(--accent-red-bg);
  color: var(--accent-red);
  padding: 10px 12px;
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
  display: none;
}
