/* UsingOpen chat — light/dark, calm, single column. */

:root {
  --bg: #ffffff;
  --fg: #16181d;
  --muted: #6b7280;
  --faint: #9aa1ac;
  --border: #e6e8ec;
  --border-strong: #d4d8df;
  --surface: #f4f5f7;
  --surface-2: #fafbfc;
  --accent: #e8663f;
  --accent-soft: rgba(232, 102, 63, 0.12);
  --ok: #2f9e5f;
  --ok-soft: rgba(47, 158, 95, 0.12);
  --warn: #b8791b;
  --warn-soft: rgba(184, 121, 27, 0.14);
  --danger: #c0413d;
  --danger-soft: rgba(217, 83, 79, 0.08);
  --shadow: 0 2px 12px -4px rgba(16, 18, 24, 0.14);
  --shadow-lg: 0 18px 45px -22px rgba(16, 18, 24, 0.45);
  --radius: 14px;
  --radius-sm: 9px;
  --max-width: 46rem;
  color-scheme: light;
}

[data-theme='dark'] {
  --bg: #101216;
  --fg: #ecedef;
  --muted: #9ba2ad;
  --faint: #6d747f;
  --border: #262a32;
  --border-strong: #333842;
  --surface: #181b21;
  --surface-2: #14171c;
  --accent: #f07a52;
  --accent-soft: rgba(240, 122, 82, 0.16);
  --ok: #52c07f;
  --ok-soft: rgba(82, 192, 127, 0.14);
  --warn: #e0a34e;
  --warn-soft: rgba(224, 163, 78, 0.16);
  --danger: #f2a5a2;
  --danger-soft: rgba(217, 83, 79, 0.14);
  --shadow: 0 2px 14px -6px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 24px 50px -26px rgba(0, 0, 0, 0.85);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Author display rules (flex, inline-flex, …) would otherwise beat the UA's
   [hidden] rule and keep menus/buttons permanently visible. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.font-display, .hero__title, .brand__name {
  font-family: 'Montserrat', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* --- selection + focus rings -------------------------------------------------- */

::selection { background: var(--accent-soft); }

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

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

.app { display: flex; flex-direction: column; height: 100%; }

/* --- top bar --------------------------------------------------------------- */

.topbar { flex: 0 0 auto; border-bottom: 1px solid transparent; }

.topbar__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--fg); text-decoration: none; }

.brand__logo {
  width: 22px; height: 22px;
  border-radius: 6px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand__name { font-weight: 600; letter-spacing: -0.01em; }

.topbar__actions { display: inline-flex; align-items: center; gap: 6px; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
  padding: 4px 8px; border-radius: 999px;
  max-width: 16rem;
}
.status__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: 0 0 auto; }
.status[data-state='ready'] .status__dot { background: var(--ok); }
.status[data-state='warn'] .status__dot { background: var(--warn); }
.status[data-state='error'] .status__dot { background: var(--danger); }
.status[data-state='loading'] .status__dot { animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* --- layout ---------------------------------------------------------------- */

.main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hero {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: clamp(34px, 10vh, 108px) 20px 8px;
  text-align: center;
  position: relative;
}

/* Vertically centered empty state: when no messages yet,
   the hero + composer sit in the middle (with room for the keyboard var). */
.main.is-empty {
  justify-content: center;
}
.main.is-empty .thread {
  flex: 0 1 auto;
  overflow-y: visible;
}
.main.is-empty .hero {
  padding-top: clamp(8px, 4vh, 48px);
}

.hero::before {
  content: '';
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(38rem, 90vw);
  height: 210px;
  background: radial-gradient(ellipse at center, var(--accent-soft), transparent 70%);
  pointer-events: none;
  filter: blur(4px);
}

.hero > * { position: relative; }
.hero > :first-child { margin-top: 0; }
.hero > :last-child { margin-bottom: 0; }

.hero__title {
  margin: 0 0 10px;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.05;
  letter-spacing: -0.025em;
  font-weight: 600;
}

.hero__subtitle {
  margin: 0 auto;
  max-width: 32rem;
  color: var(--muted);
  font-size: 14px;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.footer__hint { opacity: 0.8; }

.footer__hint kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10.5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
  background: var(--surface);
}

.messages {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* --- messages -------------------------------------------------------------- */

.msg { display: flex; flex-direction: column; gap: 8px; }

.msg__head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
}

.msg__role {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
}

.msg__dot { width: 6px; height: 6px; border-radius: 50%; }

.msg--user .msg__head { justify-content: flex-end; }

.msg--user .msg__body {
  align-self: flex-end;
  max-width: 85%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg--assistant .msg__content { overflow-wrap: anywhere; }

.msg__content > :first-child { margin-top: 0; }
.msg__content > :last-child { margin-bottom: 0; }
.msg__content p { margin: 0 0 10px; }
.msg__content ul, .msg__content ol { margin: 0 0 10px; padding-left: 22px; }
.msg__content h1, .msg__content h2, .msg__content h3 { margin: 16px 0 8px; line-height: 1.25; }
.msg__content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
}
.msg__content pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 12px;
}
.msg__content pre code { background: none; border: 0; padding: 0; font-size: 0.86em; }
.msg__content a { color: var(--accent); }
.msg__content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 12px;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}
.msg__content th, .msg__content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}
.msg__content th { background: var(--surface); font-weight: 600; }
.msg__content blockquote {
  margin: 0 0 10px;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}
