/* ==========================================================================
   GRV Chat - design system
   Dark-first, brand orange (#F54E1B), motion tuned with a spring curve.
   Patterns adapted from the OriginKit / Skiper UI vocabulary (gradient rings,
   sheen sweeps, aurora fields, spotlight hover) as dependency-free CSS.
   ========================================================================== */

:root {
  /* Brand surfaces paint their own background, so these are theme-invariant. */
  --brand: #f54e1b;
  --brand-soft: #ff7a4a;
  --brand-deep: #c93d10;
  --brand-ink: #2b0d02;
  /* Brand-coloured *text* sits on the page background, so it is theme-aware
     (see the light-theme block) to stay above the 4.5:1 contrast floor. */
  --brand-text: #ff8352;
  --brand-text-hover: #ffa480;
  --gray-brand: #9d9a96;

  --bg: #0e1013;
  --bg-deep: #0a0c0e;
  --surface: #15181d;
  --surface-2: #1b1f25;
  --surface-3: #22272e;
  --line: #262b32;
  --line-soft: #1e2329;

  --text: #e9edf1;
  --text-dim: #b3bcc6;
  --muted: #838d98;
  --muted-2: #626c77;

  --danger: #f2555a;
  --warn: #f0a83c;
  --ok: #46c98b;

  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --rail: 60px;
  --sidebar: 288px;
  --composer-max: 880px;
  --thread-max: 860px;

  --spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --ease: cubic-bezier(0.22, 0.68, 0.36, 1);
  --fast: 140ms;
  --base: 240ms;
  --slow: 420ms;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 28px 70px -24px rgba(0, 0, 0, 0.75);
  --glow: 0 0 0 1px rgba(245, 78, 27, 0.28), 0 12px 40px -14px rgba(245, 78, 27, 0.35);

  --font: "Inter", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", ui-monospace, "SFMono-Regular", Consolas, monospace;

  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-deep: #eceef2;
  --surface: #ffffff;
  --surface-2: #f4f6f8;
  --surface-3: #e9edf1;
  --line: #dde2e8;
  --line-soft: #e7ebf0;

  --text: #171b20;
  --text-dim: #3d4650;
  --muted: #666f7a;
  --muted-2: #8b949e;

  --brand-text: #c2400f;
  --brand-text-hover: #9e3309;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 10px 28px -14px rgba(16, 24, 40, 0.2);
  --shadow-lg: 0 28px 64px -26px rgba(16, 24, 40, 0.28);
  color-scheme: light;
}

/* --------------------------------------------------------------------------
   Reset
   -------------------------------------------------------------------------- */

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, figure, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img, svg, video { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { color: var(--brand-text-hover); }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

::selection { background: rgba(245, 78, 27, 0.32); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted-2) 45%, transparent);
  border: 3px solid transparent;
  border-radius: 99px;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); background-clip: content-box; }

[hidden] { display: none !important; }

.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;
}

/* --------------------------------------------------------------------------
   Ambient background (aurora field)
   -------------------------------------------------------------------------- */

.aurora {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.aurora::before,
.aurora::after {
  content: "";
  position: absolute;
  width: 62vmax;
  height: 62vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.22;
  will-change: transform;
}

.aurora::before {
  background: radial-gradient(circle at 30% 30%, var(--brand) 0%, transparent 62%);
  top: -26vmax;
  left: -14vmax;
  animation: drift-a 26s var(--ease) infinite alternate;
}

.aurora::after {
  background: radial-gradient(circle at 70% 70%, var(--gray-brand) 0%, transparent 60%);
  bottom: -30vmax;
  right: -16vmax;
  animation: drift-b 32s var(--ease) infinite alternate;
}

@keyframes drift-a {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(12vmax, 8vmax, 0) scale(1.15); }
}
@keyframes drift-b {
  from { transform: translate3d(0, 0, 0) scale(1.1); }
  to   { transform: translate3d(-10vmax, -6vmax, 0) scale(1); }
}

.grid-veil {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--line) 55%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--line) 55%, transparent) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 0%, transparent 75%);
  opacity: 0.5;
}

/* --------------------------------------------------------------------------
   Primitives
   -------------------------------------------------------------------------- */

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-line: var(--line);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  min-height: 38px;
  border: 1px solid var(--btn-line);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 13.5px;
  font-weight: 550;
  letter-spacing: 0.01em;
  cursor: pointer;
  overflow: hidden;
  transition: transform var(--fast) var(--spring), background var(--fast) var(--ease),
    border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), opacity var(--fast);
}

