/* ===== CSS Variables & Reset ===== */
:root {
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f1f5;
  --bg-input: #f8f9fc;
  --border: #e2e4eb;
  --border-hover: #c8cad4;
  --text: #1e2028;
  --text-muted: #5f6578;
  --text-dim: #8b90a0;
  --primary: #4f46e5;
  --primary-light: #4338ca;
  --primary-bg: #4f46e510;
  --green: #16a34a;
  --green-bg: #16a34a12;
  --red: #dc2626;
  --red-bg: #dc262612;
  --yellow: #d97706;
  --yellow-bg: #d9770612;
  --blue: #2563eb;
  --blue-bg: #2563eb12;
  --purple: #7c3aed;
  --purple-bg: #7c3aed12;
  --cyan: #0891b2;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.06);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --sidebar-w: 260px;
  --topbar-h: 0px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #c8cad4; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0a3b0; }

/* ===== Layout ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.sidebar-logo .icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
}

.nav-section-label {
  padding: 12px 12px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.9rem;
  user-select: none;
}

.nav-item:hover { background: var(--bg-card-hover); color: var(--text); }
.nav-item.active { background: var(--primary-bg); color: var(--primary-light); font-weight: 500; }

.nav-item .nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

#market-status { display: block; text-align: center; }

.market-status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Main content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px;
  min-height: 100vh;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--border-hover); }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== KPI Cards ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1.2;
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ===== Time Machine ===== */
.time-machine {
  background: linear-gradient(135deg, #eef2ff, #e0e7ff, #eef2ff);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  padding: 16px 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.time-machine-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #4338ca;
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-machine input[type="date"] {
  background: #ffffff;
  border: 1px solid #a5b4fc;
  color: #312e81;
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  font-family: var(--font);
}

.time-machine .btn-sm {
  background: #4f46e5;
  color: #ffffff;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
}
.time-machine .btn-sm:hover { background: #4338ca; }

.time-badge {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  background: var(--bg-card);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
th:hover { color: var(--text); }
th.sorted-asc::after { content: ' ▲'; font-size: 0.7rem; }
th.sorted-desc::after { content: ' ▼'; font-size: 0.7rem; }

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tr:hover td { background: var(--bg-card-hover); }

.text-right { text-align: right; }
.text-center { text-align: center; }

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-buy { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.badge-sell { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-linked { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.badge-draft { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.badge-published { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { background: var(--bg-card-hover); border-color: var(--border-hover); }

.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }

.btn-green { background: var(--green); border-color: var(--green); color: white; }
.btn-green:hover { background: #16a34a; }

.btn-red { background: var(--red); border-color: var(--red); color: white; }
.btn-red:hover { background: #dc2626; }

.btn-sm { padding: 5px 12px; font-size: 0.78rem; }

.btn-group {
  display: inline-flex;
  gap: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.btn-group .btn {
  border-radius: 0;
  margin: 0;
}
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== Pill Toggle ===== */
.pill-toggle {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 3px;
  gap: 2px;
}
.pill-toggle .pill {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
  border: none;
  background: none;
  font-family: var(--font);
}
.pill-toggle .pill.active { background: var(--primary); color: white; }
.pill-toggle .pill:hover:not(.active) { color: var(--text); }

/* ===== Forms ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  transition: border-color 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

textarea.form-control { min-height: 80px; resize: vertical; }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3af' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* Toggle switches */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }

.toggle-switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: 0.2s;
}
.toggle-switch .slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: 0.2s;
}
.toggle-switch input:checked + .slider { background: var(--primary); }
.toggle-switch input:checked + .slider::before { transform: translateX(18px); }

/* ===== Search / Filter Bar ===== */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.search-input {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-input input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
}
.search-input input:focus { outline: none; border-color: var(--primary); }
.search-input::before {
  content: '🔍';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
}

/* Dropdown results */
.dropdown-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow);
}
.dropdown-results .result-item {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}
.dropdown-results .result-item:hover { background: var(--bg-card-hover); }
.dropdown-results .result-item .ticker { font-weight: 600; color: var(--primary-light); }
.dropdown-results .result-item .name { color: var(--text-muted); font-size: 0.8rem; }

/* ===== Chart Container ===== */
.chart-container {
  position: relative;
  width: 100%;
  min-height: 300px;
}
.chart-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: center;
}
.chart-controls .label {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  margin-right: 4px;
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
}
.page-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Grid Layouts ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ===== Weight Bar ===== */
.weight-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.weight-bar-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.weight-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}
.weight-bar-label {
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 48px;
  text-align: right;
}

/* ===== Horizontal Bar Chart (CSS) ===== */
.hbar-chart .hbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.hbar-label {
  width: 120px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
}
.hbar-track {
  flex: 1;
  height: 22px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.hbar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s;
  display: flex;
  align-items: center;
  padding-left: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: white;
}
.hbar-value {
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 42px;
}

/* ===== Stars ===== */
.star { color: var(--text-dim); font-size: 0.9rem; }
.star.filled { color: var(--yellow); }

/* ===== Live Price Box ===== */
.live-price-box {
  background: var(--bg-input);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 12px 0;
}
.live-price-box .price {
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-mono);
}
.live-price-box .meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Loading ===== */
.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Global Loading Bar (top of viewport) ===== */
.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.loading-bar.active {
  opacity: 1;
}
.loading-bar-track {
  width: 100%;
  height: 100%;
  background: var(--border);
  overflow: hidden;
}
.loading-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light), var(--cyan));
  background-size: 200% 100%;
  animation: loading-bar-shimmer 1.5s ease-in-out infinite;
  width: 0%;
  transition: width 0.4s ease;
}
@keyframes loading-bar-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Toast notifications (top-right) */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  color: #fff;
  opacity: 0;
  transform: translateX(40px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.toast.show {
  opacity: 1;
  transform: translateX(0);
}
.toast-synced {
  background: #16a34a;
}
.toast-yahoo {
  background: #2563eb;
}
.toast-warning {
  background: #d97706;
}
.toast-info {
  background: #6366f1;
}

/* Yahoo Finance background refresh banner */
.yahoo-refresh-banner {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--yellow-bg);
  border: 1px solid rgba(217,119,6,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--yellow);
  margin: 0 0 12px 0;
  position: relative;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s ease;
  flex-wrap: wrap;
}
.yahoo-refresh-banner.active {
  display: flex;
  opacity: 1;
}
.yahoo-refresh-banner.offline {
  background: var(--red-bg);
  border-color: rgba(220,38,38,0.2);
  color: var(--red);
}
.yahoo-refresh-icon {
  font-size: 1rem;
  animation: yahoo-spin 1s linear infinite;
  flex-shrink: 0;
}
.yahoo-refresh-banner.offline .yahoo-refresh-icon {
  animation: none;
}
@keyframes yahoo-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.yahoo-refresh-text {
  flex: 1;
  min-width: 0;
}
.yahoo-refresh-text strong {
  color: var(--text);
  font-weight: 600;
}
.yahoo-refresh-pct {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}
.yahoo-refresh-bar {
  width: 100%;
  height: 3px;
  background: rgba(217,119,6,0.15);
  border-radius: 2px;
  overflow: hidden;
}
.yahoo-refresh-bar-fill {
  height: 100%;
  background: var(--yellow);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Loading overlay for initial page load */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loading-overlay .loading-icon {
  font-size: 3rem;
  animation: pulse-icon 1.5s ease-in-out infinite;
}
@keyframes pulse-icon {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 1; }
}
.loading-overlay .loading-text {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  max-width: 300px;
}
.loading-overlay .loading-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.loading-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
  transition: color 0.3s ease;
}
.loading-step.active {
  color: var(--primary-light);
}
.loading-step.done {
  color: var(--green);
}
.loading-step-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
}
.loading-step.active .loading-step-icon {
  animation: spin 0.7s linear infinite;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state h3 { color: var(--text-muted); margin-bottom: 8px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
}

/* ===== Trade Type Toggle ===== */
.trade-type-toggle {
  display: flex;
  gap: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.trade-type-toggle .toggle-btn {
  flex: 1;
  padding: 10px 24px;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  cursor: pointer;
  border: none;
  background: var(--bg-input);
  color: var(--text-muted);
  transition: all 0.15s;
  font-family: var(--font);
}
.trade-type-toggle .toggle-btn.active-buy { background: var(--green); color: white; }
.trade-type-toggle .toggle-btn.active-sell { background: var(--red); color: white; }

/* ===== Calculation Summary ===== */
.calc-summary {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 16px 0;
}
.calc-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.85rem;
}
.calc-row .label { color: var(--text-muted); }
.calc-row .value { font-family: var(--font-mono); font-weight: 600; }
.calc-row.total { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }
.calc-row.total .value { font-size: 1rem; }

/* ===== Public View ===== */
.public-header {
  background: linear-gradient(135deg, #4f46e5, #6366f1, #7c3aed);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.public-header::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 70%);
  border-radius: 50%;
}
.public-header h1 { font-size: 1.8rem; font-weight: 700; position: relative; z-index: 1; }
.public-header .desc { color: #c4b5fd; margin-top: 6px; font-size: 0.9rem; position: relative; z-index: 1; }

/* ===== Think Pieces Cards ===== */
.tp-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s;
}
.tp-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.tp-card-header {
  padding: 20px;
  font-size: 2rem;
  text-align: center;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tp-card-body { padding: 16px; }
.tp-card-title { font-weight: 600; margin-bottom: 6px; }
.tp-card-meta { font-size: 0.78rem; color: var(--text-muted); }

.tp-new-card {
  border: 2px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 1rem;
  transition: border-color 0.2s;
}
.tp-new-card:hover { border-color: var(--primary); color: var(--primary-light); }

/* ===== Snapshot Cards ===== */
.snap-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.snap-card .snap-date { font-weight: 600; font-size: 1rem; margin-bottom: 8px; }
.snap-card .snap-stats { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.snap-card .snap-stat { }
.snap-card .snap-stat .label { font-size: 0.72rem; color: var(--text-dim); }
.snap-card .snap-stat .value { font-size: 0.9rem; font-weight: 600; font-family: var(--font-mono); }

/* ===== Journal Cards ===== */
.journal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.journal-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.journal-ticker {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-light);
}
.journal-body {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.journal-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.journal-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ===== Global Indexes Grid ===== */
.etf-category {
  margin-bottom: 24px;
}
.etf-category-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.etf-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.etf-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 0.82rem;
}
.etf-row:hover { border-color: var(--border-hover); }
.etf-ticker { font-weight: 600; color: var(--primary-light); font-family: var(--font-mono); min-width: 60px; }
.etf-name { flex: 1; color: var(--text-muted); margin: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.etf-ytd { font-family: var(--font-mono); font-weight: 600; min-width: 60px; text-align: right; }

/* ===== Positive / Negative ===== */
.positive { color: var(--green); }
.negative { color: var(--red); }

/* ===== Hamburger Button (mobile only) ===== */
.hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 201;
  width: 40px;
  height: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 9px 8px;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
}
.hamburger span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.25s ease;
}
.hamburger.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Sidebar close button (mobile only) */
.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
}
.sidebar-close:hover { color: var(--text); background: var(--bg-card-hover); }

/* Sidebar overlay (mobile only) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ===== Responsive: Tablet ===== */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .etf-grid { grid-template-columns: repeat(2, 1fr); }
  .main-content { padding: 20px; }
}

