/* Drug Bank Pro - Modern Medical Reference
 * Optimized for performance, accessibility, and maintainability
 * Version: 2.0.0
 */

/* ===== CSS Custom Properties ===== */
:root {
  /* Hybrid palette: clinical navy + drug-bank indigo + gold titles */
  --primary: #4f7dff;
  --primary-dark: #3b82f6;
  --primary-light: #60a5fa;
  --secondary: #8b5cf6;
  --accent: #22d3ee;
  --success: #22c55e;
  --warning: #fbbf24;
  --danger: #ef4444;
  --info: #38bdf8;
  --gold: #fbbf24;
  --gold-bright: #fde68a;
  
  /* Backgrounds — clinical #0a0f1a blended with drugs purple */
  --bg-primary: #0a0f1a;
  --bg-secondary: #0f172a;
  --bg-tertiary: #1a1530;
  --bg-card: #151a2e;
  --bg-hover: #1f2937;
  --bg-elevated: #1e293b;
  
  /* Text */
  --text-primary: #f9fafb;
  --text-secondary: #e2e8f0;
  --text-muted: #cbd5e1;
  --text-accent: #93c5fd;
  --text-disabled: #64748b;
  --color-title: #fbbf24;
  
  /* Borders */
  --border-color: #334155;
  --border-light: #475569;
  --border-focus: #60a5fa;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 350ms ease;
  
  /* Z-index scale */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal: 300;
  --z-toast: 400;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Accessibility ===== */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: white;
  padding: 8px 16px;
  z-index: 9999;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 0;
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  html {
    scroll-behavior: auto;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --border-color: #666;
    --text-muted: #aaa;
  }
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
  border-bottom: 1px solid var(--border-color);
  padding: var(--space-md) var(--space-lg);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(10px);
}

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

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

.logo-icon {
  font-size: 2.25rem;
  filter: drop-shadow(0 0 12px rgba(99, 102, 241, 0.4));
}

.logo-text h1 {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.logo-text p {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.stats {
  display: flex;
  gap: var(--space-lg);
}

.stat {
  text-align: center;
}

.stat-value {
  font-size: 1.625rem;
  font-weight: 800;
  color: var(--primary-light);
  line-height: 1;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.offline-indicator .stat-value {
  color: var(--warning);
}

/* ===== Search Section ===== */
.search-section {
  background: var(--bg-secondary);
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
}

.search-container {
  max-width: 900px;
  margin: 0 auto;
  position: relative;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--space-sm) var(--space-md);
  transition: var(--transition-base);
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}

.search-icon {
  font-size: 1.25rem;
  margin-right: var(--space-sm);
  opacity: 0.7;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1rem;
  padding: var(--space-sm);
  min-width: 0;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.clear-btn {
  background: var(--border-light);
  border: none;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-btn.visible {
  opacity: 1;
}

.clear-btn:hover {
  background: var(--danger);
  color: white;
}

/* Autocomplete dropdown */
.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-height: 300px;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  box-shadow: var(--shadow-lg);
}

.autocomplete-item {
  padding: var(--space-md);
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item[aria-selected="true"] {
  background: var(--bg-hover);
}

.autocomplete-item-name {
  font-weight: 600;
  color: var(--text-primary);
}

.autocomplete-item-category {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 12px;
}

/* Category filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-color);
}

.filter-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.filter-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.filter-btn.loading {
  opacity: 0.6;
  cursor: wait;
  animation: pulse-opacity 1.2s ease-in-out infinite;
}

@keyframes pulse-opacity {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 0.3; }
}

.category-loading {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: var(--space-md);
}

/* ===== Main Content ===== */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-lg);
  min-height: 50vh;
}

/* Loading state */
.loading-state {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto var(--space-lg);
}

.spinner-small {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-progress {
  max-width: 300px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  margin: var(--space-lg) auto;
  overflow: hidden;
}

.loading-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  width: 0%;
  transition: width 0.3s ease;
}

/* Error state */
.error-state {
  text-align: center;
  padding: var(--space-2xl);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-lg);
  margin: var(--space-xl) auto;
  max-width: 500px;
}

.error-state h3 {
  color: var(--danger);
  margin-bottom: var(--space-md);
}

.retry-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: var(--space-lg);
  transition: var(--transition-fast);
}

.retry-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

/* Virtual scroll container */
.virtual-scroll-container {
  position: relative;
  overflow-y: auto;
  max-height: calc(100vh - 250px);
  -webkit-overflow-scrolling: touch;
}

.virtual-scroll-content {
  position: relative;
}

/* Drug grid (fallback) */
.drug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: var(--space-lg);
}

/* Drug card */
.drug-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: var(--transition-base);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.drug-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  transform: scaleX(0);
  transition: transform var(--transition-base);
}

.drug-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-light);
}

.drug-card:hover::before {
  transform: scaleX(1);
}

.drug-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.drug-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-md);
  gap: var(--space-sm);
}

.drug-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  flex: 1;
}

.drug-category {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-light);
  background: rgba(99, 102, 241, 0.15);
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.drug-forms {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-light);
  background: rgba(99, 102, 241, 0.08);
  border-left: 3px solid var(--primary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  line-height: 1.4;
  word-break: break-word;
}

.drug-forms-sep {
  color: var(--text-muted);
  font-weight: 400;
  margin: 0 2px;
}

.drug-forms-more {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8rem;
}

.drug-indication {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: var(--space-md);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.drug-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.drug-tag {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.drug-tag-info {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}

.drug-tag-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.drug-tag-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.drug-tag-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

/* No results */
.no-results {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

.no-results h3 {
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
}

.clear-filters-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: var(--space-lg);
  transition: var(--transition-fast);
}

.clear-filters-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

/* End of results */
.end-of-results {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: slideUp 0.3s ease;
}

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

.modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  transition: var(--transition-fast);
}

.modal-close:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.modal-body {
  padding: var(--space-xl);
}

/* Modal sections */
.modal-header {
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 1.5rem;
  margin-bottom: var(--space-sm);
}

.modal-section {
  margin-bottom: var(--space-lg);
}

.modal-section h3 {
  font-size: 1.125rem;
  color: var(--primary-light);
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.modal-section h4 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin: var(--space-md) 0 var(--space-sm);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--space-md);
}

.detail-item {
  background: var(--bg-card);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--primary);
}

.detail-item.warning {
  border-left-color: var(--warning);
}

.detail-item.danger {
  border-left-color: var(--danger);
}

.detail-item.success {
  border-left-color: var(--success);
}

/* ===== Footer ===== */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: var(--space-lg);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.footer a,
.footer-link {
  color: var(--primary-light);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: inherit;
}

.footer a:hover,
.footer-link:hover {
  text-decoration: underline;
}

.footer-meta {
  margin-top: var(--space-sm);
  font-size: 0.8rem;
  opacity: 0.8;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .drug-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
}