.btn:hover { background: var(--surface-3); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Sheen sweep on primary actions */
.btn-primary {
  --btn-bg: linear-gradient(180deg, var(--brand-soft), var(--brand));
  --btn-fg: var(--brand-ink);
  --btn-line: transparent;
  font-weight: 650;
  box-shadow: 0 8px 24px -12px rgba(245, 78, 27, 0.7);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #74d2de, var(--brand-soft));
  box-shadow: 0 12px 30px -12px rgba(245, 78, 27, 0.85);
}
.btn-primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 20%, rgba(255, 255, 255, 0.5) 50%, transparent 80%);
  transform: translateX(-130%);
  transition: transform 700ms var(--ease);
}
.btn-primary:hover::after { transform: translateX(130%); }

.btn-ghost { --btn-bg: transparent; --btn-line: transparent; color: var(--text-dim); }
.btn-ghost:hover { --btn-bg: var(--surface-2); color: var(--text); }

.btn-danger { --btn-bg: transparent; --btn-line: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn-danger:hover { --btn-bg: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.btn-sm { min-height: 32px; padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
    transform var(--fast) var(--spring);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.is-on { background: color-mix(in srgb, var(--brand) 18%, transparent); color: var(--brand-text); }
.icon-btn svg { width: 18px; height: 18px; }

.field { display: grid; gap: 7px; }

.label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }

.input,
.textarea,
.select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease),
    background var(--fast) var(--ease);
}

.input::placeholder, .textarea::placeholder { color: var(--muted-2); }

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--brand) 60%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
  background: var(--surface);
}

.input[aria-invalid="true"] { border-color: var(--danger); }

.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }

.select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23838d98' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 16px;
}

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 46px; }
.input-group .input-action {
  position: absolute;
  right: 6px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.input-group .input-action:hover { background: var(--surface-3); color: var(--text); }
.input-group .input-action svg { width: 17px; height: 17px; }

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color var(--fast), background var(--fast);
}
.checkbox:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.checkbox input { margin: 3px 0 0; accent-color: var(--brand); width: 15px; height: 15px; cursor: pointer; }
.checkbox .checkbox-text { display: grid; gap: 2px; }
.checkbox strong { font-size: 13px; font-weight: 600; }
.checkbox span { font-size: 11.5px; color: var(--muted); line-height: 1.45; }

