/* ============================================================
   DebtCanary - Design System
   Corporate debt maturity tracker
   Dark financial terminal aesthetic
   ============================================================ */

/* --- Custom Properties --- */
:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2234;
  --border: #1e293b;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --risk-healthy: #10b981;
  --risk-stressed: #f59e0b;
  --risk-danger: #ef4444;
  --canary-yellow: #fbbf24;
  --link: #60a5fa;
  --font-mono: 'DM Mono', 'JetBrains Mono', monospace;
  --font-sans: 'DM Sans', 'Plus Jakarta Sans', system-ui, sans-serif;
  --transition: 0.15s ease;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-pill: 9999px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3 {
  font-family: var(--font-mono);
  line-height: 1.2;
  font-weight: 700;
}

h4, h5, h6 {
  font-family: var(--font-sans);
  line-height: 1.3;
  font-weight: 600;
}

img, svg {
  display: block;
  max-width: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg-primary);
}

/* --- Layout --- */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.section {
  margin-bottom: var(--space-8);
}

.grid-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}

.grid-2col {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}

/* --- Navigation --- */
.nav {
  width: 100%;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: box-shadow var(--transition);
}

.nav--scrolled {
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
}

.nav__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.nav__logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--canary-yellow);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.125rem;
  text-decoration: none;
}

.nav__logo:hover {
  text-decoration: none;
  color: var(--canary-yellow);
}

.nav__logo svg,
.nav__logo img {
  width: 24px;
  height: 24px;
}

.nav__links {
  display: none;
  list-style: none;
}

.nav__links a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: var(--space-2) 0;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}

.nav__links a:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.nav__links a.active {
  color: var(--text-primary);
  border-bottom-color: var(--canary-yellow);
}

.nav__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1.25rem;
}

.nav__toggle:hover {
  color: var(--text-primary);
  border-color: var(--text-tertiary);
}

/* Mobile nav dropdown */
.nav__links--open {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 56px;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: var(--space-4) var(--space-6);
  gap: var(--space-3);
}

/* --- Cards --- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
}

.card__title {
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
  font-weight: 600;
}

.card__value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* --- Metric Cards --- */
.metric-card {
  display: inline-block;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-6);
}

.metric-card__label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-bottom: var(--space-1);
}

.metric-card__value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* --- Data Tables --- */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

.data-table thead th {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  position: sticky;
  top: 0;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.data-table thead th.text-right {
  text-align: right;
}

.data-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: middle;
}

.data-table tbody td.text-right {
  text-align: right;
  font-family: var(--font-mono);
}

.data-table tbody tr {
  transition: background-color var(--transition);
}

.data-table tbody tr:hover {
  background: var(--bg-tertiary);
}

.data-table--clickable tbody tr {
  cursor: pointer;
}

.data-table--sortable thead th {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 1.5rem;
}

.data-table--sortable thead th::after {
  content: '';
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.3;
}

.data-table--sortable thead th.sort-asc::after {
  content: '\25B2';
  opacity: 1;
  color: var(--canary-yellow);
  font-size: 0.55rem;
}

.data-table--sortable thead th.sort-desc::after {
  content: '\25BC';
  opacity: 1;
  color: var(--canary-yellow);
  font-size: 0.55rem;
}

