/* === CSS VARIABLES === */
:root {
  --primary: #6366F1;
  --primary-dark: #4F46E5;
  --primary-light: #818CF8;
  --primary-glow: rgba(99, 102, 241, 0.15);
  --accent: #10B981;
  --accent-light: #34D399;
  --danger: #EF4444;
  --danger-light: #FCA5A5;
  --warning: #F59E0B;
  --warning-light: #FCD34D;

  --bg: #0F172A;
  --bg-raised: #1E293B;
  --bg-card: #1E293B;
  --bg-input: #0F172A;
  --border: rgba(148, 163, 184, 0.12);
  --border-focus: var(--primary);
  --text: #F1F5F9;
  --text-secondary: #B0BEC5;
  --text-muted: #8896A6;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 4px 16px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.35);
  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.12);

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === LIGHT THEME === */
html.light {
  --bg: #F5F7FA;
  --bg-raised: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-input: #F0F2F5;
  --border: rgba(0, 0, 0, 0.08);
  --text: #1A202C;
  --text-secondary: #4A5568;
  --text-muted: #A0AEC0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.08);
  --danger: #DC2626;
  --danger-light: #DC2626;
  --warning-light: #D97706;
}
html.light .header {
  background: linear-gradient(135deg, #e8eaf6 0%, #ede7f6 40%, #e3f2fd 100%);
}
html.light .header::before {
  background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary-light));
}
html.light .json-block {
  background: #F0F2F5;
  color: #4F46E5;
  border-color: rgba(0,0,0,0.06);
}
html.light .rules-table th {
  background: #F0F2F5;
}
html.light .rules-table tbody tr:nth-child(even) {
  background: #FAFBFC;
}
html.light .xray-table .xrow-label,
html.light .xray-table .xtype-cell {
  background: #F0F2F5;
}
html.light .xray-table .xreq-cell.is-yes {
  background: rgba(16, 185, 129, 0.06);
}
html.light .conf-hint .conf-tooltip {
  background: #FFFFFF;
  border-color: rgba(0,0,0,0.1);
}
html.light .matrix-table .row-label,
html.light .matrix-table .type-cell {
  background: #F0F2F5;
}
html.light .matrix-table .req-cell.is-yes {
  background: rgba(16, 185, 129, 0.06);
}
html.light .form-group input[type="date"]::-webkit-calendar-picker-indicator {
  filter: none;
}
html.light .result-info .code-title {
  background: linear-gradient(135deg, var(--primary-dark), #059669);
  -webkit-background-clip: text;
  background-clip: text;
}
html.light .tab-bar { background: #FFFFFF; }
html.light .setup-panel { background: #FFFFFF; }
html.light .summary-card { background: #FFFFFF; }
html.light .xray-loc-group-header {
  background: #F0F2F5;
}
html.light .xray-loc-placeholder {
  border-color: rgba(0, 0, 0, 0.1);
  background: #F5F7FA;
}

/* === RESET === */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === HEADER === */
.header {
  position: relative;
  padding: 32px 40px 28px;
  background: linear-gradient(135deg, #151e35 0%, #1a2744 40%, #162037 100%);
  border-bottom: 1px solid var(--border);
  overflow: visible;
}
.header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary-light));
  z-index: 1;
}
.header-inner {
  max-width: 880px;
  margin: 0 auto;
  text-align: center;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 6px;
}
.header-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
  flex-shrink: 0;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  border: none;
  color: white;
  font-family: inherit;
}
.header-icon:hover {
  transform: scale(1.08) rotate(15deg);
  box-shadow: 0 0 28px rgba(99, 102, 241, 0.45);
}
.header-icon:active {
  transform: scale(0.97);
}
.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}
.header p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.header-subtitle-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.demo-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.15);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  color: var(--primary-light);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.demo-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-1px);
}
.demo-btn:active {
  transform: translateY(0);
}
.demo-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.demo-btn-icon {
  font-size: 13px;
}
.demo-btn.demo-loaded {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.25);
  color: var(--accent-light);
}
.header .stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.header .stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.15);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--primary-light);
  transition: var(--transition);
}
.header .stat:hover {
  background: rgba(99, 102, 241, 0.14);
}
.header .source {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* === SETUP PANEL (full-width, replaces settings popover) === */
.setup-panel {
  display: none;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 24px;
}
.setup-panel.visible { display: block; }
.setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  max-width: 1080px;
  margin: 0 auto;
}
.settings-saved {
  font-size: 11px;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.settings-saved.show { opacity: 1; }

/* === TAB NAVIGATION === */
.tab-bar {
  display: flex;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.tab-bar .tab {
  padding: 12px 24px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Inter', system-ui, sans-serif;
}
.tab-bar .tab:hover:not(.disabled) {
  color: var(--text-secondary);
}
.tab-bar .tab.active {
  color: var(--primary-light);
  border-bottom-color: var(--primary);
}
.tab-bar .tab.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.tab-badge {
  display: inline-flex;
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 6px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* === THEME TOGGLE === */
.theme-toggle {
  position: absolute;
  top: 20px;
  right: 24px;
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 20px;
  width: 44px;
  height: 24px;
  cursor: pointer;
  padding: 0;
  transition: var(--transition);
  display: flex;
  align-items: center;
}
.theme-toggle:hover {
  background: rgba(148, 163, 184, 0.18);
  border-color: rgba(148, 163, 184, 0.25);
}
.theme-toggle .toggle-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-secondary);
  margin-left: 3px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
}
html.light .theme-toggle .toggle-thumb {
  margin-left: 23px;
  background: var(--primary);
}

/* === LAYOUT === */
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

/* === CARDS === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}
.card h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2::before {
  content: '';
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background: var(--primary);
}

/* === FORMS === */
.form-row {
  display: flex;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.form-group {
  flex: 1;
  min-width: 160px;
}
.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}
.form-group input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-input);
  color: var(--text);
  transition: var(--transition);
}
.form-group input::placeholder {
  color: var(--text-muted);
}
.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow), var(--shadow-sm);
}
.form-group input:hover:not(:focus) {
  border-color: rgba(148, 163, 184, 0.25);
}
.form-group select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-input);
  color: var(--text);
  transition: var(--transition);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow), var(--shadow-sm);
}
.form-group select:hover:not(:focus) {
  border-color: rgba(148, 163, 184, 0.25);
}
.form-group select option {
  background: var(--bg-card);
  color: var(--text);
}
.form-group input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.6);
}

