/* Palette taken from grok.com: warm near-white / warm near-black neutrals,
   blue accent, hairline borders. Light is the default; dark follows the system
   unless the user picks a theme with the toggle (data-theme on <html>). */
:root {
  --bg: #f9f8f7;
  --bg-panel: #ffffff;
  --bg-raise: #f1efec;
  --line: #e6e5e3;
  --line-soft: rgba(15, 13, 10, 0.08);
  --text: #050505;
  --muted: #636363;
  --accent: #0890ff;
  --link: #0b6fd1;
  --accent-soft: rgba(8, 144, 255, 0.14);
  --accent-text: #ffffff;
  --code-bg: #f4f2ef;
  --danger: #c2381f;
  --ok: #2f8f4e;
  --radius: 12px;
  color-scheme: light;
  --font: "Inter", "Segoe UI", roboto, system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
}

:root[data-theme="dark"],
:root[data-theme="dark"] body {
  color-scheme: dark;
  --bg: #131211;
  --bg-panel: #171614;
  --bg-raise: #23211f;
  --line: rgba(252, 252, 252, 0.1);
  --line-soft: rgba(252, 252, 252, 0.06);
  --text: #fcfcfc;
  --muted: #9e9e9e;
  --accent: #299fff;
  --link: #299fff;
  --accent-soft: rgba(41, 159, 255, 0.16);
  --accent-text: #08131c;
  --code-bg: #0e0d0c;
  --danger: #e5674f;
  --ok: #8fbf7a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131211;
    --bg-panel: #171614;
    --bg-raise: #23211f;
    --line: rgba(252, 252, 252, 0.1);
    --line-soft: rgba(252, 252, 252, 0.06);
    --text: #fcfcfc;
    --muted: #9e9e9e;
    --accent: #299fff;
    --link: #299fff;
    --accent-soft: rgba(41, 159, 255, 0.16);
    --accent-text: #08131c;
    --code-bg: #0e0d0c;
    --danger: #e5674f;
    --ok: #8fbf7a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

button, input, textarea { font: inherit; color: inherit; }

/* --- login ---------------------------------------------------------------- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 26px;
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: 0.2px;
}
.login-card p.sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 13px;
}
label.field { display: block; margin-bottom: 14px; }
label.field span {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type="email"], input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent-soft); }
button.primary {
  width: 100%;
  padding: 11px 16px;
  background: var(--text);
  color: var(--bg);
  border: 0;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
}
button.primary:disabled { opacity: 0.6; cursor: default; }
.error {
  margin-top: 14px;
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin: 18px 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
a.oauth {
  display: block;
  text-align: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
a.oauth:hover { border-color: var(--accent-soft); }

/* --- chat shell ----------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  transition: grid-template-columns 0.16s ease;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.sidebar {
  transition: opacity 0.16s ease;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.sidebar header {
  padding: 16px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-weight: 600; letter-spacing: 0.2px; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.icon-btn svg { display: block; }
.icon-btn:hover { color: var(--text); border-color: var(--accent-soft); }
.new-chat {
  margin: 4px 14px 10px;
  padding: 9px 12px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
}
.new-chat:hover { border-color: var(--accent-soft); }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
}
.chat-item:hover { background: var(--bg-raise); color: var(--text); }
.chat-item.active { background: var(--bg-raise); color: var(--text); }
.chat-item span.title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tip {
  position: fixed;
  z-index: 60;
  max-width: 340px;
  padding: 6px 9px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  word-break: break-word;
}
.tip.on { opacity: 1; }

.chat-item button.del {
  opacity: 0.55;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 16px;
  line-height: 1;
}
.chat-item:hover button.del { opacity: 1; }
.chat-item button.del:hover { color: var(--danger); }
.chat-item .src {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 6px;
  flex: 0 0 auto;
}
.sidebar footer {
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar footer .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.main header {
  grid-row: 1;
  position: relative;
  z-index: 5;
  background: var(--bg);
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}
.main header h2 { margin: 0; font-size: 15px; font-weight: 500; }
.badge {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
}

.messages {
  grid-row: 2;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 20px 16px;
  overflow-anchor: auto;
}
.msg { max-width: 760px; margin: 0 auto 18px; }
.msg .role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 5px;
}
.msg .body {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.user .body {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
}
.msg.assistant .body { padding: 2px 0; }
.msg .body pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 13px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre;
}
.msg .body code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
.msg .body pre code { border: 0; padding: 0; background: none; }
.code-block { position: relative; margin: 4px 0 6px; }
.code-block pre { margin: 0; padding-top: 32px; }
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 11px;
  font-family: var(--font);
  color: var(--muted);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px 8px;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.copy-btn.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 5px;
  line-height: 0;
}
.copy-btn.icon svg { display: block; }
.copy-btn:hover { opacity: 1; color: var(--text); border-color: var(--accent-soft); }
.copy-btn.ok { color: var(--ok); border-color: var(--ok); opacity: 1; }
.copy-btn.mini {
  position: static;
  padding: 1px 4px;
  margin-left: 5px;
  color: var(--muted);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 6px;
  vertical-align: -3px;
  opacity: 0.7;
}
.copy-btn.mini:hover { color: var(--accent); border-color: var(--accent-soft); opacity: 1; }
.copy-btn.mini.ok { color: var(--ok); border-color: var(--ok); opacity: 1; }
.cmd { white-space: normal; }
.cmd code { white-space: pre-wrap; overflow-wrap: anywhere; }
.md-h { font-weight: 600; color: var(--text); margin: 10px 0 4px; line-height: 1.35; }
.md-h1 { font-size: 19px; }
.md-h2 { font-size: 17px; }
.md-h3 { font-size: 15.5px; }
.md-h4 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.md-li { margin: 1px 0; }
.md-num { color: var(--muted); }
.md-quote { border-left: 2px solid var(--accent-soft); padding-left: 10px; color: var(--muted); margin: 3px 0; }
.md-img {
  display: block;
  max-width: min(100%, 560px);
  height: auto;
  margin: 8px 0 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

.msg a, .md-li a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.msg a:hover { border-bottom-color: var(--accent); }

.md-hr { height: 1px; background: var(--line); margin: 12px 0; }
.msg:hover .copy-btn.mini, .copy-btn.mini.ok, .copy-btn.mini:focus-visible { opacity: 0.9; }
@media (hover: none) { .copy-btn.mini { opacity: 0.75; } }
@media (max-width: 480px) {
  .copy-btn.mini { font-size: 10px; padding: 0 4px; margin-left: 3px; }
}
.msg .body a { color: var(--link); }
.status-line {
  max-width: 760px;
  margin: 0 auto 6px;
  color: var(--muted);
  font-size: 12.5px;
  font-family: var(--mono);
  opacity: 0.85;
}
.cursor::after {
  content: "▌";
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* thinking indicator */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 0;
}
.typing .dots { display: inline-flex; gap: 4px; }
.typing .dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.28;
  animation: dotPulse 1.05s ease-in-out infinite;
  will-change: transform, opacity;
}
.typing .dots i:nth-child(2) { animation-delay: 0.14s; }
.typing .dots i:nth-child(3) { animation-delay: 0.28s; }
.typing-label { letter-spacing: 0.01em; }
.typing-time { font-variant-numeric: tabular-nums; opacity: 0.75; }
@keyframes dotPulse {
  0% { opacity: 0.25; transform: translateY(0) scale(0.85); }
  35% { opacity: 1; transform: translateY(-4px) scale(1.15); }
  70%, 100% { opacity: 0.25; transform: translateY(0) scale(0.85); }
}
/* Windows/Chrome «уменьшить движение» раньше полностью отключал анимацию —
   индикатор ожидания важнее, поэтому здесь лишь замедляем её */
