/* ---- self-hosted monospace, no system-font fallback to a proportional face ---- */
@font-face {
  font-family: "TUIMono";
  src: url("/fonts/mono.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}

:root {
  --bg: #0b0d0f;
  --bg-soft: #101418;
  --panel: #0e1216;
  --line: #1c2530;
  --fg: #cdd6e0;
  --fg-dim: #7d8a99;
  --muted: #55636f;
  --accent: #e8a33d; /* amber */
  --accent-2: #6cc7a8; /* mint */
  --user: #7aa2f7; /* blue */
  --danger: #f7768e;
  --ok: #9ece6a;
  --glow: rgba(232, 163, 61, 0.35);
  --mono: "TUIMono", ui-monospace, monospace;
  --fs: 14px;
  --lh: 1.55;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* The hidden attribute must win over class-level `display` rules (e.g. .field,
   .crt), otherwise the new-password field and the chat view leak into view. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: var(--fs);
  line-height: var(--lh);
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

/* faint background grid + vignette for the terminal-in-a-void feel */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 120% at 50% 0%, transparent 55%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 100% 100%, 64px 64px, 64px 64px;
  opacity: 0.14;
  pointer-events: none;
  z-index: 0;
}

.crt {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
}

/* scanline overlay */
.crt::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.018) 0px,
    rgba(255, 255, 255, 0.018) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 5;
  mix-blend-mode: overlay;
}

/* ---------------- top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  font-size: 12.5px;
  user-select: none;
}
.tb-left,
.tb-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 0 12px var(--glow);
}
.sep {
  color: var(--line);
}
.muted {
  color: var(--muted);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 transparent;
  transition: background 0.3s, box-shadow 0.3s;
}
.dot.ok {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}
.dot.busy {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1s infinite;
}
.dot.err {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}
.kbd {
  color: var(--fg-dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 11.5px;
  background: rgba(255, 255, 255, 0.02);
}

/* ---------------- screen / scrollback ---------------- */
.screen {
  overflow-y: auto;
  padding: 16px 16px 8px;
  scroll-behavior: smooth;
  outline: none;
}
.screen::-webkit-scrollbar {
  width: 10px;
}
.screen::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 6px;
}
.screen::-webkit-scrollbar-track {
  background: transparent;
}

.line {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 2px;
}
.block {
  margin: 6px 0 14px;
}

