/* ============================================================
   Nexint — dark, precise, quiet. Colour is used for meaning
   (state, danger, activity), never for decoration.
   ============================================================ */

:root {
  --bg:          #0a0b0d;
  --surface:     #101216;
  --raised:      #171a20;
  --raised-hi:   #1d212a;
  --line:        #23272f;
  --line-soft:   #1a1d24;

  --text:        #e9ebee;
  --dim:         #98a1ad;
  --faint:       #6a727d;

  --accent:      #7aa2f7;
  --ok:          #6cc98f;
  --warn:        #e0b25f;
  --danger:      #f07a7a;

  --r-sm: 6px;
  --r:    9px;
  --r-lg: 14px;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(.2, .7, .3, 1);
  --fast: 130ms var(--ease);
  --med:  220ms var(--ease);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }

svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- boot ---------- */

.boot { height: 100dvh; display: grid; place-items: center; }
.boot-mark {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--dim);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- typography bits ---------- */

.wordmark {
  display: flex; align-items: center; gap: 9px;
  font-weight: 560; letter-spacing: -.015em; font-size: 15px;
}
.wordmark .mark { width: 20px; height: 20px; stroke-width: 2.2; color: var(--text); }
.wordmark-lg { font-size: 22px; gap: 11px; margin-bottom: 6px; }
.wordmark-lg .mark { width: 27px; height: 27px; }

.inline-error {
  color: var(--danger); font-size: 13px; margin: 0;
  animation: rise var(--fast);
}

/* ---------- controls ---------- */

.btn {
  font: inherit; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--r);
  border: 1px solid transparent; background: transparent; color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background var(--fast), border-color var(--fast), color var(--fast), transform var(--fast), opacity var(--fast);
}
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--text); color: #0c0e11; font-weight: 550; }
.btn-primary:hover:not(:disabled) { background: #fff; }

.btn-quiet { border-color: var(--line); color: var(--dim); }
.btn-quiet:hover:not(:disabled) { color: var(--text); background: var(--raised); border-color: var(--line); }

.btn-icon { padding: 7px; width: 32px; height: 32px; color: var(--dim); font-size: 16px; }
.btn-icon:hover:not(:disabled) { color: var(--text); background: var(--raised); }

.btn-block { width: 100%; justify-content: flex-start; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: rgba(240, 122, 122, .1); }

input, textarea, .select {
  font: inherit; width: 100%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 9px 11px;
  transition: border-color var(--fast), box-shadow var(--fast);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, .select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 162, 247, .13);
}

.select {
  appearance: none; padding: 6px 28px 6px 10px; font-size: 13px; width: auto; max-width: 210px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2398a1ad' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M4 6.5 8 10.5l4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 13px;
  cursor: pointer; text-overflow: ellipsis;
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--dim); }
.field em { font-style: normal; font-size: 12px; }

/* ---------- auth ---------- */

.auth { height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(370px, 100%);
  display: flex; flex-direction: column; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 30px;
  animation: rise var(--med);
}
.auth-card > .dim { margin: -8px 0 6px; font-size: 14px; }

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

.app { display: flex; height: 100dvh; }

.sidebar {
  width: 252px; flex: 0 0 252px;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  transition: margin-left var(--med);
}
.sidebar.collapsed { margin-left: -252px; }

.sidebar-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 14px 16px;
}
.sidebar-bottom { padding: 8px; border-top: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 2px; }
.sidebar-bottom .btn { font-size: 13px; color: var(--dim); }
.sidebar-bottom .btn:hover { color: var(--text); }

.conversations { flex: 1; overflow-y: auto; padding: 4px 8px 12px; display: flex; flex-direction: column; gap: 1px; }

.conv {
  position: relative;
  display: flex; align-items: center; gap: 4px;
  padding: 8px 6px 8px 11px; border-radius: var(--r-sm);
  cursor: pointer; font-size: 13.5px; color: var(--dim);
  transition: background var(--fast), color var(--fast);
  animation: rise var(--fast);
}
.conv::before {
  content: ""; position: absolute; left: 2px; top: 50%;
  width: 2px; height: 0; border-radius: 2px; background: var(--accent);
  transform: translateY(-50%);
  transition: height var(--med);
}
.conv:hover { background: var(--raised); color: var(--text); }
.conv.active { background: var(--raised); color: var(--text); }
.conv.active::before { height: 15px; }
.conv-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .btn-icon { width: 24px; height: 24px; padding: 5px; opacity: 0; font-size: 13px; }
.conv:hover .btn-icon, .conv:focus-within .btn-icon { opacity: 1; }

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

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 18px; border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
}
.chat-title {
  flex: 1; margin: 0; font-size: 14.5px; font-weight: 550; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-controls { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 11px; font-family: var(--mono); letter-spacing: -.01em;
  padding: 4px 9px; border-radius: 20px;
  border: 1px solid var(--line); color: var(--dim); white-space: nowrap;
}
.badge.write { border-color: rgba(224, 178, 95, .35); color: var(--warn); }
.badge.read { border-color: rgba(108, 201, 143, .3); color: var(--ok); }

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

.messages { flex: 1; overflow-y: auto; padding: 28px 20px 8px; scroll-behavior: smooth; }

.turn { max-width: 780px; margin: 0 auto 26px; animation: rise var(--med); }

.turn-head {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 8px; font-size: 12px; color: var(--faint);
  font-family: var(--mono); letter-spacing: .02em; text-transform: lowercase;
}
.turn-head .who { color: var(--dim); }
.turn-actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity var(--fast); }
.turn:hover .turn-actions, .turn:focus-within .turn-actions { opacity: 1; }
.turn-actions .btn-icon { width: 26px; height: 26px; padding: 6px; font-size: 13px; }
.copied { color: var(--ok) !important; }