.payer-hint {
  font-size: 12px;
  color: var(--accent);
  margin-top: 5px;
  min-height: 18px;
  font-weight: 500;
  transition: var(--transition);
}
.payer-hint.error { color: var(--danger); }

/* === BUTTONS === */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  width: 100%;
  margin-top: 10px;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.45);
  transform: translateY(-1px);
}
.btn-primary:active {
  transform: translateY(0);
}
.btn-primary:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-reset {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  width: 100%;
  margin-top: 12px;
}
.btn-reset:hover {
  background: rgba(148, 163, 184, 0.06);
  border-color: rgba(148, 163, 184, 0.25);
  color: var(--text);
}

/* === RESULTS === */
.results-section { display: none; }
.results-section.visible {
  display: block;
  animation: slideUp 0.35s var(--transition-slow) forwards;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === TWO-COLUMN RESULTS LAYOUT === */
.results-columns {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
  align-items: start;
}
.results-col-left {
  position: sticky;
  top: 20px;
}
.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}
.summary-field {
  margin-bottom: 14px;
}
.summary-field:last-child {
  margin-bottom: 0;
}
.summary-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}
.summary-value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
.summary-code {
  font-size: 28px;
  font-weight: 800;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}
.summary-class-badge {
  display: inline-block;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary-light);
  font-weight: 600;
  margin-top: 4px;
  border: 1px solid rgba(99, 102, 241, 0.15);
}

.result-info {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
}
.result-info .result-left { flex: 1; min-width: 200px; }
.result-info .result-right { text-align: right; flex-shrink: 0; }
.result-info .code-title {
  font-size: 28px;
  font-weight: 800;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}
.result-info .code-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.5;
}
.result-info .code-class {
  display: inline-block;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary-light);
  font-weight: 600;
  margin-top: 8px;
  border: 1px solid rgba(99, 102, 241, 0.15);
}
.result-info .payer-id {
  font-size: 22px;
  font-weight: 800;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  color: var(--text);
}
.result-info .payer-name {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.result-info .no-rule {
  font-size: 13px;
  color: var(--warning);
  margin-top: 8px;
  padding: 8px 14px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.15);
  border-radius: var(--radius-sm);
}

