/* OVANAP CHAT — dark, clean, mobile-first UI */

:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1b2027;
  --line: #262d36;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #5eead4;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 10px;
  --gap: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

[hidden],
.hidden {
  display: none !important;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  gap: var(--gap);
  max-width: 1600px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--gap);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 56px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.composer .row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap);
}

.composer .cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.composer label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input,
.select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  font: inherit;
  outline: none;
}

.input:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(94, 234, 212, 0.15);
}

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

.mode-group {
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.mode-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  min-height: 44px;
  cursor: pointer;
}

.mode-group input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.btn,
#login-submit,
#run-btn,
#stop-btn,
#logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 88px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover,
#login-submit:hover,
#run-btn:hover,
#stop-btn:hover,
#logout-btn:hover {
  background: #232931;
}

.btn:disabled,
#login-submit:disabled,
#run-btn:disabled,
#stop-btn:disabled,
#logout-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary,
#login-submit,
#run-btn {
  background: var(--accent);
  color: #081411;
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover,
#login-submit:hover,
#run-btn:hover {
  background: #4dd9c3;
  border-color: #4dd9c3;
}

.btn-ghost,
#logout-btn,
#stop-btn {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.btn-ghost:hover,
#logout-btn:hover,
#stop-btn:hover {
  background: var(--panel-2);
}

#stop-btn {
  color: var(--danger);
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 4px;
}

#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--gap);
}

.login-box {
  width: 100%;
  max-width: 360px;
  padding: calc(var(--gap) * 1.5);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.login-box h2 {
  margin: 0 0 var(--gap);
  font-size: 1.25rem;
}

.login-box .input {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.25em;
  font-family: var(--mono);
}

#login-error {
  min-height: 1.5em;
}

.status-info {
  display: flex;
  align-items: center;
  gap: var(--gap);
  font-size: 0.9rem;
  color: var(--muted);
}

#status-badge {
  text-transform: capitalize;
}

.main {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  flex: 1 1 auto;
}

.run-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.run-list li {
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.run-list li:hover {
  border-color: var(--muted);
}

.run-list li.active {
  border-color: var(--accent);
  background: rgba(94, 234, 212, 0.08);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 4px);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.1s ease, background 0.1s ease;
}

.tab:hover {
  color: var(--text);
  background: var(--panel-2);
}

.tab.active {
  color: var(--accent);
  background: var(--panel-2);
  border-color: var(--line);
}

.panels {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  flex: 1 1 auto;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 220px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 10px var(--gap);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 0.9rem;
}

.panel-body {
  flex: 1 1 auto;
  padding: var(--gap);
  overflow: auto;
  min-height: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.cell {
  flex: 1 1 auto;
  min-width: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
}

.badge-pending {
  color: var(--muted);
  border-color: var(--line);
}

.badge-running {
  color: var(--accent);
  border-color: rgba(94, 234, 212, 0.35);
  background: rgba(94, 234, 212, 0.08);
}

.badge-done {
  color: var(--ok);
  border-color: rgba(63, 185, 80, 0.35);
  background: rgba(63, 185, 80, 0.08);
}

.badge-failed {
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.35);
  background: rgba(248, 81, 73, 0.08);
}

#agents-body {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.agent-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--gap);
  align-items: center;
  padding: var(--gap);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
}

.agent-card .agent-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.agent-card .agent-id {
  font-weight: 600;
  color: var(--text);
}

.agent-card .agent-role {
  font-size: 0.85rem;
  color: var(--muted);
}

.agent-card .agent-model {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
}

#dag-body {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.dag-node {
  padding: var(--gap);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: calc(var(--radius) - 2px);
}

.dag-node[data-status="done"] {
  border-left-color: var(--ok);
}

.dag-node[data-status="failed"] {
  border-left-color: var(--danger);
}

.dag-node[data-status="pending"] {
  border-left-color: var(--muted);
}

.dag-node-title {
  font-weight: 600;
}

.dag-node-role {
  font-size: 0.85rem;
  color: var(--muted);
}

.dag-node-deps {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
}

.dag-edge {
  width: 2px;
  height: 16px;
  background: var(--line);
  margin-left: 20px;
}

#files-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-row {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  gap: var(--gap);
  align-items: center;
  padding: 8px var(--gap);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 4px);
  font-family: var(--mono);
  font-size: 0.9rem;
  min-height: 40px;
}

.file-row .status {
  font-weight: 700;
  text-align: center;
}

.file-row .path {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row .add {
  color: var(--ok);
}

.file-row .del {
  color: var(--danger);
}

.file-row .agent {
  color: var(--muted);
  font-size: 0.8rem;
}

.terminal {
  background: #08090c;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.45;
  padding: var(--gap);
  min-height: 220px;
  max-height: 70vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.terminal-line {
  display: block;
  padding: 1px 0;
  color: var(--text);
}

.terminal-line.stderr {
  color: var(--danger);
}

.terminal-line .ts {
  color: var(--muted);
  margin-right: 8px;
  font-size: 0.8rem;
}

.terminal-line .agent {
  color: var(--accent);
  margin-right: 8px;
  font-size: 0.8rem;
}

#report-body {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  padding: var(--gap);
  line-height: 1.6;
  overflow: auto;
  max-height: 70vh;
}

#report-body h1,
#report-body h2,
#report-body h3,
#report-body h4 {
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  color: var(--accent);
}

#report-body p {
  margin: 0.6em 0;
}

#report-body pre {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 4px);
  padding: 10px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.85rem;
}