/* Gradient-ring card: the OriginKit signature border treatment */
.card {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.card-ring::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(140deg,
    color-mix(in srgb, var(--brand) 55%, transparent),
    transparent 38%,
    transparent 62%,
    color-mix(in srgb, var(--gray-brand) 40%, transparent));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.card-pad { padding: 22px; }

.glass {
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}
.pill svg { width: 12px; height: 12px; }
.pill-brand { border-color: color-mix(in srgb, var(--brand) 40%, transparent); color: var(--brand-text); background: color-mix(in srgb, var(--brand) 12%, transparent); }
.pill-ok { border-color: color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.pill-warn { border-color: color-mix(in srgb, var(--warn) 40%, transparent); color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.pill-danger { border-color: color-mix(in srgb, var(--danger) 42%, transparent); color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.pill-muted { color: var(--muted); }

.divider { height: 1px; background: var(--line-soft); border: 0; margin: 0; }

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--brand), var(--brand-soft));
  color: var(--brand-ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 96px; height: 96px; font-size: 30px; }
.avatar-sm { width: 26px; height: 26px; font-size: 10px; }

.meter {
  position: relative;
  height: 6px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.meter > i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--brand-deep), var(--brand-soft));
  transition: width var(--slow) var(--ease);
}
.meter.is-warn > i { background: linear-gradient(90deg, #c8801f, var(--warn)); }
.meter.is-over > i { background: linear-gradient(90deg, #b33b3f, var(--danger)); }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Toasts + flash messages
   -------------------------------------------------------------------------- */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100vw - 36px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in 380ms var(--spring) both;
}
.toast.is-out { animation: toast-out 220ms var(--ease) forwards; }
.toast .toast-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast .toast-icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.toast-success { border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.toast-success .toast-icon { color: var(--ok); }
.toast-error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.toast-warn .toast-icon { color: var(--warn); }
.toast-info .toast-icon, .toast-password .toast-icon { color: var(--brand-text); }
.toast code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 6px;
  user-select: all;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(24px) scale(0.97); }
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.55;
}
.alert svg { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.alert-error { border-color: color-mix(in srgb, var(--danger) 42%, transparent); background: color-mix(in srgb, var(--danger) 10%, var(--surface-2)); }
.alert-error svg { color: var(--danger); }
.alert-warn { border-color: color-mix(in srgb, var(--warn) 42%, transparent); background: color-mix(in srgb, var(--warn) 10%, var(--surface-2)); }
.alert-warn svg { color: var(--warn); }
.alert-ok { border-color: color-mix(in srgb, var(--ok) 42%, transparent); background: color-mix(in srgb, var(--ok) 10%, var(--surface-2)); }
.alert-ok svg { color: var(--ok); }
.alert-info svg { color: var(--brand-text); }
.alert ul { padding-left: 18px; list-style: disc; }

/* --------------------------------------------------------------------------
   Auth pages
   -------------------------------------------------------------------------- */

.auth {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  min-height: 100vh;
}

.auth-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 40px;
  padding: 44px 52px;
  overflow: hidden;
  border-right: 1px solid var(--line-soft);
  background:
    radial-gradient(120% 80% at 12% 0%, color-mix(in srgb, var(--brand) 16%, transparent) 0%, transparent 60%),
    var(--bg-deep);
}

.auth-brand-mark { display: flex; align-items: center; gap: 12px; }
.auth-brand-mark img { width: 38px; height: 38px; }
.auth-brand-mark strong { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

.auth-hero { max-width: 460px; display: grid; gap: 18px; }
.auth-hero h1 {
  font-size: clamp(30px, 3.4vw, 44px);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.03em;
}
.auth-hero .grad {
  background: linear-gradient(100deg, var(--brand-text), var(--brand), var(--gray-brand));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.auth-hero p { color: var(--text-dim); font-size: 15px; line-height: 1.65; }

.auth-features { display: grid; gap: 11px; margin-top: 6px; }
.auth-features li {
  display: flex;
  align-items: center;
  gap: 11px;
  list-style: none;
  font-size: 13.5px;
  color: var(--text-dim);
  animation: rise 620ms var(--spring) both;
}
.auth-features li:nth-child(1) { animation-delay: 60ms; }
.auth-features li:nth-child(2) { animation-delay: 130ms; }
.auth-features li:nth-child(3) { animation-delay: 200ms; }
.auth-features li:nth-child(4) { animation-delay: 270ms; }
.auth-features .tick {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 8px;
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  color: var(--brand-text);
}
.auth-features .tick svg { width: 14px; height: 14px; }

.auth-foot { font-size: 12px; color: var(--muted-2); }

.auth-panel {
  display: grid;
  place-items: center;
  padding: 40px 28px;
}

.auth-card {
  width: min(430px, 100%);
  padding: 32px;
  animation: rise 520ms var(--spring) both;
}

.auth-card-head { display: grid; gap: 7px; margin-bottom: 22px; }
.auth-card-head .mark { display: none; }
.auth-card-head h2 { font-size: 23px; font-weight: 700; letter-spacing: -0.02em; }
.auth-card-head p { font-size: 13.5px; color: var(--muted); }

.auth-form { display: grid; gap: 15px; }
.auth-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }

.auth-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
  color: var(--muted);
}

.auth-alt {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

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

/* Password strength bar */
.strength { display: grid; gap: 6px; }
.strength-track { display: flex; gap: 4px; }
.strength-track i {
  flex: 1;
  height: 4px;
  border-radius: 99px;
  background: var(--surface-3);
  transition: background var(--base) var(--ease);
}
.strength[data-score="1"] .strength-track i:nth-child(-n + 1) { background: var(--danger); }
.strength[data-score="2"] .strength-track i:nth-child(-n + 2) { background: #e2803c; }
.strength[data-score="3"] .strength-track i:nth-child(-n + 3) { background: var(--warn); }
.strength[data-score="4"] .strength-track i { background: var(--ok); }
.strength-label { font-size: 11.5px; color: var(--muted); }

@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-card-head .mark { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
  .auth-card-head .mark img { width: 32px; height: 32px; }
  .auth-card-head .mark strong { font-size: 16px; }
}

/* --------------------------------------------------------------------------
   App shell (chat)
   -------------------------------------------------------------------------- */

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--rail) auto 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Icon rail --------------------------------------------------------------- */

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
  border-right: 1px solid var(--line-soft);
  background: var(--bg-deep);
}

.rail-logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  transition: transform var(--base) var(--spring);
}
.rail-logo:hover { transform: scale(1.08) rotate(-4deg); }
.rail-logo img { width: 26px; height: 26px; }

.rail-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
    transform var(--fast) var(--spring);
}
.rail-btn:hover { background: var(--surface-2); color: var(--text); }
.rail-btn:active { transform: scale(0.92); }
.rail-btn.is-active { background: var(--surface-3); color: var(--brand-text); }
.rail-btn.is-active::before {
  content: "";
  position: absolute;
  left: -11px;
  width: 3px;
  height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}
.rail-btn svg { width: 19px; height: 19px; }
.rail-spacer { flex: 1; }

/* Tooltip shared by rail + toolbar */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) scale(0.94);
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow);
  transition: opacity var(--fast) var(--ease), transform var(--fast) var(--spring);
  z-index: 40;
}
.tip:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }
.tip-below::after { left: 50%; top: calc(100% + 8px); transform: translate(-50%, 0) scale(0.94); }
.tip-below:hover::after { transform: translate(-50%, 0) scale(1); }