@media (prefers-reduced-motion: reduce) {
  .typing .dots i { animation-duration: 1.6s; }
}

.empty {
  max-width: 640px;
  margin: 12vh auto 0;
  text-align: center;
  color: var(--muted);
}
.empty h3 { color: var(--text); font-weight: 500; margin-bottom: 6px; }
.empty p { margin: 0 0 18px; font-size: 14px; }
.hint-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  text-align: left;
}
.hint {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 13px;
  cursor: pointer;
}
.hint:hover { border-color: var(--accent-soft); }
.hint b { display: block; color: var(--text); font-weight: 500; margin-bottom: 2px; }

.composer { grid-row: 3; padding: 10px 20px 18px; }
.composer-inner {
  max-width: 760px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-panel);
  padding: 10px 12px 8px;
}
.composer-inner:focus-within { border-color: var(--accent-soft); }
textarea#input {
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  max-height: 220px;
  min-height: 24px;
  padding: 2px 0;
}
.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}
.modes { display: flex; gap: 4px; background: var(--bg-raise); border-radius: 999px; padding: 3px; }
.modes button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}
.modes button.on { background: var(--accent-soft); color: var(--text); }
.composer-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.icon-btn.attach {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex: 0 0 auto;
}
.icon-btn.attach svg { display: block; }
.icon-btn.attach:hover { color: var(--accent); }

/* round send button with an arrow, like Grok */
.send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: var(--text);
  color: var(--bg);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
  transition: opacity 0.15s, transform 0.1s;
}
.send svg { display: block; }
.send:hover:not(:disabled) { opacity: 0.88; }
.send:active:not(:disabled) { transform: scale(0.95); }
.send:disabled { opacity: 0.35; cursor: default; }

/* attachment chips */
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.attachments[hidden] { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 0 1px;
  font-size: 14px;
  line-height: 1;
}
.chip button:hover { color: var(--danger); }
.chip.pending { opacity: 0.6; }
.composer.dragging .composer-inner {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.msg .body .attachments { margin-top: 8px; }
.foot-note {
  max-width: 760px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
}
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* collapsed sidebar (desktop): the × in the sidebar header hides it, ☰ brings it back */
html[data-side="hidden"] .shell { grid-template-columns: 0 1fr; }
html[data-side="hidden"] .sidebar { opacity: 0; pointer-events: none; border-right: 0; }

@media (max-width: 780px) {
  html[data-side="hidden"] .shell { grid-template-columns: 1fr; }
  html[data-side="hidden"] .sidebar { opacity: 1; pointer-events: auto; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 82%;
    max-width: 300px;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }
  .sidebar.open { transform: none; }
  .hint-grid { grid-template-columns: 1fr; }
  .main header { padding: 12px 14px; }
  .messages, .composer { padding-left: 14px; padding-right: 14px; }
}