/* ===== Responsive: Mobile ===== */
@media (max-width: 768px) {
  /* Show hamburger */
  .hamburger { display: flex; }
  .sidebar-close { display: block; }

  /* Sidebar becomes a slide-out drawer */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 200;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Sidebar header: logo + close button */
  .sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  /* Main content takes full width */
  .main-content {
    margin-left: 0;
    padding: 60px 16px 24px;
  }

  /* Grids single column */
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .etf-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }

  /* KPI cards: 2 per row on mobile, 1 on very small */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 1.3rem; }

  /* Page header stacks vertically */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-title { font-size: 1.25rem; }

  /* Time machine wraps nicely */
  .time-machine {
    flex-direction: column;
    align-items: flex-start;
    padding: 14px 16px;
    gap: 10px;
  }

  /* Tables: horizontal scroll */
  .table-wrap { margin: 0 -16px; border-radius: 0; border-left: none; border-right: none; }
  table { font-size: 0.8rem; }
  th, td { padding: 8px 10px; }

  /* Filter bar stacks */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-input { min-width: 0; }

  /* Chart controls wrap */
  .chart-controls { gap: 6px; }
  .chart-container { min-height: 220px; }

  /* Pill toggle scrolls */
  .pill-toggle { overflow-x: auto; flex-wrap: nowrap; }
  .pill-toggle .pill { white-space: nowrap; padding: 6px 12px; font-size: 0.75rem; }

  /* Btn group scrolls */
  .btn-group { overflow-x: auto; }

  /* Cards reduce padding */
  .card { padding: 16px; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* Public header */
  .public-header { padding: 24px 16px; }
  .public-header h1 { font-size: 1.3rem; }

  /* Journal cards */
  .journal-card-header { flex-direction: column; gap: 8px; }
  .journal-meta { flex-direction: column; gap: 6px; }

  /* Think piece cards grid */
  .tp-card-header { min-height: 60px; font-size: 1.6rem; }

  /* Modal full-width on mobile */
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal { max-height: 90vh; border-radius: var(--radius) var(--radius) 0 0; }

  /* Buttons slightly bigger tap targets */
  .btn { padding: 10px 18px; font-size: 0.85rem; }
  .btn-sm { padding: 8px 14px; }

  /* Login card */
  .login-card { padding: 28px 20px; }

  /* Loading overlay */
  .loading-overlay .loading-icon { font-size: 2.4rem; }
  .loading-overlay .loading-text { font-size: 0.82rem; }

  /* Horizontal bar chart labels */
  .hbar-label { width: 80px; font-size: 0.72rem; }

  /* Live price box */
  .live-price-box .price { font-size: 1.1rem; }

  /* Trade type toggle */
  .trade-type-toggle .toggle-btn { padding: 10px 16px; font-size: 0.82rem; }

  /* Snap card stats wrap */
  .snap-card .snap-stats { gap: 10px; }
}