@media (max-width: 768px) {
  .header {
    padding: var(--space-md);
  }
  
  .header-content {
    flex-direction: column;
    text-align: center;
  }
  
  .stats {
    width: 100%;
    justify-content: center;
  }
  
  .search-section {
    padding: var(--space-md);
  }
  
  .main-content {
    padding: var(--space-md);
  }
  
  .drug-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  
  .filters {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: var(--space-sm);
    -webkit-overflow-scrolling: touch;
  }
  
  .modal-content {
    max-height: 95vh;
    margin: var(--space-sm);
  }
  
  .modal-body {
    padding: var(--space-lg);
  }
  
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .logo-icon {
    font-size: 1.75rem;
  }
  
  .logo-text h1 {
    font-size: 1.25rem;
  }
  
  .stat-value {
    font-size: 1.25rem;
  }
  
  .drug-card {
    padding: var(--space-md);
  }
  
  .drug-name {
    font-size: 1rem;
  }
}

/* ===== Print ===== */
@media print {
  .header,
  .search-section,
  .footer,
  .modal-overlay {
    display: none !important;
  }
  
  .main-content {
    padding: 0;
  }
  
  .drug-card {
    break-inside: avoid;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-color);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) var(--bg-secondary);
}

/* ===== Smart Prescription Styles ===== */

.smart-prescription-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  padding: 1rem 2.25rem;
  border-radius: var(--radius-xl);
  font-weight: 800;
  font-size: 1.125rem;
  text-decoration: none;
  margin-top: var(--space-md);
  transition: var(--transition-fast);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
  min-width: 180px;
  letter-spacing: 0.3px;
}

.smart-prescription-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.smart-prescription-text {
  display: inline;
}

@media (max-width: 480px) {
  .smart-prescription-text {
    display: none;
  }
}

.smart-prescription-section {
  background: var(--bg-secondary);
  min-height: calc(100vh - 200px);
  padding: var(--space-lg) var(--space-md);
}

.sp-container {
  max-width: 900px;
  margin: 0 auto;
}

.sp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.sp-header h2 {
  font-size: 1.5rem;
  color: var(--text-primary);
  margin: 0;
}

.sp-back-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition-fast);
}

.sp-back-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.sp-params,
.sp-drugs,
.sp-results {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.sp-params h3,
.sp-drugs h3 {
  font-size: 1.1rem;
  margin-top: 0;
  margin-bottom: var(--space-md);
  color: var(--text-primary);
}

.sp-optional {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.sp-params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-md);
}

.sp-params-grid > * {
  min-width: 0;
}

.sp-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.sp-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-accent);
}

.sp-field input,
.sp-field select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

.sp-field input:focus,
.sp-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.sp-field small {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.sp-derived {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: var(--space-md);
}

.sp-derived-item {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  min-width: 90px;
  text-align: center;
}

.sp-derived-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sp-derived-value {
  display: block;
  font-weight: 700;
  color: var(--accent);
  font-size: 1rem;
}

.sp-condition-select {
  min-height: 120px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  font-size: 0.9rem;
}

.sp-condition-select option {
  padding: 4px 6px;
}

.sp-condition-select optgroup {
  font-weight: 600;
  color: var(--text-accent);
}

.sp-condition-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
  min-height: 28px;
}

.sp-chip-placeholder {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.sp-condition-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 500;
}

.sp-chip-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
}

.sp-protocol-box {
  background: rgba(245, 158, 11, 0.08);
  border-left: 3px solid rgba(245, 158, 11, 0.6);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  margin-top: var(--space-sm);
}

.sp-protocol-header {
  font-size: 0.9rem;
  margin-bottom: var(--space-xs);
}

.sp-protocol-evidence {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  margin: var(--space-xs) 0;
  padding: var(--space-xs) var(--space-sm);
  background: rgba(59, 130, 246, 0.06);
  border-radius: var(--radius-sm);
  border-left: 2px solid rgba(59, 130, 246, 0.4);
}

.sp-protocol-steps {
  margin: var(--space-xs) 0 0 0;
  padding-left: var(--space-md);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.sp-protocol-steps li {
  margin-bottom: 4px;
}

.sp-protocol-alts {
  margin-top: var(--space-xs);
  font-size: 0.8rem;
  color: var(--text-accent);
}

.sp-drug-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.sp-drug-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sp-drug-search {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sp-drug-num {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sp-drug-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
}

.sp-drug-input:focus {
  outline: none;
  border-color: var(--primary);
}

.sp-drug-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--border-light);
  border: none;
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sp-drug-clear.visible {
  opacity: 1;
}

.sp-drug-remove {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sp-drug-remove:hover {
  background: var(--danger);
  color: white;
}

.sp-autocomplete {
  position: absolute;
  top: calc(100% + 4px);
  left: 32px;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-height: 220px;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  box-shadow: var(--shadow-lg);
}

.sp-autocomplete-item {
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.sp-autocomplete-item:last-child {
  border-bottom: none;
}

.sp-autocomplete-item:hover {
  background: var(--bg-hover);
}

.sp-autocomplete-name {
  font-weight: 600;
  color: var(--text-primary);
}

.sp-autocomplete-cat {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 12px;
}

.sp-drug-actions {
  display: flex;
  gap: var(--space-sm);
}

.sp-add-btn {
  background: var(--bg-tertiary);
  border: 1px dashed var(--border-light);
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition-fast);
}

.sp-add-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.sp-add-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sp-errors {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.sp-error-item {
  color: #fca5a5;
  font-size: 0.9rem;
  padding: var(--space-xs) 0;
}

.sp-generate {
  margin-bottom: var(--space-xl);
}

.sp-generate-btn {
  background: linear-gradient(135deg, var(--success), #059669);
  color: white;
  border: none;
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-xl);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-md);
}

.sp-generate-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.sp-summary {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.15));
  border: 1px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.sp-summary h3 {
  margin-top: 0;
  margin-bottom: var(--space-md);
  color: var(--text-primary);
}

.sp-summary-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.sp-tag {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

.sp-interactions {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--warning);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.sp-interactions h4 {
  margin-top: 0;
  color: #fcd34d;
}

.sp-interaction-pair {
  margin-bottom: var(--space-md);
}

.sp-interaction-drugs {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.sp-interaction-list {
  margin: 0;
  padding-left: var(--space-lg);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.sp-interaction-list li {
  margin-bottom: var(--space-xs);
}

.sp-results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
}

.sp-result-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: var(--transition-fast);
}

.sp-result-card:hover {
  border-color: var(--border-light);
}

.sp-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-color);
}

.sp-result-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sp-result-category {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 10px;
  border-radius: 12px;
}

.sp-result-body > div {
  margin-bottom: var(--space-sm);
  line-height: 1.55;
}

