/* T7 owns this file. Chat view: thread, messages, markdown, code blocks, composer, model picker.
   Uses only tokens from tokens.css (T5) and the class names of SPEC 8.6 / 8.7. */

/* ---------- header extras ---------- */
.stage__heading { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; flex: 1 1 auto; }
.stage__heading .stage__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; overflow-wrap: normal; }
.stage__tools { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; min-width: 0; }
.stage__tools .seg { max-width: 100%; }
.stage__model { min-width: 0; }
.seg__item { display: inline-flex; align-items: center; gap: var(--s-1); white-space: nowrap; }
.seg__icon { display: inline-flex; }

/* [hidden] must win over the display rules below */
.chat-banner[hidden], .composer__attachments[hidden], .model-picker__error[hidden], .thread__loading[hidden] { display: none; }

/* ---------- body layout ---------- */
.stage__body--chat {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-height: 0;
  flex: 1 1 auto;
  padding-bottom: var(--s-1);
}

/* ---------- thread (card, scroll area) ---------- */
.thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--grad-card);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: var(--s-5) var(--s-5) var(--s-6);
  scroll-behavior: smooth;
}
.thread__inner {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-height: 100%;
  max-width: 820px;
  margin: 0 auto;
}
.thread__inner > .empty { margin: auto; }
.thread__loading { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-4) 0; }
.skeleton--short { width: 60%; }

/* ---------- messages ---------- */
.msg { position: relative; max-width: 100%; min-width: 0; }
.msg__body { min-width: 0; overflow-wrap: anywhere; }
.msg__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--ink-3);
  margin-bottom: var(--s-2);
  font-variant-numeric: tabular-nums;
}
.msg__model { color: var(--ink-2); }
.msg__seg { display: inline-flex; align-items: center; max-width: 100%; min-width: 0; white-space: nowrap; }
.msg__sep { opacity: .6; margin-right: .4em; }
.msg__model { overflow-wrap: anywhere; }
.msg__tier { display: inline-flex; align-items: center; white-space: nowrap; }
.msg__seg > .msg__auto { max-width: 100%; }
.msg__status { margin-top: var(--s-2); }
.msg__actions { margin-top: var(--s-2); display: flex; }

.msg--user {
  align-self: flex-end;
  max-width: 78%;
  background: var(--grad-raised);
  color: var(--ink);
  border-radius: var(--r-row) var(--r-row) var(--r-tag) var(--r-row);
  box-shadow: var(--shadow-raised);
  padding: var(--s-3) var(--s-4);
}
.msg--user .msg__body { white-space: pre-wrap; font-size: 15px; line-height: 1.45; }
.msg--user .msg__media { margin-top: var(--s-2); }

.msg--assistant {
  align-self: stretch;
  background-color: var(--card-1);
  background-image: var(--dots);
  background-size: 10px 10px;
  border-radius: var(--r-row);
  box-shadow: var(--shadow-inset);
  padding: var(--s-4) var(--s-5);
}
.msg--assistant.is-streaming .msg__pending { display: flex; align-items: center; gap: var(--s-2); color: var(--ink-3); }
.msg--assistant .msg__body { font-size: 15px; line-height: 1.5; }

.msg__pending .spinner { width: 14px; height: 14px; }

.msg__copy { font-size: 12px; }

/* ---------- live + error chips inside messages ---------- */
.msg .chip--live .chip__dot { animation: chat-pulse 1.4s ease-in-out infinite; }
@keyframes chat-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.7); }
}

/* ---------- media ---------- */
.msg__media { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-top: var(--s-3); }
.msg__media-item { margin: 0; display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-2); max-width: 100%; }
.msg__img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  width: auto;
  height: auto;
  border-radius: var(--r-control);
  background: var(--well);
  box-shadow: var(--shadow-raised);
}
.msg__media-actions { text-decoration: none; }
.msg__audio { display: block; width: min(100%, 360px); height: 40px; }
.msg__video { display: block; max-width: 100%; max-height: 420px; border-radius: var(--r-control); background: var(--graphite-2); }

/* ---------- attachment chips (messages and composer) ---------- */
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  max-width: 100%;
  min-height: 30px;
  padding: 0 var(--s-3) 0 var(--s-2);
  border-radius: var(--r-pill);
  background: var(--soft);
  color: var(--ink);
  font: 400 13px/1 var(--font-ui);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
