/* MedCode Pro - Modern Medical Coding SaaS Design System */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", Monaco, "JetBrains Mono", "Cascadia Code", Consolas, monospace;

  /* Neutrals */
  --neutral-0: #ffffff;
  --neutral-50: #f8fafc;
  --neutral-100: #f1f5f9;
  --neutral-200: #e2e8f0;
  --neutral-300: #cbd5e1;
  --neutral-400: #94a3b8;
  --neutral-500: #64748b;
  --neutral-600: #475569;
  --neutral-700: #334155;
  --neutral-800: #1e293b;
  --neutral-900: #0f172a;

  /* Primary Brand (Clinical Indigo / Royal Teal) */
  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-800: #3730a3;

  /* Surfaces */
  --bg-canvas: #f8fafc;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: #f1f5f9;

  --text-primary: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;

  --border-default: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Category colors */
  --icd-color: #0284c7;
  --icd-bg: #e0f2fe;
  --icd-border: #bae6fd;

  --cpt-color: #7c3aed;
  --cpt-bg: #f3e8ff;
  --cpt-border: #e9d5ff;

  --hcpcs-color: #059669;
  --hcpcs-bg: #d1fae5;
  --hcpcs-border: #a7f3d0;

  /* Semantic Alerts */
  --success-fg: #15803d;
  --success-bg: #dcfce7;
  --success-border: #86efac;

  --warning-fg: #b45309;
  --warning-bg: #fef3c7;
  --warning-border: #fde68a;

  --error-fg: #b91c1c;
  --error-bg: #fee2e2;
  --error-border: #fca5a5;

  --info-fg: #1d4ed8;
  --info-bg: #dbeafe;
  --info-border: #bfdbfe;

  --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
}

.dark {
  --bg-canvas: #090d16;
  --bg-surface: #101623;
  --bg-elevated: #182234;
  --bg-hover: #1e293b;

  --neutral-0: #101623;
  --neutral-50: #131c2d;
  --neutral-100: #1a253a;
  --neutral-200: #25334d;
  --neutral-300: #334466;
  --neutral-400: #64748b;
  --neutral-500: #94a3b8;
  --neutral-600: #cbd5e1;
  --neutral-700: #e2e8f0;
  --neutral-800: #f1f5f9;
  --neutral-900: #f8fafc;

  --text-primary: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;

  --border-default: #223048;
  --border-strong: #2e4162;

  --brand-50: rgba(79, 70, 229, 0.15);
  --brand-100: rgba(79, 70, 229, 0.25);
  --brand-600: #6366f1;
  --brand-700: #818cf8;

  --icd-color: #38bdf8;
  --icd-bg: rgba(2, 132, 199, 0.15);
  --icd-border: rgba(56, 189, 248, 0.3);

  --cpt-color: #c084fc;
  --cpt-bg: rgba(124, 58, 237, 0.18);
  --cpt-border: rgba(192, 132, 252, 0.3);

  --hcpcs-color: #34d399;
  --hcpcs-bg: rgba(5, 150, 105, 0.18);
  --hcpcs-border: rgba(52, 211, 153, 0.3);

  --success-fg: #4ade80;
  --success-bg: rgba(22, 163, 74, 0.15);
  --success-border: rgba(74, 222, 128, 0.3);

  --warning-fg: #fbbf24;
  --warning-bg: rgba(217, 119, 6, 0.15);
  --warning-border: rgba(251, 191, 36, 0.3);

  --error-fg: #f87171;
  --error-bg: rgba(220, 38, 38, 0.15);
  --error-border: rgba(248, 113, 113, 0.3);

  --info-fg: #60a5fa;
  --info-bg: rgba(37, 99, 235, 0.15);
  --info-border: rgba(96, 165, 250, 0.3);

  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* App Shell Layout */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top Navigation Bar */
.topbar {
  height: 54px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--brand-600), #2563eb);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.25);
}

.logo-text-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-version {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--brand-50);
  color: var(--brand-600);
  border: 1px solid var(--border-default);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Tab Bar */
.tab-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  overflow-x: auto;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 120ms ease;
  white-space: nowrap;
}

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

.tab-btn.active {
  color: var(--brand-600);
  border-bottom-color: var(--brand-600);
  font-weight: 600;
}

.tab-count {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--neutral-100);
  color: var(--neutral-600);
  font-weight: 600;
}

.tab-btn.active .tab-count {
  background: var(--brand-50);
  color: var(--brand-600);
}

