@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ========== RESET & BASE ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #0f172a;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: #f0f4fa;
  min-height: 100vh;
}

/* ========== TAB CONTENT ========== */
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* ========== HIDDEN UTILITY ========== */
.hidden {
  display: none !important;
}

/* ========== SIDEBAR ========== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100vh;
  background: #334155;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px;
}

.sidebar-brand svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.sidebar-brand span {
  font-size: 1.125rem;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin: 2px 12px;
  border-radius: 8px;
  color: #c7d2fe;
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: #475569;
}

.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: #ffffff;
  border-left: 3px solid rgba(255,255,255,0.5);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: #a5b4fc;
}

.nav-item.active svg {
  color: #ffffff;
}

.nav-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 8px 24px;
}

.sidebar-footer {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-btn {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #c7d2fe;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease;
}

.sidebar-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* ========== CONTENT AREA ========== */
.content {
  margin-left: 260px;
  min-height: 100vh;
}

/* ========== TOP BAR ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 64px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
}

.topbar-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
}

.topbar-actions {
  display: flex;
  gap: 12px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: #475569;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: #2563eb;
  border: 1px solid #2563eb;
  border-radius: 8px;
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: #2563eb;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #475569;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-ghost:hover {
  background: #f8fafc;
}

.btn-ghost-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #dc2626;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-ghost-danger:hover {
  background: #fef2f2;
}

/* ========== MAIN CONTENT ========== */
.main {
  padding: 24px 32px;
}

/* ========== SUMMARY CARDS ========== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.summary-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.summary-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.summary-card.gain-accent {
  border-left: 4px solid #059669;
}

.summary-card.dark-accent {
  border-left: 4px solid #0f172a;
}

.summary-card-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  font-weight: 600;
  margin-bottom: 8px;
}

.summary-card-value {
  font-size: 1.875rem;
  font-weight: 700;
  color: #0f172a;
}

.summary-card-value.gain {
  color: #059669;
}

.summary-card-value.loss {
  color: #dc2626;
}

.summary-card-sub {
  font-size: 0.8125rem;
  margin-top: 4px;
}

.pill-gain {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ecfdf5;
  color: #059669;
  border-radius: 9999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.pill-loss {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fef2f2;
  color: #dc2626;
  border-radius: 9999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ========== ALLOCATION BAR ========== */
.allocation-bar-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  margin-bottom: 24px;
}

.allocation-bar-card .chart-card-header {
  margin-bottom: 12px;
}

.allocation-bar-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 12px;
}

.allocation-bar {
  display: flex;
  height: 12px;
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 12px;
}

.allocation-bar-segment {
  height: 100%;
  transition: width 0.6s ease;
}

.allocation-legend {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: #475569;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-pct {
  color: #64748b;
}

/* ========== CHART CARDS GRID ========== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.chart-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.chart-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
}

.chart-card-link {
  font-size: 0.8125rem;
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.chart-card-link:hover {
  text-decoration: underline;
}

/* ========== DONUT CHART ========== */
.donut-layout {
  display: flex;
  gap: 32px;
  align-items: center;
}

.donut-container {
  position: relative;
  width: 180px;
  height: 180px;
  flex-shrink: 0;
}

.donut-svg {
  display: block;
  overflow: visible;
}

.donut-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  text-align: center;
}

.donut-center-label {
  font-size: 0.75rem;
  color: #64748b;
  display: block;
}

.donut-center-value {
  font-size: 1.125rem;
  font-weight: 700;
  color: #0f172a;
  display: block;
  white-space: nowrap;
}

/* Scale down for 7-figure values ($1,000,000+) */
.donut-center-value.donut-value-7 {
  font-size: 0.875rem;
}

/* Scale down further for 8-figure values ($10,000,000+) */
.donut-center-value.donut-value-8 {
  font-size: 0.75rem;
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
}

.donut-legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.donut-legend-name {
  color: #475569;
  white-space: nowrap;
}

.donut-legend-value {
  font-weight: 600;
  color: #0f172a;
  margin-left: auto;
  white-space: nowrap;
}