.sp-result-dose {
  background: rgba(16, 185, 129, 0.1);
  border-left: 3px solid var(--success);
  padding: var(--space-sm) var(--space-md);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.sp-result-dose em,
.sp-result-indication em {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.sp-result-note {
  font-size: 0.9rem;
  color: var(--text-secondary);
  padding: var(--space-xs) 0;
}

.sp-result-renal {
  border-left: 2px solid var(--info);
  padding-left: var(--space-sm);
}

.sp-result-hepatic {
  border-left: 2px solid var(--warning);
  padding-left: var(--space-sm);
}

.sp-result-pediatric {
  border-left: 2px solid var(--accent);
  padding-left: var(--space-sm);
}

.sp-result-geriatric {
  border-left: 2px solid var(--secondary);
  padding-left: var(--space-sm);
}

.sp-result-contra {
  border-left: 2px solid var(--danger);
  padding-left: var(--space-sm);
}

@media (max-width: 640px) {
  .sp-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .sp-params-grid {
    grid-template-columns: 1fr;
  }
  
  .sp-derived {
    flex-direction: row;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .sp-derived-item {
    flex: 1 1 70px;
    min-width: 70px;
  }
  
  .smart-prescription-btn {
    width: 100%;
    justify-content: center;
    margin-top: var(--space-sm);
  }
}

/* ===== Smart Prescription Phase 2: History, Print & Safety ===== */

.sp-header-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.sp-history-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition-fast);
}

.sp-history-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.sp-history-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.sp-history-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: var(--space-md);
}

.sp-history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.sp-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
}

.sp-history-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sp-history-drugs {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.sp-history-patient {
  font-size: 0.8rem;
  color: var(--text-accent);
}

.sp-history-actions {
  display: flex;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.sp-history-actions button {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
}

.sp-history-actions button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.sp-history-footer {
  display: flex;
  justify-content: flex-end;
}

.sp-history-clear {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
}

.sp-history-clear:hover {
  background: var(--danger);
  color: white;
}

.sp-report-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-color);
}

.sp-save-btn,
.sp-print-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.sp-save-btn:hover {
  border-color: var(--success);
  color: var(--success);
}

.sp-print-btn:hover {
  border-color: var(--info);
  color: var(--info);
}

.sp-contra-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  font-weight: 600;
}

.sp-print-header {
  display: none;
}

@media print {
  .header,
  .search-section,
  .footer,
  .sp-back-btn,
  .sp-history-btn,
  .sp-params,
  .sp-drugs,
  .sp-generate,
  .sp-drug-actions,
  .sp-errors,
  .sp-add-btn,
  .sp-drug-remove,
  .sp-drug-clear,
  .sp-report-actions,
  .sp-history-panel {
    display: none !important;
  }

  body {
    background: white !important;
    color: black !important;
  }

  .smart-prescription-section {
    background: white !important;
    color: black !important;
    padding: 0 !important;
    min-height: auto !important;
  }

  .sp-container {
    max-width: 100% !important;
    margin: 0 !important;
  }

  .sp-results {
    background: white !important;
    border: none !important;
    padding: 0 !important;
  }

  .sp-summary {
    background: #f8f9fa !important;
    border: 1px solid #dee2e6 !important;
    color: black !important;
  }

  .sp-tag {
    background: #e9ecef !important;
    border-color: #dee2e6 !important;
    color: #212529 !important;
  }

  .sp-interactions {
    background: #fff3cd !important;
    border: 1px solid #ffc107 !important;
    color: #212529 !important;
  }

  .sp-result-card {
    break-inside: avoid;
    page-break-inside: avoid;
    background: white !important;
    border: 1px solid #dee2e6 !important;
    color: black !important;
  }

  .sp-result-name,
  .sp-result-body,
  .sp-result-dose,
  .sp-result-indication,
  .sp-result-note {
    color: black !important;
  }

  .sp-result-dose {
    background: #d4edda !important;
    border-left-color: #28a745 !important;
  }

  .sp-contra-banner {
    background: #f8d7da !important;
    border-color: #dc3545 !important;
    color: #721c24 !important;
  }

  .sp-level-hard {
    background: #fef2f2 !important;
    border-left-color: #dc2626 !important;
  }

  .sp-hard-banner {
    color: #991b1b !important;
  }

  .sp-level-caution {
    background: #fffbeb !important;
    border-left-color: #f59e0b !important;
  }

  .sp-caution-title {
    color: #92400e !important;
  }

  .sp-interaction-hard {
    background: #fee2e2 !important;
    color: #991b1b !important;
  }

  .sp-interaction-caution {
    background: #fef3c7 !important;
    color: #92400e !important;
  }

  .sp-interaction-info {
    background: #dbeafe !important;
    color: #1e40af !important;
  }

  .sp-print-header {
    display: block !important;
    text-align: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #000;
  }

  .sp-print-logo {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
  }

  .sp-print-meta {
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 0.5rem;
  }

  .sp-print-disclaimer {
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
  }
}

/* ===== Smart Prescription Phase 3: Liver & History UI ===== */

.sp-subsection {
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-color);
}

.sp-subsection h4 {
  font-size: 1rem;
  color: var(--text-accent);
  margin: 0 0 var(--space-md) 0;
}

.sp-params-grid-1col {
  grid-template-columns: 1fr;
}

.sp-field textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

.sp-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* ===== Smart Prescription Phase 3: Layered Report Levels ===== */

.sp-level-hard {
  border-left: 4px solid var(--danger);
  background: rgba(239, 68, 68, 0.08);
  padding: var(--space-sm) var(--space-md);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-bottom: var(--space-sm);
}

.sp-hard-banner {
  font-weight: 700;
  color: #fca5a5;
  margin-bottom: var(--space-xs);
}

