:root {
  color-scheme: dark;
  /* Dark Mode (Default) */
  --ink: #f8fafc;
  --muted: #94a3b8;
  --paper: #0f172a;
  --panel: #1e293b;
  --surface: #1e293b;
  --line: #334155;
  --asset: #2dd4bf;
  --asset-soft: rgba(45, 212, 191, 0.1);
  --liability: #fb7185;
  --liability-soft: rgba(251, 113, 133, 0.1);
  --gold: #fbbf24;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  --overlay: rgba(15, 23, 42, 0.7);
  --brand: var(--asset);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="light"] {
  color-scheme: light;
  --ink: #17201a;
  --muted: #68706a;
  --paper: #f7f4ee;
  --panel: #ffffff;
  --surface: #ffffff;
  --line: #ddd7cd;
  --asset: #127c73;
  --asset-soft: #dff3ef;
  --liability: #b43f55;
  --liability-soft: #f7e1e6;
  --gold: #b6892e;
  --shadow: 0 18px 50px rgba(35, 29, 21, 0.08);
  --overlay: rgba(255, 255, 255, 0.7);
  --brand: var(--asset);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(45, 212, 191, 0.05), transparent 34%),
    linear-gradient(225deg, rgba(251, 113, 133, 0.05), transparent 30%),
    var(--paper);
  color: var(--ink);
  transition: background 0.3s ease, color 0.3s ease;
}

button {
  font: inherit;
}

.app-header,
main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 36px 0 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 4.5rem);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  font-size: 1.08rem;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.icon-button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.primary-button {
  border-radius: 8px;
  min-height: 44px;
  padding: 0 18px;
  font-weight: 800;
}

.icon-button {
  border-radius: 999px;
  width: 44px;
  height: 44px;
  font-size: 1.25rem;
}

.primary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.primary-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

/* ── User profile pill ── */

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  transition: box-shadow 140ms ease;
}

.user-pill:hover {
  box-shadow: 0 4px 16px rgba(35, 29, 21, 0.06);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  object-fit: cover;
  border: 2px solid var(--asset-soft);
}

.user-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ghost-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}

.ghost-button:hover {
  color: var(--liability);
  border-color: var(--liability);
  background: var(--liability-soft);
}

.status-strip {
  display: grid;
  gap: 8px;
  margin: 8px 0 18px;
}

.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  background: var(--panel);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--muted);
}

.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-bottom: 32px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-heading h2 {
  font-size: 2.25rem;
  margin: 4px 0;
  letter-spacing: -0.03em;
}

.bank-group {
  margin-bottom: 24px;
}

.bank-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 8px;
}

.bank-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}

.bank-header span {
  font-weight: 700;
  color: var(--ink);
  font-size: 1rem;
}

.metric strong {
  display: block;
  font-size: clamp(1.75rem, 3.5vw, 2.75rem);
  line-height: 1;
  letter-spacing: 0;
}

.metric:not(.primary-metric) strong {
  font-size: clamp(1.4rem, 2.5vw, 2rem);
}

.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 32px;
}

.wide-panel {
  grid-column: span 1;
}

.panel {
  min-height: 330px;
  padding: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.chart-shell {
  height: 280px;
  width: 100%;
}

.chart-shell svg {
  display: block;
  width: 100%;
  height: 100%;
}

.axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.account-list,
.holding-list {
  display: flex;
  flex-direction: column;
}

.row-title span {
  font-size: 0.88rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sparkline-container {
  width: 100%;
}

.sparkline {
  display: block;
  width: 100%;
  max-width: 120px;
  height: 16px;
}

.holding-grid-row {
  display: grid;
  grid-template-columns: 140px 1fr 160px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}

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

.col-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ticker {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.name-sub {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-center {
  display: flex;
  justify-content: center;
  min-width: 0;
}

.col-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  line-height: 1.2;
}

.price-line {
  font-size: 0.84rem;
  color: var(--ink);
}

.change-percent {
  font-weight: 600;
  margin-left: 4px;
}

.position-value {
  font-size: 0.84rem;
  font-weight: 700;
}

.account-row {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.account-row:last-child,
.holding-row:last-child {
  border-bottom: none;
}

.row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.row-title {
  flex: 1;
  min-width: 0;
}

.row-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-title span {
  font-size: 0.88rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
  vertical-align: middle;
  flex-shrink: 0;
}

.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
}

.amount.negative {
  color: var(--liability);
}

.empty {
  color: var(--muted);
  padding: 22px 0;
}

@media (max-width: 850px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }
}

@media (max-width: 480px) {
  .holding-grid-row {
    grid-template-columns: 80px 1fr 120px;
    gap: 8px;
  }
  
  .row-right {
    gap: 8px;
  }
  
  .amount {
    font-size: 0.94rem;
  }
  
  h1 {
    font-size: 2rem;
  }
}

@media (max-width: 520px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 24px 0 12px;
  }
  
  .header-actions {
    width: 100%;
    margin-top: 12px;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  
  .bank-btn {
    flex: 1;
    min-width: 140px;
  }
  
  .app-header,
  main {
    width: calc(100% - 24px);
  }

  .metric,
  .panel {
    padding: 16px;
    min-height: auto;
  }

  .chart-shell {
    height: 200px;
  }
}
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay);
  backdrop-filter: blur(20px);
  z-index: 1000;
  display: none;
  justify-content: center;
  align-items: flex-end;
  animation: fadeIn 0.3s ease;
}