.donut-legend-pct {
  font-size: 0.75rem;
  color: #64748b;
  white-space: nowrap;
}

/* SVG donut slices — true arc paths for crisp rendering */
.donut-slice {
  cursor: pointer;
  transform-origin: 90px 90px; /* center of 180×180 viewBox */
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              filter 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.donut-slice.active {
  transform: translate(var(--hover-x), var(--hover-y)) scale(1.02);
  filter: brightness(1.1) drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}

/* Tooltip element positioned inside donut-container but outside clip-path */
.donut-hover-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  background: rgba(15, 23, 42, 0.9);
  color: #ffffff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
  left: 50%;
  top: -8px;
  transform: translateX(-50%);
}

/* ========== HORIZONTAL BARS ========== */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bar-item-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.bar-item-label {
  font-size: 0.875rem;
  color: #0f172a;
  font-weight: 500;
}

.bar-item-value {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #475569;
}

.bar-track {
  width: 100%;
  height: 10px;
  background: #f1f5f9;
  border-radius: 9999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.6s ease;
}

/* ========== HOLDINGS TABLE ========== */
.holdings-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.holdings-table-scroll {
  overflow-x: auto;
}

.holdings-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
}

.holdings-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
}

.holdings-badge {
  display: inline-flex;
  align-items: center;
  background: #eef2ff;
  color: #2563eb;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 9999px;
}

.holdings-table {
  width: 100%;
  border-collapse: collapse;
}

.holdings-table thead th {
  background: transparent;
  color: #64748b;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 10px 16px;
  border-bottom: 2px solid #e2e8f0;
  text-align: left;
  white-space: nowrap;
}

.holdings-table thead th:nth-child(n+5) {
  text-align: right;
}

.holdings-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
  color: #0f172a;
}

.holdings-table tbody td:nth-child(n+5) {
  text-align: right;
}

.holdings-table tbody tr:not(.account-group-row):hover td {
  background: #f8fafc;
}

.account-group-row td {
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  border-bottom: 1px solid #f1f5f9;
}

.account-group-row {
  cursor: default;
}

.account-group-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ticker-cell {
  font-weight: 600;
  color: #2563eb;
}

.name-cell {
  color: #475569;
}

.category-cell, .type-cell {
  color: #475569;
  font-size: 0.8125rem;
}

/* ========== SECTION DIVIDER ========== */
.section-divider {
  margin: 48px 0;
  border: none;
  border-top: 2px solid #e2e8f0;
}

.section-preview-header {
  margin-bottom: 24px;
}

.section-preview-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.section-preview-desc {
  font-size: 0.875rem;
  color: #64748b;
}

/* ========== ACCOUNT CARDS ========== */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  min-width: 0;
}

.account-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 24px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.account-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.account-card-name {
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 4px;
}

.account-type-badge {
  display: inline-flex;
  align-self: flex-start;
  background: #f1f5f9;
  color: #475569;
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 9999px;
}

.account-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
  margin: 16px 0 4px;
}

.account-card-holdings {
  font-size: 0.8125rem;
  color: #64748b;
}

.account-card-gain {
  font-size: 0.875rem;
  margin-top: 8px;
}

.account-card-gain.positive {
  color: #059669;
}

.account-card-gain.negative {
  color: #dc2626;
}

.account-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #f1f5f9;
}

.account-card-actions .btn-secondary {
  margin-left: auto;
}

/* ========== NEW INVESTMENT CALCULATOR ========== */
.calculator-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 32px;
}

.calculator-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 24px;
}

.calculator-form {
  max-width: 600px;
}

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

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #475569;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  color: #0f172a;
  background: #ffffff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.checkbox-row {
  display: flex;
  gap: 24px;
  align-items: center;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: #0f172a;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #2563eb;
  cursor: pointer;
}

.calculator-results {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid #e2e8f0;
}

.calculator-results-title {
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 16px;
}

.results-table {
  width: 100%;
  max-width: 600px;
  border-collapse: collapse;
  margin-bottom: 32px;
}

