/* Gracestack Med — clinical UI shell */
:root {
  --bg0: #07141a;
  --bg1: #0c1e28;
  --panel: #0f2430;
  --ink: #e8f1f4;
  --ink-soft: #b7cdd6;
  --mute: #7a9aa8;
  --line: rgba(43, 179, 163, 0.28);
  --teal: #2bb3a3;
  --teal-dim: #1a6b7c;
  --sand: #e8a87c;
  --bad: #e07a7a;
  --user: #f0d9c0;
  --glow: rgba(43, 179, 163, 0.35);
  --font: "Fraunces", "Source Serif 4", Georgia, serif;
  --body: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(800px 480px at 12% -8%, rgba(43, 179, 163, 0.14), transparent 55%),
    radial-gradient(640px 420px at 92% 8%, rgba(26, 107, 124, 0.28), transparent 50%),
    linear-gradient(168deg, #0a1c26 0%, var(--bg0) 45%, #050f14 100%);
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 1px solid rgba(43, 179, 163, 0.5);
  background: linear-gradient(180deg, rgba(43, 179, 163, 0.28), rgba(43, 179, 163, 0.06));
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
}
button:hover { box-shadow: 0 0 18px var(--glow); }
button:disabled { opacity: 0.45; cursor: wait; }
button.ghost {
  background: transparent;
  border-color: var(--line);
  font-weight: 500;
  font-size: 0.88rem;
  padding: 8px 12px;
}
input, select {
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(43, 179, 163, 0.18);
}

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 20, 26, 0.88);
}
.brand strong {
  font-family: var(--font);
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--teal);
}
.brand span {
  display: block;
  color: var(--mute);
  font-size: 0.82rem;
  margin-top: 2px;
}
.pills { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.pill {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: rgba(0, 0, 0, 0.28);
  text-decoration: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
}
.toolbar label {
  font-size: 0.82rem;
  color: var(--mute);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.model-select {
  min-width: 160px;
  font-weight: 600;
}
.disclaimer {
  flex: 1;
  min-width: 200px;
  font-size: 0.86rem;
  color: var(--sand);
  line-height: 1.35;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 400px);
  min-height: 0;
  height: 100%;
}
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100%; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(240px, 42vh);
  }
  .chat-panel { order: -1; max-height: min(52vh, 440px); }
  #medNetwork { min-height: 200px !important; }
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(43, 179, 163, 0.12), transparent 52%),
    linear-gradient(180deg, #0c2430 0%, #07141a 100%);
}
#medNetwork {
  width: 100%;
  height: 100%;
  min-height: 420px;
  background: transparent;
}
#medNetwork canvas { background: transparent !important; }

.graph-tools {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}
.graph-tools > * { pointer-events: auto; }
.graph-tools input { max-width: 220px; }
.stat {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(7, 20, 26, 0.85);
}
.trail {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 4;
  max-width: min(70%, 520px);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(7, 20, 26, 0.9);
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: #0c1e28;
}
.chat-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.chat-head strong {
  font-family: var(--font);
  color: var(--teal);
  font-size: 1.15rem;
}
.chat-head span { display: block; color: var(--mute); font-size: 0.86rem; margin-top: 2px; }
.chat-log {
  flex: 1;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-empty { color: var(--mute); line-height: 1.45; font-size: 0.95rem; }
.bubble {
  max-width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  font-size: 1rem;
}
.bubble.user {
  align-self: flex-end;
  background: rgba(232, 168, 124, 0.14);
  border: 1px solid rgba(232, 168, 124, 0.35);
  color: var(--user);
}
.bubble.med {
  align-self: flex-start;
  background: rgba(43, 179, 163, 0.1);
  border: 1px solid var(--line);
}
.step-chip {
  border: 1px dashed rgba(43, 179, 163, 0.4);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--sand);
  background: rgba(0, 0, 0, 0.25);
}
.cites {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
}
.cite {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.8rem;
  color: var(--teal);
  background: rgba(43, 179, 163, 0.08);
  cursor: pointer;
}
.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.composer input { flex: 1; }
@media (max-width: 900px) {
  .composer {
    position: sticky;
    bottom: 0;
    background: #0c1e28;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

#gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
}
#gate.hidden { display: none; }
.login {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(15, 36, 48, 0.95), rgba(7, 20, 26, 0.92));
}
.login h1 {
  font-family: var(--font);
  color: var(--teal);
  margin: 0 0 8px;
  font-size: 2rem;
}
.login p { color: var(--ink-soft); margin: 0 0 18px; line-height: 1.45; }
.login .stack { display: flex; flex-direction: column; gap: 10px; }
.err { color: var(--bad); min-height: 1.2em; font-size: 0.9rem; }
#app.hidden { display: none; }
