/* ═══════════════════════════════════════════════════════════════════════════
   GEARS Design System — Develop Medical Capability
   External stylesheet for the three-tab medical platform SPA.
   Requirements: 12.1, 12.2, 12.4
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ── */
:root {
  /* Backgrounds */
  --bg-dark:            #0A0A09;
  --bg-light:           #F2F2F2;
  --bg-accent:          #FFDD00;

  /* Surfaces */
  --surface-white:      #FFFFFF;
  --surface-dark:       #202020;
  --surface-header:     #0A0A09;
  --surface-header-scrolled: rgba(32,32,32,0.92);

  /* Text */
  --text-on-dark:       #FFFFFF;
  --text-on-dark-muted: #D6D6D6;
  --text-on-dark-dim:   rgba(255,255,255,0.38);
  --text-on-light:      #202020;
  --text-on-light-muted:#5C5C5C;

  /* Borders */
  --border-on-dark:     #5C5C5C;
  --border-on-light:    #D6D6D6;
  --border-strong:      #333533;

  /* Semantic colors */
  --accent:             #FFDD00;
  --ink:                #0A0A09;
  --ink-soft:           #2C2C2A;
  --ink-muted:          #6B6A64;
  --chalk:              #F2F2F2;
  --chalk-warm:         #EDE9E0;
  --chalk-mid:          #D4CFC2;

  /* Typography */
  --type-display: 'League Gothic', Impact, 'Arial Narrow', sans-serif;
  --type-body:    'Figtree', 'Helvetica Neue', Arial, sans-serif;
  --type-serif:   'Instrument Serif', Georgia, serif;

  /* Spacing scale */
  --sp-1:4px; --sp-2:8px; --sp-3:12px; --sp-4:16px;
  --sp-5:20px; --sp-6:24px; --sp-8:32px; --sp-10:40px;
  --sp-12:48px; --sp-16:64px; --sp-20:80px;

  /* Layout */
  --container-max:   100%;
  --header-h-desktop:84px;
  --header-h-mobile: 64px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--type-body);
  background: var(--bg-light);
  color: var(--text-on-light);
  line-height: 1.65;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
main { padding-top: calc(var(--header-h-desktop) + 52px); }
@media (max-width: 767px) { main { padding-top: calc(var(--header-h-mobile) + 44px); } }

/* ── HEADER ── */
.gear-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--header-h-desktop);
  background: var(--surface-header);
  transition: background 0.3s var(--ease-out), backdrop-filter 0.3s var(--ease-out);
}
.gear-header.is-scrolled {
  background: var(--surface-header-scrolled);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.gear-header__inner {
  margin: 0 auto;
  height: 100%;
  padding: 0 var(--sp-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-6);
}
.gear-header__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-decoration: none;
}
.gear-header__gears-logo {
  height: 28px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
.gear-header__divider {
  display: block;
  width: 1px;
  height: 20px;
  background: var(--border-on-dark);
  flex-shrink: 0;
}
.gear-header__app-name {
  font-family: var(--type-display);
  font-size: 1.1rem;
  letter-spacing: 0.03em;
  color: var(--text-on-dark-muted);
  text-transform: uppercase;
  line-height: 1;
}
@media (max-width: 767px) {
  .gear-header { height: var(--header-h-mobile); }
  .gear-header__inner { padding: 0 var(--sp-6); }
  .gear-header__gears-logo { height: 22px; }
  .gear-header__app-name { font-size: 0.9rem; }
}

/* ── TAB NAVIGATION ── */
.tab-nav {
  position: fixed;
  top: var(--header-h-desktop);
  left: 0;
  right: 0;
  z-index: 190;
  background: var(--surface-header);
  border-bottom: 2px solid var(--border-strong);
  padding: 0 var(--sp-8);
}
.tab-nav__inner {
  display: flex;
  gap: 0;
  margin: 0 auto;
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--type-body);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-on-dark-dim);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: var(--sp-4) var(--sp-6);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tab-btn:hover {
  color: var(--text-on-dark-muted);
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
@media (max-width: 767px) {
  .tab-nav {
    top: var(--header-h-mobile);
    padding: 0 var(--sp-3);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tab-nav__inner {
    width: 100%;
  }
  .tab-btn {
    font-size: 0.72rem;
    padding: var(--sp-3) var(--sp-4);
  }
}

/* ── BUTTONS ── */
.gear-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--type-body);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  padding: var(--sp-2) var(--sp-6);
  border: 2px solid transparent;
  border-radius: 0;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
  height: 40px;
}
.gear-btn:active { transform: translateY(1px); }
.gear-btn:focus-visible { outline: 2px solid var(--bg-accent); outline-offset: 3px; }
.gear-btn--primary {
  background: var(--bg-accent);
  color: var(--text-on-light);
  border-color: var(--border-strong);
}
.gear-btn--primary:hover { opacity: 0.88; }
.gear-btn--ghost {
  background: transparent;
  color: var(--text-on-dark-muted);
  border-color: var(--border-on-dark);
}
.gear-btn--ghost:hover { color: var(--text-on-dark); border-color: var(--border-on-light); }
.gear-btn--light {
  background: var(--surface-white);
  color: var(--text-on-light);
  border-color: var(--border-strong);
}
.gear-btn--light:hover { opacity: 0.85; }