/* === MATRIX TABLE (horizontal) === */
.matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 16px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.matrix-table th, .matrix-table td {
  padding: 12px 14px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.matrix-table th:last-child, .matrix-table td:last-child {
  border-right: none;
}
.matrix-table tr:last-child th, .matrix-table tr:last-child td {
  border-bottom: none;
}
.matrix-table .row-label {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.5);
  width: 100px;
  white-space: nowrap;
}
.matrix-table .type-cell {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: rgba(15, 23, 42, 0.3);
}
.matrix-table .req-cell {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.matrix-table .req-cell.is-yes {
  color: var(--accent);
  text-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.04);
}
.matrix-table .req-cell.is-no {
  color: var(--text-muted);
}
.matrix-table .extra-cell {
  font-size: 11px;
  color: var(--text-muted);
  min-height: 14px;
}
.yes {
  color: var(--accent);
  text-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
}
.no { color: var(--text-muted); }

.delivery-info {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.delivery-info strong { color: var(--text); }
.delivery-info::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* === JSON BLOCK === */
.json-block {
  margin-top: 12px;
  background: #0B1120;
  color: #A5B4FC;
  padding: 20px;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 400px;
  line-height: 1.6;
  border: 1px solid rgba(99, 102, 241, 0.1);
}

.error-msg {
  background: rgba(239, 68, 68, 0.08);
  color: var(--danger-light);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid rgba(239, 68, 68, 0.15);
}

/* === X-RAY BREAKDOWN === */
.xray-section { margin-top: 24px; }
.xray-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.xray-section h3::before {
  content: '';
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
}

.xray-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 0;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.xray-spinner .dot-pulse { display: inline-flex; gap: 5px; }
.xray-spinner .dot-pulse span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-light);
  animation: dotPulse 1.4s infinite ease-in-out both;
}
.xray-spinner .dot-pulse span:nth-child(1) { animation-delay: -0.32s; }
.xray-spinner .dot-pulse span:nth-child(2) { animation-delay: -0.16s; }
@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0.4); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}
.classify-progress {
  width: 100%;
  max-width: 400px;
  height: 6px;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 3px;
  overflow: hidden;
}
.classify-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 3px;
  transition: width 0.3s ease;
}
.classify-progress-text {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 8px;
}

.xray-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 10px;
  border-radius: var(--radius);
  overflow-x: auto;
  border: 1px solid var(--border);
  display: block;
}
.xray-table table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 600px;
}
.xray-table th, .xray-table td {
  padding: 10px 12px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  font-size: 12px;
}
.xray-table th:last-child, .xray-table td:last-child { border-right: none; }
.xray-table tr:last-child th, .xray-table tr:last-child td { border-bottom: none; }
.xray-table .xrow-label {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.5);
  width: 90px;
  white-space: nowrap;
}
.xray-table .xtype-cell {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(15, 23, 42, 0.3);
}
.xray-table .xreq-cell {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.xray-table .xreq-cell.is-yes {
  color: var(--accent);
  text-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.04);
}
.xray-table .xreq-cell.is-no { color: var(--text-muted); }
.xray-table .xsrc-cell { font-size: 11px; color: var(--text-muted); }
.xray-table .xnote-cell { font-size: 11px; color: var(--text-secondary); }
.xray-table .xextra-cell { font-size: 11px; color: var(--text-muted); font-style: italic; }

.conf-hint {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  cursor: help;
  position: relative;
}
.conf-hint .conf-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  z-index: 10;
  font-style: normal;
  text-align: left;
}
.conf-hint:hover .conf-tooltip { display: block; }

.src-hint {
  cursor: help;
  position: relative;
  border-bottom: 1px dotted var(--text-muted);
}
.src-hint .src-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  z-index: 100;
  box-shadow: var(--shadow);
  line-height: 1.6;
}
.src-hint:hover .src-tooltip { display: block; }
html.light .src-hint .src-tooltip {
  background: #FFFFFF;
  border-color: rgba(0,0,0,0.1);
}

.xray-footer {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
}
.xray-error {
  background: rgba(245, 158, 11, 0.08);
  color: var(--warning-light);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 12px;
  border: 1px solid rgba(245, 158, 11, 0.15);
}

