:root {
  --bg: #e8f1fb;
  --panel: #ffffff;
  --panel-2: #f1f6fc;
  --text: #10243f;
  --muted: #5c718c;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #16a34a;
  --green-hover: #15803d;
  --red: #dc2626;
  --red-hover: #b91c1c;
  --border: #dbe7f3;
  --shadow: 0 8px 30px rgba(30, 64, 120, .10);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg) url("bg.png") center / cover fixed no-repeat;
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 14px rgba(30, 64, 120, .06);
  flex: 0 0 auto;
}
.topbar .logo {
  font-size: 22px;
}
.topbar .logo-img { height: 34px; width: auto; display: block; }
.topbar .logo-text {
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 20px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  padding: 6px 12px;
  border-radius: 8px;
}
.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}
.topbar .status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .3s;
}
.dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.offline { background: var(--red); }

.container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 14px 20px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Anruf-Layout: Video links (groß), Chat rechts */
.call-layout {
  display: flex;
  gap: 16px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}
.video-col {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.side-col {
  flex: 0 0 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}
/* feste Karten dürfen nicht zusammengedrückt werden */
.side-col > .patient-card,
.side-col > .notes-card,
.side-col > #histCard {
  flex: 0 0 auto;
}
.chat-col {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  flex: 1 0 auto;
  min-height: 300px;
  box-shadow: var(--shadow);
}
@media (max-width: 900px) {
  .call-layout { flex-direction: column; }
  .side-col { flex: 0 0 auto; overflow: visible; }
  .chat-col { flex: 0 0 auto; height: 260px; min-height: 0; }
}

/* Patientendaten-Karte (Arzt) */
.patient-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  flex: 0 0 auto;
  box-shadow: var(--shadow);
}
.patient-card h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.patient-card .empty { color: var(--muted); font-size: 14px; }
.pdata { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 13.5px; }
.pdata dt { color: var(--muted); }
.pdata dd { margin: 0; word-break: break-word; font-weight: 600; }
.ecard-thumb {
  margin-top: 10px;
  width: 100%;
  max-height: 150px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
  cursor: zoom-in;
  display: block;
}

/* Notizen (Arzt) */
.notes-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  flex: 0 0 auto;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 15px;
}
.notes-head .chev { transition: transform .2s; color: var(--muted); }
.notes-card.open .notes-head .chev { transform: rotate(180deg); }
.notes-body { display: none; padding: 0 12px 12px; }
.notes-card.open .notes-body { display: block; }
.notes-body textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.notes-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.notes-saved { color: var(--green); font-size: 12.5px; }

/* Chat */
.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chat-msg .who { display: block; font-size: 11px; opacity: .7; margin-bottom: 2px; }
.chat-msg.mine { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.theirs { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.chat-msg.system { align-self: center; background: rgba(148,163,184,.12); color: var(--muted); font-size: 12.5px; text-align: center; }
.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}
.chat-input input:focus { outline: 2px solid var(--primary); }
.chat-input button { padding: 10px 16px; }

/* Startseite */
.landing {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 24px;
}
@media (max-width: 720px) { .landing { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  text-decoration: none;
  color: var(--text);
  display: block;
  box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s, background .15s;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
  background: var(--panel-2);
}
.card .icon { font-size: 46px; }
.card h2 { margin: 12px 0 6px; }
.card p { color: var(--muted); margin: 0; }

/* Anruf-Bereich */
.videos {
  position: relative;
  background: #0b1220;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  box-shadow: var(--shadow);
}
#callStep, #formStep { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#formStep { overflow-y: auto; }
#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
#localVideo {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 26%;
  max-width: 260px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,.35);
  object-fit: cover;
  background: #111;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  background: linear-gradient(180deg, rgba(15,32,60,.78), rgba(15,32,60,.9));
  padding: 24px;
  color: #f1f5f9;
}
.overlay.hidden { display: none; }
.overlay h2 { margin: 0; font-size: 24px; color: #fff; }
.overlay p { color: #cbd5e1; margin: 0; }

.pulse {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 38px;
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(37,99,235,.6); }
  70% { box-shadow: 0 0 0 22px rgba(37,99,235,0); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); }
}
.ring { animation: shake 0.6s infinite; }
@keyframes shake {
  0%,100% { transform: rotate(0); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}

/* Formular */
.form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 460px;
  margin: 0 auto 20px;
  box-shadow: var(--shadow);
}
.form label { display: block; font-size: 14px; margin-bottom: 8px; color: var(--muted); }
.form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
}
.form input:focus { outline: 2px solid var(--primary); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-green { background: var(--green); }
.btn-green:hover:not(:disabled) { background: var(--green-hover); }
.btn-red { background: var(--red); }
.btn-red:hover:not(:disabled) { background: var(--red-hover); }
.btn-block { width: 100%; justify-content: center; }

.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 16px;
}
.hidden { display: none !important; }

