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

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666666;
  --border: #e0e0e0;
  --accent: #b71c1c;
  --accent-light: #ffebee;
  --warning: #e65100;
  --warning-light: #fff3e0;
  --info: #1565c0;
  --info-light: #e3f2fd;
  --neutral: #37474f;
  --neutral-light: #eceff1;
  --success: #2e7d32;
  --success-light: #e8f5e9;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
header {
  background: var(--accent);
  color: white;
  padding: 16px 24px;
  box-shadow: var(--shadow);
}
.header-inner { max-width: 900px; margin: 0 auto; }
header h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.5px; display: flex; align-items: center; gap: 8px; }
.beta-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 1px;
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  vertical-align: middle;
  text-transform: uppercase;
}
header .subtitle { font-size: 0.85rem; opacity: 0.85; margin-top: 2px; }

/* === Main === */
main {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}

/* === Dev Banner === */
.dev-banner {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-left: 4px solid #ffa000;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #5d4037;
  margin-bottom: 16px;
}
.dev-banner strong { color: #e65100; }

/* === Upload Area === */
.upload-area { max-width: 600px; margin: 40px auto; }
.upload-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  background: var(--surface);
  transition: border-color 0.2s, background 0.2s;
}
.upload-box.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-icon { font-size: 2.5rem; margin-bottom: 12px; }
.upload-or { color: var(--text-muted); font-size: 0.85rem; margin: 12px 0; }
.upload-btn {
  display: inline-block;
  padding: 10px 24px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
  font-family: var(--font);
  transition: opacity 0.2s;
}
.upload-btn:hover { opacity: 0.9; }

.paste-area { margin-top: 16px; }
.paste-area textarea {
  width: 100%;
  height: 200px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
}
.paste-actions { margin-top: 8px; display: flex; gap: 8px; }

.sample-link { text-align: center; margin-top: 16px; }
.link-btn {
  background: none;
  border: none;
  color: var(--info);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: underline;
  font-family: var(--font);
}

.error {
  background: var(--accent-light);
  color: var(--accent);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-top: 16px;
  font-size: 0.9rem;
}

/* === Buttons === */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: var(--font);
  background: var(--accent);
  color: white;
  transition: opacity 0.2s;
}
.btn:hover { opacity: 0.9; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); opacity: 1; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* === Toolbar === */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.view-toggle { display: flex; gap: 4px; }
.view-toggle .btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.view-toggle .btn:not(.active) { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

/* === Emergency Card === */
.emergency-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.card-header {
  background: var(--accent);
  color: white;
  padding: 12px 20px;
  font-weight: 700;
}
.card-badge { font-size: 1.1rem; letter-spacing: 1px; }
.card-header .beta-badge {
  background: rgba(255,255,255,0.25);
  font-size: 0.55rem;
  margin-left: 8px;
}

.patient-banner {
  padding: 16px 20px;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}
.patient-name { font-size: 1.3rem; font-weight: 700; }
.patient-details { font-size: 0.95rem; color: var(--text-muted); margin-top: 4px; }

/* === Card Sections === */
.card-section { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-section:empty { display: none; }

.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-critical .section-title { color: var(--accent); }
.section-warning .section-title { color: var(--warning); }
.section-info .section-title { color: var(--info); }
.section-neutral .section-title { color: var(--neutral); }

.section-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

/* === Resource Items === */
.resource-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--bg);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.resource-item:last-child { border-bottom: none; }
.resource-name { font-weight: 500; }
.resource-detail { font-size: 0.85rem; color: var(--text-muted); text-align: right; flex-shrink: 0; }

.status-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-active { background: var(--accent-light); color: var(--accent); }
.status-resolved, .status-inactive, .status-completed { background: var(--success-light); color: var(--success); }
.status-on-hold { background: var(--warning-light); color: var(--warning); }
.status-default { background: var(--neutral-light); color: var(--neutral); }

/* === Severity Badges === */
.severity-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  animation: pulse-subtle 2s ease-in-out infinite;
}
.severity-high {
  background: var(--accent);
  color: white;
}
.severity-warning {
  background: var(--warning);
  color: white;
}
@keyframes pulse-subtle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

/* Critical / warning item highlighting */
.item-critical {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  margin-left: -11px;
  background: rgba(183, 28, 28, 0.03);
}
.item-warning {
  border-left: 3px solid var(--warning);
  padding-left: 8px;
  margin-left: -11px;
  background: rgba(230, 81, 0, 0.03);
}

/* NKDA (No Known Drug Allergies) — standard EMS abbreviation */
.nkda {
  color: var(--success);
  font-weight: 600;
  font-style: normal;
}

/* === Collapsible Sections === */
.collapsible-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  transition: background 0.15s;
}
.collapsible-header:hover { background: var(--bg); }
.collapsible-header .section-title { margin-bottom: 0; }
.collapsible-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 12px;
}
.collapsible-arrow { transition: transform 0.2s; color: var(--text-muted); }
.collapsible-header.open .collapsible-arrow { transform: rotate(90deg); }
.collapsible-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.collapsible-body.open { max-height: 2000px; }
.collapsible-body-inner { padding: 8px 20px 16px; }

/* === Card Footer === */
.card-footer {
  padding: 12px 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
}

/* === Detail View === */
.detail-view { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.detail-section { padding: 20px; border-bottom: 1px solid var(--border); }
.detail-section:last-child { border-bottom: none; }
.detail-section h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
  color: var(--accent);
}
.detail-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.detail-table th {
  text-align: left;
  padding: 6px 8px;
  background: var(--bg);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-muted);
}
.detail-table td { padding: 8px; border-bottom: 1px solid var(--bg); vertical-align: top; }
.detail-table tr:last-child td { border-bottom: none; }

