/* ============================================================
   Agent Ops — Bone & Ink (Flicker Effect)
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,300;9..144,400&family=JetBrains+Mono:wght@300;400;500&family=Instrument+Serif:ital,wght@0,400;1,400&display=swap");

:root {
  --bone: #f4efe6;
  --bone-soft: #e8e2d4;
  --bone-shadow: #c8c2b4;
  --ink: #0a0a0a;
  --ink-soft: #2a2825;
  --muted: #6b6862;
  --line: rgba(10, 10, 10, 0.10);
  --line-strong: rgba(10, 10, 10, 0.20);
  --line-rail: rgba(244, 239, 230, 0.08);
  --pursue: #2a4d3a;
  --ask: #6b5818;
  --reject: #5a3838;
  --serif: "Instrument Serif", "Cormorant Garamond", Georgia, serif;
  --body: "Fraunces", Georgia, 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: 300;
  color: var(--ink);
  background: var(--bone);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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.9'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

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

.rail-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px 4px;
}

.rail-brand .mark { width: 30px; height: 30px; color: var(--bone); }
.rail-brand .mark svg { width: 100%; height: 100%; display: block; }

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

.rail-brand strong {
  font-family: var(--mono);
  font-weight: 300;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  color: var(--bone);
}

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

.rail-section-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 24px 6px;
  border-top: 1px solid var(--line-rail);
}

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

.agent-button {
  display: grid;
  grid-template-columns: 8px 1fr;
  gap: 12px;
  align-items: center;
  padding: 14px 24px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line-rail);
  text-align: left;
  cursor: pointer;
  color: var(--bone-shadow);
  transition: background 0.15s ease, color 0.15s ease;
  font: inherit;
}

.agent-button:hover { background: rgba(244, 239, 230, 0.04); color: var(--bone); }

.agent-button.active {
  background: rgba(244, 239, 230, 0.06);
  color: var(--bone);
}

.agent-button .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  justify-self: start;
}

.agent-button.active .dot,
.agent-button.busy .dot {
  background: #8aab8a;
  box-shadow: 0 0 0 3px rgba(138, 171, 138, 0.15);
}

.agent-button .name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  line-height: 1.15;
  color: inherit;
  display: block;
}

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

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

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

.rail-footer p {
  font-family: var(--body);
  font-size: 11.5px;
  font-weight: 300;
  line-height: 1.5;
  color: var(--bone-shadow);
  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(--bone);
  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(--bone);
}

.chat-header h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 42px;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--ink);
}

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

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

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

.chat-controls .status[data-state="thinking"] { color: var(--ink); 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: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ink);
  background: var(--bone);
  border: 1px solid var(--line-strong);
  padding: 8px 12px;
  cursor: pointer;
}

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

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

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

.conversation:empty::before {
  content: "Select an agent to begin.";
  font-family: var(--body);
  font-style: italic;
  font-size: 16px;
  color: var(--muted);
  text-align: center;
  margin: 64px auto;
}

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

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

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

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

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

.message.user .body {
  background: var(--ink);
  color: var(--bone);
  padding: 14px 18px;
  border-radius: 0;
  display: inline-block;
  text-align: left;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 400;
}

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

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

.message.agent .body em {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink);
}

.tool-call, .tool-result {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  padding: 6px 12px;
  border-left: 2px solid var(--bone-shadow);
  margin: 4px 0;
  background: var(--bone-soft);
}

.tool-call::before { content: "› "; color: var(--ink); font-style: normal; }
.tool-result::before { content: "✓ "; color: var(--pursue); font-style: normal; }

.cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--ink);
  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(--bone);
}

.composer textarea {
  font-family: var(--body);
  font-size: 15px;
  font-weight: 300;
  color: var(--ink);
  background: var(--bone);
  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(--ink); }

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

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

.composer button:hover { opacity: 0.85; }
.composer button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   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-rail);
    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: 6px minmax(0, 1fr);
    min-width: 150px;
    max-width: 180px;
    padding: 10px;
    border: 1px solid var(--line-rail);
    background: rgba(244, 239, 230, 0.035);
    scroll-snap-align: start;
  }

  .agent-button .name {
    font-size: 16px;
    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: 28px; }

  .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 an agent above to begin.";
    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%;
  }
}
