* { box-sizing: border-box; }

:root {
  color-scheme: dark;
  --bg: #08121f;
  --surface: #0c1826;
  --surface-2: #101f30;
  --border: #233043;
  --text: #eef5ff;
  --muted: #a9b6c8;
  --accent: #56b4ff;
  --danger: #ff7c8b;
}

html { background: var(--bg); }
body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 1000;
  transform: translateY(-150%);
  padding: 10px 14px;
  border-radius: 10px;
  background: #fff;
  color: #07111d;
  text-decoration: none;
}
.skip:focus { transform: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px max(28px, env(safe-area-inset-right)) 18px max(28px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: rgba(8, 18, 31, .96);
}
.brand, .back { color: #fff; text-decoration: none; }
.brand { font-weight: 800; letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.back { color: #c9d7e8; }
.topchips { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.topchips span {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 9px;
  color: #c8d4e3;
  font-size: .78rem;
  white-space: nowrap;
}

.shell {
  width: 100%;
  max-width: 1500px;
  margin: auto;
  padding: 32px 28px calc(70px + env(safe-area-inset-bottom));
}

.visit-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 20px;
  margin-bottom: 22px;
}
.visit-head > *, .workspace > *, .main-column > *, .side-column > * { min-width: 0; }
.eyebrow {
  margin: 0 0 7px;
  color: #8fcfff;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}
h1, h2, p { overflow-wrap: anywhere; }
h1 {
  margin: 0;
  max-width: 860px;
  font-size: clamp(2.3rem, 5vw, 4.8rem);
  line-height: .98;
  letter-spacing: -.045em;
}
h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.08;
  letter-spacing: -.025em;
}
.lede {
  max-width: 850px;
  margin: 20px 0 0;
  color: #d4deeb;
  font-size: clamp(1.02rem, 1.8vw, 1.25rem);
}

.appointment-card {
  display: grid;
  min-width: 230px;
  gap: 3px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}
.appointment-card span, .appointment-card small { color: var(--muted); }
.appointment-card strong { font-size: 1rem; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  align-items: start;
  gap: 18px;
}
.main-column, .side-column { display: grid; min-width: 0; gap: 16px; }

.stage-card, .mode-card, .diagnostic-card, .panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  padding: 16px;
  overflow: hidden;
}

.stage-topline, .section-title, .panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.stage-topline {
  margin-bottom: 12px;
  color: #cbd7e5;
  font-size: .9rem;
}
.stage-topline > *, .section-title > *, .panel-row > * { min-width: 0; }
.live-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-radius: 50%;
  background: #66778a;
}
.live-dot.active { background: #4bd889; box-shadow: 0 0 0 4px rgba(75,216,137,.13); }

.video-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(220px, .7fr);
  gap: 10px;
  min-height: 460px;
}
.video-tile {
  position: relative;
  min-width: 0;
  min-height: 460px;
  overflow: hidden;
  border: 1px solid #182637;
  border-radius: 18px;
  background: #02070d;
  isolation: isolate;
}
.local-tile video,
.share-video {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 460px;
  object-fit: cover;
}
.local-tile video { position: absolute; inset: 0; z-index: 1; }
.share-video {
  position: absolute;
  inset: 0;
  z-index: 8;
  border-radius: 18px;
  background: #02070d;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 30px;
  text-align: center;
  background: radial-gradient(circle at 50% 35%, #12243a 0, #06101b 58%, #02070d 100%);
}
.video-placeholder span { max-width: 420px; color: var(--muted); }
.lens-mark {
  width: 74px;
  aspect-ratio: 1;
  border: 2px solid #51657c;
  border-radius: 50%;
  box-shadow: inset 0 0 0 13px #0d1c2b;
}

.remote-tile {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  padding: 24px;
  text-align: center;
  background: linear-gradient(145deg, #09121e, #0b1c2e);
}
.remote-tile > span { color: var(--muted); }
.clinician-avatar {
  display: grid;
  place-items: center;
  width: 78px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #16314c;
  color: #d9ecff;
  font-weight: 800;
  font-size: 1.35rem;
}
.tile-label {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  background: rgba(3, 9, 15, .78);
  backdrop-filter: blur(9px);
}
.tile-label small { color: #a9b6c8; text-align: right; }
.coach {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  max-width: calc(100% - 24px);
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(3, 9, 15, .78);
  color: #dce8f7;
  font-size: .82rem;
  backdrop-filter: blur(9px);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.toolbar button, .mode, .panel button, dialog button {
  min-height: 42px;
  border: 1px solid #34465b;
  border-radius: 12px;
  background: #132236;
  color: #edf5ff;
  padding: 9px 13px;
  cursor: pointer;
}
.toolbar button:disabled, .panel button:disabled { cursor: not-allowed; opacity: .48; }
.toolbar .primary, .toolbar .accent { border-color: #3179ad; background: #123452; }
.toolbar .danger { border-color: #6b3540; color: #ffd7dc; }

.mode-card, .diagnostic-card { padding: 18px; }
.section-title { margin-bottom: 14px; }
.section-title > span { color: var(--muted); font-size: .82rem; text-align: right; }
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.mode {
  display: grid;
  gap: 5px;
  width: 100%;
  text-align: left;
}
.mode span { color: var(--muted); font-size: .86rem; }
.mode.selected { border-color: #3f98d5; background: #102a42; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}
.metric-grid > div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px;
  border: 1px solid #1f3043;
  border-radius: 13px;
  background: #0a1522;
}
.metric-grid span { color: var(--muted); font-size: .78rem; }
.metric-grid strong { font-size: .9rem; overflow-wrap: anywhere; }

.panel { padding: 19px; }
.panel h2 { margin-bottom: 15px; }
.panel p { color: #d5dfeb; }
.panel-row > span { color: var(--muted); font-size: .78rem; }
.timeline { display: grid; gap: 13px; }
.step {
  display: grid;
  grid-template-columns: 28px minmax(0,1fr);
  gap: 10px;
  align-items: start;
}
.step > span {
  display: grid;
  place-items: center;
  width: 28px;
  aspect-ratio: 1;
  border: 1px solid #38506a;
  border-radius: 50%;
  color: #a8c9e6;
  font-size: .75rem;
}
.step div { display: grid; gap: 3px; }
.step small { color: var(--muted); line-height: 1.35; }
.step.active > span { border-color: #58b8ff; color: #dff2ff; background: #123553; }

.synthetic-note {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #20354b;
  border-radius: 14px;
  background: #0a1522;
}
.synthetic-note > span { color: var(--muted); font-size: .8rem; }
.synthetic-note p { margin: 4px 0 0; color: #cbd7e5; }
.panel button { width: 100%; }

dialog {
  width: min(720px, calc(100vw - 28px));
  max-height: min(85vh, 760px);
  margin: auto;
  overflow: auto;
  border: 1px solid #34465b;
  border-radius: 22px;
  background: #0c1826;
  color: var(--text);
  padding: 0;
}
dialog::backdrop { background: rgba(0, 5, 10, .76); backdrop-filter: blur(5px); }
dialog form { position: relative; padding: 24px; }
.close-dialog {
  position: absolute;
  top: 13px;
  right: 13px;
  width: 42px;
  padding: 0;
  font-size: 1.6rem;
}
.companion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 9px;
  margin: 18px 0;
}
.companion-grid > div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px;
  border: 1px solid #20354b;
  border-radius: 12px;
  background: #0a1522;
}
.companion-grid span { color: var(--muted); font-size: .78rem; }

footer {
  padding: 24px max(28px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  color: #91a2b5;
  font-size: .8rem;
  text-align: center;
}

@media (max-width: 1050px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .side-column { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .research-panel { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 14px 16px;
  }
  .topchips { order: 3; width: 100%; justify-content: flex-start; }
  .shell { padding: 24px 16px calc(56px + env(safe-area-inset-bottom)); }
  .visit-head { grid-template-columns: minmax(0,1fr); align-items: start; }
  .appointment-card { min-width: 0; width: 100%; }
  .workspace, .main-column, .side-column { min-width: 0; width: 100%; }
  .side-column { grid-template-columns: minmax(0,1fr); }
  .research-panel { grid-column: auto; }

  .video-grid {
    grid-template-columns: minmax(0,1fr);
    min-height: 0;
  }
  .video-tile {
    width: 100%;
    min-height: 0;
  }
  .local-tile { min-height: 260px; aspect-ratio: 4 / 3; }
  .remote-tile { min-height: 190px; aspect-ratio: 16 / 9; }
  .local-tile video, .share-video {
    min-height: 0;
    height: 100%;
  }
  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
  .toolbar button { width: 100%; min-width: 0; }
  .mode-grid { grid-template-columns: minmax(0,1fr); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stage-topline, .section-title, .panel-row { align-items: flex-start; flex-wrap: wrap; }
  .section-title > span { text-align: left; }
}

@media (max-width: 430px) {
  h1 { font-size: clamp(2.15rem, 12vw, 3.2rem); }
  .lede { font-size: 1rem; }
  .stage-card, .mode-card, .diagnostic-card, .panel { border-radius: 18px; padding: 14px; }
  .video-placeholder { padding: 20px; }
  .local-tile { min-height: 230px; }
  .remote-tile { min-height: 170px; }
  .toolbar { grid-template-columns: minmax(0,1fr); }
  .metric-grid, .companion-grid { grid-template-columns: minmax(0,1fr); }
  dialog { width: calc(100vw - 18px); max-height: calc(100dvh - 28px); }
  dialog form { padding: 20px 16px; }
  footer { padding-left: 16px; padding-right: 16px; }
}