/* The rail sits directly against the sidebar, so a tooltip opening to the
   right lands exactly on top of whatever sidebar row is at that height - a
   real conversation can happen to share its title with a tooltip label (e.g.
   "Nova conversa"), which then reads as garbled/overlapping text. The rail's
   tooltips exist for the icon-only, collapsed-sidebar state; once the sidebar
   is open its buttons already carry full labels, so suppressing them there
   removes the collision without losing anything useful. */
.shell:not(.sidebar-collapsed) .rail .tip::after { content: none; }

/* Sidebar ---------------------------------------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar);
  border-right: 1px solid var(--line-soft);
  background: var(--bg-deep);
  overflow: hidden;
  transition: width var(--base) var(--ease), opacity var(--base) var(--ease);
}
.shell.sidebar-collapsed .sidebar { width: 0; opacity: 0; border-right-color: transparent; }

.sidebar-head { display: grid; gap: 10px; padding: 14px 12px 10px; }

.btn-new-chat {
  justify-content: flex-start;
  gap: 10px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-weight: 600;
}
.btn-new-chat:hover {
  background: var(--surface-2);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
}
.btn-new-chat svg { color: var(--brand-text); }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search svg {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--muted-2);
  pointer-events: none;
}
.search input {
  width: 100%;
  padding: 8px 10px 8px 31px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
}
.search input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--brand) 55%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent);
}

.sidebar-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }

.sidebar-group {
  padding: 12px 6px 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.conv {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.conv:hover { background: var(--surface-2); color: var(--text); }
.conv.is-active { background: var(--surface-3); color: var(--text); }
.conv.is-active::before {
  content: "";
  position: absolute;
  left: 2px;
  width: 3px;
  height: 16px;
  border-radius: 99px;
  background: var(--brand);
}
.conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-actions { display: flex; gap: 1px; opacity: 0; transition: opacity var(--fast); }
.conv:hover .conv-actions, .conv.is-active .conv-actions { opacity: 1; }
.conv-actions button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.conv-actions button:hover { background: var(--surface); color: var(--text); }
.conv-actions button:hover.danger { color: var(--danger); }
.conv-actions svg { width: 14px; height: 14px; }
.conv .pin { color: var(--brand-text); }

.sidebar-foot { padding: 10px; border-top: 1px solid var(--line-soft); display: grid; gap: 10px; }

.budget-card {
  display: grid;
  gap: 7px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.budget-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.budget-row .k { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.budget-row .v { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.budget-card .note { font-size: 11px; color: var(--muted-2); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background var(--fast), border-color var(--fast);
}
.user-chip:hover { background: var(--surface-2); border-color: var(--line); }
.user-chip .meta { min-width: 0; flex: 1; }
.user-chip .meta b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .meta span { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Main column ------------------------------------------------------------ */

.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  min-height: 54px;
}

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px 6px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  cursor: pointer;
  max-width: 340px;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.model-pill:hover { background: var(--surface-2); border-color: var(--line); }