.results-table thead th {
  background: transparent;
  color: #64748b;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 10px 16px;
  border-bottom: 2px solid #e2e8f0;
  text-align: left;
}

.results-table thead th:nth-child(n+2) {
  text-align: right;
}

.results-table tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
  color: #0f172a;
}

.results-table tbody td:nth-child(n+2) {
  text-align: right;
}

.projected-title {
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 16px;
}

.projected-bars {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 600px;
}

.bar-item-detail {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 4px;
}

.bar-detail-total {
  font-weight: 600;
  color: #0f172a;
}

.bar-detail-variance {
  color: #64748b;
}

.bar-detail-variance.positive {
  color: #059669;
}

.bar-detail-variance.negative {
  color: #dc2626;
}

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 24px;
}

.modal-container {
  background: rgba(15, 23, 42, 0.25);
  padding: 40px;
  border-radius: 16px;
  display: flex;
  justify-content: center;
}

.modal {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 4px 16px rgba(0, 0, 0, 0.08);
  max-width: 560px;
  width: 100%;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: #0f172a;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 1.25rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.modal-close:hover {
  background: #f8fafc;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.modal-form-grid .full-width {
  grid-column: 1 / -1;
}

.modal-form-grid .third-width {
  grid-column: span 1;
}

.form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  color: #64748b;
  background: #ffffff;
  appearance: auto;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  color: #0f172a;
  background: #ffffff;
  resize: vertical;
  min-height: 72px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.form-input.focus-state {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid #f1f5f9;
  flex-shrink: 0;
}

.three-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1024px) {
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .accounts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 1100px) {
  .summary-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .account-card-actions {
    flex-wrap: wrap;
  }
  .account-card-actions button {
    white-space: nowrap;
  }
  .account-card-actions .btn-secondary {
    margin-left: 0;
  }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .content {
    margin-left: 0;
  }
  .summary-grid {
    grid-template-columns: 1fr;
  }
  .accounts-grid {
    grid-template-columns: 1fr;
  }
  .topbar {
    padding: 0 16px;
  }
  .main {
    padding: 16px;
  }

  /* Card padding: 24px → 16px to reclaim width on mobile */
  .chart-card {
    padding: 16px;
  }

  /* Donut charts: side-by-side with smaller donut on mobile */
  .donut-layout {
    gap: 12px;
  }
  .donut-container {
    width: 110px;
    height: 110px;
  }
  .donut-svg {
    width: 100%;
    height: 100%;
  }
  .donut-center-value {
    font-size: 0.75rem;
  }
  .donut-center-label {
    font-size: 0.5625rem;
  }
  .donut-legend {
    min-width: 0;
  }
  .donut-legend-item {
    font-size: 0.8125rem;
  }
  .donut-legend-value {
    font-size: 0.75rem;
  }
  .donut-legend-pct {
    font-size: 0.6875rem;
  }

  /* Bar charts: stack label above value on mobile */
  .bar-item-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
  .bar-item-value {
    font-size: 0.75rem;
  }
}

/* ========== ASSET ANALYSIS: 3-COLUMN SUMMARY GRID ========== */
.summary-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.summary-cards-grid .summary-card {
  text-align: center;
}

@media (max-width: 1100px) {
  .summary-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .summary-cards-grid {
    grid-template-columns: 1fr;
  }
}

.summary-card-pct {
  font-size: 0.875rem;
  color: #64748b;
  font-weight: 500;
  margin-top: 4px;
}

/* ========== ASSET ANALYSIS: BREAKDOWN TABLE ========== */
.breakdown-table {
  width: 100%;
  border-collapse: collapse;
}

.breakdown-table thead th {
  background: transparent;
  color: #64748b;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 10px 16px;
  border-bottom: 2px solid #e2e8f0;
  text-align: left;
  white-space: nowrap;
}

.breakdown-table thead th:nth-child(n+2) {
  text-align: right;
}

.breakdown-table thead th:last-child {
  text-align: left;
  width: 30%;
}

