/* === CIED MR Cross-Reference — Styles === */

:root {
  --text-xs:   clamp(0.75rem, 0.7rem + 0.25vw, 0.8rem);
  --text-sm:   clamp(0.8rem, 0.78rem + 0.15vw, 0.875rem);
  --text-base: clamp(0.875rem, 0.85rem + 0.15vw, 0.9375rem);
  --text-lg:   clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-xl:   clamp(1.25rem, 1.1rem + 0.5vw, 1.5rem);

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* Medical/clinical palette */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --border: #e2e5ea;
  --border-strong: #c9cdd4;
  --text: #1a1d23;
  --text-muted: #5f6672;
  --text-faint: #9ca3af;

  --accent: #1e5c8a;
  --accent-light: #edf4fa;
  --accent-hover: #174a70;

  --green: #0d7a3f;
  --green-bg: #e8f5ee;
  --green-border: #b8e0c8;

  --red: #b91c1c;
  --red-bg: #fef2f2;
  --red-border: #f5c6c6;

  --orange: #b45309;
  --orange-bg: #fffbeb;
  --orange-border: #fde68a;

  --yellow: #a16207;
  --yellow-bg: #fefce8;

  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
  --transition: 150ms ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

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

/* === HEADER === */
.site-header {
  background: linear-gradient(135deg, #0f2942 0%, #1e5c8a 100%);
  color: #fff;
  padding: var(--space-5) var(--space-6);
  border-bottom: 3px solid #0d4a6e;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}

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

.logo-icon { color: #6bbfed; flex-shrink: 0; }

.site-title {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.site-subtitle {
  font-size: var(--text-sm);
  opacity: 0.75;
  font-weight: 400;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-sm);
}

.header-stats strong {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.stat-sep {
  width: 1px;
  height: 16px;
  background: rgba(255,255,255,0.3);
}

/* === TAB NAV === */
.tab-nav {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-6);
  max-width: 1440px;
  margin: 0 auto;
  gap: var(--space-1);
  overflow-x: auto;
}

.tab {
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
}

.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* === TAB CONTENT === */
.tab-content {
  display: none;
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-6);
}

.tab-content.active { display: block; }

/* === PANEL === */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  box-shadow: var(--shadow-sm);
}

.panel-title {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-1);
  color: var(--text);
}

.panel-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-5);
  max-width: 72ch;
}

/* === FILTERS === */
.filter-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.filter-select,
.search-input {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition);
  min-width: 160px;
}

.filter-select:focus,
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-input { flex: 1; min-width: 200px; }

/* === SELECTOR GRID (Cross-Reference) === */
.selector-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  margin-bottom: var(--space-5);
}

@media (max-width: 900px) {
  .selector-grid { grid-template-columns: 1fr; }
}

.selector-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.device-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.device-item {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--transition);
}

.device-item:last-child { border-bottom: none; }
.device-item:hover { background: var(--accent-light); }
.device-item.selected { background: var(--accent-light); font-weight: 600; }

.device-item .mfr-tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--border);
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 28px;
  text-align: center;
}

.device-item .device-name { flex: 1; }

.device-item .device-num {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.device-item .mr-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mr-dot.green { background: var(--green); }
.mr-dot.red { background: var(--red); }

/* === RESULT PANEL === */
.result-panel {
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-top: var(--space-4);
  background: var(--surface-alt);
}

.result-panel.hidden { display: none; }

.result-panel.status-ok {
  border-color: var(--green-border);
  background: var(--green-bg);
}

.result-panel.status-warn {
  border-color: var(--orange-border);
  background: var(--orange-bg);
}

.result-panel.status-danger {
  border-color: var(--red-border);
  background: var(--red-bg);
}

.result-title {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-3);
}

.result-badge {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.badge-ok { background: var(--green); color: #fff; }
.badge-warn { background: var(--orange); color: #fff; }
.badge-danger { background: var(--red); color: #fff; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
}

.result-card-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.result-card-value {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text);
}

.result-card-value.mono {
  font-family: var(--font-mono);
}

.off-label-warning {
  background: var(--orange-bg);
  border: 1px solid var(--orange-border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
}

.off-label-warning strong { color: var(--orange); }

.lead-result-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  background: var(--surface);
}

.lead-result-item.off-label { border-left: 4px solid var(--orange); }
.lead-result-item.not-mr { border-left: 4px solid var(--red); }
.lead-result-item.ok { border-left: 4px solid var(--green); }

/* === TABLES === */
.table-info {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
  padding: var(--space-1) 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead {
  background: #1e3a52;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
}

th {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  user-select: none;
}

th.sortable { cursor: pointer; }
th.sortable:hover { background: rgba(255,255,255,0.1); }
th.sorted-asc::after { content: ' ▲'; font-size: 0.65em; }
th.sorted-desc::after { content: ' ▼'; font-size: 0.65em; }

td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:nth-child(even) { background: var(--surface-alt); }
tbody tr:hover { background: var(--accent-light); }

.mr-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.mr-pill.conditional { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.mr-pill.legacy { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }

td.conditions-cell {
  max-width: 300px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.4;
}

/* === MRI SETTINGS === */
.mfr-settings-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-5);
  overflow: hidden;
}

.mfr-settings-header {
  padding: var(--space-4) var(--space-5);
  font-weight: 700;
  font-size: var(--text-lg);
  border-bottom: 1px solid var(--border);
}

.mfr-settings-header.medtronic { background: #003b6f; color: #fff; }
.mfr-settings-header.abbott { background: #7b1fa2; color: #fff; }
.mfr-settings-header.boston { background: #0d47a1; color: #fff; }
.mfr-settings-header.biotronik { background: #00695c; color: #fff; }
.mfr-settings-header.livanova { background: #c62828; color: #fff; }

.mfr-settings-body {
  padding: var(--space-4) var(--space-5);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-4);
}

.setting-group h4 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.setting-group ul {
  list-style: none;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.setting-group li {
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--border);
}

.setting-group li:last-child { border-bottom: none; }

.setting-group li strong {
  color: var(--text);
}

/* === DISCLAIMER === */
.disclaimer-bar {
  margin-top: var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: var(--yellow-bg);
  border: 1px solid var(--orange-border);
  border-radius: var(--radius);
  font-size: var(--text-xs);
  color: var(--yellow);
  line-height: 1.5;
}

/* === FOOTER === */
.site-footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-6);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-faint);
  border-top: 1px solid var(--border);
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: underline;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .header-stats { flex-wrap: wrap; gap: var(--space-2); }
  .tab-nav { padding: 0 var(--space-3); }
  .tab-content { padding: var(--space-3); }
  .panel { padding: var(--space-3) var(--space-4); }
  .filter-row { flex-direction: column; }
  .filter-select, .search-input { min-width: 100%; }
}

/* Scrollbar styling */
.device-list::-webkit-scrollbar { width: 6px; }
.device-list::-webkit-scrollbar-track { background: transparent; }
.device-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.table-wrap::-webkit-scrollbar { height: 6px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.empty-state {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-sm);
}