.model-pill .glyph {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  flex: none;
  border-radius: 7px;
  background: color-mix(in srgb, var(--brand) 15%, transparent);
  color: var(--brand-text);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.model-pill .glyph img { width: 16px; height: 16px; }
.model-pill .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-pill .chev { width: 15px; height: 15px; flex: none; color: var(--muted); }

.topbar-spacer { flex: 1; }

/* Thread ----------------------------------------------------------------- */

.thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.thread-inner {
  max-width: var(--thread-max);
  margin: 0 auto;
  padding: 8px 24px 24px;
  display: grid;
  gap: 22px;
}

/* Greeting (empty state), mirrors the reference layout */
.greeting {
  display: grid;
  /* Explicit track: children sizing to 100% need a definite column width. */
  grid-template-columns: min(var(--composer-max), 100%);
  align-content: center;
  justify-content: center;
  justify-items: center;
  gap: 24px;
  min-height: 100%;
  padding: 24px;
  text-align: center;
}
.greeting > * { width: 100%; }
.greeting-title, .greeting-sub { justify-self: center; }
.greeting-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: clamp(26px, 3.6vw, 40px);
  font-weight: 700;
  letter-spacing: -0.03em;
  animation: rise 560ms var(--spring) both;
}
.greeting-title img { width: 42px; height: 42px; }
.greeting-title .who {
  background: linear-gradient(100deg, var(--brand-text), var(--brand));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.greeting-sub { font-size: 14px; color: var(--muted); animation: rise 640ms var(--spring) 80ms both; }

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 10px;
  width: min(var(--composer-max), 100%);
  animation: rise 700ms var(--spring) 160ms both;
}
.suggestion {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform var(--base) var(--spring), border-color var(--fast), background var(--fast);
}
.suggestion:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  background: var(--surface-2);
}
/* Cursor spotlight, driven by --mx/--my set in JS */
.suggestion::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(180px circle at var(--mx, 50%) var(--my, 50%),
    color-mix(in srgb, var(--brand) 16%, transparent), transparent 65%);
  opacity: 0;
  transition: opacity var(--base) var(--ease);
  pointer-events: none;
}
.suggestion:hover::after { opacity: 1; }
.suggestion b { font-size: 13px; font-weight: 650; }
.suggestion span { font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* Messages --------------------------------------------------------------- */

.msg { display: grid; gap: 9px; animation: rise 380ms var(--ease) both; }

.msg-head { display: flex; align-items: center; gap: 9px; }
.msg-head .who { font-size: 12.5px; font-weight: 650; }
.msg-head .when { font-size: 11px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
.msg-avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-3);
  font-size: 10px;
  font-weight: 700;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-avatar.is-bot { background: color-mix(in srgb, var(--brand) 14%, transparent); padding: 4px; }
.msg-avatar.is-bot img { object-fit: contain; }

/* The user's turn is right-aligned and capped, so the speaker is obvious
   without repeating a name label on every message. */
.msg-user { justify-items: end; }
.msg-user .msg-head { flex-direction: row-reverse; }
.msg-user .bubble {
  max-width: min(82%, 640px);
  padding: 11px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 6px var(--radius);
  background: var(--surface-2);
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-user .attachments { justify-content: flex-end; }

.msg-assistant .bubble { padding: 0 0 0 35px; }

.msg-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 35px;
  opacity: 0;
  transition: opacity var(--fast) var(--ease);
}
.msg:hover .msg-foot, .msg-foot:focus-within { opacity: 1; }
.msg-foot .meta { font-size: 11px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
.msg-foot .icon-btn { width: 28px; height: 28px; }
.msg-foot .icon-btn svg { width: 15px; height: 15px; }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-img {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  max-width: 320px;
  max-height: 320px;
  object-fit: cover;
  cursor: zoom-in;
  transition: transform var(--base) var(--spring);
}
.attachment-img:hover { transform: scale(1.015); }

.attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 280px;
}
.attachment-file svg { width: 15px; height: 15px; flex: none; color: var(--brand-text); }
.attachment-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-file audio { height: 32px; }

/* Streaming caret */
.caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 2px;
  background: var(--brand);
  animation: blink 1.05s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.thinking { display: flex; align-items: center; gap: 8px; padding-left: 35px; color: var(--muted); font-size: 13px; }
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand);
  animation: bounce 1.1s var(--ease) infinite;
}
.dots i:nth-child(2) { animation-delay: 0.14s; }
.dots i:nth-child(3) { animation-delay: 0.28s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Reasoning disclosure */
.reasoning { margin-left: 35px; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: var(--surface-2); }
.reasoning > summary {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.reasoning > summary::-webkit-details-marker { display: none; }
.reasoning > summary::before { content: "▸ "; }
.reasoning[open] > summary::before { content: "▾ "; }
.reasoning .body {
  padding: 0 12px 12px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

/* Markdown --------------------------------------------------------------- */

.prose { overflow-wrap: anywhere; }
.prose > * + * { margin-top: 12px; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 680;
  letter-spacing: -0.015em;
  line-height: 1.3;
  margin-top: 20px;
}
.prose h1 { font-size: 21px; }
.prose h2 { font-size: 18px; }
.prose h3 { font-size: 16px; }
.prose h4 { font-size: 14.5px; }
.prose p { line-height: 1.7; }
.prose ul, .prose ol { padding-left: 22px; display: grid; gap: 5px; }
.prose ul { list-style: disc; }
.prose ol { list-style: decimal; }
.prose li > ul, .prose li > ol { margin-top: 5px; }
.prose blockquote {
  padding: 3px 0 3px 14px;
  border-left: 3px solid color-mix(in srgb, var(--brand) 55%, transparent);
  color: var(--text-dim);
}
.prose a { text-decoration: underline; text-underline-offset: 2px; }
.prose hr { border: 0; border-top: 1px solid var(--line); }
.prose img { border-radius: var(--radius-sm); border: 1px solid var(--line); }
.prose code {
  font-family: var(--mono);
  font-size: 0.885em;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-3);
}
.prose pre {
  position: relative;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-deep);
  overflow: hidden;
}
.prose pre code {
  display: block;
  padding: 14px 15px;
  background: transparent;
  font-size: 12.8px;
  line-height: 1.65;
  overflow-x: auto;
}
.prose pre .copy-code {
  position: absolute;
  top: 7px;
  right: 7px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--fast), color var(--fast);
}
.prose pre:hover .copy-code { opacity: 1; }
.prose pre .copy-code:hover { color: var(--text); }

.prose .table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.prose table { width: 100%; border-collapse: collapse; font-size: 13px; }
.prose th, .prose td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.prose th { background: var(--surface-2); font-weight: 650; font-size: 12px; }
.prose tr:last-child td { border-bottom: 0; }

/* Composer --------------------------------------------------------------- */