/* ── LAYOUT ── */
.container {
  margin: 0 auto;
  padding: 0 var(--sp-8);
}
@media (max-width: 767px) { .container { padding: 0 var(--sp-6); } }

.shell {
  margin: 0 auto;
  padding: var(--sp-8);
}
@media (max-width: 767px) { .shell { padding: var(--sp-6); } }

/* Tab view containers */
.tab-view {
  display: none;
}
.tab-view.active {
  display: block;
}

/* ── EYEBROW ── */
.gear-eyebrow {
  font-family: var(--type-body);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-on-light-muted);
  margin-bottom: var(--sp-3);
}
.gear-eyebrow--accent { color: var(--bg-accent); }

/* ── SEARCH PANEL ── */
.search-panel {
  background: var(--surface-white);
  border: 1px solid var(--border-on-light);
  padding: var(--sp-5) var(--sp-6);
  margin-bottom: var(--sp-6);
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  align-items: flex-end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  flex: 1;
  min-width: 160px;
}
.field label {
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
}
.field input,
.field select {
  height: 40px;
  border: 1.5px solid var(--border-on-light);
  border-radius: 0;
  padding: 0 var(--sp-3);
  font-size: 0.9rem;
  font-family: var(--type-body);
  color: var(--text-on-light);
  background: var(--surface-white);
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus,
.field select:focus {
  border-color: var(--ink);
}
.field input::placeholder {
  color: var(--ink-muted);
  opacity: 0.7;
}
@media (max-width: 767px) {
  .search-panel {
    flex-direction: column;
    align-items: stretch;
  }
  .field {
    min-width: 100%;
  }
}

/* ── RESULTS META ── */
.earnings-banner {
  display: none;
  background: var(--bg-dark);
  color: var(--text-on-dark);
  padding: var(--sp-6) var(--sp-8);
  margin-bottom: var(--sp-6);
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-4);
  border-left: 4px solid var(--bg-accent);
}
.earnings-label {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-on-dark-muted);
  margin-bottom: var(--sp-2);
}
.earnings-value {
  font-family: var(--type-display);
  font-size: clamp(2.5rem, 5vw, 3.5rem);
  line-height: 1;
  color: var(--bg-accent);
  font-variant-numeric: tabular-nums;
}
.earnings-main {
  flex: 1;
}
.earnings-breakdown {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-width: 240px;
}
.source-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: 0.82rem;
  color: var(--text-on-dark-muted);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.source-row:last-child { border-bottom: none; }
.source-detail {
  line-height: 1.4;
}
.source-detail strong {
  color: var(--text-on-dark);
}
.source-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  min-width: 40px;
  text-align: center;
}
.source-tms {
  background: var(--bg-accent);
  color: var(--text-on-light);
}
.source-rce {
  background: #4ECDC4;
  color: var(--text-on-light);
}
.source-gmg {
  background: var(--border-on-dark);
  color: var(--text-on-dark);
}

.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.results-count {
  font-size: 0.78rem;
  color: var(--ink-muted);
}
.results-count strong { color: var(--text-on-light); }

