/* ============================================================
   Healsafe Agent Ops - Flicker Effect workshop brand
   Ink ground · Off-white type · Oxblood mark · Inter / JetBrains Mono
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700;900&family=JetBrains+Mono:wght@300;400;500&display=swap");

:root {
  --ground:        #131211;   /* INK — ground */
  --ground-soft:   #1c1b1a;   /* INK DEEP — card */
  --ground-press:  #2a2825;   /* INK DEEP+ — pressed */
  --type:          #e8e6e0;   /* BONE — type */
  --type-soft:     #b8b6b0;   /* BONE secondary */
  --muted:         #6b6862;
  --line:          rgba(232, 230, 224, 0.10);
  --line-strong:   rgba(232, 230, 224, 0.18);
  --ox:            #8a3530;   /* OXBLOOD — mark */
  --pursue:        #5a8a6e;
  --ask:           #b89a4a;
  --reject:        #b56a64;

  --display: "Inter", system-ui, -apple-system, sans-serif;
  --body:    "Inter", system-ui, -apple-system, sans-serif;
  --mono:    "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--body);
  font-weight: 400;
  color: var(--type);
  background: var(--ground);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Subtle paper grain across the page */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================================================
   Left rail
   ============================================================ */

.rail {
  background: var(--ground);
  color: var(--type);
  padding: 28px 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  z-index: 2;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px 18px;
  border-bottom: 1px solid var(--line);
}

.rail-brand .mark { width: 28px; height: 28px; color: var(--type); flex-shrink: 0; }
.rail-brand .mark svg { width: 100%; height: 100%; display: block; }

.rail-brand div { display: grid; gap: 2px; }

.rail-brand strong {
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--type);
}

.rail-brand span:last-child {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 400;
}

.rail-section-label {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 24px 6px;
}

.rail-agents {
  display: flex;
  flex-direction: column;
}

/* Agent buttons */
.agent-button {
  display: grid;
  grid-template-columns: 4px 1fr;
  gap: 14px;
  align-items: start;
  padding: 14px 24px;
  background: transparent;
  border: none;
  border-top: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
  color: var(--type-soft);
  transition: background 0.15s ease, color 0.15s ease;
  font: inherit;
  position: relative;
}

.agent-button:last-child { border-bottom: 1px solid var(--line); }

.agent-button:hover {
  background: var(--ground-soft);
  color: var(--type);
}

.agent-button.active {
  background: var(--ground-soft);
  color: var(--type);
}

.agent-button .dot {
  width: 4px;
  height: 100%;
  min-height: 50px;
  background: transparent;
  border-radius: 0;
  justify-self: start;
}

.agent-button.active .dot {
  background: var(--ox);
}

.agent-button .name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.005em;
  text-transform: uppercase;
  color: inherit;
  display: block;
  line-height: 1.15;
}

.agent-button .role {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 5px;
  display: block;
}

.agent-button .status {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 300;
  color: var(--muted);
  margin-top: 4px;
  display: block;
  line-height: 1.4;
}

.rail-footer {
  margin-top: auto;
  padding: 16px 24px 8px;
  border-top: 1px solid var(--line);
}

.rail-footer p {
  font-family: var(--body);
  font-size: 11px;
  font-weight: 300;
  line-height: 1.5;
  color: var(--muted);
  margin: 6px 0 0;
}

/* ============================================================
   Main chat column
   ============================================================ */

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  position: relative;
  z-index: 2;
  background: var(--ground);
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 32px 48px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--ground);
}

.chat-header h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: 36px;
  letter-spacing: -0.015em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--type);
}

.chat-header .mono {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 10px;
  display: block;
}

.chat-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.chat-controls .status {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 10px;
  border: 1px solid var(--line);
}

.chat-controls .status[data-state="thinking"] { color: var(--type); border-color: var(--line-strong); }
.chat-controls .status[data-state="ready"] { color: var(--pursue); border-color: var(--pursue); }
.chat-controls .status[data-state="error"] { color: var(--reject); border-color: var(--reject); }

.chat-controls button {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--type);
  background: transparent;
  border: 1px solid var(--line-strong);
  padding: 8px 12px;
  cursor: pointer;
}

.chat-controls button:hover { background: var(--ground-soft); }

/* ============================================================
   Conversation
   ============================================================ */