.composer-wrap { flex: none; padding: 8px 24px 12px; }
/* Empty when the composer is docked in the centred greeting instead. */
.composer-wrap:empty { padding: 0; }
.composer-slot { width: 100%; }
.composer-shell { max-width: var(--composer-max); margin: 0 auto; display: grid; gap: 8px; }

.composer {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 12px 14px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color var(--base) var(--ease), box-shadow var(--base) var(--ease);
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--brand) 48%, transparent);
  box-shadow: var(--glow);
}
.composer.is-dragging {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 7%, var(--surface));
}

.composer-input {
  width: 100%;
  min-height: 26px;
  max-height: 264px;
  padding: 2px 2px 0;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 15px;
  line-height: 1.6;
  overflow-y: auto;
}
.composer-input::placeholder { color: var(--muted-2); }

.composer-row { display: flex; align-items: center; gap: 3px; }
.composer-row .spacer { flex: 1; }

.send-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
    transform var(--fast) var(--spring), box-shadow var(--fast) var(--ease);
}
.send-btn svg { width: 17px; height: 17px; }
.send-btn.is-ready {
  background: linear-gradient(180deg, var(--brand-soft), var(--brand));
  color: var(--brand-ink);
  box-shadow: 0 6px 18px -8px rgba(245, 78, 27, 0.8);
}
.send-btn.is-ready:hover { transform: translateY(-1px) scale(1.05); }
.send-btn.is-ready:active { transform: scale(0.94); }
.send-btn.is-stop { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

.composer-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px 5px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12px;
  animation: rise 320ms var(--spring) both;
}
.chip img { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; }
.chip .ic { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; background: var(--surface-3); color: var(--brand-text); }
.chip .ic svg { width: 15px; height: 15px; }
.chip .nm { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .sz { color: var(--muted-2); font-size: 11px; }
.chip .x {
  display: grid; place-items: center;
  width: 19px; height: 19px;
  border: 0; border-radius: 50%;
  background: var(--surface-3); color: var(--muted);
  cursor: pointer;
}
.chip .x:hover { background: var(--danger); color: #fff; }
.chip .x svg { width: 11px; height: 11px; }
.chip.is-busy { opacity: 0.65; }

.composer-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted-2);
  text-align: center;
}
.composer-note b { color: var(--muted); font-weight: 600; }

.mode-banner {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--brand) 38%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  font-size: 12.5px;
  color: var(--brand-text);
  animation: rise 320ms var(--spring) both;
}
.mode-banner svg { width: 16px; height: 16px; flex: none; }
.mode-banner .spacer { flex: 1; }
.mode-banner button {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 12px; text-decoration: underline; text-underline-offset: 2px;
}
.mode-banner.is-frozen {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
}

/* Share modal --------------------------------------------------------------- */

.share-card {
  position: fixed;
  z-index: 71;
  left: 50%;
  top: 16vh;
  transform: translateX(-50%);
  width: min(480px, calc(100vw - 32px));
  padding: 22px;
  animation: pop-sm 220ms var(--spring) both;
}
.share-card h3 { font-size: 16px; font-weight: 650; margin-bottom: 4px; }
.share-card p { font-size: 13px; color: var(--muted); line-height: 1.5; }
.share-card .share-row { display: flex; gap: 8px; margin-top: 14px; }
.share-card .share-row .input { font-size: 12.5px; font-family: var(--mono); }
.share-card .share-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; }

/* Recording state */
.recording {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 13px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 9%, transparent);
  font-size: 13px;
}
.recording .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s var(--ease) infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.8); } }
.recording .time { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--danger); }
.recording .spacer { flex: 1; }
.wave { display: flex; align-items: center; gap: 2.5px; height: 20px; }
.wave i {
  width: 2.5px;
  height: 20%;
  border-radius: 99px;
  background: var(--danger);
  transform-origin: center;
  animation: wave 900ms var(--ease) infinite;
}
.wave i:nth-child(2n) { animation-delay: 120ms; }
.wave i:nth-child(3n) { animation-delay: 240ms; }
.wave i:nth-child(4n) { animation-delay: 60ms; }
.wave i:nth-child(5n) { animation-delay: 300ms; }
@keyframes wave { 0%, 100% { height: 20%; } 50% { height: 100%; } }

/* Footer ---------------------------------------------------------------- */

.app-foot {
  flex: none;
  padding: 0 24px 12px;
  text-align: center;
  font-size: 11px;
  color: var(--muted-2);
}
.app-foot b { color: var(--brand-text); font-weight: 600; }