.modal-content {
  background: var(--surface);
  width: 100%;
  max-width: 900px;
  height: 92vh;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.modal-title-group { flex: 1; }
.modal-title-group h2 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.modal-title-group p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.modal-price-group { text-align: right; }
.modal-price-group h2 { margin: 0; font-size: 1.5rem; }

.btn-icon:hover {
  background: var(--line);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Form Styling */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.form-group input {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--asset);
  box-shadow: 0 0 0 4px var(--asset-soft);
}
.btn-icon:hover { background: rgba(0,0,0,0.05); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px; /* Reduced from 32px */
}

.chart-panel {
  display: flex;
  flex-direction: column;
  gap: 8px; /* Reduced from 16px */
}

.large-chart {
  height: 240px;
}

.range-toggles {
  display: flex;
  gap: 4px;
  background: rgba(0,0,0,0.04);
  padding: 4px;
  border-radius: 8px;
  width: fit-content;
}

.range-toggles button {
  background: none;
  border: none;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
}

.range-toggles button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chart-note {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  margin-top: -8px;
}

.holding-grid-row {
  cursor: pointer;
  transition: background 0.1s;
}
.holding-grid-row:hover {
  background: rgba(0,0,0,0.02);
}

@media (max-width: 520px) {
  .modal-content {
    height: 100vh;
    border-radius: 0;
    max-width: 100% !important;
  }
  .modal-body {
    padding: 20px 12px;
    gap: 24px;
  }
  .modal-header {
    padding: 16px 12px;
    gap: 12px;
  }
  .range-toggles {
    overflow-x: auto;
    width: 100%;
    scrollbar-width: none; /* Hide scrollbar for cleaner look */
  }
  .range-toggles::-webkit-scrollbar { display: none; }
  
  .large-chart {
    height: 280px; /* Slightly taller on mobile for better detail */
  }
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 36px;
  height: 36px;
}

.logo-text {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: -0.05em;
  margin: 0;
  color: var(--ink);
}

/* Pull to Refresh */
.pull-indicator {
  position: fixed;
  top: -60px;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  pointer-events: none;
  transition: transform 0.1s ease-out;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(0,0,0,0.1);
  border-top-color: var(--asset);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.pulling-down .app-container {
  transition: none;
}

.refreshing .spinner {
  border-top-color: var(--gold);
}

/* Account Modal Specifics */
.account-holdings-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: padding-left 0.2s ease;
}
.detail-row:hover {
  padding-left: 8px;
  background: var(--asset-soft);
}
.detail-row:last-child {
  border-bottom: none;
}
.row-info {
  flex: 1;
  min-width: 0;
}
.row-main {
  display: flex;
  flex-direction: column;
}
.row-main strong {
  font-size: 1rem;
  font-weight: 800;
}
.row-main span {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 600;
}
.row-values {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.row-values strong {
  font-size: 1rem;
  font-weight: 800;
}
.row-values small {
  font-size: 0.85rem;
  font-weight: 700;
}
#accModalName {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 900;
}

/* Progress Bar */
.progress-bar-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: rgba(45, 212, 191, 0.05);
  z-index: 10000;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--brand);
  box-shadow: 0 0 10px var(--brand);
  transition: width 0.3s ease;
}

.app-version {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
  margin-left: 8px;
  vertical-align: middle;
}