.sp-hard-list {
  margin: 0;
  padding-left: var(--space-lg);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.sp-hard-list li {
  margin-bottom: var(--space-xs);
}

.sp-level-caution {
  border-left: 4px solid var(--warning);
  background: rgba(245, 158, 11, 0.08);
  padding: var(--space-sm) var(--space-md);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-bottom: var(--space-sm);
}

.sp-caution-title {
  font-weight: 700;
  color: #fcd34d;
  margin-bottom: var(--space-xs);
}

.sp-level-info {
  padding: var(--space-xs) 0;
}

.sp-interaction-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sp-interaction-hard {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.sp-interaction-caution {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.sp-interaction-info {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

/* ===== D4: Interaction Severity Visual System ===== */
.sp-severity-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.sp-severity-contraindicated {
  background: #DC2626;
  color: #FFFFFF;
  border: 2px solid #991B1B;
}
.sp-severity-contraindicated::before { content: '🚫 '; }

.sp-severity-major {
  background: #EA580C;
  color: #FFFFFF;
  border: 2px solid #9A3412;
}
.sp-severity-major::before { content: '⚠️ '; }

.sp-severity-moderate {
  background: #CA8A04;
  color: #FFFFFF;
  border: 2px solid #854D0E;
}
.sp-severity-moderate::before { content: '⚡ '; }

.sp-severity-minor {
  background: #2563EB;
  color: #FFFFFF;
  border: 2px solid #1E40AF;
}
.sp-severity-minor::before { content: 'ℹ️ '; }

.sp-severity-icon {
  margin-right: 4px;
}

/* Ensure WCAG AA contrast on dark theme by using white text on all severity badges */
.sp-interaction-badge.sp-severity-contraindicated,
.sp-interaction-badge.sp-severity-major,
.sp-interaction-badge.sp-severity-moderate,
.sp-interaction-badge.sp-severity-minor,
.sp-conflict-badge.sp-severity-contraindicated,
.sp-conflict-badge.sp-severity-major,
.sp-conflict-badge.sp-severity-moderate,
.sp-conflict-badge.sp-severity-minor,
.sp-severity-badge.sp-severity-contraindicated,
.sp-severity-badge.sp-severity-major,
.sp-severity-badge.sp-severity-moderate,
.sp-severity-badge.sp-severity-minor {
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.3);
}

/* Patient name field spans full width */
.sp-field-wide {
  grid-column: 1 / -1;
  min-width: 0;
}

/* ─── Antibiotic Stewardship Guidance Panel ─── */
.sp-abx-panel {
  border-left: 4px solid #14b8a6;
  background: rgba(20, 184, 166, 0.08);
  padding: var(--space-sm) var(--space-md);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-top: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.sp-abx-panel-header {
  font-weight: 700;
  color: #5eead4;
  font-size: 0.95rem;
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.sp-abx-panel-section {
  margin-bottom: var(--space-sm);
}

.sp-abx-panel-section-title {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-xs);
}

.sp-abx-pathogen-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: var(--space-xs);
}

.sp-abx-pathogen-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(20, 184, 166, 0.15);
  color: #5eead4;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid rgba(20, 184, 166, 0.3);
}

.sp-abx-resistance-alert {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  margin-bottom: var(--space-sm);
  font-size: 0.85rem;
}

.sp-abx-resistance-alert strong {
  color: #fca5a5;
}

.sp-abx-regimen-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-bottom: var(--space-sm);
}

.sp-abx-regimen-table th,
.sp-abx-regimen-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sp-abx-regimen-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(20, 184, 166, 0.1);
}

.sp-abx-regimen-table tr:last-child td {
  border-bottom: none;
}