.msg__content hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.msg__content del { color: var(--muted); }
.codeblock { position: relative; margin: 0 0 12px; }
.codeblock pre { margin: 0; }
.codeblock__copy {
  position: absolute;
  top: 8px;
  right: 8px;
}

.cursor {
  display: inline-block;
  width: 7px; height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--accent);
  border-radius: 1px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* --- reasoning ------------------------------------------------------------- */

.reasoning {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}
.reasoning > summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 7px;
  user-select: none;
}
.reasoning > summary::-webkit-details-marker { display: none; }
.reasoning > summary::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}
.reasoning[open] > summary { border-bottom: 1px solid var(--border); }
.reasoning__body {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 22rem;
  overflow-y: auto;
}

/* --- meta line ------------------------------------------------------------- */

.msg__meta {
  font-size: 11.5px;
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.msg__error {
  border: 1px solid rgba(217, 83, 79, 0.4);
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
}

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

.composer-wrap {
  flex: 0 0 auto;
  padding: 8px 20px 14px;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

.composer {
  max-width: var(--max-width);
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--bg);
  box-shadow: 0 2px 10px -4px rgba(0, 0, 0, 0.12);
  padding: 6px 6px 6px 4px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.composer textarea {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 15px;
  resize: none;
  outline: none;
  min-height: 4rem;
  max-height: 12rem;
  padding: 14px 16px 2px;
  field-sizing: content;
}
@media (min-width: 640px) {
  .composer textarea { font-size: 14px; }
}

.composer__row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 2px;
}

.composer-meta {
  max-width: var(--max-width);
  margin: 8px auto 0;
  min-height: 1em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--faint);
}

.composer-note { text-align: center; }

.meter {
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}
.meter[data-state='near'] { color: var(--warn); border-color: rgba(184, 121, 27, 0.35); }
.meter[data-state='over'] { color: var(--danger); border-color: rgba(217, 83, 79, 0.45); }

/* --- chips, buttons -------------------------------------------------------- */

.picker { position: relative; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  max-width: 15rem;
  transition: border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--border-strong); }
.chip--quiet { color: var(--muted); }
.chip--icon {
  width: 34px;
  padding: 0;
  justify-content: center;
  color: var(--muted);
  flex: 0 0 auto;
}
.chip--icon:hover { color: var(--accent); border-color: var(--accent); }
.chip__logo {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: 0 0 auto;
  border-radius: 4px;
}
.chip__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__caret { color: var(--muted); flex: 0 0 auto; }
.chip__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex: 0 0 auto;
}
.chip__dot[data-state='adding_capacity'] { background: var(--warn); }
.chip__dot[data-state='unavailable'], .chip__dot[data-state='off'] { background: var(--faint); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, color 0.15s;
}
.btn--icon {
  width: 34px; height: 34px;
  border-color: var(--border);
  color: var(--muted);
}
.btn--icon:hover { border-color: var(--border-strong); color: var(--fg); }

.btn--ghost {
  height: 32px;
  padding: 0 12px;
  border-color: var(--border);
  color: var(--muted);
  font-size: 12.5px;
}
.btn--ghost:hover { border-color: var(--border-strong); color: var(--fg); }