/* === JSON View === */
.json-view {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  overflow-x: auto;
}
.json-view pre {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* === Footer === */
footer {
  padding: 24px 16px 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  max-width: 900px;
  margin: 0 auto;
}
footer a { color: var(--accent); }
.footer-sources, .footer-disclaimer { margin-bottom: 16px; }
.footer-sources h4, .footer-disclaimer h4 {
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 8px;
}
.footer-sources ul {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 4px 16px;
}
.footer-sources li { padding: 2px 0; }
.footer-sources a { font-weight: 500; }
.footer-disclaimer p {
  margin-bottom: 10px;
  line-height: 1.6;
  text-align: justify;
}
.footer-disclaimer p strong:first-child {
  color: var(--text);
  white-space: nowrap;
}
.footer-copy {
  text-align: center;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* === Status Indicator === */
.status-indicator {
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
}
.si-bar {
  height: 4px;
  border-radius: 2px;
  margin-bottom: 8px;
}
.si-bar-red { background: linear-gradient(90deg, var(--accent) 0%, #e53935 100%); }
.si-bar-yellow { background: linear-gradient(90deg, #f9a825 0%, #ffb300 100%); }
.si-bar-green { background: linear-gradient(90deg, #43a047 0%, #66bb6a 100%); }
.si-items { display: flex; flex-wrap: wrap; gap: 6px; }
.si-item {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.si-red { background: var(--accent-light); color: var(--accent); }
.si-yellow { background: var(--warning-light); color: var(--warning); }
.si-green { background: var(--success-light); color: var(--success); }

/* === Privacy / Redaction === */
.sensitive { transition: all 0.2s; }
.sensitive.redacted {
  filter: blur(8px);
  user-select: none;
  pointer-events: none;
}
.btn-privacy {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  white-space: nowrap;
}
.btn-privacy.privacy-active {
  background: var(--neutral) !important;
  color: white !important;
  border-color: var(--neutral) !important;
}
.toolbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* === Code Badges & Links === */
.code-link, .code-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  font-weight: 500;
  vertical-align: middle;
  margin-left: 4px;
  white-space: nowrap;
}
.code-link {
  background: var(--info-light);
  color: var(--info);
  text-decoration: none;
  border: 1px solid rgba(21, 101, 192, 0.2);
  transition: background 0.15s, border-color 0.15s;
}
.code-link:hover {
  background: #bbdefb;
  border-color: var(--info);
  text-decoration: none;
}
.code-badge {
  background: var(--neutral-light);
  color: var(--neutral);
  border: 1px solid var(--border);
}
/* Primary code display (when no human-readable text exists) */
.code-link-primary, .code-badge-primary {
  font-size: 0.85rem;
  padding: 2px 8px;
  margin-left: 2px;
}
.code-system-tag {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-right: 2px;
}
.text-muted { color: var(--text-muted); }

/* === Utility === */
.hidden { display: none !important; }

/* === Responsive === */
@media (max-width: 600px) {
  header { padding: 12px 16px; }
  main { padding: 16px 12px; }
  .emergency-card { border-radius: 0; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .view-toggle { justify-content: center; }
  .resource-item { flex-direction: column; gap: 2px; }
  .resource-detail { text-align: left; }
  .detail-table { font-size: 0.8rem; }
  .detail-table th, .detail-table td { padding: 6px 4px; }
}

/* === Print / PDF === */
.btn-print {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  white-space: nowrap;
}

@media print {
  /* Hide UI chrome */
  header, .toolbar, .upload-area, .view-toggle, #paste-area,
  .btn-print, .btn-privacy, #back-btn, .sample-link,
  .footer-sources, .footer-copy, .dev-banner { display: none !important; }

  /* Reset layout */
  body { background: white; font-size: 10pt; }
  main { max-width: 100%; padding: 0; margin: 0; }
  .emergency-card { box-shadow: none; border: 1px solid #ccc; }

  /* Force all collapsible sections open */
  .collapsible-body { max-height: none !important; overflow: visible !important; }
  .collapsible-header { cursor: default; }
  .collapsible-arrow { display: none; }

  /* Show card view, hide others */
  #card-view { display: block !important; }
  #detail-view, #json-view { display: none !important; }
  #summary { display: block !important; }

  /* Ensure severity badges print with color */
  .severity-badge, .status-badge, .si-item, .si-bar,
  .code-link, .code-badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .severity-badge { animation: none; }

  /* Item highlighting */
  .item-critical { border-left: 3px solid #b71c1c !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .item-warning { border-left: 3px solid #e65100 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Make code links look like plain badges (not clickable in PDF) */
  .code-link { color: #1565c0 !important; text-decoration: none; }

  /* Privacy: if redacted, show placeholder instead of blur (blur doesn't print) */
  .sensitive.redacted { filter: none; color: transparent; background: #ddd; border-radius: 3px; }

  /* Page break control */
  .card-section { page-break-inside: avoid; }
  .collapsible { page-break-inside: avoid; }

  /* Print header */
  .card-header::after {
    content: ' — Ausdruck vom ' attr(data-print-date);
    font-weight: normal;
    font-size: 0.8em;
    opacity: 0.7;
  }

  /* Disclaimer prints at bottom */
  .footer-disclaimer {
    display: block !important;
    font-size: 7pt;
    border-top: 1px solid #ccc;
    padding-top: 8px;
    margin-top: 16px;
    page-break-inside: avoid;
  }
}