.sp-abx-line-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sp-abx-line-first {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.sp-abx-line-second {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.sp-abx-line-resistant {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.sp-abx-line-alt {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.sp-abx-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
  padding-left: var(--space-sm);
  border-left: 2px solid rgba(255,255,255,0.1);
}

.sp-abx-duration {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: var(--space-xs);
}

.sp-abx-monitoring {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: var(--space-xs);
}

/* Print overrides for severity system */
@media print {
  .sp-severity-contraindicated {
    background: #fee2e2 !important;
    color: #991b1b !important;
    border-color: #fca5a5 !important;
  }
  .sp-severity-major {
    background: #ffedd5 !important;
    color: #9a3412 !important;
    border-color: #fdba74 !important;
  }
  .sp-severity-moderate {
    background: #fef9c3 !important;
    color: #854d0e !important;
    border-color: #fde047 !important;
  }
  .sp-severity-minor {
    background: #dbeafe !important;
    color: #1e40af !important;
    border-color: #93c5fd !important;
  }
  .sp-print-signature {
    display: block !important;
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 1px solid #000;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .sp-print-signature-line {
    margin-top: 2.5rem;
    border-bottom: 1px solid #000;
    width: 60%;
  }
  .sp-print-signature-label {
    font-size: 0.85rem;
    color: #555;
    margin-top: 4px;
  }
}

/* ===== Rx Print Layout (D1) ===== */
body.printing-rx .header,
body.printing-rx .search-section,
body.printing-rx .footer,
body.printing-rx .sp-back-btn,
body.printing-rx .sp-history-btn,
body.printing-rx .sp-params,
body.printing-rx .sp-drugs,
body.printing-rx .sp-generate,
body.printing-rx .sp-drug-actions,
body.printing-rx .sp-errors,
body.printing-rx .sp-add-btn,
body.printing-rx .sp-drug-remove,
body.printing-rx .sp-drug-clear,
body.printing-rx .sp-report-actions,
body.printing-rx .sp-history-panel,
body.printing-rx .sp-infusion-panel,
body.printing-rx .sp-compare-btn,
body.printing-rx .sp-infusion-btn,
body.printing-rx .sp-allergy-section,
body.printing-rx .sp-combination-section {
  display: none !important;
}

body.printing-rx {
  background: white !important;
  color: black !important;
}

body.printing-rx .smart-prescription-section {
  background: white !important;
  color: black !important;
  padding: 0 !important;
  min-height: auto !important;
}

body.printing-rx .sp-container {
  max-width: 100% !important;
  margin: 0 !important;
}

body.printing-rx .sp-results {
  background: white !important;
  border: none !important;
  padding: 0 !important;
}

body.printing-rx .sp-summary {
  background: #f8f9fa !important;
  border: 1px solid #dee2e6 !important;
  color: black !important;
  page-break-inside: avoid;
  break-inside: avoid;
}

body.printing-rx .sp-tag {
  background: #e9ecef !important;
  border-color: #dee2e6 !important;
  color: #212529 !important;
}

body.printing-rx .sp-result-card {
  break-inside: avoid;
  page-break-inside: avoid;
  background: white !important;
  border: 1px solid #dee2e6 !important;
  color: black !important;
  margin-bottom: 1rem;
}

body.printing-rx .sp-result-name,
body.printing-rx .sp-result-body,
body.printing-rx .sp-result-dose,
body.printing-rx .sp-result-indication,
body.printing-rx .sp-result-note {
  color: black !important;
}

body.printing-rx .sp-result-dose {
  background: #d4edda !important;
  border-left-color: #28a745 !important;
}

body.printing-rx .sp-contra-banner {
  background: #f8d7da !important;
  border-color: #dc3545 !important;
  color: #721c24 !important;
}

body.printing-rx .sp-level-hard {
  background: #fef2f2 !important;
  border-left-color: #dc2626 !important;
}

body.printing-rx .sp-hard-banner {
  color: #991b1b !important;
}

body.printing-rx .sp-level-caution {
  background: #fffbeb !important;
  border-left-color: #f59e0b !important;
}

body.printing-rx .sp-caution-title {
  color: #92400e !important;
}

body.printing-rx .sp-interaction-hard {
  background: #fee2e2 !important;
  color: #991b1b !important;
}

body.printing-rx .sp-interaction-caution {
  background: #fef3c7 !important;
  color: #92400e !important;
}

body.printing-rx .sp-interaction-info {
  background: #dbeafe !important;
  color: #1e40af !important;
}

body.printing-rx .sp-print-header {
  display: block !important;
  text-align: left;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #000;
  page-break-inside: avoid;
  break-inside: avoid;
}

body.printing-rx .sp-print-logo {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  text-align: center;
}

body.printing-rx .sp-print-meta {
  font-size: 0.8rem;
  color: #555;
  margin-bottom: 0.75rem;
  text-align: center;
}

body.printing-rx .sp-print-disclaimer {
  font-size: 0.75rem;
  color: #666;
  font-style: italic;
  text-align: center;
  border-top: 1px solid #ddd;
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}

body.printing-rx .sp-print-patient {
  margin: 0.75rem 0;
  padding: 0.5rem;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 4px;
}

body.printing-rx .sp-print-patient-name {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

body.printing-rx .sp-print-patient-demo {
  font-size: 0.85rem;
  color: #333;
  margin-bottom: 0.25rem;
}

body.printing-rx .sp-print-patient-conditions {
  font-size: 0.8rem;
  color: #555;
}

body.printing-rx .sp-renal-badge,
body.printing-rx .sp-renal-rule-box {
  background: #fff7ed !important;
  border-color: #fdba74 !important;
  color: #7c2d12 !important;
}

body.printing-rx .sp-renal-rule-contraindicated {
  background: #fef2f2 !important;
  border-color: #fca5a5 !important;
  color: #7f1d1d !important;
}

/* Available Forms & Strengths */
.form-notes {
  font-size: 0.9em;
  color: var(--text-muted, #cbd5e1);
  margin-top: var(--space-xs);
  font-style: italic;
}

/* ============================================================================
   Smart Prescription — Structured Conflict Cards & Dose Adjustments
   ============================================================================ */

.sp-conflict-card {
  border-radius: 8px;
  margin: 8px 0;
  padding: 12px;
  border-left: 4px solid var(--border-color, #475569);
  background: rgba(30, 41, 59, 0.6);
}

.sp-conflict-card[data-severity="hard"] {
  border-left-color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
}

.sp-conflict-card[data-severity="caution"] {
  border-left-color: #f59e0b;
  background: rgba(245, 158, 11, 0.08);
}

.sp-conflict-card[data-severity="info"] {
  border-left-color: #3b82f6;
  background: rgba(59, 130, 246, 0.08);
}

.sp-conflict-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
}

.sp-conflict-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sp-conflict-hard {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.sp-conflict-caution {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.sp-conflict-info {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.sp-conflict-condition {
  color: var(--text-primary, #f1f5f9);
  font-size: 0.95rem;
}

.sp-conflict-body {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-secondary, #cbd5e1);
}

.sp-conflict-section {
  margin: 6px 0;
}

.sp-conflict-section strong {
  color: var(--text-primary, #f1f5f9);
  font-weight: 600;
}

.sp-conflict-alt {
  display: inline-block;
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  padding: 2px 8px;
  border-radius: 4px;
  margin: 2px 4px 2px 0;
  font-size: 0.85rem;
}

/* Dose adjustment inline display */
.sp-dose-adjustment {
  display: block;
  margin: 6px 0;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.sp-dose-renal {
  background: rgba(56, 189, 248, 0.1);
  border-left: 3px solid #38bdf8;
  color: #bae6fd;
}

.sp-dose-hepatic {
  background: rgba(168, 85, 247, 0.1);
  border-left: 3px solid #a855f7;
  color: #d8b4fe;
}

.sp-dose-obesity {
  background: rgba(245, 158, 11, 0.1);
  border-left: 3px solid #f59e0b;
  color: #fcd34d;
}

.sp-dose-separator {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-color, #475569), transparent);
  margin: 8px 0;
}

/* Real-time conflict highlighting on drug rows */
.sp-drug-row--conflict {
  border-color: #f59e0b !important;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
  animation: sp-row-pulse 2s ease-in-out infinite;
}

@keyframes sp-row-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3); }
  50% { box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.15); }
}

.sp-drug-row--hardstop {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3);
  animation: sp-row-pulse-hard 2s ease-in-out infinite;
}

@keyframes sp-row-pulse-hard {
  0%, 100% { box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3); }
  50% { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15); }
}

/* ===== Drug Comparison (D2) ===== */
.sp-compare-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}
.sp-compare-checkbox-label:hover {
  background: rgba(255,255,255,0.1);
  border-color: var(--accent-primary);
}
.sp-compare-checkbox-label input[type="checkbox"] {
  width: 22px;
  height: 22px;
  cursor: pointer;
  accent-color: var(--accent-primary);
}

.sp-compare-floating-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 16px 28px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: #fff;
  border: none;
  border-radius: 50px;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.sp-compare-floating-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

@media print {
  .sp-compare-checkbox-label,
  .sp-compare-floating-btn {
    display: none !important;
  }
}

.compare-modal-content {
  max-width: 1100px;
  width: 95%;
}

.compare-modal-body h2 {
  margin-bottom: var(--space-lg);
  font-size: 1.5rem;
  color: var(--text-primary);
}

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

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 600px;
}

.compare-table thead th {
  background: var(--bg-tertiary);
  padding: var(--space-md);
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.compare-table thead th:first-child {
  width: 160px;
  min-width: 140px;
}

.compare-drug-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.compare-drug-cat {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.compare-table tbody td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
  line-height: 1.5;
}

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

.compare-table tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

.compare-row-label {
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.compare-empty {
  color: var(--text-muted);
  font-style: italic;
}

.compare-sev-contraindicated {
  color: #ef4444;
  font-weight: 600;
}

.compare-sev-major {
  color: #f97316;
  font-weight: 600;
}

.compare-sev-moderate {
  color: #eab308;
  font-weight: 600;
}

.compare-sev-minor {
  color: #3b82f6;
  font-weight: 600;
}

.sp-compare-btn {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  border: none;
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-xl);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  margin-left: var(--space-md);
}

.sp-compare-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.sp-infusion-btn {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: white;
  border: none;
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-xl);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  margin-left: var(--space-md);
}

.sp-infusion-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

@media (max-width: 640px) {
  .sp-compare-btn,
  .sp-infusion-btn {
    display: block;
    width: 100%;
    margin-left: 0;
    margin-top: var(--space-md);
  }

  .compare-modal-content {
    max-width: 100%;
    width: 100%;
    margin: var(--space-sm);
  }

  .compare-table {
    font-size: 0.8rem;
  }

  .compare-table thead th:first-child {
    width: 100px;
    min-width: 90px;
  }

  .compare-table tbody td,
  .compare-table thead th {
    padding: var(--space-sm);
  }
}

/* Inline conflict icon next to drug input */
.sp-drug-conflict-icon {
  margin-left: 6px;
  font-size: 0.9rem;
  cursor: help;
}

/* ============================================================================
   Smart Prescription — Drug History Rows & Condition Dropdown
   ============================================================================ */

.sp-drug-history-row {
  background: rgba(30, 41, 59, 0.4);
  border-color: rgba(99, 102, 241, 0.25);
}

.sp-drug-history-row .sp-drug-num {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
}

.sp-drug-history-row input::placeholder {
  color: rgba(165, 180, 252, 0.5);
}

#spAddHistoryDrugBtn {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border: 1px dashed rgba(99, 102, 241, 0.4);
  margin-top: 8px;
}

#spAddHistoryDrugBtn:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.25);
  border-style: solid;
}

#spAddHistoryDrugBtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sp-condition-select option:first-child {
  color: #64748b;
  font-style: italic;
}

/* ===== Infusion Calculator ===== */
.sp-infusion-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.sp-infusion-panel h3 {
  margin-bottom: var(--space-md);
  color: var(--text-primary);
  font-size: 1.1rem;
}

.sp-infusion-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.sp-infusion-grid-simple {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
  max-width: 600px;
}

.sp-input-group {
  display: flex;
  gap: 0;
}

.sp-input-group .sp-input {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  border-right: none;
  flex: 1;
}

.sp-input-group .sp-select {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  border-left: none;
  min-width: 120px;
}

.sp-input-group .sp-input-suffix {
  display: flex;
  align-items: center;
  padding: 0 var(--space-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.sp-calc-btn {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: white;
  border: none;
  padding: 14px 32px;
  border-radius: var(--radius-xl);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.sp-calc-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.sp-infusion-results {
  margin-top: var(--space-lg);
}

.sp-infusion-result-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
}

.sp-infusion-result-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  text-align: center;
}

.sp-infusion-result-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.sp-infusion-result-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sp-infusion-result-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.sp-infusion-verify {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .sp-infusion-grid {
    grid-template-columns: 1fr;
  }
  .sp-infusion-grid-simple {
    grid-template-columns: 1fr;
  }
  .sp-infusion-result-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .sp-infusion-result-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Allergy Cross-Reactivity ===== */
.sp-allergy-chip {
  background: rgba(239, 68, 68, 0.12) !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
  color: #fca5a5 !important;
}

.sp-allergy-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.sp-allergy-section .sp-section-title {
  margin-bottom: var(--space-md);
  color: #ef4444;
  font-size: 1.05rem;
}

.sp-allergy-item {
  padding: var(--space-md);
  background: rgba(239, 68, 68, 0.04);
  border: 1px solid rgba(239, 68, 68, 0.15);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
}

.sp-allergy-item:last-child {
  margin-bottom: 0;
}

.sp-allergy-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
  flex-wrap: wrap;
}

.sp-allergy-title {
  font-weight: 600;
  color: var(--text-primary);
}

.sp-allergy-note {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-top: var(--space-xs);
}

.sp-allergy-alts {
  margin-top: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px solid rgba(239, 68, 68, 0.1);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Renal Dose Alert Badge ===== */
.sp-renal-badge {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  margin: 0 var(--space-md) var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.sp-renal-normal {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #86efac;
}

.sp-renal-mild {
  background: rgba(234, 179, 8, 0.1);
  border: 1px solid rgba(234, 179, 8, 0.3);
  color: #fde047;
}

.sp-renal-moderate {
  background: rgba(249, 115, 22, 0.1);
  border: 1px solid rgba(249, 115, 22, 0.3);
  color: #fdba74;
}

.sp-renal-severe {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.sp-renal-dialysis {
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid rgba(220, 38, 38, 0.4);
  color: #fecaca;
}

.sp-renal-icon {
  font-size: 1rem;
}

.sp-renal-data {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-left: auto;
  font-style: italic;
}

.sp-renal-nodata {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-left: auto;
  font-style: italic;
  color: var(--text-muted);
}

/* ── Renal Alert Rule Box (v33) ── */
.sp-renal-rule-box {
  margin: var(--space-sm) var(--space-md) var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  line-height: 1.5;
  border-left: 3px solid;
}
.sp-renal-rule-active {
  background: rgba(249, 115, 22, 0.08);
  border-left-color: #f97316;
  color: #fdba74;
}
.sp-renal-rule-contraindicated {
  background: rgba(239, 68, 68, 0.1);
  border-left-color: #ef4444;
  color: #fca5a5;
}
.sp-renal-rule-fallback {
  background: rgba(148, 163, 184, 0.08);
  border-left-color: #94a3b8;
  color: #cbd5e1;
}
.sp-renal-rule-header {
  font-weight: 600;
  margin-bottom: var(--space-xs);
}
.sp-renal-rule-dose,
.sp-renal-rule-max,
.sp-renal-rule-action,
.sp-renal-rule-dialysis,
.sp-renal-rule-notes {
  margin-top: var(--space-xs);
}
.sp-renal-rule-action {
  font-style: italic;
  opacity: 0.9;
}
.sp-renal-rule-notes {
  font-size: 0.78rem;
  opacity: 0.85;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: var(--space-xs);
  margin-top: var(--space-sm);
}

@media (max-width: 640px) {
  .sp-renal-badge {
    font-size: 0.8rem;
    padding: var(--space-xs) var(--space-sm);
  }
}

/* ===== Smart Infusion Engine (v48) ===== */
.sp-infusion-smart-card {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-top: var(--space-lg);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.sp-infusion-smart-header {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-primary);
  padding-bottom: var(--space-sm);
  margin-bottom: var(--space-md);
  border-bottom: 2px solid var(--accent-primary);
}

.sp-infusion-smart-section {
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sp-infusion-smart-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.sp-infusion-smart-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sp-infusion-smart-value {
  font-size: 1rem;
  color: var(--text-primary);
  line-height: 1.5;
}

.sp-infusion-smart-freq {
  color: var(--accent-secondary);
  font-weight: 600;
}

.sp-infusion-smart-warning {
  color: #fca5a5;
  font-weight: 600;
  margin-top: 4px;
  padding: 6px 10px;
  background: rgba(220, 38, 38, 0.15);
  border-radius: 4px;
  border-left: 3px solid #ef4444;
}

.sp-infusion-smart-steps {
  margin: 0;
  padding-left: 20px;
  color: var(--text-primary);
}

.sp-infusion-smart-steps li {
  margin-bottom: 6px;
  line-height: 1.5;
}

/* Rate Converter */
.sp-rate-converter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
}

.sp-rate-converter span {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.sp-rate-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  min-width: 70px;
}

.sp-rate-btn:hover {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.sp-rate-btn strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-top: 2px;
}

.sp-rate-btn:hover strong {
  color: #fff;
}

@media (max-width: 640px) {
  .sp-infusion-smart-card {
    padding: var(--space-md);
  }
  .sp-rate-converter {
    justify-content: center;
  }
  .sp-rate-btn {
    min-width: 60px;
    padding: 5px 8px;
  }
}

/* Mobile accessibility & overflow fixes — v48 QA patch */
@media (max-width: 640px) {
  .sp-header-actions {
    flex-wrap: wrap;
    width: 100%;
  }
  .sp-header-actions button {
    flex: 1 1 auto;
    min-width: 120px;
  }
  .sp-field input,
  .sp-field select {
    min-height: 44px;
    font-size: 16px; /* prevent iOS zoom on focus */
  }
  .sp-rate-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 12px;
  }
  .sp-calc-btn {
    min-height: 44px;
    width: 100%;
  }
}

@media print {
  .sp-infusion-smart-card {
    break-inside: avoid;
    background: #fff !important;
    color: #000 !important;
    border: 1px solid #ccc;
  }
  .sp-infusion-smart-header {
    color: #000 !important;
    border-bottom-color: #333;
  }
  .sp-infusion-smart-label {
    color: #444 !important;
  }
  .sp-infusion-smart-value {
    color: #000 !important;
  }
}

/* =============================================
   Smart Rx — Stability & Storage Section
   ============================================= */
.sp-stability-section {
  margin-top: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(30,64,175,0.08) 0%, rgba(30,64,175,0.04) 100%);
  border: 1px solid rgba(59,130,246,0.25);
  border-radius: 12px;
}
.sp-stability-header {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #60a5fa;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sp-stability-item {
  font-size: 0.8rem;
  color: #cbd5e1;
  margin-bottom: 6px;
  line-height: 1.5;
}
.sp-stability-item:last-child { margin-bottom: 0; }
.sp-stability-item strong {
  color: #93c5fd;
}
.sp-stability-special {
  background: rgba(239,68,68,0.12);
  border-left: 3px solid #ef4444;
  padding: 8px 10px;
  border-radius: 6px;
  margin-top: 4px;
}
.sp-stability-info {
  background: rgba(59,130,246,0.08);
  border-left: 3px solid #3b82f6;
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 4px;
}

/* =============================================
   Smart Rx — Preparation & Administration Section
   ============================================= */
.sp-prep-section {
  margin-top: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(6,95,70,0.08) 0%, rgba(6,95,70,0.04) 100%);
  border: 1px solid rgba(16,185,129,0.25);
  border-radius: 12px;
}
.sp-prep-header {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #34d399;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sp-prep-item {
  font-size: 0.8rem;
  color: #cbd5e1;
  margin-bottom: 6px;
  line-height: 1.5;
}
.sp-prep-item:last-child { margin-bottom: 0; }
.sp-prep-item strong {
  color: #6ee7b7;
}
.sp-prep-rate {
  background: rgba(16,185,129,0.1);
  border-left: 3px solid #10b981;
  padding: 8px 10px;
  border-radius: 6px;
  margin-top: 4px;
}
.sp-prep-compat {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sp-prep-compat-ok {
  background: rgba(16,185,129,0.08);
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(16,185,129,0.2);
}
.sp-prep-compat-no {
  background: rgba(239,68,68,0.08);
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(239,68,68,0.2);
}
.sp-prep-compat-no strong { color: #fca5a5; }

/* =============================================
   Smart Rx — Enhanced Interactions Section
   ============================================= */
.sp-enhanced-interactions-section {
  margin-top: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(139,92,246,0.06) 0%, rgba(59,130,246,0.04) 100%);
  border: 1px solid rgba(139,92,246,0.25);
  border-radius: 12px;
}
.sp-enhanced-interactions-header {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a78bfa;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sp-interaction-type-card {
  margin-bottom: 10px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid;
}
.sp-interaction-type-card:last-child { margin-bottom: 0; }
.sp-interaction-type-card.sp-sev-info {
  background: rgba(59,130,246,0.06);
  border-color: rgba(59,130,246,0.2);
}
.sp-interaction-type-card.sp-sev-caution {
  background: rgba(245,158,11,0.06);
  border-color: rgba(245,158,11,0.25);
}
.sp-interaction-type-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.sp-interaction-type-icon {
  font-size: 1rem;
}
.sp-interaction-type-label {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #e2e8f0;
}
.sp-interaction-type-explanation {
  font-size: 0.75rem;
  color: #94a3b8;
  line-height: 1.5;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(148,163,184,0.1);
  font-style: italic;
}
.sp-interaction-type-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sp-interaction-type-item {
  font-size: 0.78rem;
  color: #cbd5e1;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(15,23,42,0.4);
  line-height: 1.4;
}
.sp-interaction-type-item strong {
  color: #e2e8f0;
}
.sp-interaction-type-detail {
  color: #94a3b8;
}
.sp-interaction-type-more {
  font-size: 0.7rem;
  color: #64748b;
  font-style: italic;
  margin-top: 4px;
  padding: 4px 8px;
}

/* =============================================
   Smart Rx — Off-Label Uses Section
   ============================================= */
.sp-offlabel-section {
  margin-top: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(217,119,6,0.08) 0%, rgba(217,119,6,0.04) 100%);
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: 12px;
}
.sp-offlabel-header {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fbbf24;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sp-offlabel-item {
  margin-bottom: 12px;
  padding: 12px;
  background: rgba(15,23,42,0.4);
  border-radius: 10px;
  border: 1px solid rgba(245,158,11,0.15);
  transition: border-color 0.2s;
}
.sp-offlabel-item:last-child { margin-bottom: 0; }
.sp-offlabel-item:hover {
  border-color: rgba(245,158,11,0.3);
}
.sp-offlabel-use {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fcd34d;
  margin-bottom: 6px;
  line-height: 1.4;
}
.sp-offlabel-evidence {
  font-size: 0.76rem;
  color: #cbd5e1;
  line-height: 1.5;
  margin-bottom: 4px;
}
.sp-offlabel-source {
  font-size: 0.7rem;
  color: #94a3b8;
  line-height: 1.4;
  padding-top: 4px;
  border-top: 1px solid rgba(148,163,184,0.08);
}
.sp-offlabel-more {
  font-size: 0.72rem;
  color: #64748b;
  font-style: italic;
  text-align: center;
  padding-top: 6px;
}

/* Print styles for new sections */
@media print {
  .sp-stability-section,
  .sp-prep-section,
  .sp-enhanced-interactions-section,
  .sp-offlabel-section {
    background: #fff !important;
    color: #000 !important;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
  .sp-stability-header,
  .sp-prep-header,
  .sp-enhanced-interactions-header,
  .sp-offlabel-header {
    color: #333 !important;
  }
  .sp-stability-item,
  .sp-prep-item,
  .sp-interaction-type-item,
  .sp-offlabel-evidence {
    color: #222 !important;
  }
  .sp-interaction-type-explanation,
  .sp-offlabel-source {
    color: #555 !important;
  }
  .sp-do-not-use {
    background: #fff !important;
    color: #000 !important;
    border: 2px solid #dc2626 !important;
    break-inside: avoid;
  }
  .sp-dnu-header h4 {
    color: #dc2626 !important;
  }
  .sp-dnu-item {
    color: #222 !important;
  }
}

/* ── Do Not Use / Safety Warning Banner ── */
.sp-do-not-use {
  margin: 1rem 0;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  background: linear-gradient(135deg, rgba(127, 29, 29, 0.4) 0%, rgba(69, 10, 10, 0.3) 100%);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.sp-dnu-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(239, 68, 68, 0.2);
  background: rgba(220, 38, 38, 0.08);
}

.sp-dnu-header-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.sp-dnu-header h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #fca5a5;
  letter-spacing: -0.2px;
}

.sp-dnu-subtitle {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: #f87171;
  opacity: 0.9;
}

.sp-dnu-hard-group,
.sp-dnu-caution-group {
  padding: 0.75rem 1.25rem;
}

.sp-dnu-hard-group {
  border-bottom: 1px solid rgba(239, 68, 68, 0.15);
}

.sp-dnu-group-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 0.5rem;
  opacity: 0.85;
}

.sp-dnu-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sp-dnu-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.25);
  border: 1px solid rgba(148, 163, 184, 0.08);
}