/* e-card Scan-Fenster */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal.hidden { display: none !important; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  max-width: 560px;
  width: 100%;
}
.modal-box h3 { margin: 0 0 6px; }
.modal-box p { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.scan-view { position: relative; }
#scanVideo, #scanShot {
  width: 100%;
  border-radius: 10px;
  background: #000;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}
/* Aufnahmen-Galerie (Arzt) */
.snaps { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
.snap-item { position: relative; }
.snap-item img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; display: block;
}
.snap-dl {
  position: absolute; right: 4px; bottom: 4px;
  background: rgba(0, 0, 0, .6); color: #fff; text-decoration: none;
  width: 24px; height: 24px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.snap-dl:hover { background: rgba(0, 0, 0, .85); }

/* Historie */
.hist-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.hist-item {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-2); cursor: pointer; transition: background .12s, border-color .12s;
}
.hist-item:hover { background: var(--panel); border-color: var(--primary); }
.hist-name { font-weight: 600; font-size: 14px; }
.hist-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.hist-box { max-width: 640px; max-height: 88vh; overflow-y: auto; }
.hist-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hist-detail-head h3 { margin: 0; }
.hist-h4 { margin: 16px 0 6px; font-size: 14px; }
.hist-notes { white-space: pre-wrap; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 14px; }
.hist-ecard { width: 100%; max-width: 420px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.scan-status { color: var(--muted); font-size: 14px; margin-top: 10px; min-height: 20px; }

/* Feld-Zeile mit Button daneben */
.field-row { display: flex; gap: 8px; }
.field-row input { flex: 1; margin-bottom: 0 !important; }
.field-row .btn { white-space: nowrap; }
.small-note { color: var(--muted); font-size: 12.5px; margin: 6px 0 16px; }

/* PIN-Anmeldung */
.pin-box { text-align: center; }
.pin-box h3 { margin-top: 0; }
.pin-input {
  font-size: 30px;
  letter-spacing: 10px;
  text-align: center;
  padding: 12px 10px;
  width: 200px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  margin: 6px 0 4px;
}
.pin-input:focus { outline: 2px solid var(--primary); }
.pin-error { color: var(--red); font-size: 14px; min-height: 18px; margin: 6px 0; }

/* Patientenformular kompakt (zwei Spalten) */
.form.form-wide { max-width: 720px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.form-grid input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}
.form-grid input:focus { outline: 2px solid var(--primary); }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } }

/* Namenszeile: Vorname | Nachname | e-card-Button */
.name-row { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 6px; flex-wrap: wrap; }
.name-row .nf { flex: 1 1 160px; }
.name-row .nf label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.name-row .nf input {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); font-size: 15px; margin-bottom: 0;
}
.name-row .nf input:focus { outline: 2px solid var(--primary); }
.name-row .scan-btn { flex: 0 0 auto; padding: 11px 16px; height: 44px; white-space: nowrap; }
@media (max-width: 620px) { .name-row .scan-btn { flex: 1 1 100%; justify-content: center; } }

/* Haus-Nr. / Stock / Tür nebeneinander */
.triple { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
.triple label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.triple input {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); font-size: 15px; margin-bottom: 12px;
}
.triple input:focus { outline: 2px solid var(--primary); }

/* vergroessertes Foto */
#photoModal img { max-width: 92vw; max-height: 86vh; border-radius: 10px; }