.breakdown-table tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
  color: #0f172a;
}

.breakdown-table tbody td:nth-child(n+2) {
  text-align: right;
}

.breakdown-table tbody td:last-child {
  text-align: left;
}

.breakdown-table tbody tr:hover td {
  background: #f8fafc;
}

.breakdown-category-row td {
  font-weight: 700;
  font-size: 0.8125rem;
  color: #0f172a;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  padding: 8px 16px;
}

.breakdown-category-row:hover td {
  background: #f1f5f9 !important;
}

.breakdown-sub-label {
  padding-left: 24px !important;
  color: #475569;
  font-weight: 400;
}

.breakdown-bar-cell {
  padding-right: 24px !important;
}

.breakdown-bar-track {
  width: 100%;
  height: 8px;
  background: #f1f5f9;
  border-radius: 9999px;
  overflow: hidden;
}

.breakdown-bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.6s ease;
}

/* ========== REBALANCE SECTION ========== */
.rebalance-form-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 32px;
  margin-bottom: 24px;
}

.rebalance-form-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.rebalance-form-subtitle {
  font-size: 0.875rem;
  color: #64748b;
  margin-bottom: 24px;
}

.rebalance-inputs-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.rebalance-results-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 24px;
}

.rebalance-results-title {
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 16px;
}

.rebalance-table {
  width: 100%;
  border-collapse: collapse;
}

.rebalance-table thead th {
  background: transparent;
  color: #64748b;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 10px 16px;
  border-bottom: 2px solid #e2e8f0;
  text-align: left;
  white-space: nowrap;
}

.rebalance-table thead th:nth-child(n+2) {
  text-align: right;
}

.rebalance-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
  color: #0f172a;
}

.rebalance-table tbody td:nth-child(n+2) {
  text-align: right;
}

.rebalance-table tbody tr:hover td {
  background: #f8fafc;
}

/* ========== SETTINGS SECTION ========== */
.settings-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 28px;
  margin-bottom: 20px;
}

.settings-card-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.settings-card-subtitle {
  font-size: 0.8125rem;
  color: #64748b;
  margin-bottom: 20px;
}

.settings-subcard {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  background: #fafbfc;
}

.settings-subcard:last-child {
  margin-bottom: 0;
}

.settings-subcard-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 4px;
}

.settings-subcard-desc {
  font-size: 0.8125rem;
  color: #64748b;
  margin-bottom: 12px;
}

.settings-form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.settings-form-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

.settings-form-row .btn-primary,
.settings-form-row .btn-secondary {
  flex-shrink: 0;
  height: 36px;
  align-self: flex-end;
}

.settings-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: #0f172a;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #94a3b8;
}

.status-dot.green {
  background: #059669;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

.settings-account-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-account-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: #0f172a;
}

.settings-account-item .checkmark {
  color: #059669;
  font-weight: 700;
}

.settings-sync-time {
  font-size: 0.8125rem;
  color: #475569;
}

.settings-targets-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}

/* ========== VALIDATION SECTION ========== */
.validation-header-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.validation-header-text h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.validation-header-text p {
  font-size: 0.875rem;
  color: #64748b;
}

.validation-results-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  padding: 24px;
}

.validation-results-title {
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 16px;
}

.validation-check-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.validation-check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #f1f5f9;
}

.validation-check-item:last-child {
  border-bottom: none;
}

.validation-check-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  flex-shrink: 0;
}

.validation-check-icon.pass {
  background: #ecfdf5;
  color: #059669;
}

.validation-check-icon.fail {
  background: #fef2f2;
  color: #dc2626;
}

.validation-check-text {
  flex: 1;
  font-size: 0.875rem;
  color: #0f172a;
}

.validation-check-result {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #475569;
  white-space: nowrap;
}