/* Main Workspace */
.workspace-content {
  flex: 1;
  padding: 16px 20px 32px;
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
}

/* Split Pane: Analyzer */
.split-pane {
  display: grid;
  grid-template-columns: 460px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

@media (max-width: 1100px) {
  .split-pane {
    grid-template-columns: 1fr;
  }
}

/* Card primitives */
.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-body {
  padding: 16px;
}

/* Presets Dropdown & Bar */
.presets-strip {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.preset-pills-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.preset-pill {
  font-size: 11.5px;
  padding: 5px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-canvas);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 120ms ease;
  font-weight: 500;
}

.preset-pill:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.preset-pill.active {
  background: var(--brand-50);
  color: var(--brand-600);
  border-color: var(--brand-200);
  font-weight: 600;
}

/* Clinical Textarea */
.textarea-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
}

.scenario-textarea {
  width: 100%;
  min-height: 280px;
  max-height: 480px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-canvas);
  color: var(--text-primary);
  resize: vertical;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.scenario-textarea:focus {
  border-color: var(--brand-600);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
  background: var(--bg-surface);
}

.textarea-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-subtle);
}

/* Primary buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 120ms ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--brand-600);
  color: #ffffff;
  border-color: var(--brand-600);
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2);
}

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

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

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

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

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm {
  height: 26px;
  padding: 0 8px;
  font-size: 11.5px;
}

.btn-lg {
  height: 38px;
  padding: 0 16px;
  font-size: 13.5px;
  font-weight: 600;
}

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 768px) {
  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

.kpi-card {
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-subtle);
  margin-top: 2px;
}

/* Code Result Cards */
.code-card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.code-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: all 120ms ease;
  position: relative;
}

.code-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.code-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.code-badge-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.code-pill {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13.5px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.code-pill-icd {
  background: var(--icd-bg);
  color: var(--icd-color);
  border: 1px solid var(--icd-border);
}

.code-pill-cpt {
  background: var(--cpt-bg);
  color: var(--cpt-color);
  border: 1px solid var(--cpt-border);
}

.code-pill-hcpcs {
  background: var(--hcpcs-bg);
  color: var(--hcpcs-color);
  border: 1px solid var(--hcpcs-border);
}

.tag-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--neutral-100);
  color: var(--neutral-600);
}

.tag-badge-primary {
  background: var(--brand-50);
  color: var(--brand-600);
}

.tag-badge-hcc {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.tag-badge-global {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.tag-badge-rvu {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  font-family: var(--font-mono);
}

.code-desc {
  margin: 6px 0 4px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
}

.code-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.code-rationale {
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--bg-canvas);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
  border-left: 2px solid var(--brand-500);
}

.modifiers-box {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mod-chip {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}

/* Alert Boxes */
.alert-box {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  font-size: 12.5px;
  line-height: 1.45;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.alert-warning {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-fg);
}

.alert-error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-fg);
}

.alert-info {
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  color: var(--info-fg);
}

.alert-success {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-fg);
}

/* Medical Necessity Matrix Table */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  padding: 9px 12px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-canvas);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-default);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-default);
  vertical-align: top;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--bg-hover);
}

/* CMS-1500 Preview Sheet */
.cms-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 1000px;
  margin: 0 auto;
  box-shadow: var(--shadow-sm);
  font-family: var(--font-sans);
}

.cms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--neutral-300);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.cms-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.cms-box {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--bg-canvas);
}

.cms-box-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.diagnosis-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  background: var(--bg-surface);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
}

.diag-pointer {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--brand-600);
  font-size: 12px;
}

/* Search engine in Code Explorer */
.search-input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color 150ms ease;
}

.search-input:focus {
  border-color: var(--brand-600);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.search-icon-pos {
  position: absolute;
  left: 10px;
  color: var(--text-subtle);
  pointer-events: none;
}

/* Copy notification toast */
.toast-notice {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--neutral-900);
  color: var(--neutral-0);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  animation: toast-slide-up 200ms ease-out;
}

@keyframes toast-slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Highlight badge */
.entity-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  margin: 2px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-default);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
}

.empty-icon {
  margin: 0 auto 12px;
  color: var(--neutral-400);
}

/* Print Styles */
@media print {
  .topbar, .tab-nav, .panel-actions, .btn, .presets-strip {
    display: none !important;
  }
  .split-pane {
    grid-template-columns: 1fr;
  }
  body {
    background: #fff;
    color: #000;
  }
}
