/* ═══════════════════════════════════════════════════════════════════════════
   NSE Viewer – Content-First Design System (Mobile-First Responsive)
   Inspired by: Cassie.codes Design Philosophy
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset & Root Variables ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Color system - Neutral palette */
  --bg:           #FFFFFF;
  --text:         #111111;
  --text-muted:   #666666;
  --border:       #E5E5E5;
  --surface:      #F9F9F9;
  --accent:       #0066CC;
  --accent-light: #E6F0FF;
  --success:      #00AA44;
  --danger:       #CC0000;
  
  /* Spacing scale (8px base) - MOBILE FIRST */
  --space-xs:     4px;
  --space-sm:     8px;
  --space-md:     12px;
  --space-lg:     16px;
  --space-xl:     20px;
  --space-2xl:    28px;
  --space-3xl:    36px;
  --space-4xl:    48px;
  
  /* Typography */
  --font-family:  -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  --line-height:  1.6;
  
  /* Radius */
  --radius-sm:    4px;
  --radius-md:    8px;
  --radius-lg:    12px;
  
  /* Transitions */
  --transition:   150ms ease;
}

html, body {
  height: 100%;
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--text);
  line-height: var(--line-height);
}

/* ── Layout Structure ── */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header / Navigation (MOBILE FIRST) ── */
.header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: var(--space-md) 0;
}

.header-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
  position: relative;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

/* ── Hamburger Menu (Mobile) ── */
.hamburger {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: transparent;
  border: none;
  padding: var(--space-sm);
  cursor: pointer;
  z-index: 101;
  flex-shrink: 0;
  margin-left: auto;
}

.hamburger-line {
  width: 24px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all var(--transition);
  transform-origin: center;
}

.hamburger[aria-expanded="true"] .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(10px, 8px);
}

.hamburger[aria-expanded="true"] .hamburger-line:nth-child(2) {
  opacity: 0;
}

.hamburger[aria-expanded="true"] .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(8px, -8px);
}

/* ── Navigation (MOBILE FIRST - Hidden by default) ── */
.nav {
  display: none;
  flex-direction: column;
  gap: 0;
  list-style: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: var(--space-md) 0;
  width: 100%;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.nav.nav-open {
  display: flex;
}

.nav-item a {
  padding: var(--space-md) var(--space-md);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: color var(--transition), background var(--transition);
  border-left: 3px solid transparent;
  display: block;
}

.nav-item a:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.nav-item a.active {
  color: var(--accent);
  background: var(--accent-light);
  border-left-color: var(--accent);
}

.header-right {
  display: none;
  align-items: center;
  gap: var(--space-md);
}

.api-status {
  font-size: 12px;
  color: var(--text-muted);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: inline-block;
  white-space: nowrap;
}

/* ── Main Content ── */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.page-intro {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-2xl) var(--space-md);
  width: 100%;
  text-align: center;
}

.page-intro h1 {
  font-size: clamp(28px, 7vw, 56px);
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: var(--space-md);
  color: var(--text);
}

.page-intro p {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto;
}

.content {
  flex: 1;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
  padding: 0 var(--space-md) var(--space-2xl);
}

/* ── Sections with spacing ── */
.section {
  margin-bottom: var(--space-2xl);
}

.section-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: var(--space-lg);
  color: var(--text);
}

/* ── Stats Grid (MOBILE FIRST) ── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-2xl);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  text-align: center;
  transition: all var(--transition);
}

.stat-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-sm);
  font-weight: 600;
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
}

/* ── Cards ── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: var(--space-lg);
}

.card-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.card-header h2,
.card-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.card-body {
  padding: var(--space-md);
}

/* ── Tables (MOBILE FIRST - Horizontal scroll) ── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 500px;
}

.data-table thead {
  background: var(--surface);
}

.data-table th {
  padding: var(--space-md);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.data-table th:hover {
  color: var(--text);
  background: #F3F3F3;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: var(--surface);
}

.data-table td {
  padding: var(--space-md);
  vertical-align: middle;
  color: var(--text);
}

.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: "Courier New", monospace;
}

.data-table td.muted {
  color: var(--text-muted);
}

.data-table td.up {
  color: var(--success);
  font-weight: 600;
}

.data-table td.dn {
  color: var(--danger);
  font-weight: 600;
}

/* ── Empty & Loading States ── */
.empty-state,
.loading-state,
.error-state {
  padding: var(--space-2xl) var(--space-md);
  text-align: center;
  color: var(--text-muted);
  font-size: 16px;
}