a.attach-chip:hover { background: var(--well); }
.attach-chip > svg { color: var(--ink-2); }
.attach-chip__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.attach-chip__size { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.attach-chip.is-uploading { background: var(--hatch), var(--soft); color: var(--ink-2); }
.attach-chip__remove {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-left: var(--s-1);
  border: 0;
  border-radius: var(--r-pill);
  background: var(--raised-1);
  color: var(--ink-2);
  cursor: pointer;
  flex-shrink: 0;
}
.attach-chip__remove:hover { color: var(--ink); }
.attach-chip__remove:focus-visible { outline: 2px solid var(--graphite-2); outline-offset: 2px; }

/* ---------- markdown ---------- */
.md { font-family: var(--font-ui); color: var(--ink); overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .75em; }
.md h1, .md h2, .md h3, .md h4 { font-weight: 500; line-height: 1.25; margin: 1.1em 0 .45em; letter-spacing: -.005em; }
.md h1 { font-size: 22px; }
.md h2 { font-size: 19px; }
.md h3 { font-size: 17px; }
.md h4 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 .75em; padding-left: 1.4em; }
.md ul { list-style: disc; }
.md ol { list-style: decimal; }
.md li { margin: .2em 0; padding-left: .15em; }
.md li::marker { color: var(--ink-3); }
.md blockquote {
  margin: 0 0 .75em;
  padding: var(--s-1) var(--s-4);
  border-left: 3px solid var(--line);
  color: var(--ink-2);
}
.md blockquote > :last-child { margin-bottom: 0; }
.md a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--ink-3); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: var(--ink); }
.md a:focus-visible { outline: 2px solid var(--graphite-2); outline-offset: 2px; border-radius: 4px; }
.md strong { font-weight: 600; }
.md code {
  font-family: var(--font-mono);
  font-size: .86em;
  padding: .1em .38em;
  border-radius: var(--r-keycap);
  background: var(--well);
  overflow-wrap: anywhere;
}
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md__table-wrap { overflow-x: auto; margin: 0 0 .75em; border-radius: var(--r-tag); border: 1px solid var(--line); }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.md th, .md td { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { font-weight: 500; color: var(--ink-2); background: var(--raised-2); }
.md tr:last-child td { border-bottom: 0; }

/* ---------- code blocks ---------- */
.code-block {
  margin: 0 0 .75em;
  border-radius: var(--r-control);
  background: var(--graphite-2);
  color: var(--on-graphite);
  overflow: hidden;
  box-shadow: var(--shadow-raised);
}
.code-block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: 36px;
  padding: var(--s-1) var(--s-2) var(--s-1) var(--s-4);
  background: var(--graphite-1);
}
.code-block__lang {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(244, 245, 246, .72);
}
.code-block__copy {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  height: 26px;
  padding: 0 var(--s-3);
  border: 1px solid rgba(244, 245, 246, .22);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--on-graphite);
  font: 500 12px/1 var(--font-ui);
  cursor: pointer;
}
.code-block__copy:hover { background: rgba(244, 245, 246, .1); }
.code-block__copy:focus-visible { outline: 2px solid var(--on-graphite); outline-offset: 2px; }
.code-block pre {
  margin: 0;
  padding: var(--s-3) var(--s-4) var(--s-4);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.code-block code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

/* ---------- composer ---------- */
.composer-host { width: 100%; max-width: 820px; margin: 0 auto; flex-shrink: 0; }
.composer {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  background: var(--grad-card);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: var(--s-3) var(--s-4) var(--s-2);
  transition: box-shadow .15s ease;
}
.composer:focus-within { box-shadow: var(--shadow-card), 0 0 0 2px var(--graphite-2); }
.composer.is-dragover {
  box-shadow: var(--shadow-card), 0 0 0 2px var(--graphite-2);
  background-image: var(--hatch), var(--grad-card);
}
.composer__attachments { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.composer__row { display: flex; align-items: flex-end; min-width: 0; }
.composer__input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 44px;
  max-height: 200px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: none;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--ink);
  padding: var(--s-2) var(--s-2);
  font: 400 15px/1.45 var(--font-ui);
}
.composer__input::placeholder { color: var(--ink-3); }
.composer__input:disabled { color: var(--ink-3); cursor: not-allowed; }
.composer__actions { display: flex; align-items: center; gap: var(--s-3); }
.composer__hint { flex: 1 1 auto; min-width: 0; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer__send { margin-left: auto; flex-shrink: 0; }
.composer__send .btn__kbd { margin-left: var(--s-1); }
.composer__actions .btn--icon { flex-shrink: 0; }
.composer__actions .btn--icon:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- chat banner (missing key) ---------- */
.chat-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-pill);
  background: var(--hatch), var(--panel-2);
  color: var(--ink-2);
  font: 400 13px/1.3 var(--font-ui);
}