/* ── DATA TABLE ── */
.table-wrap {
  background: var(--surface-white);
  border: 1px solid var(--border-on-light);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
thead {
  background: var(--bg-dark);
  color: var(--text-on-dark);
}
thead th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.sortable-th {
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.sortable-th:hover {
  background: var(--surface-dark);
}
.sortable-th.sorted {
  color: var(--accent);
}
.sort-indicator {
  font-size: 0.6rem;
  margin-left: 4px;
  opacity: 0.5;
}
.sorted .sort-indicator {
  opacity: 1;
  color: var(--accent);
}
tbody tr {
  border-bottom: 1px solid var(--border-on-light);
  cursor: pointer;
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(even) { background: #FAFAF8; }
tbody tr:hover { background: #F7F6F2; }
tbody td {
  padding: var(--sp-3) var(--sp-4);
  vertical-align: top;
  word-break: break-word;
}
.cell-name {
  font-weight: 600;
  color: var(--ink);
}
.cell-name:hover { text-decoration: underline; }
.mg-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  line-height: 1.6;
}
.tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--ink);
  color: var(--text-on-dark);
  letter-spacing: 0.03em;
}
.cases-num { font-weight: 600; font-variant-numeric: tabular-nums; }
.earnings-num { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.muted { color: var(--ink-muted); font-style: italic; }

/* Responsive table: hide less important columns on mobile */
@media (max-width: 767px) {
  .table-wrap { overflow-x: auto; }
  table { min-width: 600px; }
}

/* ── PAGINATION ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-5);
  background: var(--surface-white);
  border-top: 1px solid var(--border-on-light);
}
.page-btn {
  height: 32px;
  min-width: 32px;
  padding: 0 10px;
  border: 1.5px solid var(--border-on-light);
  border-radius: 0;
  background: var(--surface-white);
  color: var(--text-on-light);
  font-size: 0.82rem;
  font-family: var(--type-body);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s;
}
.page-btn:hover { background: var(--chalk); }
.page-btn.active {
  background: var(--bg-dark);
  color: var(--text-on-dark);
  border-color: var(--bg-dark);
}
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.page-btn:focus-visible { outline: 2px solid var(--bg-accent); outline-offset: 3px; }
.page-ellipsis {
  color: var(--ink-muted);
  padding: 0 4px;
  font-size: 0.82rem;
}

/* ── MODAL ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,10,9,0.7);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
.overlay.open { display: flex; }
.modal {
  background: var(--surface-white);
  width: 720px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-strong);
}
.modal-header {
  background: var(--bg-dark);
  color: var(--text-on-dark);
  padding: var(--sp-5) var(--sp-6);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  border-bottom: 2px solid var(--bg-accent);
}
.modal-header h2 {
  font-family: var(--type-display);
  font-size: 1.6rem;
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-on-dark-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: var(--sp-2);
  flex-shrink: 0;
  transition: color 0.1s;
}
.modal-close:hover { color: var(--text-on-dark); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-body {
  padding: var(--sp-6);
  overflow-y: auto;
  flex: 1;
}
@media (max-width: 767px) {
  .modal {
    width: 100%;
    max-width: 100vw;
    max-height: 100vh;
    border: none;
  }
  .modal-body { padding: var(--sp-4); }
}

/* Modal detail grid */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-5);
  margin-bottom: var(--sp-6);
  padding-bottom: var(--sp-6);
  border-bottom: 1px solid var(--border-on-light);
}
.detail-item { display: flex; flex-direction: column; gap: var(--sp-1); }
.detail-item dt {
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
}
.detail-item dd {
  font-size: 0.95rem;
  color: var(--text-on-light);
  font-weight: 500;
}
.detail-item dd.big {
  font-family: var(--type-display);
  font-size: 2rem;
  font-weight: 400;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 767px) {
  .detail-grid { grid-template-columns: 1fr 1fr; }
}

/* Modal sections */
.section-title {
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
  margin-bottom: var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border-on-light);
}
.mg-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.mg-card {
  background: var(--bg-light);
  border-left: 3px solid var(--bg-accent);
  padding: var(--sp-3) var(--sp-4);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}
.no-mgs { color: var(--ink-muted); font-style: italic; font-size: 0.88rem; }

/* Solutions list in modals */
.solutions-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-6);
}
.solution-card {
  background: var(--bg-light);
  border-left: 3px solid var(--accent);
  padding: var(--sp-3) var(--sp-4);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}
.solution-card__name { font-weight: 600; color: var(--ink); }
.solution-card__meta { font-size: 0.75rem; color: var(--ink-muted); }

/* ── CHART CONTAINERS ── */
.chart-container {
  background: var(--surface-dark);
  border: 1px solid var(--border-strong);
  padding: var(--sp-5);
  margin-top: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.chart-container canvas {
  width: 100% !important;
  height: 200px !important;
}
.chart-title {
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-on-dark-muted);
  margin-bottom: var(--sp-3);
}
.chart-placeholder {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-on-dark-dim);
  font-size: 0.88rem;
  font-style: italic;
}
@media (max-width: 767px) {
  .chart-container { padding: var(--sp-3); }
  .chart-container canvas { height: 160px !important; }
}

/* ── ERROR & EMPTY STATES ── */
.state-box {
  text-align: center;
  padding: 64px 24px;
  color: var(--ink-muted);
}
.state-box .icon { font-size: 36px; margin-bottom: var(--sp-3); }
.state-box p { font-size: 0.9rem; }
.error-msg {
  color: #8B1A1A;
  background: #FDF0EE;
  border-left: 3px solid #C0392B;
  padding: var(--sp-3) var(--sp-4);
  font-size: 0.82rem;
  margin-bottom: var(--sp-4);
}
.error-msg .retry-btn {
  display: inline-block;
  margin-top: var(--sp-2);
  font-size: 0.78rem;
  font-weight: 600;
  color: #C0392B;
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--type-body);
}
.empty-state {
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
  color: var(--ink-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: var(--sp-4); }
.empty-state p { font-size: 0.9rem; max-width: 320px; margin: 0 auto; }

/* ── SPINNER ── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border-on-light);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; opacity: 0.6; }
}

/* ── RESPONSIVE BREAKPOINTS ── */

/* Desktop: side-by-side layout for detail grid and charts */
@media (min-width: 768px) {
  .detail-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-6);
  }
  .detail-layout--full {
    grid-template-columns: 1fr;
  }
}

/* Mobile: stacked layout */
@media (max-width: 767px) {
  .detail-layout {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
  }
  .tab-nav {
    padding: 0;
  }
  .tab-nav__inner {
    width: 100%;
  }
  .tab-btn {
    flex: 1;
    justify-content: center;
    text-align: center;
  }
}

/* ── UTILITY CLASSES ── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
.text-center { text-align: center; }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }
