:root {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-input: #ffffff;
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

body.theme-dark {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-elevated: #334155;
  --bg-input: #1e293b;
  --border-subtle: #334155;
  --border-strong: #475569;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --primary: #38bdf8;
  --primary-hover: #7dd3fc;
  --primary-light: rgba(56, 189, 248, 0.15);
}

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

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

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Header */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.75rem 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  background: var(--bg-surface-elevated);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font-sans);
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Layout */
.app-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.25rem;
  margin-top: 1.25rem;
  margin-bottom: 2rem;
  align-items: start;
}

@media (max-width: 860px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
}

/* Panels */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.panel-header {
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

/* Forms */
.medical-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background-color: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}

.input-with-suffix {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-suffix .suffix {
  position: absolute;
  right: 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

.input-with-suffix input {
  padding-right: 3rem;
}

/* Segmented Control */
.segmented-control {
  display: flex;
  background: var(--bg-surface-elevated);
  padding: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.segmented-control input[type="radio"] {
  display: none;
}

.segmented-control label {
  flex: 1;
  text-align: center;
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.segmented-control input[type="radio"]:checked + label {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-block {
  width: 100%;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* Results Table */
.results-table-wrapper {
  margin-top: 0.85rem;
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.85rem;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.results-table td {
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--border-subtle);
}

.results-table .val-cell {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
}

.highlight-row {
  background: var(--primary-light);
}

.highlight-row td {
  border-bottom: none;
  color: var(--text-primary);
}

.highlight-row .val-cell {
  color: var(--primary);
  font-size: 0.95rem;
}

/* Nomogram Canvas */
.nomogram-container {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 480px;
  background: var(--bg-surface);
  overflow: hidden;
}

#nomogram-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.nomogram-tooltip {
  position: absolute;
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  pointer-events: none;
  z-index: 10;
  transform: translate(-50%, -120%);
}

.nomogram-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.dot-patient {
  background: #dc2626;
  box-shadow: 0 0 0 2px #dc2626;
}

.legend-line {
  width: 14px;
  height: 2.5px;
  border-radius: 2px;
}

.line-regression {
  background: #2563eb;
}

.line-limits {
  background: #94a3b8;
}

.legend-band {
  width: 12px;
  height: 9px;
  background: rgba(34, 197, 94, 0.25);
  border: 1px solid #16a34a;
  border-radius: 2px;
}

/* ==========================================================================
   Tab 2: Explanation & Bibliography Styles
   ========================================================================== */
.explanation-container {
  margin-top: 1.25rem;
  margin-bottom: 2rem;
}

.explanation-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

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

.info-card {
  background: var(--bg-surface-elevated);
  padding: 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.info-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.info-card p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.formula-box {
  background: var(--bg-surface);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-size: 0.78rem;
}

.formula-box code {
  display: block;
  font-family: var(--font-mono);
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  margin: 0.2rem 0 0.4rem 0;
  font-size: 0.75rem;
}

.formula-note {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.clean-list {
  list-style: none;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.clean-list li {
  padding-left: 0.5rem;
  border-left: 2px solid var(--border-strong);
  color: var(--text-secondary);
}

.table-section {
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
}

.table-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.table-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.table-scroll {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  text-align: right;
}

.data-table th, .data-table td {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border-subtle);
}

.data-table th {
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table td:first-child, .data-table th:first-child {
  text-align: left;
}

.bibliography-section {
  border-top: 1px solid var(--border-subtle);
  padding-top: 1.25rem;
}

.bibliography-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.biblio-list {
  padding-left: 1.25rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.biblio-list a {
  color: var(--primary);
  text-decoration: none;
}

.biblio-list a:hover {
  text-decoration: underline;
}

.is-hidden {
  display: none !important;
}