/* === X-RAY LOCATION === */
.xray-loc-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.xray-loc-section h3::before {
  content: '';
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--warning);
}

/* Model #1 card — indigo tint */
#xrayCard {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.06) 0%, var(--bg-card) 60%);
  border-color: rgba(99, 102, 241, 0.12);
}
#xrayCard h2 { color: var(--primary-light); }

/* Model #2 card — amber/warm tint */
#xrayLocCard {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.07) 0%, var(--bg-card) 60%);
  border-color: rgba(245, 158, 11, 0.12);
}
#xrayLocCard h2 { color: var(--warning-light); }

html.light #xrayCard {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, var(--bg-card) 60%);
  border-color: rgba(99, 102, 241, 0.1);
}
html.light #xrayLocCard {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.05) 0%, var(--bg-card) 60%);
  border-color: rgba(245, 158, 11, 0.1);
}

.xray-loc-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.xray-loc-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.xray-loc-group-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.xray-loc-group-header .timing-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary-light);
  border: 1px solid rgba(99, 102, 241, 0.15);
  text-transform: none;
  letter-spacing: 0;
}
.xray-loc-items {
  display: flex;
  gap: 14px;
  padding: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
.xray-loc-item {
  flex: 0 0 140px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.xray-loc-placeholder {
  width: 140px;
  height: 140px;
  border: 2px dashed rgba(148, 163, 184, 0.2);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 11px;
  transition: var(--transition);
  position: relative;
}
.xray-loc-placeholder:hover {
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.04);
  cursor: pointer;
}
.xray-loc-placeholder .placeholder-icon {
  font-size: 28px;
  opacity: 0.4;
  transition: var(--transition);
}
.xray-loc-placeholder .placeholder-text {
  transition: var(--transition);
}
.xray-loc-placeholder .enlarge-btn {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: var(--transition);
  pointer-events: none;
}
.xray-loc-placeholder:hover .enlarge-btn { opacity: 1; }
.xray-loc-placeholder:hover .placeholder-icon { opacity: 0.15; }
.xray-loc-placeholder:hover .placeholder-text { opacity: 0; }
.enlarge-btn span {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.25);
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary-light);
  letter-spacing: 0.3px;
}
.xray-loc-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 8px;
}
.xray-loc-conf {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}
.xray-loc-conf .conf-val {
  font-weight: 700;
  color: var(--text-muted);
}
.xray-loc-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}
.xray-loc-date {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}
.xray-loc-pending {
  font-size: 11px;
  color: var(--text-muted);
  padding: 12px 16px;
  text-align: center;
  font-style: italic;
}

/* === RULES BROWSER === */
.rules-view { display: none; }
.rules-view.visible { display: block; animation: slideUp 0.3s ease forwards; }
.main-view.hidden { display: none; }

.rules-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.btn-back {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', system-ui, sans-serif;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.btn-back:hover { background: rgba(148,163,184,0.08); border-color: rgba(148,163,184,0.25); color: var(--text); }

.rules-search {
  flex: 1;
  min-width: 200px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-input);
  color: var(--text);
  transition: var(--transition);
}
.rules-search::placeholder { color: var(--text-muted); }
.rules-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

.rules-count {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.rules-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  font-size: 13px;
}
.rules-table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.5);
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.rules-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.rules-table tbody tr { transition: var(--transition); }
.rules-table tbody tr:hover { background: rgba(99, 102, 241, 0.04); }
.rules-table tbody tr:nth-child(even) { background: rgba(15, 23, 42, 0.25); }
.rules-table tbody tr:nth-child(even):hover { background: rgba(99, 102, 241, 0.06); }
.rules-table tr:last-child td { border-bottom: none; }
.rules-table .mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 600; }
.rules-table .pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-align: center;
  min-width: 32px;
}
.rules-table .pill.yes { background: rgba(16,185,129,0.12); color: var(--accent-light); }
.rules-table .pill.no { background: rgba(148,163,184,0.08); color: var(--text-muted); }

.rules-table-wrap {
  max-height: 520px;
  overflow-y: auto;
  border-radius: var(--radius);
}
.rules-table-wrap::-webkit-scrollbar { width: 6px; }
.rules-table-wrap::-webkit-scrollbar-track { background: transparent; }
.rules-table-wrap::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.2); border-radius: 3px; }

