/* 2ARK layout on the H tokens. Colours, type and radii come from tenark-tokens.css only. */

:root {
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--tk-bg);
  color: var(--tk-ink);
  font-family: var(--tk-font-sans);
  font-size: var(--tk-fs-body);
  line-height: var(--tk-lh, 1.5);
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--tk-accent);
  outline-offset: 2px;
}

.glass {
  background: linear-gradient(180deg, var(--tk-glass-top), var(--tk-glass-bot));
  border: 1px solid var(--tk-line-2);
  border-radius: var(--tk-r-md);
  box-shadow: var(--tk-shadow);
  -webkit-backdrop-filter: blur(var(--tk-blur));
  backdrop-filter: blur(var(--tk-blur));
}

/* ---- shell ---- */

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: var(--tk-space-4);
  height: 100vh;
  height: 100dvh;
  padding: var(--tk-gutter);
}

.rail {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-3);
  padding: var(--tk-space-4);
  min-height: 0;
}

.brand {
  font-size: var(--tk-fs-h2);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-1);
}

.session-item {
  width: 100%;
  text-align: left;
  padding: var(--tk-space-2) var(--tk-space-3);
  border: 1px solid transparent;
  border-radius: var(--tk-r-sm);
  background: transparent;
  color: var(--tk-ink-2);
  font: inherit;
  cursor: pointer;
  transition: background var(--tk-dur-fast) var(--tk-ease), border-color var(--tk-dur-fast) var(--tk-ease);
}

.session-item:hover {
  background: var(--tk-chip);
}

.session-list li {
  display: flex;
  align-items: stretch;
  gap: var(--tk-space-1);
}

.session-list li .session-item {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-delete {
  flex: none;
  width: 28px;
  border: 1px solid transparent;
  border-radius: var(--tk-r-sm);
  background: transparent;
  color: var(--tk-ink-3);
  font: inherit;
  cursor: pointer;
}

.session-delete:hover {
  background: var(--tk-chip);
  color: var(--tk-ink);
}

.session-item[aria-current="true"] {
  background: var(--tk-accent-soft);
  border-color: var(--tk-accent-line);
  color: var(--tk-ink);
}

.session-item[data-state="busy"]::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: var(--tk-space-2);
  border-radius: 50%;
  background: var(--tk-dot-warn);
  vertical-align: middle;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  gap: var(--tk-space-3);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--tk-space-3);
  min-height: 40px;
}

.thread-title {
  margin: 0;
  font-size: var(--tk-fs-h1);
  font-weight: 400;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  display: flex;
  align-items: center;
  gap: var(--tk-space-2);
}

.pill {
  font-family: var(--tk-font-mono);
  font-size: var(--tk-fs-mono-s);
  font-variant-numeric: tabular-nums;
  color: var(--tk-ink-2);
  padding: var(--tk-space-1) var(--tk-space-3);
  border: 1px solid var(--tk-line-2);
  border-radius: 20px;
  background: var(--tk-chip);
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tk-ink-4);
}

.dot[data-state="ok"] {
  background: var(--tk-dot-ok);
}

.dot[data-state="warn"] {
  background: var(--tk-dot-warn);
}

/* ---- timeline ---- */

.timeline {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-3);
  padding: var(--tk-space-2) var(--tk-space-2) var(--tk-space-4);
  scroll-behavior: smooth;
}

.entry {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-1);
  max-width: min(74ch, 92%);
  padding: var(--tk-space-3) var(--tk-space-4);
  border-radius: var(--tk-r-md);
  animation: enter var(--tk-dur) var(--tk-ease) both;
}

.entry-meta {
  font-size: var(--tk-fs-label, 11px);
  color: var(--tk-ink-3);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.entry-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.entry-user {
  align-self: flex-end;
  background: var(--tk-accent-soft);
  border: 1px solid var(--tk-accent-line);
}

.entry-assistant {
  align-self: flex-start;
  background: linear-gradient(180deg, var(--tk-glass-top), var(--tk-glass-bot));
  border: 1px solid var(--tk-line-2);
}

.entry-assistant.streaming .entry-body::after {
  content: "▍";
  margin-left: 2px;
  color: var(--tk-accent-ink);
  animation: blink 1s steps(2, start) infinite;
}

.entry-tool,
.entry-tool-result,
.entry-tool-error {
  align-self: flex-start;
  max-width: min(74ch, 92%);
  padding: var(--tk-space-2) var(--tk-space-3);
  border-left: 2px solid var(--tk-accent-line);
  font-family: var(--tk-font-mono);
  font-size: var(--tk-fs-mono-s);
  color: var(--tk-ink-3);
}

.entry-tool-error {
  border-left-color: var(--tk-neg-line);
  color: var(--tk-neg-text);
}

.entry-tool-result summary,
.entry-tool-error summary {
  cursor: pointer;
  color: var(--tk-ink-3);
}

.entry-error {
  align-self: flex-start;
  color: var(--tk-neg-text);
  background: var(--tk-neg-soft);
  border: 1px solid var(--tk-neg-line);
}

.entry-system {
  align-self: center;
  padding: var(--tk-space-1) var(--tk-space-3);
  color: var(--tk-warn);
  background: var(--tk-warn-soft);
  border-radius: 20px;
  font-size: var(--tk-fs-mono-s);
}

.entry-system .entry-meta {
  display: none;
}

/* ---- composer ---- */

.composer {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-2);
  padding: var(--tk-space-2);
  border-radius: var(--tk-r-input, 16px);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: var(--tk-space-2);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tk-space-1);
}