/* --- Risk Pills --- */
.risk-pill {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.risk-pill--low {
  background: rgba(16, 185, 129, 0.15);
  color: var(--risk-healthy);
}

.risk-pill--medium {
  background: rgba(245, 158, 11, 0.15);
  color: var(--risk-stressed);
}

.risk-pill--high {
  background: rgba(239, 68, 68, 0.15);
  color: var(--risk-danger);
}

/* --- Sector Badges --- */
.sector-badge {
  display: inline-block;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.btn:hover {
  background: #222d42;
  color: var(--text-primary);
  text-decoration: none;
}

.btn--active {
  border-color: var(--canary-yellow);
  color: var(--canary-yellow);
}

/* --- Search Input --- */
.search-input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  transition: border-color var(--transition);
  width: 100%;
  max-width: 320px;
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

.search-input:focus {
  border-color: var(--link);
  outline: none;
}

/* --- Filter Bar --- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-6);
}

.filter-bar select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  cursor: pointer;
}

.filter-bar select:focus {
  border-color: var(--link);
  outline: none;
}

.filter-bar__count {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-left: auto;
  font-family: var(--font-mono);
}

/* --- Breadcrumbs --- */
.breadcrumbs {
  color: var(--text-tertiary);
  font-size: 0.875rem;
  margin-bottom: var(--space-6);
}

.breadcrumbs a {
  color: var(--text-tertiary);
}

.breadcrumbs a:hover {
  color: var(--text-secondary);
}

.breadcrumbs span.separator {
  margin: 0 var(--space-2);
}

.breadcrumbs .current {
  color: var(--text-secondary);
}

/* --- Company Header --- */
.company-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.company-header__info h1 {
  font-size: 1.5rem;
  margin-bottom: var(--space-1);
}

.company-header__ticker {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  margin-right: var(--space-3);
}

.company-header__score {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.company-header__score-value {
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
}

.company-header__score-value--low { color: var(--risk-healthy); }
.company-header__score-value--medium { color: var(--risk-stressed); }
.company-header__score-value--high { color: var(--risk-danger); }

/* --- Chart Container --- */
.chart-container {
  position: relative;
  padding: var(--space-4) 0;
}

.chart-container svg,
.chart-container canvas {
  width: 100%;
  height: auto;
}

/* --- Footer --- */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: var(--space-8) 0;
  margin-top: var(--space-8);
}

.footer__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.footer__disclaimer {
  color: var(--text-tertiary);
  font-size: 0.8rem;
  max-width: 700px;
  line-height: 1.5;
  margin-bottom: var(--space-4);
}

.footer__links {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
}

.footer__links a {
  color: var(--text-tertiary);
  font-size: 0.8rem;
}

.footer__links a:hover {
  color: var(--text-secondary);
}

/* --- Ad Slots --- */
.ad-slot {
  border: 1px dashed var(--border);
  border-radius: 4px;
  display: none;
}

.ad-slot--leaderboard {
  min-height: 90px;
  max-width: 728px;
  margin: var(--space-4) auto;
}

.ad-slot--rectangle {
  min-height: 250px;
  width: 300px;
}

.ad-slot--native {
  min-height: 100px;
  width: 100%;
}

/* --- Canary Icon States --- */
.canary-icon {
  width: 24px;
  height: 24px;
  display: inline-block;
  transition: transform var(--transition), color var(--transition);
}

.canary-icon--healthy {
  color: var(--risk-healthy);
}

.canary-icon--stressed {
  color: var(--risk-stressed);
  transform: rotate(15deg);
}

.canary-icon--danger {
  color: var(--risk-danger);
  transform: rotate(90deg);
}

/* --- Utility Classes --- */
.font-mono { font-family: var(--font-mono); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-tertiary); }
.text-healthy { color: var(--risk-healthy); }
.text-stressed { color: var(--risk-stressed); }
.text-danger { color: var(--risk-danger); }
.mt-1 { margin-top: var(--space-2); }
.mt-2 { margin-top: var(--space-4); }
.mt-3 { margin-top: var(--space-6); }
.mt-4 { margin-top: var(--space-8); }
.mb-1 { margin-bottom: var(--space-2); }
.mb-2 { margin-bottom: var(--space-4); }
.mb-3 { margin-bottom: var(--space-6); }
.mb-4 { margin-bottom: var(--space-8); }

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

/* --- Responsive: Tablet --- */
@media (min-width: 768px) {
  .grid-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-2col {
    grid-template-columns: 1fr 1fr;
  }

  .nav__links {
    display: flex;
    gap: var(--space-6);
    list-style: none;
  }

  .nav__toggle {
    display: none;
  }

  .company-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }

  .company-header__info h1 {
    font-size: 1.75rem;
  }
}

/* --- Responsive: Desktop --- */
@media (min-width: 1024px) {
  .grid-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .company-header__info h1 {
    font-size: 2rem;
  }
}

/* --- Responsive: Mobile table adaptations --- */
@media (max-width: 767px) {
  .data-table thead th.hide-mobile,
  .data-table tbody td.hide-mobile {
    display: none;
  }
}

/* --- Print Styles --- */
@media print {
  body {
    background: #fff;
    color: #000;
  }

  .nav,
  .footer,
  .ad-slot,
  .filter-bar,
  .nav__toggle {
    display: none !important;
  }

  .card,
  .metric-card {
    border-color: #ccc;
    break-inside: avoid;
  }

  a {
    color: #000;
  }

  .data-table thead th {
    background: #f0f0f0;
    color: #333;
  }

  .data-table tbody tr:hover {
    background: none;
  }
}