.conversation {
  overflow-y: auto;
  padding: 40px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.conversation:empty::before {
  content: "Select a Growth Engine specialist on the left.";
  font-family: var(--body);
  font-style: normal;
  font-weight: 300;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  margin: 64px auto;
  letter-spacing: 0.02em;
}

.message {
  max-width: 720px;
  display: grid;
  gap: 6px;
}

.message.user {
  justify-self: end;
  text-align: right;
}

.message .who {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 400;
}

.message.user .who { color: var(--type-soft); }

.message .body {
  font-family: var(--body);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--type);
  font-weight: 400;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .body {
  background: var(--ground-soft);
  color: var(--type);
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 0;
  display: inline-block;
  text-align: left;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.55;
}

.message.agent .body {
  background: transparent;
  padding: 0;
}

.message.agent .body strong {
  font-weight: 700;
  color: var(--type);
}

.message.agent .body em {
  font-style: normal;
  font-weight: 500;
  color: var(--type);
}

.message.agent .body ul, .message.agent .body ol {
  margin: 8px 0 8px 18px;
  padding: 0;
}

.message.agent .body li {
  margin: 4px 0;
}

.tool-call, .tool-result {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  padding: 6px 12px 6px 18px;
  border-left: 2px solid var(--line-strong);
  margin: 4px 0;
  background: transparent;
  position: relative;
  letter-spacing: 0.02em;
}

.tool-call::before {
  content: "→";
  position: absolute;
  left: 6px;
  color: var(--type-soft);
}

.tool-result::before {
  content: "✓";
  position: absolute;
  left: 6px;
  color: var(--pursue);
}

.cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--type);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: cursorBlink 1s step-end infinite;
}

@keyframes cursorBlink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* ============================================================
   Composer
   ============================================================ */

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 20px 48px 28px;
  border-top: 1px solid var(--line);
  background: var(--ground);
}

.composer textarea {
  font-family: var(--body);
  font-size: 14.5px;
  font-weight: 400;
  color: var(--type);
  background: var(--ground-soft);
  border: 1px solid var(--line-strong);
  padding: 12px 16px;
  border-radius: 0;
  outline: none;
  resize: none;
  line-height: 1.5;
  max-height: 200px;
  min-height: 48px;
}

.composer textarea:focus { border-color: var(--type-soft); }

.composer textarea:disabled {
  background: var(--ground);
  color: var(--muted);
  cursor: not-allowed;
}

.composer textarea::placeholder { color: var(--muted); }

.composer button {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ground);
  background: var(--type);
  border: 1px solid var(--type);
  padding: 0 24px;
  cursor: pointer;
  min-height: 48px;
}

.composer button:hover { opacity: 0.88; }
.composer button:disabled { opacity: 0.35; cursor: not-allowed; }

/* ============================================================
   Prepared-for stamp (sits subtly above the rail-footer)
   ============================================================ */

.rail-footer::before {
  content: "PREPARED FOR HEALSAFE · EDITION 01";
  display: block;
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.22em;
  color: var(--ox);
  margin-bottom: 10px;
  text-transform: uppercase;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
  body {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .rail {
    display: flex;
    flex: 0 0 auto;
    gap: 10px;
    padding: 14px 0 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: hidden;
  }

  .rail-brand {
    padding: 0 16px;
  }

  .rail-brand .mark {
    width: 24px;
    height: 24px;
  }

  .rail-section-label {
    padding: 2px 16px 0;
    border-top: 0;
  }

  .rail-agents {
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    padding: 0 16px 6px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .agent-button {
    grid-template-columns: 4px minmax(0, 1fr);
    min-width: 150px;
    max-width: 180px;
    padding: 10px;
    border: 1px solid var(--line);
    background: var(--ground-soft);
    scroll-snap-align: start;
  }

  .agent-button:last-child {
    border-bottom: 1px solid var(--line);
  }

  .agent-button .dot {
    min-height: 38px;
  }

  .agent-button .name {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .agent-button .role {
    font-size: 8px;
  }

  .agent-button .status {
    display: none;
  }

  .rail-footer {
    display: none;
  }

  .chat {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .chat-header {
    align-items: flex-start;
    gap: 14px;
    padding: 20px;
  }

  .chat-header, .conversation, .composer {
    padding-left: 20px;
    padding-right: 20px;
  }

  .chat-header h1 { font-size: 24px; }

  .chat-controls {
    gap: 8px;
    margin-left: auto;
  }

  .chat-controls .status {
    font-size: 9px;
    padding: 6px 8px;
  }

  .chat-controls button {
    padding: 8px 10px;
  }

  .conversation {
    min-height: 0;
    padding-top: 24px;
    padding-bottom: 24px;
  }

  .conversation:empty::before {
    content: "Select a Growth Engine specialist above.";
    margin: 28px auto;
  }

  .composer {
    grid-template-columns: 1fr;
    gap: 10px;
    padding-top: 14px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .composer button {
    width: 100%;
  }
}