.attachments:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--tk-space-2);
  max-width: 100%;
  padding: var(--tk-space-1) var(--tk-space-2) var(--tk-space-1) var(--tk-space-3);
  border: 1px solid var(--tk-line-2);
  border-radius: 20px;
  background: var(--tk-chip);
  font-family: var(--tk-font-mono);
  font-size: var(--tk-fs-mono-s);
  color: var(--tk-ink-2);
}

.chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-remove {
  border: 0;
  background: transparent;
  color: var(--tk-ink-3);
  font: inherit;
  cursor: pointer;
  padding: 0 var(--tk-space-1);
}

.chip-remove:hover {
  color: var(--tk-ink);
}

.chip[data-state="uploading"] {
  opacity: 0.6;
}

.chip[data-state="error"] {
  border-color: var(--tk-neg-line);
  color: var(--tk-neg-text);
}

.entry-files {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tk-space-1);
  margin-top: var(--tk-space-1);
}

/* ---- login (layout follows the Tenark console auth screen) ---- */

[hidden] {
  display: none !important;
}

.auth {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 40px 16px;
}

.auth-card {
  width: min(440px, 100%);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-4);
}

.auth-step {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-4);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--tk-space-3);
}

.auth-brand .brand-mark {
  color: var(--tk-accent);
  display: grid;
  place-items: center;
}

.wordmark {
  font-size: 18px;
  font-weight: 400;
  color: var(--tk-ink);
}

.wordmark strong {
  font-weight: 600;
}

.auth-title {
  margin: 0;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.auth-title-md {
  font-size: 26px;
}

.eyebrow {
  font-size: var(--tk-fs-label, 11px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tk-ink-4);
}

.note {
  margin: 0;
  font-size: var(--tk-fs-sub, 13px);
  color: var(--tk-ink-3);
  line-height: 1.55;
}

.note.neg {
  color: var(--tk-neg-text);
}

.note:empty {
  display: none;
}

.or-divider {
  display: flex;
  align-items: center;
  gap: var(--tk-space-3);
}

.or-divider .divider {
  flex: 1;
  height: 1px;
  background: var(--tk-line-2);
}

.or-divider .sub {
  font-size: var(--tk-fs-sub, 13px);
  color: var(--tk-ink-3);
}

.form-tight {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-3);
}

.input {
  height: 42px;
  padding: 0 var(--tk-space-3);
  border: 1px solid var(--tk-input-line);
  border-radius: var(--tk-r-sm);
  background: var(--tk-input-bg);
  color: var(--tk-ink);
  font: inherit;
}

.input:focus {
  outline: 2px solid var(--tk-accent);
  outline-offset: 0;
}

.mono {
  font-family: var(--tk-font-mono);
}

.otp {
  font-size: 22px;
  letter-spacing: 0.35em;
  text-align: center;
  height: 52px;
}

.btn-tall {
  height: 46px;
}

.rail-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-2);
}

/* ---- new session form ---- */

.new-session {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-2);
  padding: var(--tk-space-3);
  border: 1px solid var(--tk-line-2);
  border-radius: var(--tk-r-sm);
  background: var(--tk-chip);
}

.new-session[hidden] {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-1);
  font-size: var(--tk-fs-label, 11px);
  color: var(--tk-ink-3);
}

.select {
  position: relative;
  display: block;
}

.select::after {
  content: "▾";
  position: absolute;
  right: var(--tk-space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--tk-ink-3);
  pointer-events: none;
}

.field select {
  width: 100%;
  appearance: none;
  padding: var(--tk-space-2) var(--tk-space-6, 32px) var(--tk-space-2) var(--tk-space-3);
  border: 1px solid var(--tk-input-line);
  border-radius: var(--tk-r-sm);
  background: var(--tk-input-bg);
  color: var(--tk-ink);
  font: inherit;
}

.new-session-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--tk-space-2);
}

.composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 200px;
  resize: none;
  padding: var(--tk-space-2) var(--tk-space-3);
  border: 1px solid var(--tk-input-line);
  border-radius: var(--tk-r-sm);
  background: var(--tk-input-bg);
  color: var(--tk-ink);
  font: inherit;
  line-height: 1.5;
}

.composer textarea:disabled {
  opacity: 0.5;
}

.btn {
  height: 40px;
  padding: 0 var(--tk-space-4);
  border-radius: var(--tk-r-sm);
  border: 1px solid var(--tk-line);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--tk-dur-fast) var(--tk-ease), opacity var(--tk-dur-fast) var(--tk-ease);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-ghost {
  background: var(--tk-seg-bg);
  color: var(--tk-ink-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--tk-seg-on);
  color: var(--tk-ink);
}

.btn-accent {
  background: var(--tk-accent);
  border-color: var(--tk-accent);
  color: var(--tk-on-accent);
}

.btn-accent:hover:not(:disabled) {
  filter: brightness(1.08);
}

/* ---- motion ---- */

@keyframes enter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes blink {
  to { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
  .timeline {
    scroll-behavior: auto;
  }
}

/* ---- phone width: rail becomes a strip above the timeline ---- */

@media (max-width: 760px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: var(--tk-space-3);
    padding: var(--tk-gutter-mobile);
  }

  .rail {
    flex-direction: row;
    align-items: center;
    padding: var(--tk-space-2) var(--tk-space-3);
    overflow-x: auto;
  }

  .brand {
    flex: none;
  }

  .session-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .session-item {
    width: auto;
    white-space: nowrap;
  }

  .main {
    min-height: 0;
  }

  .thread-title {
    font-size: var(--tk-fs-h2);
  }

  .entry {
    max-width: 96%;
  }
}

/* rooms: two agent pickers, a starter choice and a long opening text */
.agent-pick,
.starter {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.agent-pick {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--tk-space-2);
}

.agent-pick legend,
.starter legend {
  width: 100%;
  margin-bottom: var(--tk-space-1);
  font-size: var(--tk-fs-label, 11px);
  color: var(--tk-ink-3);
}

.agent-pick .field,
.new-session .field {
  min-width: 0;
}

.new-session-actions .btn {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
}

.starter {
  display: flex;
  align-items: center;
  gap: var(--tk-space-3);
  font-size: var(--tk-fs-label, 11px);
  color: var(--tk-ink-2);
}

.starter legend {
  width: auto;
  margin: 0 var(--tk-space-2) 0 0;
}

textarea.input {
  min-height: 120px;
  max-height: 60vh;
  resize: vertical;
  font: inherit;
}

.entry-relay {
  opacity: 0.85;
  border-style: dashed;
}

/* new room: a panel in the main area, one card per agent */
.new-room {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: var(--tk-space-5, 28px);
  border-radius: var(--tk-r-md, 14px);
}

.new-room-form {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-4, 18px);
  max-width: 760px;
  margin: 0 auto;
}

.new-room-head {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-1);
}

.agent-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--tk-space-3);
}

.agent-card {
  display: flex;
  flex-direction: column;
  gap: var(--tk-space-3);
  min-width: 0;
  margin: 0;
  padding: var(--tk-space-4, 18px);
  border: 1px solid var(--tk-line-2);
  border-radius: var(--tk-r-md, 14px);
  background: var(--tk-chip);
}

.agent-card legend {
  padding: 0 var(--tk-space-1);
  font-size: var(--tk-fs-body, 14px);
  color: var(--tk-ink);
}

.starter-pick {
  display: flex;
  align-items: center;
  gap: var(--tk-space-2);
  font-size: var(--tk-fs-label, 11px);
  color: var(--tk-ink-2);
  cursor: pointer;
}

.new-room-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--tk-space-2);
}

.new-room-actions .btn {
  min-width: 140px;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .agent-cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* every text entry has a copy button; the room status pill pulses while an agent is thinking */
.entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--tk-space-2);
}

.entry-copy {
  flex: 0 0 auto;
  display: inline-flex;
  padding: 2px;
  border: 0;
  background: none;
  color: var(--tk-ink-3);
  cursor: pointer;
  border-radius: 6px;
}

.entry-copy:hover,
.entry-copy:focus-visible {
  color: var(--tk-ink-1);
}

.entry-copy[data-done] {
  color: var(--tk-accent, var(--tk-ink-1));
}

.pill[data-state="busy"] {
  color: var(--tk-ink-1);
  border-color: var(--tk-accent-line, var(--tk-line-2));
}

.pill[data-state="busy"]::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: var(--tk-space-2);
  border-radius: 50%;
  background: var(--tk-accent, currentColor);
  animation: ark-pulse 1.2s ease-in-out infinite;
}

@keyframes ark-pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

@media (prefers-reduced-motion: reduce) {
  .pill[data-state="busy"]::before {
    animation: none;
  }
}