/* ===== Responsive: Very small phones ===== */
@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.1rem; }
  .main-content { padding: 56px 12px 20px; }
  .page-title { font-size: 1.1rem; }
  .etf-row { flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px 12px; }
  .etf-name { margin: 0; }
  .etf-ytd { text-align: left; }
}

/* ===== Article Content ===== */
.article-content {
  line-height: 1.8;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.article-content h1, .article-content h2, .article-content h3 { color: var(--text); margin: 20px 0 10px; }
.article-content p { margin-bottom: 12px; }

/* ===== Blurred Draft ===== */
.blurred-draft {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
  position: relative;
}
.draft-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 246, 250, 0.75);
  border-radius: var(--radius);
  font-weight: 600;
  color: var(--text-muted);
  filter: none;
}

/* ===== Settings 2-col ===== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 768px) { .settings-grid { grid-template-columns: 1fr; } }

/* ===== Watchlist alert ===== */
.alert-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
}
.alert-badge.triggered { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-badge.pending { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-badge.none { background: var(--bg-input); color: var(--text-dim); border: 1px solid var(--border); }

/* ===== Sharpe rating pills ===== */
.rating-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  position: relative;
  cursor: help;
}

/* Sharpe tooltip — uses JS-positioned fixed tooltip to escape overflow:auto containers */
.sharpe-tip {
  position: relative;
  display: inline-block;
  cursor: help;
}
.sharpe-tip-popup {
  position: fixed;
  z-index: 9999;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-muted);
  white-space: pre;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  min-width: 280px;
  max-width: 340px;
  text-align: left;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.sharpe-tip-popup.visible {
  opacity: 1;
}
.sharpe-tip-popup::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
}
.sharpe-tip-popup.above::after {
  top: 100%;
  border-top-color: #ffffff;
}
.sharpe-tip-popup.below::after {
  bottom: 100%;
  border-bottom-color: #ffffff;
}
@media (max-width: 768px) {
  .sharpe-tip-popup {
    min-width: 240px;
    font-size: 0.68rem;
  }
}

/* ===== Login Page ===== */
.login-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
}
.login-header {
  text-align: center;
  margin-bottom: 28px;
}
.login-icon {
  font-size: 2.4rem;
  margin-bottom: 8px;
}
.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.login-subtitle {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.login-input-wrap {
  position: relative;
}
.login-input-wrap .form-control {
  padding-right: 44px;
}
.login-eye {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.5;
  padding: 4px;
}
.login-eye:hover { opacity: 0.9; }
.login-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.82rem;
  margin-bottom: 16px;
}
.login-success {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.82rem;
  margin-bottom: 16px;
}

/* --- Custom Index Search Dropdown --- */
.index-search-wrap {
  padding: 8px 0;
  position: relative;
}
.index-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}
.index-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-bg);
}
.index-search-results {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  background: var(--bg-card);
}
.index-search-results:empty {
  display: none;
}
.index-result-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.84rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.index-result-item:last-child {
  border-bottom: none;
}
.index-result-item:hover {
  background: var(--primary-bg);
}
.series-remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.series-remove-btn:hover {
  background: var(--red-bg, #fef2f2);
  color: var(--red, #ef4444);
}