/* --------------------------------------------------------------------------
   Command palette (model picker)
   -------------------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(4, 6, 8, 0.62);
  backdrop-filter: blur(4px);
  animation: fade 180ms var(--ease) both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.palette {
  position: fixed;
  z-index: 71;
  left: 50%;
  top: 11vh;
  transform: translateX(-50%);
  width: min(660px, calc(100vw - 32px));
  max-height: 74vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop 300ms var(--spring) both;
}
@keyframes pop {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(0.97); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.palette-search { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.palette-search svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.palette-search input { flex: 1; border: 0; background: transparent; font-size: 15px; outline: none; }
.palette-search kbd {
  padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface-2); font-family: var(--font); font-size: 10.5px; color: var(--muted);
}

.palette-filters { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); overflow-x: auto; }
.filter-chip {
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--fast) var(--ease);
}
.filter-chip:hover { color: var(--text); border-color: var(--muted-2); }
.filter-chip.is-on {
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  border-color: color-mix(in srgb, var(--brand) 45%, transparent);
  color: var(--brand-text);
}

.palette-list { overflow-y: auto; padding: 6px; }
.palette-group {
  padding: 10px 10px 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.palette-item:hover, .palette-item.is-cursor { background: var(--surface-2); }
.palette-item.is-current { background: color-mix(in srgb, var(--brand) 11%, transparent); }
.palette-item .body { flex: 1; min-width: 0; }
.palette-item .nm { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 600; }
.palette-item .nm span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .id { font-size: 11px; color: var(--muted-2); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .price { flex: none; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.palette-item .price b { display: block; font-size: 12px; color: var(--text-dim); font-weight: 650; }
.palette-item .caps { display: flex; gap: 3px; flex: none; }
.palette-item .cap {
  display: grid; place-items: center;
  width: 20px; height: 20px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--muted);
}
.palette-item .cap svg { width: 12px; height: 12px; }
.palette-item .cap.on { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand-text); }
.fav-toggle {
  display: grid; place-items: center;
  flex: none;
  width: 26px; height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-2);
  cursor: pointer;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.fav-toggle:hover { background: var(--surface-3); color: var(--muted); }
.fav-toggle svg { width: 15px; height: 15px; }
.fav-toggle.is-on { color: #e3a008; }
.fav-toggle.is-on svg { fill: currentColor; }

.palette-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 15px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--muted-2);
}
.palette-foot .spacer { flex: 1; }
.palette-foot kbd {
  padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px;
  background: var(--surface-2); font-family: var(--font); font-size: 10px;
}

.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }

/* Menus ----------------------------------------------------------------- */

.menu {
  position: fixed;
  z-index: 72;
  min-width: 208px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg);
  animation: pop-sm 200ms var(--spring) both;
}
@keyframes pop-sm {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: color-mix(in srgb, var(--danger) 13%, transparent); }
.menu-item svg { width: 16px; height: 16px; flex: none; }
.menu-sep { height: 1px; margin: 5px 6px; background: var(--line-soft); }

/* Lightbox -------------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 76px 28px 28px;
  background: rgba(3, 5, 6, 0.88);
  backdrop-filter: blur(6px);
  animation: fade 200ms var(--ease) both;
}

/* The stage fills the space between the toolbar and the caption, and centres
   the image both ways inside it - true middle-of-the-screen, not just
   horizontally. flex:1 + min-height:0 lets max-height:100% work on the img. */
.lightbox-stage {
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 0;
  width: 100%;
}
.lightbox-stage img {
  /* A grid item's default min-width/min-height is content-based (its
     intrinsic size), which stops it from ever shrinking below that and
     defeats max-width/max-height entirely for large images. Overriding both
     to 0 is what lets the image actually scale down to fit the stage. */
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  /* Not the shared `pop` keyframes: those bake in translateX(-50%) for
     .palette, which is position:fixed;left:50%. Applied here - a plain
     grid-centered element - it shoves the image a half-width off-centre. */
  animation: lightbox-pop 320ms var(--spring) both;
  cursor: default;
}
@keyframes lightbox-pop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.lightbox-toolbar {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 81;
  display: flex;
  gap: 8px;
}
.lightbox-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-sm);
  background: rgba(20, 22, 26, 0.55);
  color: #fff;
  backdrop-filter: blur(8px);
  transition: background var(--fast) var(--ease), transform var(--fast) var(--spring);
}
.lightbox-btn:hover { background: rgba(255, 255, 255, 0.16); transform: translateY(-1px); }
.lightbox-btn:active { transform: scale(0.94); }
.lightbox-btn svg { width: 19px; height: 19px; }

.lightbox-caption {
  flex: none;
  max-width: min(90vw, 640px);
  padding: 6px 14px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.78);
  font-size: 12.5px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}

/* --------------------------------------------------------------------------
   Content pages (profile / admin / galeria) - same rail shell as chat, just
   without the conversations sidebar column.
   -------------------------------------------------------------------------- */

.shell-page { grid-template-columns: var(--rail) 1fr; }
.shell-page .main { overflow: auto; }

.page-subnav { display: flex; gap: 2px; flex-wrap: wrap; }
.page-subnav a {
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  transition: background var(--fast), color var(--fast);
}
.page-subnav a:hover { background: var(--surface-2); color: var(--text); }
.page-subnav a.is-active { background: var(--surface-3); color: var(--brand-text); }