.bubble { border-radius: var(--r); }
.turn.user .bubble {
  background: var(--surface); border: 1px solid var(--line-soft);
  padding: 11px 14px; white-space: pre-wrap; word-break: break-word;
}

.prose { word-break: break-word; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 12px; }
.prose h1, .prose h2, .prose h3 { margin: 22px 0 10px; font-size: 15.5px; font-weight: 600; letter-spacing: -.01em; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 20px; }
.prose li { margin-bottom: 4px; }
.prose a { color: var(--accent); text-decoration-color: rgba(122, 162, 247, .4); text-underline-offset: 2px; }
.prose code {
  font-family: var(--mono); font-size: 12.8px;
  background: var(--raised); padding: 2px 5px; border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
}
.prose pre {
  margin: 0 0 14px; padding: 13px 15px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  overflow-x: auto;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: 12.8px; line-height: 1.65; }

/* streaming caret */
.streaming .prose::after {
  content: ""; display: inline-block; vertical-align: text-bottom;
  width: 7px; height: 15px; margin-left: 3px; border-radius: 1px;
  background: var(--accent); animation: blink 1.1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- attachments ---------- */

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; font-size: 12.5px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 20px;
  color: var(--dim);
}
.file-chip .name { color: var(--text); max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip svg { width: 13px; height: 13px; flex: none; }
.file-chip .btn-icon { width: 18px; height: 18px; padding: 3px; font-size: 11px; margin-right: -4px; }

.thumb {
  display: block; max-width: 260px; max-height: 220px; width: auto; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface);
}

/* ---------- tool activity ---------- */

.tool {
  max-width: 780px; margin: 0 auto 10px;
  border: 1px solid var(--line-soft); border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
  animation: rise var(--fast);
}
.tool summary {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 13px; cursor: pointer; list-style: none;
  font-size: 13px; color: var(--dim);
}
.tool summary::-webkit-details-marker { display: none; }
.tool summary:hover { background: var(--raised); }
.tool .label { color: var(--text); }
.tool .detail {
  margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46%;
}
.tool .chevron { transition: transform var(--fast); width: 12px; height: 12px; color: var(--faint); }
.tool[open] .chevron { transform: rotate(90deg); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--faint); }
.dot.running { background: var(--accent); animation: pulse 1.2s var(--ease) infinite; }
.dot.ok { background: var(--ok); }
.dot.empty { background: var(--warn); }
.dot.error { background: var(--danger); }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.72); }
}

.tool.write .label::after {
  content: "write"; margin-left: 8px; padding: 1px 6px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .03em;
  border: 1px solid rgba(224, 178, 95, .35); border-radius: 4px; color: var(--warn);
}
.tool pre {
  margin: 0; padding: 11px 13px; border-top: 1px solid var(--line-soft);
  background: var(--bg); font-family: var(--mono); font-size: 11.8px; line-height: 1.6;
  color: var(--dim); max-height: 300px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}
.tool[open] pre { animation: unfold var(--med); }

/* ---------- status + notices ---------- */

