/* MedTrain AI - Main stylesheet */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0284c7;
  --info-bg: #e0f2fe;
  --live: #16a34a;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.08), 0 8px 10px -6px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }

.container { max-width: 1280px; margin: 0 auto; padding: 0 16px; }

/* ===== Topbar ===== */
.topbar {
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-inner { display: flex; align-items: center; gap: 14px; height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; flex-shrink: 0; }
.brand-logo { font-size: 18px; }
.brand-name { font-size: 15px; }

/* Hauptnavigation: einreihig, kein Wrap mehr */
.nav { display: flex; gap: 2px; flex: 1; align-items: center; min-width: 0; }
.nav-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  color: var(--text-muted); transition: all .15s;
  white-space: nowrap; text-decoration: none;
  background: transparent; border: 0; cursor: pointer; font-family: inherit;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link.nav-live.active { background: var(--live); }
.nav-ico { font-size: 14px; }

/* Verwaltungs-Dropdown */
.nav-dropdown { position: relative; }
.nav-dropdown-trigger.active { background: rgba(15,23,42,0.06); color: var(--text); }
.nav-dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.06);
  padding: 6px;
  display: none;
  z-index: 40;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 6px;
  font-size: 13.5px; color: var(--text);
  text-decoration: none;
  transition: background .12s;
}
.nav-dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-dropdown-item.active { background: rgba(37,99,235,0.10); color: var(--primary); font-weight: 600; }
.nav-dropdown-item .nav-ico { font-size: 15px; width: 18px; text-align: center; }

/* User-Menü */
.user-menu { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.user-name {
  font-size: 13px; color: var(--text-muted);
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-decoration: none;
  padding: 4px 6px; border-radius: 6px;
  transition: background .12s, color .12s;
}
.user-name:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.logout-form { display: inline; }

/* Mobile-Toggle */
.nav-toggle {
  display: none;
  background: transparent; border: 0; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: 6px;
  margin-left: auto;
}
.nav-toggle:hover { background: var(--surface-2); color: var(--text); }

/* Auf engen Viewports: Burger zeigen, Nav verstecken bis auf-getoggelt */
@media (max-width: 1024px) {
  .nav-toggle { display: inline-flex; align-items: center; }
  .nav {
    position: absolute;
    top: 56px; left: 0; right: 0;
    background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
    padding: 10px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    display: none;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
  .topbar.nav-open .nav { display: flex; }
  .nav-link { padding: 10px 14px; font-size: 14px; }
  .nav-dropdown { width: 100%; }
  .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border: 0;
    border-left: 2px solid var(--border);
    border-radius: 0;
    margin: 4px 0 4px 16px;
    padding: 4px 0;
    min-width: 0;
  }
  .nav-dropdown-trigger { width: 100%; justify-content: flex-start; }
  .nav-dropdown.open .nav-dropdown-menu { display: block; }
  .user-menu .user-name { max-width: 120px; }
}

@media (max-width: 600px) {
  .brand-name { display: none; }
  .user-menu .user-name { display: none; }
  .topbar-inner { gap: 8px; padding-left: 12px; padding-right: 12px; }
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 9999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-muted); }
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-orgleitung { background: #ede9fe; color: #6d28d9; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-easy { background: #dcfce7; color: #15803d; }
.badge-medium { background: #fef3c7; color: #b45309; }
.badge-hard { background: #fee2e2; color: #b91c1c; }

/* ===== Main ===== */
.main-content { padding: 24px 0 64px; min-height: calc(100vh - 56px - 60px); }
.page { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header h1 { font-size: 28px; }
.page-header .lead { color: var(--text-muted); margin: 4px 0 0; }

.footer { padding: 24px 0; color: var(--text-soft); text-align: center; border-top: 1px solid var(--border); }

/* ===== Card ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: 16px; font-weight: 600; margin: 0; }
.card-sub { color: var(--text-muted); font-size: 13px; margin: 4px 0 0; }

/* ===== Form ===== */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, label.label { font-size: 13px; font-weight: 600; color: var(--text); }
.hint { font-size: 12px; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=search], textarea, select {
  width: 100%; padding: 10px 12px; font-size: 14px; font-family: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea { min-height: 80px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .row, .row-3 { grid-template-columns: 1fr; } }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius); font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid transparent; transition: all .15s; text-decoration: none; line-height: 1; }
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }

/* ===== Alerts ===== */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 12px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.alert-error, .alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #fde68a; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #bae6fd; }
.flash-container { padding-top: 16px; }

/* ===== Tables ===== */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: var(--surface-2); font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tr:hover td { background: rgba(241,245,249,.5); }
.table-actions { white-space: nowrap; text-align: right; }

/* ===== Auth ===== */
.auth-body { background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%); min-height: 100vh; }
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { background: #fff; border-radius: var(--radius-lg); padding: 32px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); }
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; margin-bottom: 24px; color: var(--text); }
.auth-logo { font-size: 22px; }
.auth-title { font-size: 22px; margin: 0 0 6px; }
.auth-sub { color: var(--text-muted); margin: 0 0 20px; font-size: 14px; }
.auth-links { margin-top: 16px; text-align: center; font-size: 13px; color: var(--text-muted); }
.auth-links a { color: var(--text-muted); }
.auth-links span { margin: 0 6px; }
.auth-footer { color: rgba(255,255,255,.6); font-size: 12px; margin-top: 16px; }

/* ===== Grid layouts ===== */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ===== Stat cards ===== */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; }
.stat-label { font-size: 12px; text-transform: uppercase; color: var(--text-muted); letter-spacing: .03em; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; }