.sp-dnu-item.sp-dnu-hard {
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(239, 68, 68, 0.2);
}

.sp-dnu-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.sp-dnu-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sp-dnu-body strong {
  color: #e2e8f0;
  font-size: 0.88rem;
}

.sp-dnu-text {
  color: #cbd5e1;
  font-size: 0.82rem;
  line-height: 1.4;
}

.sp-dnu-detail {
  color: #94a3b8;
  font-size: 0.75rem;
  font-style: italic;
  line-height: 1.4;
}


/* ── Intensive Warning Box (Smart Prescription) ── */
.sp-intensive-warning {
  margin: 0 0 1.25rem;
  border-radius: var(--radius-lg);
  border: 2px solid rgba(220, 38, 38, 0.5);
  background: linear-gradient(135deg, rgba(69, 10, 10, 0.6) 0%, rgba(30, 5, 5, 0.5) 100%);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.sp-iw-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: rgba(220, 38, 38, 0.15);
  border-bottom: 1px solid rgba(239, 68, 68, 0.25);
}

.sp-iw-header-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.sp-iw-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: #fca5a5;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.sp-iw-body {
  padding: 1rem 1.25rem;
}

.sp-iw-general {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(239, 68, 68, 0.15);
}

.sp-iw-general h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: #f87171;
  font-weight: 700;
}