.rules-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}
.rules-pagination button {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', system-ui, sans-serif;
  transition: var(--transition);
}
.rules-pagination button:hover:not(:disabled) { background: rgba(148,163,184,0.08); border-color: rgba(148,163,184,0.25); color: var(--text); }
.rules-pagination button:disabled { opacity: 0.35; cursor: not-allowed; }
.rules-pagination .page-info { font-size: 12px; color: var(--text-muted); }

.stat-clickable { cursor: pointer; }
.stat-clickable:hover { background: rgba(99, 102, 241, 0.2) !important; border-color: rgba(99, 102, 241, 0.3) !important; }

/* === ATTACHMENT NEEDED BANNER === */
.attach-needed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  border: 1px solid;
}
.attach-needed-label {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.attach-needed-value {
  font-size: 22px;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 1px;
}
.attach-needed-yes {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
}
.attach-needed-yes .attach-needed-label { color: var(--text-secondary); }
.attach-needed-yes .attach-needed-value { color: var(--accent); text-shadow: 0 0 16px rgba(16, 185, 129, 0.3); }
.attach-needed-no {
  background: rgba(148, 163, 184, 0.06);
  border-color: var(--border);
}
.attach-needed-no .attach-needed-label { color: var(--text-secondary); }
.attach-needed-no .attach-needed-value { color: var(--text-muted); }

/* === APTERYX STATUS === */
.apteryx-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; padding: 5px 12px; border-radius: 20px;
  background: rgba(99, 102, 241, 0.08); border: 1px solid rgba(99, 102, 241, 0.15);
  margin-top: 10px; color: var(--text-secondary); transition: var(--transition);
}
.apteryx-status .dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.apteryx-status .dot.connected { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.apteryx-status .dot.disconnected { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.apteryx-status .dot.checking { background: var(--warning); animation: pulse-dot 1s infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* === APTERYX PATIENT INFO === */
.apteryx-patient-info {
  background: rgba(99, 102, 241, 0.06); border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: var(--radius-sm); padding: 14px 18px; margin-bottom: 16px; font-size: 13px;
}
.apteryx-patient-info .patient-field { margin-bottom: 4px; color: var(--text-secondary); }
.apteryx-patient-info .patient-field strong { color: var(--primary-light); font-size: 12px; }

/* === IMAGE FILTER BAR === */
.image-filter-bar {
  display: flex; align-items: flex-end; gap: 16px; margin-top: 16px;
  padding: 12px 16px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.image-filter-bar .filter-group { display: flex; flex-direction: column; gap: 4px; }
.image-filter-bar .filter-group label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.image-filter-bar .filter-group select,
.image-filter-bar .filter-group input {
  padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); color: var(--text); min-width: 120px;
}
.image-filter-bar .filter-group select:focus,
.image-filter-bar .filter-group input:focus { border-color: var(--primary); outline: none; }
.image-filter-bar .filter-count {
  font-size: 12px; color: var(--text-muted); margin-left: auto; white-space: nowrap;
}

/* === IMAGE GRID === */
.image-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-top: 16px;
}
.image-tile {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: var(--transition);
}
.image-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.image-tile .thumb-container {
  width: 100%; height: 140px; background: #0F172A; display: flex;
  align-items: center; justify-content: center; overflow: hidden;
}
.image-tile .thumb-container img { max-width: 100%; max-height: 100%; object-fit: contain; }
.image-tile .thumb-placeholder { color: var(--text-muted); font-size: 12px; text-align: center; padding: 10px; }
.image-tile .tile-info { padding: 10px 12px; font-size: 12px; color: var(--text-muted); }
.image-tile .tile-info .tile-id {
  font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--primary-light);
  word-break: break-all; margin-bottom: 4px; font-weight: 600;
}
.image-tile .tile-info .tile-meta { margin-top: 2px; }
.image-tile .tile-info .tile-teeth { margin-top: 4px; color: var(--accent); font-weight: 600; }
.image-tile .match-badge {
  display: inline-block; background: rgba(16, 185, 129, 0.12); color: var(--accent-light);
  font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 10px;
  margin-top: 4px; border: 1px solid rgba(16, 185, 129, 0.2);
}

/* === IMAGE COUNT === */
.image-count {
  display: inline-block; background: var(--primary); color: white;
  font-size: 11px; font-weight: 600; padding: 2px 10px; border-radius: 12px; margin-left: 8px;
}

/* === IMAGE PREVIEW MODAL === */
.image-modal-overlay {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85); z-index: 1000; align-items: center; justify-content: center;
}
.image-modal-overlay.visible { display: flex; }
.image-modal {
  background: var(--bg-card); border-radius: var(--radius-lg); max-width: 90vw; max-height: 90vh;
  overflow: hidden; position: relative; display: flex; flex-direction: column;
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.image-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.image-modal-header h3 { font-size: 14px; color: var(--primary-light); margin: 0; font-weight: 600; }
.image-modal-close {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--text-muted); padding: 0 4px; line-height: 1; transition: var(--transition);
}
.image-modal-close:hover { color: var(--danger); }
.image-modal-body {
  padding: 20px; overflow: auto; display: flex; align-items: center; justify-content: center;
  background: #0F172A; min-width: 400px; min-height: 300px;
}
.image-modal-body img { max-width: 80vw; max-height: 75vh; object-fit: contain; }
.image-modal-body .loading-text { color: var(--text-muted); font-size: 14px; }
.image-modal-footer {
  padding: 10px 20px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted); background: var(--bg-raised);
}