/* ========== POSITIVE / NEGATIVE UTILITIES ========== */
.positive { color: #059669; }
.negative { color: #dc2626; }

/* ========== ACCESSIBILITY ========== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

*:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* ========== MOBILE BOTTOM NAVIGATION ========== */

/* Hidden on desktop */
.mobile-nav { display: none; }

@media (max-width: 768px) {
    /* ---- Bottom Tab Bar ---- */
    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(56px + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: #334155;
        z-index: 1000;
        justify-content: space-around;
        align-items: center;
        border-top: 1px solid rgba(255,255,255,0.1);
    }

    .mobile-nav-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        flex: 1;
        height: 56px;
        min-width: 44px;
        min-height: 44px;
        padding: 6px 4px;
        color: #c7d2fe;
        text-decoration: none;
        font-size: 0.625rem;
        font-weight: 500;
        font-family: inherit;
        background: none;
        border: none;
        cursor: pointer;
        transition: color 0.15s ease;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        position: relative;
    }

    .mobile-nav-tab svg {
        width: 22px;
        height: 22px;
        flex-shrink: 0;
    }

    .mobile-nav-tab.active {
        color: #ffffff;
    }

    /* Active indicator — top accent bar */
    .mobile-nav-tab.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 25%;
        right: 25%;
        height: 2px;
        background: rgba(255,255,255,0.5);
        border-radius: 0 0 2px 2px;
    }

    /* Focus visible (keyboard only) */
    .mobile-nav-tab:focus-visible {
        outline: 2px solid #a5b4fc;
        outline-offset: -2px;
        border-radius: 8px;
    }
    .mobile-nav-tab:focus:not(:focus-visible) {
        outline: none;
    }

    /* Content padding so nothing hides behind the nav */
    .main {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 16px) !important;
    }

    /* ---- "More" Popover (native popover API) ---- */
    #mobileMorePopover {
        position: fixed;
        inset: unset;
        bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 8px);
        right: 8px;
        margin: 0;
        padding: 0;
        width: 220px;
        background: #334155;
        border: 1px solid rgba(255,255,255,0.15);
        border-radius: 12px;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
        overflow: hidden;
        opacity: 0;
        transform: translateY(8px);
        transition: opacity 0.15s ease, transform 0.15s ease,
                    display 0.15s allow-discrete, overlay 0.15s allow-discrete;
    }

    #mobileMorePopover:popover-open {
        opacity: 1;
        transform: translateY(0);
    }

    @starting-style {
        #mobileMorePopover:popover-open {
            opacity: 0;
            transform: translateY(8px);
        }
    }

    #mobileMorePopover::backdrop {
        background: rgba(0,0,0,0.15);
        transition: background-color 0.15s,
                    display 0.15s allow-discrete, overlay 0.15s allow-discrete;
    }

    @starting-style {
        #mobileMorePopover:popover-open::backdrop {
            background: transparent;
        }
    }

    .mobile-more-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 16px;
        color: #c7d2fe;
        text-decoration: none;
        font-size: 0.875rem;
        font-weight: 500;
        font-family: inherit;
        background: none;
        border: none;
        cursor: pointer;
        transition: background 0.15s ease;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        text-align: left;
        width: 100%;
    }

    .mobile-more-item:hover,
    .mobile-more-item:active {
        background: #475569;
    }

    .mobile-more-item.active {
        color: #ffffff;
        background: rgba(255,255,255,0.12);
    }

    .mobile-more-item svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }

    .mobile-more-divider {
        height: 1px;
        background: rgba(255,255,255,0.1);
        margin: 4px 0;
    }

    .mobile-more-action {
        color: #a5b4fc;
    }

    .mobile-more-item:focus-visible {
        outline: 2px solid #a5b4fc;
        outline-offset: -2px;
    }
}