/* message roles */
.role {
  display: inline-block;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.role.user {
  color: var(--user);
}
.role.assistant {
  color: var(--accent);
}
.role.sys {
  color: var(--accent-2);
}
.role.err {
  color: var(--danger);
}
.gutter {
  color: var(--muted);
  user-select: none;
}
.msg-user {
  color: var(--fg);
}
.msg-assistant {
  color: var(--fg);
}
.msg-sys {
  color: var(--fg-dim);
}
.msg-err {
  color: var(--danger);
}

/* boot / ascii */
.ascii {
  color: var(--accent);
  text-shadow: 0 0 14px var(--glow);
  white-space: pre;
  line-height: 1.05;
  font-size: 13px;
  margin-bottom: 4px;
  overflow-x: auto;
  max-width: 100%;
}
@media (max-width: 560px) {
  .ascii {
    font-size: 9px;
  }
}
.dim {
  color: var(--fg-dim);
}
.accent {
  color: var(--accent);
}
.mint {
  color: var(--accent-2);
}

/* lightweight markdown */
.md code {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
  color: var(--accent-2);
}
.md pre {
  background: #0a0c0f;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.md pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--fg);
}
.md a {
  color: var(--user);
  text-decoration: underline dotted;
}
.md b {
  color: #fff;
  font-weight: 700;
}

/* blinking cursor for the typewriter effect */
.cursor {
  display: inline-block;
  width: 0.6ch;
  height: 1.05em;
  background: var(--accent);
  translate: 0 0.18em;
  animation: blink 1.05s steps(1) infinite;
  box-shadow: 0 0 8px var(--glow);
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ---------------- input dock ---------------- */
.dock {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 14px 8px;
}
.prompt-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.prompt-glyph {
  color: var(--accent);
  font-weight: 700;
  padding-top: 2px;
  text-shadow: 0 0 10px var(--glow);
}
.prompt-glyph.locked {
  color: var(--muted);
  text-shadow: none;
}
.input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--fg);
  font-family: var(--mono);
  font-size: var(--fs);
  line-height: var(--lh);
  max-height: 40vh;
  caret-color: var(--accent);
}
.input::placeholder {
  color: var(--muted);
}
.input:disabled {
  color: var(--muted);
}
.hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11.5px;
  gap: 12px;
  flex-wrap: wrap;
}
.hint-keys {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* password field masks as a normal terminal line */
.input.secret {
  -webkit-text-security: disc;
  text-security: disc;
}

@media (max-width: 640px) {
  .hint-keys {
    display: none;
  }
  :root {
    --fs: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cursor,
  .dot.busy {
    animation: none;
  }
  .screen {
    scroll-behavior: auto;
  }
}

/* ---------------- login view ---------------- */
.login-view {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg) 100%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 30px 80px rgba(0, 0, 0, 0.5);
  padding: 28px 26px 20px;
}
.login-card .ascii {
  overflow-x: auto;
  max-width: 100%;
}
.login-sub {
  color: var(--fg-dim);
  margin: 2px 0 20px;
  font-size: 13px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.field input {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--fg);
  background: #0a0c0f;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 11px 12px;
  outline: none;
  caret-color: var(--accent);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input::placeholder {
  color: var(--muted);
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 14px var(--glow);
}
.btn {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #0a0c0f;
  background: var(--accent);
  border: none;
  border-radius: 5px;
  padding: 11px 14px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
  box-shadow: 0 0 18px var(--glow);
}
.btn:hover {
  filter: brightness(1.08);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
  box-shadow: none;
}
.btn-glyph {
  font-weight: 700;
}
.login-status {
  min-height: 1.3em;
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--fg-dim);
}
.login-status.err {
  color: var(--danger);
}
.login-status.ok {
  color: var(--ok);
}
.login-status.busy {
  color: var(--accent);
}
.login-foot {
  margin-top: 18px;
  font-size: 11.5px;
  text-align: center;
}

/* logout link + who label */
.linkbtn {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 7px;
  cursor: pointer;
  margin-left: 6px;
}
.linkbtn:hover {
  color: var(--fg);
  border-color: var(--fg-dim);
}
#who {
  max-width: 30vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- Module 2: model selector + metrics ---------------- */
.tb-select {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.tb-select select {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  background: #0a0c0f;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  outline: none;
}
.tb-select select:focus {
  border-color: var(--accent);
}

/* per-response metrics line */
.metrics-line {
  color: var(--muted);
  font-size: 12px;
  margin: 2px 0 14px;
  padding-left: 2px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* small model tag next to an assistant reply */
.model-chip {
  color: var(--accent-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 5px;
  font-size: 11px;
}

/* ---------------- compare grid ---------------- */
.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin: 6px 0 16px;
}
.cmp-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0a0c0f;
  padding: 10px;
  min-width: 0;
}
.cmp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
}
.cmp-name {
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 700;
}
.cmp-status {
  font-size: 11px;
  padding: 0 5px;
  border-radius: 3px;
}
.cmp-status.pending {
  color: var(--muted);
}
.cmp-status.ok {
  color: var(--ok);
}
.cmp-status.err {
  color: var(--danger);
}
.cmp-body {
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}
.cmp-metrics {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
  font-size: 11px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------- eval table ---------------- */
.eval-table-wrap {
  overflow-x: auto;
  margin: 8px 0 6px;
}
.eval-table {
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 520px;
}
.eval-table th,
.eval-table td {
  text-align: right;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.eval-table th {
  color: var(--muted);
  font-weight: 700;
  border-bottom: 1px solid var(--fg-dim);
}
.eval-table td.eval-model,
.eval-table th:first-child {
  text-align: left;
  color: var(--accent);
}
.eval-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* ---------------- Module 4: document bar + cache badges ---------------- */
.docbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(232, 163, 61, 0.06);
  font-size: 12px;
  flex-wrap: wrap;
}
.docbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.doc-ico {
  color: var(--accent);
}
.doc-name {
  color: var(--fg);
  font-weight: 700;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.docbar-right {
  font-size: 11.5px;
  text-align: right;
}

/* per-response cache HIT/MISS badge in the metrics line */
.cache-badge {
  border-radius: 3px;
  padding: 0 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.cache-badge.hit {
  color: #0a0c0f;
  background: var(--ok);
}
.cache-badge.miss {
  color: #0a0c0f;
  background: var(--accent);
}
.cache-badge.none {
  color: var(--muted);
  border: 1px solid var(--line);
}