#report-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 4px;
}

.empty {
  color: var(--muted);
  font-style: italic;
  padding: var(--gap) 0;
}

.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.conn-status.live::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}

.conn-status.polling::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.conn-status.offline::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

@media (min-width: 900px) {
  .main {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "runs composer"
      "runs panels";
  }

  .run-section {
    grid-area: runs;
  }

  .composer {
    grid-area: composer;
  }

  .panels {
    grid-area: panels;
  }

  .panels {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, minmax(260px, 1fr));
    gap: var(--gap);
  }

  .panel {
    min-height: 260px;
  }

  .terminal,
  #report-body {
    max-height: none;
  }
}

/* ---- run list ------------------------------------------------------------
   A run is scanned, not read: outcome and size first, the prompt as one
   clipped line under it. The full prompt is on the card's title attribute. */

.run-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.run-card + .run-card { margin-top: 8px; }

.run-card:hover,
.run-card:focus-visible {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.03);
}

.run-card[aria-current="true"] {
  border-color: var(--accent);
  background: rgba(94, 234, 212, 0.06);
}

.run-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.run-card-repo {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Pushed right so the badge and repo stay together on the left. */
.run-card-when {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.run-card-task {
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.run-card-meta {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---- pieces the markup needs and the sheet did not have -------------------
   Everything above was written for a layout the old markup never used. These
   fill the remaining gaps, sized against what the mobile audit measured:
   a 21px-tall PIN field, 13px radio hit areas, 11.5px body text. */

.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--gap);
}

.login-box h2 { margin: 0 0 6px; font-size: 1.15rem; letter-spacing: .01em; }

.login-hint {
  margin: 0 0 var(--gap);
  font-size: 0.85rem;
  color: var(--muted);
}

/* Was 185x21. A PIN is typed once, under stress, often on a phone. */
.pin-input {
  width: 100%;
  min-height: 52px;
  margin-bottom: var(--gap);
  font-family: var(--mono);
  font-size: 1.4rem;
  letter-spacing: .4em;
  text-align: center;
  text-transform: uppercase;
}
.pin-input::placeholder { letter-spacing: .3em; opacity: .35; }

.btn-block { width: 100%; min-height: 48px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.brand { font-weight: 700; font-size: 0.95rem; }
.brand-tag {
  margin-left: 6px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: .1em;
  color: var(--muted);
  vertical-align: middle;
}

.topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  flex-wrap: wrap;
}
.composer-buttons { display: flex; gap: 8px; }

/* 13x13 hit areas. The label carries the target, so the whole word is tappable. */
.mode-group label {
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.mode-group input { width: 18px; height: 18px; accent-color: var(--accent); }
.mode-group label:has(input:checked) {
  border-color: var(--accent);
  background: rgba(94, 234, 212, 0.08);
}

/* 11.5px is below the 12px floor on a phone. */
.run-card-when, .run-card-meta { font-size: 0.78rem; }

.run-section .panel-body { max-height: 40vh; }
@media (min-width: 900px) {
  .run-section .panel-body { max-height: none; }
}

/* A badge that overflowed the right edge by 36px on a 390px screen. */
.badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* An empty badge still renders: min-height, padding and a 999px radius turn no
   text into a bare circle in the topbar. Hide it until it says something. */
.badge:empty { display: none; }

/* Five tabs wrapped onto two rows at 390px. One scrolling row keeps the panel
   header a fixed height and the tabs where the thumb expects them. */
@media (max-width: 640px) {
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; min-height: 44px; }
}

/* The topbar is the first thing on a phone; keep it one line. */
@media (max-width: 480px) {
  .brand-tag { display: none; }
  .topbar { padding: 10px var(--gap); }
}

/* ---- agent cards ---------------------------------------------------------
   The four-column grid squeezed into 390px wrapped every model name over three
   lines and clipped the status badge to "AILE". A phone gets a stack. */
.agent-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.agent-card + .agent-card { margin-top: 8px; }

.agent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.agent-id { font-weight: 600; font-size: 0.85rem; }

.agent-model {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.agent-meta {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (min-width: 700px) {
  .agent-card {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
  }
  .agent-head { grid-column: 1; }
  .agent-model { grid-column: 1; }
  .agent-meta { grid-column: 2; grid-row: 1 / span 2; text-align: right; white-space: nowrap; }
}

/* ---- diff viewer ---------------------------------------------------------
   A changed file used to be a line of text with nothing to click. */

.file-row {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: inherit;
  font: inherit;
  font-family: var(--mono);
  text-align: left;
  cursor: pointer;
  min-height: 44px;
}
.file-row + .file-row { margin-top: 6px; }
.file-row:hover, .file-row:focus-visible { border-color: var(--accent); }
.file-row .path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Full screen on a phone, a centred sheet with room to breathe above that. */
.diff-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--bg, #0b0d10);
}
.diff-view[hidden] { display: none; }

.diff-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--gap);
  border-bottom: 1px solid var(--line);
  padding-top: calc(var(--gap) + env(safe-area-inset-top));
}

.diff-title {
  font-family: var(--mono);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diff-body {
  flex: 1 1 auto;
  margin: 0;
  padding: var(--gap);
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}

.diff-add  { color: var(--ok, #5cc08c); }
.diff-del  { color: var(--bad, #e0776a); }
.diff-hunk { color: var(--accent); }
.diff-ctx  { color: var(--muted); }

@media (min-width: 900px) {
  .diff-view {
    inset: 5vh 10vw;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px rgba(0,0,0,.5);
  }
}
