/* ========== CSS Variables & Theming ========== */
:root {
  --bg-primary: #f8f9fb;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f2f5;
  --text-primary: #1a1d23;
  --text-secondary: #5f6577;
  --text-muted: #9099a8;
  --border-color: #e2e5eb;
  --border-light: #eef0f4;
  --accent: #4361ee;
  --accent-light: #eef1fd;
  --positive: #10b981;
  --positive-bg: #ecfdf5;
  --negative: #ef4444;
  --negative-bg: #fef2f2;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --neutral: #6b7280;
  --neutral-bg: #f3f4f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --nav-height: 52px;
  --header-height: 56px;
}

[data-theme="dark"] {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242836;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0b0;
  --text-muted: #5f6577;
  --border-color: #2d3244;
  --border-light: #232738;
  --accent: #6380f0;
  --accent-light: #1e2440;
  --positive: #34d399;
  --positive-bg: #0d2a1f;
  --negative: #f87171;
  --negative-bg: #2a0f0f;
  --warning: #fbbf24;
  --warning-bg: #2a2008;
  --neutral: #9ca3af;
  --neutral-bg: #1f2937;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ========== Modal ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}
.modal.hidden {
  display: none;
}
.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.modal-content h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.modal-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}
.modal-content input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}
.modal-content input:focus {
  outline: none;
  border-color: var(--accent);
}
.modal-hint {
  font-size: 0.8rem !important;
  color: var(--text-muted) !important;
  margin-top: 0.5rem;
}

/* ========== Buttons ========== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-icon:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ========== Header ========== */
header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}
.header-left h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.last-refresh {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.header-right {
  display: flex;
  gap: 0.5rem;
}

/* ========== Navigation ========== */
nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 1.5rem;
  height: var(--nav-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  position: sticky;
  top: var(--header-height);
  z-index: 99;
  -webkit-overflow-scrolling: touch;
}
nav::-webkit-scrollbar { height: 0; }

.nav-btn {
  flex-shrink: 0;
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.nav-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.nav-btn.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ========== Main Content ========== */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

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

.section-header {
  margin-bottom: 1.25rem;
}
.section-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.section-subtitle {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-top: 0.2rem;
}

/* ========== KPI Cards ========== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  transition: box-shadow 0.2s, border-color 0.2s;
  cursor: default;
}
.kpi-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.kpi-change {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.35rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.kpi-change.positive {
  background: var(--positive-bg);
  color: var(--positive);
}
.kpi-change.negative {
  background: var(--negative-bg);
  color: var(--negative);
}
.kpi-change.neutral {
  background: var(--neutral-bg);
  color: var(--neutral);
}

.kpi-meta {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.kpi-sparkline {
  height: 36px;
  margin-top: 0.5rem;
}

/* ========== Panels ========== */
.panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.panel h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

/* ========== Overview ========== */
.overview-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.yield-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.yield-status-badge.normal {
  background: var(--positive-bg);
  color: var(--positive);
}
.yield-status-badge.inverted {
  background: var(--negative-bg);
  color: var(--negative);
}
.yield-status-badge.flat {
  background: var(--warning-bg);
  color: var(--warning);
}

.yield-status-detail {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ========== Charts ========== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
  gap: 1rem;
}

.chart-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  min-height: 340px;
}
.chart-container h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}
.chart-container .chart-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* ========== Yield Curve Page ========== */
.yield-curve-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

#yield-curve-date {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.yield-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.85rem;
}
.yield-table th,
.yield-table td {
  padding: 0.5rem 0.75rem;
  text-align: center;
  border-bottom: 1px solid var(--border-light);
}
.yield-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.yield-table td {
  font-weight: 500;
}

/* ========== Release Calendar ========== */
#calendar-content {
  display: grid;
  gap: 0.75rem;
}

.calendar-group {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.calendar-group-header {
  padding: 0.7rem 1rem;
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
}

.calendar-item {
  display: flex;
  align-items: center;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.88rem;
  gap: 1rem;
}
.calendar-item:last-child {
  border-bottom: none;
}

.calendar-time {
  color: var(--text-muted);
  font-size: 0.8rem;
  min-width: 70px;
  font-weight: 500;
}

.calendar-name {
  font-weight: 500;
  flex: 1;
}

.calendar-source {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}

.calendar-today {
  border-left: 3px solid var(--accent);
}

/* ========== Loading ========== */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(248,249,251,0.85);
  backdrop-filter: blur(6px);
  gap: 1rem;
}
[data-theme="dark"] .loading-overlay {
  background: rgba(15,17,23,0.85);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* ========== Skeleton loading ========== */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border-light) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-value {
  height: 2rem;
  width: 80px;
  margin-bottom: 0.35rem;
}
.skeleton-change {
  height: 1.2rem;
  width: 60px;
}

/* ========== Footer ========== */
footer {
  text-align: center;
  padding: 2rem 1.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
  margin-top: 2rem;
}

/* ========== Error States ========== */
.error-msg {
  background: var(--negative-bg);
  color: var(--negative);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .overview-panels {
    grid-template-columns: 1fr;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

@media (max-width: 600px) {
  header {
    padding: 0 1rem;
  }
  .header-left h1 {
    font-size: 1rem;
  }
  nav {
    padding: 0 0.75rem;
  }
  main {
    padding: 1rem;
  }
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .modal-content {
    padding: 1.5rem;
  }
}

/* ========== Range selector buttons ========== */
.range-selector {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}
.range-btn {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
}
.range-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.range-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ========== Plotly overrides ========== */
.js-plotly-plot .plotly .modebar {
  top: 4px !important;
  right: 4px !important;
}