.btn--tiny {
  height: 22px;
  padding: 0 9px;
  border-color: var(--border);
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.01em;
}
.btn--tiny:hover { color: var(--fg); border-color: var(--border-strong); }

.btn--send {
  width: 36px; height: 36px;
  margin-left: auto;
  background: var(--fg);
  color: var(--bg);
}
.btn--send:hover:not(:disabled) { opacity: 0.85; }
.btn--send:disabled { opacity: 0.35; cursor: default; }
.btn--stop { background: var(--surface); color: var(--fg); border-color: var(--border); }

.stop-square { width: 10px; height: 10px; border-radius: 2px; background: currentColor; }

/* --- menus ----------------------------------------------------------------- */

.menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  overflow: hidden;
}

.menu--compact {
  width: 15rem;
  padding: 6px;
}
.menu--models {
  width: min(30rem, 92vw);
  display: flex;
  flex-direction: column;
  max-height: min(30rem, 68vh);
}

.menu__head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--border);
}

.menu__filter {
  flex: 1 1 auto;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  outline: none;
  padding: 4px 6px;
}
.menu__filter::placeholder { color: var(--faint); }

.menu__refresh {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.menu__refresh:hover { color: var(--fg); border-color: var(--border-strong); }
.menu__refresh:disabled { opacity: 0.45; cursor: default; }

.menu__count {
  margin: 0;
  padding: 6px 12px 4px;
  font-size: 11px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.menu__list {
  overflow-y: auto;
  padding: 0 6px 8px;
  overscroll-behavior: contain;
}

.menu__section {
  margin: 8px 0 4px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}
.menu__section--quiet { color: var(--warn); }

.menu__empty {
  margin: 0;
  padding: 14px 12px;
  font-size: 13px;
  color: var(--muted);
}

.menu__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.menu__item:hover, .menu__item[aria-selected='true'] { background: var(--surface); }
.menu__item[aria-selected='true'] { box-shadow: inset 2px 0 0 var(--accent); }
.menu__item-name { font-size: 13.5px; font-weight: 600; }
.menu__item-hint { font-size: 11.5px; color: var(--faint); }

/* --- model rows ------------------------------------------------------------ */

.model-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  padding: 9px 10px;
  cursor: pointer;
  transition: background 0.12s;
}
.model-row:hover:not(:disabled) { background: var(--surface); }
.model-row[aria-selected='true'] { background: var(--surface); }
.model-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.model-row:disabled { cursor: default; opacity: 0.55; }

.tile {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--maker, var(--accent));
  margin-top: 1px;
  overflow: hidden;
  flex: 0 0 auto;
}

.model-logo {
  width: 28px; height: 28px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-top: 1px;
  flex: 0 0 auto;
}

.msg__logo {
  width: 14px; height: 14px;
  border-radius: 4px;
  object-fit: contain;
  vertical-align: -2px;
}

.model-row__main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.model-row__top {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.model-row__name { font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; }

.model-row__facts {
  font-size: 11.5px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.model-row__tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 1px; }

.model-row__blurb {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.model-row__good { font-size: 11.5px; color: var(--faint); }

.model-row__check {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

/* --- badges ---------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge--ready { color: var(--ok); background: var(--ok-soft); }
.badge--capacity { color: var(--warn); background: var(--warn-soft); }
.badge--off { color: var(--muted); background: var(--surface); }
.badge--warn { color: var(--warn); background: var(--warn-soft); }
.badge--soft {
  color: var(--faint);
  background: transparent;
  border-color: var(--border);
  text-transform: none;
  letter-spacing: 0.01em;
  font-weight: 500;
}

/* --- footer ---------------------------------------------------------------- */

.footer {
  flex: 0 0 auto;
  text-align: center;
  padding: 6px 16px 12px;
  font-size: 11.5px;
  color: var(--faint);
}
.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { color: var(--fg); }

@media (max-width: 640px) {
  .messages { padding: 18px 14px 4px; gap: 18px; }
  .composer-wrap { padding: 6px 12px 10px; }
  .hero { padding-top: 9vh; }
  .chip { max-width: 9.5rem; }
  .menu--models { width: min(30rem, 94vw); max-height: 72vh; }
  .status { max-width: 8.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