.page-body { padding: 26px 22px 60px; }
.container { max-width: 1180px; margin: 0 auto; display: grid; gap: 22px; }
.container-narrow { max-width: 800px; }

.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 240px; display: grid; gap: 4px; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.025em; }
.page-head p { font-size: 13.5px; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.gallery-item {
  position: relative;
  display: block;
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: zoom-in;
  transition: transform var(--fast), border-color var(--fast);
}
.gallery-item:hover { transform: translateY(-2px); border-color: var(--surface-3); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat {
  position: relative;
  display: grid;
  gap: 5px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--brand), transparent 70%);
}
.stat .k { font-size: 11px; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .d { font-size: 11.5px; color: var(--muted-2); }

.panel { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.panel-head p { font-size: 12px; color: var(--muted); }
.panel-head .titles { flex: 1; min-width: 0; display: grid; gap: 2px; }
.panel-body { padding: 20px; display: grid; gap: 16px; }
.panel-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.panel-foot .spacer { flex: 1; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 15px; }
.form-grid .span-2 { grid-column: 1 / -1; }

.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 11px 16px; text-align: left; white-space: nowrap; }
table.data th {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
table.data td { border-bottom: 1px solid var(--line-soft); }
table.data tbody tr { transition: background var(--fast); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .who { display: flex; align-items: center; gap: 10px; }
table.data .who .meta { display: grid; }
table.data .who b { font-weight: 600; }
table.data .who span { font-size: 11.5px; color: var(--muted); }

.bars { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; align-items: center; gap: 12px; font-size: 12.5px; }
.bar-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 64px; }
.spark i {
  flex: 1;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, var(--brand), color-mix(in srgb, var(--brand) 22%, transparent));
  transition: height var(--slow) var(--ease);
}
.spark i:hover { background: var(--brand-soft); }

.model-picker { display: grid; gap: 10px; }
.model-picker-list {
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 6px;
  display: grid;
  gap: 2px;
}
.model-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 12.5px;
  transition: background var(--fast);
}
.model-opt:hover { background: var(--surface-3); }
.model-opt input { accent-color: var(--brand); width: 15px; height: 15px; flex: none; cursor: pointer; }
.model-opt .body { flex: 1; min-width: 0; display: grid; }
.model-opt .body b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-opt .body span { font-size: 11px; color: var(--muted-2); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-opt .price { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }

.avatar-editor { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.avatar-drop {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 50%;
  transition: transform var(--base) var(--spring);
}
.avatar-drop:hover { transform: scale(1.03); }
.avatar-drop .overlay-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(4, 6, 8, 0.62);
  color: #fff;
  opacity: 0;
  transition: opacity var(--fast);
}
.avatar-drop:hover .overlay-hint { opacity: 1; }
.avatar-drop .overlay-hint svg { width: 22px; height: 22px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}
.history-item:last-child { border-bottom: 0; }
.history-item .titles { flex: 1; min-width: 0; display: grid; gap: 2px; }
.history-item b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item span { font-size: 11.5px; color: var(--muted); }

/* --------------------------------------------------------------------------
   Error page
   -------------------------------------------------------------------------- */

.error-wrap { position: relative; z-index: 1; display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.error-card { width: min(440px, 100%); padding: 34px; text-align: center; display: grid; gap: 14px; justify-items: center; }
.error-card .code {
  font-size: 54px;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(140deg, var(--brand-text), var(--gray-brand));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.error-card p { color: var(--muted); font-size: 14px; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

.mobile-only { display: none; }

@media (max-width: 1024px) {
  :root { --sidebar: 260px; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: var(--rail) 1fr; }
  .sidebar {
    position: fixed;
    left: var(--rail);
    top: 0;
    bottom: 0;
    z-index: 60;
    width: min(300px, calc(100vw - var(--rail)));
    box-shadow: var(--shadow-lg);
    transform: translateX(0);
    transition: transform var(--base) var(--ease);
  }
  .shell.sidebar-collapsed .sidebar {
    width: min(300px, calc(100vw - var(--rail)));
    opacity: 1;
    transform: translateX(-110%);
    border-right-color: var(--line-soft);
  }
  .thread-inner, .composer-wrap { padding-left: 14px; padding-right: 14px; }
  .msg-assistant .bubble, .msg-foot, .thinking, .reasoning { padding-left: 0; margin-left: 0; }
  .page-nav nav { display: none; }
  .mobile-only { display: inline-flex; }
  .palette { top: 4vh; max-height: 88vh; }
}

@media (max-width: 560px) {
  .auth-panel { padding: 22px 14px; }
  .auth-card { padding: 24px 20px; }
  .auth-form .row { grid-template-columns: 1fr; }
  .greeting-title { font-size: 25px; }
  .greeting-title img { width: 32px; height: 32px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .page-body { padding: 18px 14px 48px; }
}

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