.error-state {
  color: var(--danger);
}

.loading-cell,
.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 24px !important;
  font-size: 13px;
}

.error-cell {
  text-align: center;
  color: var(--danger);
  padding: 24px !important;
  font-size: 13px;
}

/* ── Toolbar (MOBILE FIRST - Stacked) ── */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  align-items: stretch;
  margin-bottom: var(--space-lg);
}

.result-count {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Form Elements (MOBILE FIRST - Full width) ── */
.search-input,
.select-input {
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font-family);
  color: var(--text);
  background: var(--bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

.search-input:focus,
.select-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-input-lg {
  width: 100%;
  padding: var(--space-lg);
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input-lg:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ── Buttons ── */
.btn {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
  font-family: var(--font-family);
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  padding: var(--space-sm);
  cursor: pointer;
  transition: color var(--transition);
}

.btn-close:hover {
  color: var(--text);
}

.btn-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--accent);
  padding: var(--space-sm) var(--space-md);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  font-weight: 600;
  white-space: nowrap;
}

.btn-detail:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Tags & Badges ── */
.symbol-tag {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  font-family: "Courier New", monospace;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.pill {
  display: inline-block;
  background: var(--surface);
  color: var(--text);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-lg);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border);
}

.pill.green {
  background: #E8F5E9;
  color: var(--success);
  border-color: #A5D6A7;
}

.pill.red {
  background: #FFEBEE;
  color: var(--danger);
  border-color: #EF9A9A;
}

.pill.blue {
  background: var(--accent-light);
  color: var(--accent);
  border-color: #90CAF9;
}

.pill.orange {
  background: #FFF3E0;
  color: #F57C00;
  border-color: #FFB74D;
}

.pill.grey {
  background: var(--surface);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ── Detail Panel ── */
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
  gap: var(--space-md);
}

.detail-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
  word-break: break-word;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
}

.detail-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

.detail-key {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: var(--space-sm);
  display: block;
}

.detail-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

/* ── Filter Checkboxes ── */
.filter-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  padding: var(--space-sm) 0;
}

.checkbox-label input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
}

/* ── Footer ── */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: var(--space-xl) var(--space-md);
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: auto;
}

.footer-content {
  max-width: 1280px;
  margin: 0 auto;
}

/* ── Typography Utilities ── */
h1 {
  font-size: clamp(28px, 7vw, 56px);
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1.2;
  margin-bottom: var(--space-lg);
}

h2 {
  font-size: clamp(22px, 5vw, 40px);
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
  margin-bottom: var(--space-md);
}

h3 {
  font-size: clamp(18px, 4vw, 28px);
  font-weight: 700;
  letter-spacing: -0.25px;
  line-height: 1.3;
  margin-bottom: var(--space-md);
}

p {
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: var(--space-md);
  color: var(--text);
}

p.muted {
  color: var(--text-muted);
}

/* ── Bar Chart ── */
.bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.bar-label {
  flex: 0 0 120px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.bar-track {
  flex: 1;
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
  min-width: 0;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  background: var(--accent);
}

.bar-value {
  flex: 0 0 40px;
  text-align: right;
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
}

/* ── Backward Compatibility Classes ── */
.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.card.mt {
  margin-top: var(--space-lg);
}

.card.mt0 {
  margin-top: 0;
}

.name-cell {
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 13px;
}

.muted {
  color: var(--text-muted);
}

.up {
  color: var(--success);
}

.dn {
  color: var(--danger);
}

.badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xs) var(--space-md);
  font-size: 11px;
  color: var(--text-muted);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Accessibility ── */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* Visible focus states for keyboard navigation */