.sp-iw-general p {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #e2e8f0;
  line-height: 1.5;
}

.sp-iw-general ul {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
  font-size: 0.82rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.sp-iw-general li {
  margin-bottom: 0.25rem;
}

.sp-iw-call {
  background: rgba(220, 38, 38, 0.1);
  border-left: 3px solid #ef4444;
  padding: 0.6rem 0.75rem;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 0.84rem !important;
  color: #fecaca !important;
}

.sp-iw-drug-block {
  margin-bottom: 0.75rem;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.sp-iw-drug-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  background: rgba(220, 38, 38, 0.2);
  font-size: 0.9rem;
  color: #fecaca;
}

.sp-iw-skull {
  font-size: 1.1rem;
}

.sp-iw-drug-body {
  padding: 0.75rem 0.9rem;
  background: rgba(15, 23, 42, 0.3);
}

.sp-iw-verdict {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #f87171;
}

.sp-iw-complications {
  margin: 0 0 0.6rem;
  padding-left: 1.25rem;
  font-size: 0.8rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.sp-iw-complications li {
  margin-bottom: 0.2rem;
}

.sp-iw-contra {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  color: #94a3b8;
  line-height: 1.4;
}

.sp-iw-alt {
  margin: 0;
  font-size: 0.8rem;
  color: #86efac;
  background: rgba(34, 197, 94, 0.08);
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border-left: 2px solid #22c55e;
  line-height: 1.4;
}

/* ── Modal Warning Banner (Drug Detail) ── */
.modal-warning-banner {
  margin: 0 0 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 2px solid;
}

.modal-warning-oncology {
  background: linear-gradient(135deg, rgba(69, 10, 10, 0.5) 0%, rgba(30, 5, 5, 0.4) 100%);
  border-color: rgba(220, 38, 38, 0.4);
}

.modal-warning-insulin {
  background: linear-gradient(135deg, rgba(69, 50, 10, 0.5) 0%, rgba(30, 20, 5, 0.4) 100%);
  border-color: rgba(234, 179, 8, 0.4);
}

.modal-warning-title {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  letter-spacing: 0.3px;
}

.modal-warning-oncology .modal-warning-title {
  color: #fca5a5;
}

.modal-warning-insulin .modal-warning-title {
  color: #fde047;
}

.modal-warning-message {
  font-size: 0.85rem;
  line-height: 1.5;
  color: #e2e8f0;
}

/* ── Card-level warning styles ── */
.drug-indication-warning {
  color: #fca5a5 !important;
  font-weight: 500;
  background: rgba(220, 38, 38, 0.08);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  border-left: 2px solid #ef4444;
}

/* ── Suppressed dose display ── */
.sp-suppressed-dose {
  display: block;
  color: #fca5a5;
  font-weight: 600;
  background: rgba(220, 38, 38, 0.1);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  border-left: 2px solid #ef4444;
  margin: 0.25rem 0;
}

/* Print styles for intensive warning */
@media print {
  .sp-intensive-warning {
    background: #fff !important;
    color: #000 !important;
    border: 2px solid #dc2626 !important;
    break-inside: avoid;
  }
  .sp-iw-header h3 {
    color: #dc2626 !important;
  }
  .sp-iw-general p,
  .sp-iw-general li,
  .sp-iw-complications li {
    color: #222 !important;
  }
  .sp-iw-call {
    color: #7f1d1d !important;
    background: #fee2e2 !important;
  }
  .modal-warning-banner {
    background: #fff !important;
    border: 2px solid #dc2626 !important;
    break-inside: avoid;
  }
  .modal-warning-message {
    color: #222 !important;
  }
}


/* ===== Hybrid Bank chrome ===== */
.logo-text h1 { color: var(--gold); letter-spacing: 0.02em; }
.logo-text p { color: var(--accent); font-weight: 600; }
.hybrid-nav-btn { background: linear-gradient(135deg, #155e75, #0e7490); }
.hybrid-nav-gold { background: linear-gradient(135deg, #b45309, #d97706); }
.hybrid-nav-btn:hover, .hybrid-nav-gold:hover { filter: brightness(1.12); }
.source-badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; padding: 0.15rem 0.5rem; border-radius: 999px;
  margin-left: 0.4rem; vertical-align: middle;
}
.source-both { background: #155dfc33; color: #93c5fd; border: 1px solid #60a5fa66; }
.source-clinical { background: #854d0e33; color: #fbbf24; border: 1px solid #fbbf2466; }
.source-drugs { background: #5b21b633; color: #c4b5fd; border: 1px solid #8b5cf666; }
.hybrid-clinical-section {
  border: 1px solid #fbbf2433;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-radius: 14px;
  padding: 1rem;
  margin-top: 0.75rem;
}
.hybrid-clinical-section h3 { color: var(--gold); margin-top: 0; }
.filter-btn.quick-filter {
  background: #1e2937;
  border: 1px solid #38bdf866;
  color: #e0f2fe;
}
.filter-btn.quick-filter.active, .filter-btn.active {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-color: #818cf8;
  color: #fff;
}
.header {
  background: linear-gradient(90deg, #0a0f1a 0%, #111827 50%, #1e1b4b 100%);
  border-bottom: 1px solid #fbbf2433;
}
.stat-value { color: var(--gold); }