/* ---------- model picker ---------- */
.model-picker { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2); min-width: 0; }
.model-picker__label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.model-picker__controls { display: flex; align-items: center; gap: var(--s-2); min-width: 0; flex-wrap: wrap; }
.model-picker__filter {
  width: 128px;
  height: var(--h-sm);
  padding: 0 var(--s-3);
  border: 0;
  border-radius: var(--r-control);
  background: var(--well);
  color: var(--ink);
  font: 400 13px/1 var(--font-ui);
  outline: none;
}
.model-picker__filter::placeholder { color: var(--ink-3); }
.model-picker__filter:focus-visible,
.model-picker__select:focus-visible { box-shadow: 0 0 0 2px var(--graphite-2); }
.model-picker__select {
  height: var(--h-sm);
  min-width: 180px;
  max-width: 300px;
  padding: 0 40px 0 var(--s-3);
  border: 0;
  border-radius: var(--r-control);
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--well);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235E646C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  color: var(--ink);
  font: 500 13px/1 var(--font-ui);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  cursor: pointer;
  outline: none;
}
.model-picker__select:disabled { color: var(--ink-3); cursor: default; }
.model-picker__error { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

/* ---------- reduced motion, narrow screens ---------- */
@media (prefers-reduced-motion: reduce) {
  .thread { scroll-behavior: auto; }
  .msg .chip--live .chip__dot { animation: none; }
  .composer { transition: none; }
}

@media (max-width: 859px) {
  .stage__header { flex-wrap: nowrap; }
  .stage__heading { flex: 0 0 auto; }
  .stage__heading .stage__title {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .stage__tools { width: 100%; gap: var(--s-2); }
  .stage__tools .seg { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .stage__tools .seg::-webkit-scrollbar { display: none; }
  .stage__model { width: 100%; }
  .model-picker { width: 100%; }
  .model-picker__controls { flex: 1 1 auto; }
  .model-picker__filter { width: 100%; min-width: 0; flex: 1 1 120px; }
  .model-picker__select { flex: 2 1 180px; min-width: 0; max-width: none; }
  .thread { padding: var(--s-4) var(--s-3) var(--s-5); border-radius: var(--r-row); }
  .thread__inner { gap: var(--s-3); }
  .msg--user { max-width: 90%; }
  .msg--assistant { padding: var(--s-3) var(--s-4); }
  .composer { padding: var(--s-2) var(--s-3) var(--s-2); border-radius: var(--r-row); }
  .composer__hint { display: none; }
  .composer__send { min-height: 40px; }
  .composer__input { font-size: 16px; }
  .attach-chip__name { max-width: 160px; }
}

/* ---------- Otomatis (SPEC 11): tier chip, meta segments, retry action, picker hint ---------- */
.tier-chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--r-tag);
  background: var(--well);
  color: var(--ink-2);
  font: 400 11px/1 var(--font-mono);
  letter-spacing: .04em;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--line);
}
.msg__auto { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); min-width: 0; }
.msg__esc { color: var(--ink-3); }
.msg__cost { color: var(--ink-2); }
.msg__actions { flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.msg__stronger { font-size: 12px; }
.model-picker__hint {
  flex: 1 1 100%;
  margin: 0;
  font: 400 11px/1.4 var(--font-mono);
  letter-spacing: .02em;
  color: var(--ink-3);
}
.model-picker__hint[hidden] { display: none; }

@media (max-width: 640px) {
  .model-picker__hint { display: none; }
}