/* Reduced motion — disable nav animations */
@media (prefers-reduced-motion: reduce) {
    .mobile-nav-tab,
    #mobileMorePopover,
    #mobileMorePopover::backdrop,
    .mobile-more-item {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ========== WINDOW CONTROLS OVERLAY (PWA title bar) ========== */
@media (display-mode: window-controls-overlay) {
  .sidebar::before {
    content: '';
    flex-shrink: 0;
    height: env(titlebar-area-height, 0px);
    -webkit-app-region: drag;
    app-region: drag;
  }

  .sidebar-brand {
    -webkit-app-region: drag;
    app-region: drag;
  }

  .content::before {
    content: '';
    display: block;
    height: env(titlebar-area-height, 0px);
    -webkit-app-region: drag;
    app-region: drag;
  }

  .topbar {
    top: env(titlebar-area-height, 0px);
  }
}

/* ========== AUTO-SYNC INDICATOR ========== */

.sync-indicator {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f0f4fa;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  z-index: 1050;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sync-indicator.visible {
  opacity: 1;
}

@media (min-width: 769px) {
  .sync-indicator {
    bottom: 24px;
  }
}

/* Auto-sync toggle in Settings */
.auto-sync-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  cursor: pointer;
  font-size: 14px;
  color: #64748b;
}

.auto-sync-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========== PRINT STYLES ========== */
@media print {
  .sidebar { display: none; }
  .content { margin-left: 0; }
  .topbar { display: none; }
  .modal-overlay { display: none; }
  .btn-primary, .btn-secondary, .btn-ghost, .btn-ghost-danger { display: none; }
  .summary-card { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
  .chart-card { break-inside: avoid; }
  .holdings-card { break-inside: avoid; }
  body { background: white; }
}

/* ========== EMPTY STATE & LOADING ========== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #64748b;
  font-size: 0.875rem;
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #e2e8f0;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ========== FORM ERROR STATE ========== */
.form-error {
  color: #dc2626;
  font-size: 0.75rem;
  margin-top: 4px;
}

.form-input.error,
.form-select.error {
  border-color: #dc2626;
}

/* ========== TEXT UTILITIES ========== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: #64748b; }

/* ========== ALERTS ========== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 16px;
}

.alert-success {
  background: #ecfdf5;
  color: #059669;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.alert-warning {
  background: #fffbeb;
  color: #d97706;
  border: 1px solid #fde68a;
}

/* ========== EMPOWER MULTI-STEP MODAL ========== */
/* Step containers must pass flex layout through to modal-body/footer */
#empowerLoginStep,
#empowerAccountStep,
#empower2FAStep,
#empowerProgressStep {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
/* Forms inside steps also need to pass flex through */
#empowerLoginForm,
#empower2FAForm {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.empower-step { padding: 24px; }
.empower-progress { text-align: center; padding: 32px; }
.empower-progress .loading-spinner { width: 32px; height: 32px; border-width: 3px; }
.account-selection-list { display: flex; flex-direction: column; gap: 8px; }
.account-select-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.account-select-item:hover { background: #f8fafc; border-color: #cbd5e1; }
.account-select-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: #4f46e5; flex-shrink: 0; }
.account-select-info {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}
.account-select-info strong {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
}
.account-institution { font-size: 0.75rem; color: #64748b; }
.account-balance { font-size: 0.875rem; font-weight: 600; color: #0f172a; margin-top: 2px; }

/* ========== PROGRESS SPINNER (SYNC) ========== */
.progress-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 12px;
  color: #64748b;
  font-size: 0.875rem;
}

/* ========== USERS LIST (SETTINGS) ========== */
.users-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.user-card { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border: 1px solid #e2e8f0; border-radius: 8px; background: #fafbfc; }
.user-info { display: flex; align-items: center; gap: 8px; }
.user-id { font-size: 0.875rem; font-weight: 500; color: #0f172a; }
.btn-remove {
  font-size: 0.75rem;
  font-weight: 500;
  color: #dc2626;
  background: none;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-remove:hover { background: #fef2f2; border-color: #dc2626; }

/* ========== MODAL DESCRIPTIONS ========== */
.modal-desc { font-size: 0.875rem; color: #334155; margin-bottom: 16px; line-height: 1.5; }
.modal-desc-muted { font-size: 0.8rem; color: #94a3b8; margin-bottom: 16px; line-height: 1.4; }

/* ========== ADD USER FORM (SETTINGS) ========== */
.add-user-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

/* ========== SECTION HEADER ========== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.section-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
}