.btn:focus,
.search-input:focus,
.select-input:focus,
.checkbox-label input:focus,
.nav-item a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ════════════════════════════════════════════════════════════════════════════
   TABLET BREAKPOINT (768px+)
   ════════════════════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  :root {
    /* Increase spacing for tablet */
    --space-md:     16px;
    --space-lg:     24px;
    --space-xl:     32px;
    --space-2xl:    48px;
    --space-3xl:    64px;
    --space-4xl:    96px;
  }

  /* ── Header Layout (Horizontal) ── */
  .header {
    padding: var(--space-md) 0;
  }

  .header-container {
    flex-wrap: nowrap;
    gap: var(--space-lg);
  }

  .hamburger {
    display: none;
  }

  /* ── Navigation (Horizontal) ── */
  .nav {
    display: flex !important;
    flex-direction: row;
    position: static;
    gap: var(--space-md);
    align-items: center;
    flex: 1;
    border: none;
    padding: 0;
    box-shadow: none;
    background: transparent;
  }

  .nav-item a {
    padding: var(--space-sm) var(--space-md);
    border-left: none;
    border-bottom: 2px solid transparent;
  }

  .nav-item a:hover,
  .nav-item a.active {
    color: var(--accent);
    background: transparent;
    border-bottom-color: var(--accent);
  }

  /* ── Header Right (Always visible) ── */
  .header-right {
    display: flex !important;
    position: static !important;
    margin-left: auto;
  }

  /* ── Page Intro ── */
  .page-intro {
    padding: var(--space-3xl) var(--space-md);
  }

  .page-intro h1 {
    font-size: clamp(42px, 8vw, 56px);
  }

  /* ── Content Padding ── */
  .content {
    padding: 0 var(--space-md) var(--space-3xl);
  }

  /* ── Stats Grid (Multi-column) ── */
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
  }

  /* ── Toolbar (Horizontal) ── */
  .toolbar {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .result-count {
    margin-left: auto;
    text-align: right;
  }

  /* ── Search Inputs ── */
  .search-input {
    max-width: 300px;
    width: auto;
  }

  /* ── Detail Grid (Multi-column) ── */
  .detail-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  /* ── Two Column Layout ── */
  .two-col {
    grid-template-columns: 1fr 1fr;
  }

  /* ── Typography ── */
  .page-intro p {
    font-size: 18px;
  }

  .stat-value {
    font-size: 48px;
  }

  /* ── Bar Chart (Wider) ── */
  .bar-label {
    flex: 0 0 140px;
  }

  .bar-value {
    flex: 0 0 50px;
  }

  /* ── Table Smaller Font Size (More content fits) ── */
  .data-table {
    font-size: 14px;
  }

  .data-table th {
    font-size: 12px;
  }

  .detail-key {
    font-size: 11px;
  }

  .detail-val {
    font-size: 15px;
  }
}

/* ════════════════════════════════════════════════════════════════════════════
   DESKTOP BREAKPOINT (1024px+)
   ════════════════════════════════════════════════════════════════════════════ */
@media (min-width: 1024px) {
  :root {
    /* Increase spacing for desktop */
    --space-lg:     24px;
    --space-xl:     32px;
    --space-2xl:    48px;
    --space-3xl:    64px;
  }

  /* ── Page Intro ── */
  .page-intro {
    padding: var(--space-3xl) var(--space-md);
  }

  .page-intro h1 {
    font-size: clamp(48px, 8vw, 72px);
  }

  /* ── Stats Grid (Larger) ── */
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-lg);
  }

  .stat-card {
    padding: var(--space-lg);
  }

  .stat-value {
    font-size: 56px;
  }

  /* ── Detail Grid (Wider columns) ── */
  .detail-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  /* ── Name Cell (More space) ── */
  .name-cell {
    max-width: 250px;
  }

  /* ── Typography ── */
  .detail-val {
    font-size: 16px;
  }
}

/* ════════════════════════════════════════════════════════════════════════════
   LARGE DESKTOP BREAKPOINT (1440px+)
   ════════════════════════════════════════════════════════════════════════════ */
@media (min-width: 1440px) {
  :root {
    --space-2xl:    64px;
    --space-3xl:    96px;
  }

  /* ── Stats Grid (Larger minmax) ── */
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-lg);
  }

  /* ── Detail Grid (Wider) ── */
  .detail-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }

  /* ── Name Cell (Full width) ── */
  .name-cell {
    max-width: 300px;
  }
}

/* ── Print Styles ── */
@media print {
  .header,
  .footer,
  .toolbar,
  .hamburger {
    display: none;
  }

  .content {
    padding: 0;
  }

  .data-table {
    page-break-inside: avoid;
  }
}