/* ===== Empty / Loading ===== */
.empty { padding: 48px 24px; text-align: center; color: var(--text-muted); border: 2px dashed var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.empty .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty h3 { color: var(--text); }
.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Vital monitor ===== */
.vital-monitor { background: #0c1117; color: #e5e7eb; border-radius: var(--radius-lg); padding: 16px; font-family: "SF Mono", Menlo, Consolas, monospace; }
.vital-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; }
.vital { padding: 8px 12px; background: rgba(255,255,255,0.04); border-radius: var(--radius); border: 1px solid rgba(255,255,255,0.08); }
.vital-label { font-size: 10px; text-transform: uppercase; color: #94a3b8; letter-spacing: .05em; }
.vital-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.vital-unit { font-size: 11px; color: #94a3b8; margin-left: 4px; }
.vital-rr { color: #34d399; }
.vital-hr { color: #f87171; }
.vital-spo2 { color: #60a5fa; }
.vital-af { color: #fbbf24; }
.vital-gcs { color: #c4b5fd; }
.vital-temp { color: #fb923c; }
.vital-bz { color: #f472b6; }

/* ===== Simulation log ===== */
.sim-log { display: flex; flex-direction: column; gap: 12px; max-height: 480px; overflow-y: auto; padding: 4px; }
.sim-log-entry { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; border-left: 3px solid var(--accent); }
.sim-log-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.sim-log-input { font-size: 13px; font-weight: 600; }
.sim-log-reaction { font-size: 13px; color: var(--text-muted); margin-top: 4px; font-style: italic; }

/* ===== Misc ===== */
.muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mt-4 { margin-top: 16px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 9999px; font-size: 11px; background: var(--surface-2); color: var(--text-muted); }
.list-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.list-cards .card { display: flex; flex-direction: column; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 16px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* Installer */
.install-shell { background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%); min-height: 100vh; padding: 32px 16px; }
.install-card { max-width: 720px; margin: 0 auto; background: #fff; border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-lg); }
.install-steps { display: flex; gap: 8px; margin-bottom: 24px; }
.install-step { flex: 1; padding: 8px 12px; border-radius: var(--radius); background: var(--surface-2); color: var(--text-muted); font-size: 12px; font-weight: 600; text-align: center; border: 1px solid var(--border); }
.install-step.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.install-step.done { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