.activity {
  max-width: 780px; margin: 0 auto 20px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--dim);
}
.activity .shimmer {
  background: linear-gradient(90deg, var(--faint) 20%, var(--text) 45%, var(--faint) 70%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: sweep 2.1s linear infinite;
}
@keyframes sweep { to { background-position: -220% 0; } }

.notice {
  max-width: 780px; margin: 0 auto 18px; padding: 10px 14px;
  border-radius: var(--r); font-size: 13.5px;
  border: 1px solid var(--line); background: var(--surface); color: var(--dim);
  animation: rise var(--med);
}
.notice.warn { border-color: rgba(224, 178, 95, .3); color: var(--warn); background: rgba(224, 178, 95, .05); }
.notice.error { border-color: rgba(240, 122, 122, .32); color: var(--danger); background: rgba(240, 122, 122, .05); }
.notice strong { display: block; margin-bottom: 2px; color: inherit; font-weight: 600; }

.empty-state {
  max-width: 780px; margin: 12vh auto 0; text-align: center; color: var(--faint);
  animation: rise var(--med);
}
.empty-state .mark { width: 34px; height: 34px; stroke-width: 2; color: var(--line); margin-bottom: 14px; }
.empty-state p { margin: 0; font-size: 14px; }

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

.composer-wrap { padding: 8px 20px 18px; position: relative; }
.composer {
  max-width: 780px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 8px;
  transition: border-color var(--fast), box-shadow var(--fast);
}
.composer:focus-within { border-color: var(--line); box-shadow: 0 0 0 3px rgba(122, 162, 247, .1); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  border: 0; background: none; padding: 7px 4px; resize: none; max-height: 220px;
}
.composer textarea:focus { box-shadow: none; }
.btn-send, .btn-stop { width: 34px; height: 34px; padding: 0; flex: none; border-radius: var(--r); }
.btn-stop { background: var(--raised-hi); color: var(--text); border: 1px solid var(--line); }
.btn-stop svg { fill: currentColor; }

.tray { display: flex; flex-wrap: wrap; gap: 7px; padding: 5px 4px 9px; }

.composer-hint {
  max-width: 780px; margin: 8px auto 0; font-size: 11.5px; text-align: center;
  min-height: 15px; color: var(--faint);
}

.drop-hint {
  position: absolute; inset: 8px 20px 18px;
  display: grid; place-items: center;
  border: 1.5px dashed var(--accent); border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--bg) 88%, var(--accent));
  color: var(--accent); font-size: 14px; z-index: 3;
  animation: rise var(--fast);
}

/* ---------- dialogs ---------- */

.dialog {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  width: min(660px, 94vw); max-height: 86dvh; padding: 0;
  overflow: hidden;
}
.dialog-sm { width: min(460px, 94vw); }
.dialog::backdrop { background: rgba(5, 6, 8, .66); animation: fade var(--fast); }
.dialog[open] { animation: pop var(--med); }

.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line-soft);
}
.dialog-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.dialog-body { padding: 20px 18px 24px; overflow-y: auto; max-height: calc(86dvh - 56px); }
.dialog-body section { margin-bottom: 30px; }
.dialog-body section:last-child { margin-bottom: 0; }
.dialog-body h3 { margin: 0; font-size: 14px; font-weight: 600; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.dialog-body section > .dim { margin: 0 0 14px; }

.card {
  border: 1px solid var(--line); border-radius: var(--r); padding: 13px 14px;
  animation: rise var(--fast);
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.card-head strong { font-weight: 550; font-size: 14px; }
.card-meta { font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.card-actions { margin-left: auto; display: flex; gap: 2px; }

.probe-box {
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line-soft);
}
.probe-box h4 { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
.probe-box > .dim { margin: 0 0 12px; }
.probe-box .select { max-width: none; flex: 1; }

.probe {
  margin-top: 12px; padding: 11px 13px; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--bg);
  animation: rise var(--fast);
}
.probe.good { border-color: rgba(108, 201, 143, .3); }
.probe.bad { border-color: rgba(240, 122, 122, .3); }
.probe-line { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.probe-line:last-child { margin-bottom: 0; }
.probe-line .k { color: var(--faint); font-family: var(--mono); font-size: 11px; min-width: 74px; }
.probe-line .v { color: var(--dim); }
.probe-line .v.ok { color: var(--ok); }
.probe-line .v.off { color: var(--warn); }
.probe-note { color: var(--warn); margin-top: 8px; line-height: 1.5; }
.probe-error { color: var(--danger); line-height: 1.5; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.chip.adjusted { border-color: rgba(224, 178, 95, .35); color: var(--warn); }
.chip {
  font-family: var(--mono); font-size: 11px; color: var(--dim);
  border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px;
}

.toggle {
  display: flex; align-items: center; gap: 9px; margin-top: 9px;
  font-size: 13px; color: var(--dim); cursor: pointer;
}
.toggle input { width: auto; margin: 0; accent-color: var(--accent); cursor: pointer; }
.toggle input:disabled { cursor: not-allowed; }
.toggle.locked { opacity: .5; }

.status-text.error { color: var(--danger); }

.audit { display: flex; flex-direction: column; gap: 5px; margin-top: 12px; }
.audit-row {
  display: flex; gap: 11px; align-items: center;
  padding: 7px 11px; font-size: 12px;
  border: 1px solid var(--line-soft); border-radius: var(--r-sm);
}
.audit-row .when { color: var(--faint); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.audit-row .what { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); }
.audit-row.bad { border-color: rgba(240, 122, 122, .25); }

/* ---------- animation primitives ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop  { from { opacity: 0; transform: scale(.985) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes unfold { from { opacity: 0; max-height: 0; } to { opacity: 1; max-height: 300px; } }

/* ---------- responsive ---------- */

@media (max-width: 780px) {
  .sidebar { position: absolute; z-index: 6; height: 100dvh; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .messages { padding: 20px 14px 8px; }
  .composer-wrap { padding: 6px 12px 12px; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .select { max-width: 128px; }
  .turn-actions { opacity: 1; }
  .badge { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .dot.running { opacity: .8; }
}