/* === IMAGES GALLERY MODAL === */
.images-gallery-modal {
  background: var(--bg-card); border-radius: var(--radius-lg); width: 90vw; max-height: 90vh;
  overflow: hidden; position: relative; display: flex; flex-direction: column;
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.images-gallery-body {
  padding: 20px; overflow-y: auto; flex: 1;
}

/* === APTERYX LOADING === */
.apteryx-loading { text-align: center; padding: 32px; color: var(--text-muted); font-size: 14px; }
.apteryx-loading .spinner {
  display: inline-block; width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite;
  margin-bottom: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === COST TABLE === */
.cost-tbd { color: var(--text-muted); font-style: italic; }
.cost-note { font-size: 12px; color: var(--text-muted); margin-top: 16px; }

/* === RESPONSIVE === */
@media (max-width: 640px) {
  .header { padding: 24px 20px 20px; }
  .header h1 { font-size: 18px; }
  .header p { margin-left: 0; margin-top: 6px; }
  .header-top { flex-wrap: wrap; }
  .container { padding: 20px 16px 60px; }
  .card { padding: 20px; }
  .form-row { flex-direction: column; gap: 12px; }
  .form-group { min-width: 100%; }
  .result-info .code-title { font-size: 22px; }
  .matrix-table th, .matrix-table td { padding: 8px 6px; font-size: 10px; }
  .matrix-table .req-cell { font-size: 13px; }
  .xray-table th, .xray-table td { padding: 6px 8px; font-size: 10px; }
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .image-modal-body { min-width: unset; }
  .image-modal-body img { max-width: 95vw; }
  .results-columns { grid-template-columns: 1fr; }
  .results-col-left { position: static; }
  .tab-bar { padding: 0 12px; }
  .tab-bar .tab { padding: 10px 14px; font-size: 12px; }
  .setup-grid { grid-template-columns: 1fr; }
}

/* =============================================
   Image Lab Tab
   ============================================= */
.lab-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  min-height: 60vh;
}

.lab-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.lab-search {
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.lab-search input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
}

.lab-patient-list {
  flex: 1;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.lab-patient-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.lab-patient-item:hover {
  background: rgba(99, 102, 241, 0.08);
}

.lab-patient-item.active {
  background: rgba(99, 102, 241, 0.15);
  border-left: 3px solid var(--primary);
}

.lab-patient-name-text {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.lab-patient-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.lab-patient-modalities {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
}

.lab-pagination {
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.lab-pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.btn-pagination {
  padding: 4px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-pagination:hover:not(:disabled) {
  background: var(--primary-glow);
}

.btn-pagination:disabled {
  opacity: 0.35;
  cursor: default;
}

.lab-pagination-page {
  font-size: 13px;
  color: var(--text-secondary);
}

.lab-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lab-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lab-patient-name {
  font-weight: 700;
  font-size: 16px;
}

.lab-image-count {
  color: var(--text-muted);
  font-size: 13px;
  flex: 1;
}

.lab-progress {
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lab-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.lab-image-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}

.lab-image-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.lab-thumb-wrap {
  width: 100%;
  height: 160px;
  background: #0F172A;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lab-thumb-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: pointer;
}

.lab-card-info {
  padding: 8px 12px;
}

.lab-card-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
}

.lab-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.lab-card-bars {
  padding: 8px 12px 12px;
  min-height: 20px;
}

.lab-classified-label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.lab-bar-container {
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  overflow: hidden;
}

.lab-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.lab-bar-details {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.lab-bar-reasoning {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
  line-height: 1.3;
}

.lab-bar-skipped {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* Summary Card */
.lab-summary-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.06) 0%, var(--bg-card) 60%);
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: var(--radius);
  padding: 20px;
}

.lab-summary-card h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.lab-summary-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.lab-summary-stats span {
  background: var(--surface);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

.lab-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.lab-summary-item {
  text-align: center;
  padding: 8px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.lab-summary-thumb {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: 4px;
  background: #0F172A;
  cursor: pointer;
}

.lab-summary-type {
  font-size: 11px;
  font-weight: 600;
  margin-top: 6px;
  color: var(--text);
}

.lab-summary-conf {
  font-size: 14px;
  font-weight: 700;
}

.lab-summary-id {
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.lab-summary-empty {
  opacity: 0.5;
}

.lab-summary-no-match {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--text-muted);
}

.lab-empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.lab-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .lab-layout {
    grid-template-columns: 1fr;
  }
  .lab-patient-list {
    max-height: 200px;
  }
}

/* === BATCH LAB === */

.batch-stats-bar {
  display: flex;
  gap: 24px;
  padding: 12px 0;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.batch-stats-bar span {
  font-weight: 600;
  color: var(--text);
}

.batch-status-msg {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  margin-bottom: 12px;
}

.batch-progress-text {
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Progress Panel (Ingestion + Classification) */
.batch-progress-panel {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 12px;
}
.batch-progress-phase {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.batch-progress-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.batch-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.batch-progress-bar.complete {
  background: var(--accent);
}
.batch-progress-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.batch-progress-stats span {
  font-weight: 500;
}

/* Patient Grid Table */
.batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.batch-table th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.batch-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.batch-patient-row {
  cursor: pointer;
  transition: background 0.15s;
}
.batch-patient-row:hover {
  background: var(--primary-glow);
}
.batch-patient-row.expanded {
  background: var(--bg-input);
}
.expand-arrow {
  width: 30px;
  text-align: center;
  color: var(--text-muted);
  font-size: 10px;
}
.batch-image-row td {
  padding: 0;
  background: var(--bg);
}
.batch-image-container {
  padding: 16px;
}

/* Batch Image Grid (inside expanded patient) */
.batch-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.batch-image-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.batch-image-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}
.batch-thumb-wrap {
  aspect-ratio: 1;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.batch-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.batch-card-info {
  padding: 8px;
}
.batch-card-type {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 2px;
}
.batch-card-conf {
  font-size: 11px;
  color: var(--text-muted);
}
.batch-card-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Quality Tier Badges */
.tier-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tier-gold {
  background: rgba(234, 179, 8, 0.15);
  color: #EAB308;
  border: 1px solid rgba(234, 179, 8, 0.3);
}
.tier-silver {
  background: rgba(148, 163, 184, 0.15);
  color: #94A3B8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}
.tier-bronze {
  background: rgba(217, 119, 6, 0.15);
  color: #D97706;
  border: 1px solid rgba(217, 119, 6, 0.3);
}
.tier-copper {
  background: rgba(180, 83, 9, 0.15);
  color: #B45309;
  border: 1px solid rgba(180, 83, 9, 0.3);
}

/* Small button */
.btn-sm {
  padding: 4px 12px;
  font-size: 11px;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-sm:hover {
  background: var(--primary-glow);
  border-color: var(--primary);
}

/* Danger button */
.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
  border-color: #ef4444;
}

/* Source badges (main_workflow vs batch_lab) */
.source-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  vertical-align: middle;
}
.source-main {
  background: rgba(59, 130, 246, 0.15);
  color: #3B82F6;
  border: 1px solid rgba(59, 130, 246, 0.3);
}
.source-batch {
  background: rgba(148, 163, 184, 0.1);
  color: #94A3B8;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

/* Delete button on image card thumbnail */
.batch-delete-img-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  padding: 0;
  display: none;
  z-index: 2;
}
.batch-thumb-wrap {
  position: relative;
}
.batch-image-card:hover .batch-delete-img-btn {
  display: block;
}

/* Batch Detail Modal */
.batch-detail-modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: 95%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.batch-detail-body {
  padding: 24px;
}
.batch-detail-image {
  text-align: center;
  margin-bottom: 16px;
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.batch-detail-image img {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
}
.batch-detail-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.batch-detail-consensus {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.batch-detail-consensus h4 {
  margin: 0;
  font-size: 14px;
}
.batch-detail-labels {
  margin-bottom: 16px;
}
.batch-detail-labels h4 {
  margin-bottom: 8px;
  font-size: 14px;
}
.batch-reasoning-row td {
  padding: 4px 12px 8px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
/* Model vote summary on image cards */
.batch-card-models {
  padding: 4px 8px 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.batch-model-vote {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
}
.batch-model-agree {
  color: var(--accent);
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.08);
}
.batch-model-disagree {
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.08);
}
/* Prominent reasoning block in modal */
.batch-reasoning-block {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
  margin: 4px 0;
}
.batch-reasoning-block strong {
  color: var(--text);
  text-transform: capitalize;
}
/* Collapsible raw response JSON */
.batch-raw-response {
  padding: 4px 12px 8px;
}
.batch-raw-json {
  margin-top: 8px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.batch-detail-override {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 0;
  border-top: 1px solid var(--border);
}
.batch-detail-override h4 {
  margin: 0;
  font-size: 13px;
  white-space: nowrap;
}
.batch-detail-override select {
  flex: 1;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 13px;
}

/* === BATCH LAB ENHANCEMENTS === */

/* Confirm Modal */
.batch-confirm-dialog {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.batch-confirm-header {
  padding: 16px 20px;
  font-size: 14px;
  font-weight: 700;
  color: #ef4444;
  border-bottom: 1px solid var(--border);
}
.batch-confirm-body {
  padding: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.batch-confirm-body img {
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  max-width: 120px;
  display: block;
}
.batch-confirm-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* Filter Bar */
.batch-filter-bar {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.batch-filter-bar .filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.batch-filter-bar .filter-group label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.batch-filter-bar input,
.batch-filter-bar select {
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 12px;
  min-width: 100px;
}
.batch-filter-bar .filter-count {
  font-size: 12px;
  color: var(--text-muted);
  align-self: center;
  white-space: nowrap;
}

/* Pagination */
.batch-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 12px 0 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.batch-pagination button {
  padding: 4px 12px;
  font-size: 11px;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 600;
}
.batch-pagination button:hover:not(:disabled) {
  background: var(--primary-glow);
  border-color: var(--primary);
}
.batch-pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Image pagination (per-patient) */
.batch-img-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 10px 0 0;
  font-size: 11px;
  color: var(--text-muted);
}
.batch-img-pagination button {
  padding: 3px 10px;
  font-size: 10px;
  border-radius: 5px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 600;
}
.batch-img-pagination button:hover:not(:disabled) {
  background: var(--primary-glow);
  border-color: var(--primary);
}
.batch-img-pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Sortable columns */
.batch-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.batch-table th.sortable:hover {
  color: var(--primary);
}
.sort-arrow {
  font-size: 10px;
  margin-left: 4px;
}

/* Bulk action bar */
.batch-bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-input);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* Bulk select mode — image card checkbox overlay */
.batch-select-check {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: rgba(99, 102, 241, 0.2);
  border: 2px solid rgba(99, 102, 241, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  font-size: 14px;
  color: transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.batch-image-card.selected .batch-select-check {
  background: rgba(99, 102, 241, 0.9);
  border-color: #6366f1;
  color: #fff;
}
.batch-image-card.selected {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

/* Confidence bar on image cards */
.batch-conf-bar {
  height: 3px;
  border-radius: 2px;
  margin: 4px 8px 0;
}

/* Unclassified image indicator */
.batch-image-card.unclassified {
  border-style: dashed;
  opacity: 0.75;
}
.batch-image-card.unclassified:hover {
  opacity: 1;
}

/* Image zoom in modal */
.batch-detail-image.zoomable {
  overflow: auto;
  cursor: zoom-in;
}
.batch-detail-image.zoomable.zoomed {
  cursor: zoom-out;
}
.batch-detail-image.zoomable img {
  transition: transform 0.2s ease;
  transform-origin: center center;
}
