/* --- Small Tech brand book styling for Skiftrade AI ---
   Tokens pulled from the official brand pages (Notion: Small Tech — Материалы бренда):
   accent brand/500 #FF5A23, accent orange/500 #F97316, full neutral/50–950 scale,
   heading font Tilda Sans (Inter used here as the closest freely-licensable stand-in
   isn't quite right either — Golos Text is used instead, a Cyrillic-friendly display
   grotesque in the same spirit), body/UI font Inter (the brand book's own choice,
   used as-is). */

:root {
  --bg-primary: #FAFAFA;    /* neutral/50 */
  --bg-sidebar: #ffffff;
  --bg-panel: #F5F5F5;      /* neutral/100 */
  --border-color: #E5E5E5;  /* neutral/200 */

  --accent-primary: #FF5A23;   /* brand/500 */
  --accent-secondary: #F97316; /* orange/500 */
  --accent-gradient: linear-gradient(135deg, #F97316, #FF5A23);
  --accent-soft: rgba(255, 90, 35, 0.12);
  --accent-glow: rgba(255, 90, 35, 0.18);
  --accent-glow-secondary: rgba(249, 115, 22, 0.18);

  --accent-green: #16a34a;
  --accent-red: #dc2626;

  --text-main: #171717;   /* neutral/900 */
  --text-muted: #737373;  /* neutral/500 */
  --text-link: #FF5A23;

  --font-main: 'Inter', sans-serif;
  --font-heading: 'Golos Text', 'Inter', sans-serif; /* stand-in for Tilda Sans (brand's own display font, not freely licensable) */
  --font-code: 'Roboto Mono', monospace;
}

/* Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Ambient background blobs — the brand book's own "accent light spots" (glow,
   blur 250) in the two accent hues, kept subtle behind the light UI. */
.bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(140px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
}

.bg-glow-1 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, var(--accent-glow-secondary) 0%, transparent 70%);
  top: -100px;
  left: 20%;
}

.bg-glow-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  bottom: -150px;
  right: 15%;
}

/* Container Structure */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  background: var(--bg-primary);
}

/* Sidebar Styling */
.sidebar {
  width: 320px;
  flex-shrink: 0; /* never let a long unbroken string in the chat area squeeze this */
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px;
  z-index: 10;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 36px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  color: var(--accent-primary);
  width: 24px;
  height: 24px;
}

.logo-text {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-main);
}

.version-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-primary);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 20px;
}

.sidebar-section {
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title svg {
  width: 14px;
  height: 14px;
}

/* Select Control */
.select-wrapper {
  position: relative;
  width: 100%;
}

select {
  width: 100%;
  appearance: none;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.preset-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.preset-row select {
  flex: 1;
  min-width: 0;
}

.preset-row .icon-btn {
  flex: 0 0 auto;
}

.select-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

/* Sliders */
.parameter-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.param-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
}

.param-badge {
  background: var(--bg-panel);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-family: var(--font-code);
  font-weight: 600;
  border: 1px solid var(--border-color);
}

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--border-color);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.param-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: -4px;
}

/* System Prompt Textarea */
.system-prompt-section {
  flex-grow: 1;
}

textarea {
  resize: none;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 13px;
  line-height: 1.5;
  transition: all 0.2s;
}

textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #ffffff;
}

.system-prompt-section textarea {
  height: 100%;
  min-height: 100px;
}

.system-prompt-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-text-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 10px;
  padding: 6px 12px;
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-text-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-soft);
}

.icon-text-btn svg {
  width: 13px;
  height: 13px;
}

.system-prompt-saved-hint {
  font-size: 11.5px;
  color: var(--accent-green);
  font-weight: 600;
}

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.usage-stat {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
}

.usage-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.usage-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.usage-row-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.usage-refresh-btn {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.usage-refresh-btn:hover {
  color: var(--accent-primary);
  background: var(--accent-soft);
}

.usage-refresh-btn svg {
  width: 12px;
  height: 12px;
}

.usage-refresh-btn.spinning svg {
  animation: spin 0.6s linear;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.usage-value {
  font-family: var(--font-code);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-main);
}

.usage-bar {
  height: 5px;
  border-radius: 3px;
  background: var(--border-color);
  overflow: hidden;
  margin-bottom: 5px;
}

.usage-bar-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.usage-reset {
  font-size: 10px;
  color: var(--text-muted);
}

.secondary-btn {
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 14px;
  padding: 12px;
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--accent-red);
}

.secondary-btn svg {
  width: 14px;
  height: 14px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  justify-content: center;
}

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

.status-dot.online {
  background-color: var(--accent-green);
}

/* ── Header: usage + DB connection dots (index.html) ── */

#db-status-stat {
  gap: 6px;
}

.db-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted); /* default: unknown/checking */
  flex-shrink: 0;
}

.db-status-dot.ok {
  background: var(--accent-green);
}

.db-status-dot.down {
  background: var(--accent-red);
}

/* Main Chat Container */
.chat-area {
  flex-grow: 1;
  min-width: 0; /* flex items default to min-width:auto — without this, a long unbroken
                   string (URL, hash) in a message forces the whole row wider and steals
                   space from .sidebar instead of wrapping/scrolling in place */
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

/* Header */
.chat-header {
  height: 76px;
  border-bottom: 1px solid var(--border-color);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
}

.active-model-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.model-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--accent-gradient);
  display: flex;
  justify-content: center;
  align-items: center;
}

.model-avatar-icon {
  width: 18px;
  height: 18px;
  color: white;
}

.active-model-info h2 {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.active-model-info .subtext {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-code);
  margin-top: 1px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.chat-stats {
  display: flex;
  gap: 16px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 11px;
  font-family: var(--font-code);
  font-weight: 500;
  color: var(--text-muted);
}

/* Same [hidden] trap as .image-preview/.owner-tool-badge elsewhere in this file —
   the unconditional display:flex above beats the browser's own [hidden]{display:none}.
   Was already silently affecting #weather-stat before usage/db-status stats were added. */
.stat-item[hidden] {
  display: none;
}

.stat-item svg {
  width: 12px;
  height: 12px;
  color: var(--accent-primary);
}

/* Chat Messages Viewport */
.messages-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar for messages container */
.messages-container::-webkit-scrollbar,
textarea::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
  width: 8px;
}

.messages-container::-webkit-scrollbar-track,
textarea::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
  background: #D4D4D4; /* neutral/300 */
  border-radius: 10px;
}

.messages-container::-webkit-scrollbar-thumb:hover,
textarea::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
  background: #A3A3A3; /* neutral/400 */
}

/* Welcome Splash screen */
.welcome-screen {
  max-width: 600px;
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: fadeIn 0.6s ease-out;
}

.welcome-icon-box {
  width: 72px;
  height: 72px;
  border-radius: 24px;
  background: var(--accent-soft);
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 8px;
}

.welcome-icon {
  width: 36px;
  height: 36px;
  color: var(--accent-primary);
}

.welcome-screen h1 {
  font-family: var(--font-heading);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--text-main);
}

.welcome-screen p {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 12px;
}

.suggestion-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
}

.suggestion-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.25s;
}

.suggestion-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-soft);
  box-shadow: 0 12px 24px rgba(23, 23, 23, 0.08);
}

.card-icon {
  width: 20px;
  height: 20px;
  margin-bottom: 10px;
  color: var(--accent-primary);
}

.suggestion-card h4 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-main);
}

.suggestion-card p {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

/* Chat Messages Bubble styling */
.message {
  display: flex;
  gap: 16px;
  max-width: 80%;
  animation: slideUp 0.3s ease-out;
}

/* Images embedded via ![]() (download_file tool, see local_tools.py) — kept inside
   whatever bubble/card they render in, never overflowing it. */
.answer-content img,
.battle-stage-content img,
.battle-final-content img {
  max-width: 100%;
  border-radius: 10px;
  display: block;
  margin: 8px 0;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.assistant {
  align-self: flex-start;
}

.msg-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}

.message.user .msg-content {
  align-items: flex-end;
}

.msg-copy-btn,
.msg-regenerate-btn,
.msg-edit-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 6px;
  opacity: 0;
  transition: all 0.2s;
}

.message:hover .msg-copy-btn,
.message:hover .msg-regenerate-btn,
.message:hover .msg-edit-btn {
  opacity: 1;
}

.msg-copy-btn svg,
.msg-regenerate-btn svg,
.msg-edit-btn svg {
  width: 13px;
  height: 13px;
}

.msg-copy-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-primary);
}

.msg-copy-btn.copied {
  opacity: 1;
  color: var(--accent-green);
}

.msg-regenerate-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-secondary);
}

.msg-edit-btn:hover {
  background: var(--bg-panel);
  color: var(--text-main);
}

.msg-edit-textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.45;
  resize: vertical;
  box-sizing: border-box;
  margin-bottom: 8px;
  outline: none;
}

.msg-edit-textarea:focus {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.msg-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.msg-edit-save,
.msg-edit-cancel {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.msg-edit-save {
  background: var(--accent-primary);
  color: #ffffff;
}

.msg-edit-save:hover {
  background: var(--accent-secondary);
}

.msg-edit-cancel {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.msg-edit-cancel:hover {
  background: rgba(255, 255, 255, 0.4);
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

.message.user .msg-avatar {
  background: var(--accent-gradient);
}

.message.assistant .msg-avatar {
  background: var(--accent-soft);
  border: 1px solid var(--border-color);
}

.msg-avatar svg {
  width: 14px;
  height: 14px;
  color: white;
}

.message.assistant .msg-avatar svg {
  color: var(--accent-primary);
}

.msg-bubble {
  padding: 14px 18px;
  border-radius: 20px;
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: break-word; /* long unbroken URLs/hashes wrap instead of widening the layout */
  word-break: break-word;
}

.message.user .msg-bubble {
  background: var(--accent-gradient);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .msg-bubble {
  background: #ffffff;
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 8px rgba(23, 23, 23, 0.04);
}

/* Markdown Rendering Inside Bubbles */
.msg-bubble p {
  margin-bottom: 12px;
}

.msg-bubble p:last-child {
  margin-bottom: 0;
}

/* Code highlight blocks */
.msg-bubble pre {
  background: #171717; /* neutral/900 */
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  overflow-x: auto;
  font-family: var(--font-code);
  font-size: 12.5px;
  margin: 14px 0;
  position: relative;
  color: #F5F5F5; /* neutral/100 */
}

.msg-bubble code {
  font-family: var(--font-code);
  font-size: 12.5px;
  background: var(--bg-panel);
  padding: 2px 6px;
  border-radius: 4px;
}

/* .msg-bubble code has no explicit color, so it inherits the bubble's own text color — fine
   for assistant bubbles (dark text), but in a user bubble that's white, and white-on-light-gray
   (var(--bg-panel)) is nearly unreadable. Use a dark-tinted overlay instead so white text still
   has real contrast against it. */
.message.user .msg-bubble code {
  background: rgba(0, 0, 0, 0.18);
  color: #ffffff;
}

.msg-bubble pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

/* Code block headers */
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #262626; /* neutral/800 */
  border: 1px solid var(--border-color);
  border-bottom: none;
  padding: 6px 14px;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  font-size: 11px;
  color: #D4D4D4; /* neutral/300 */
  font-family: var(--font-code);
  text-transform: uppercase;
  margin-top: 14px;
  margin-bottom: -14px; /* Counter margin to align perfectly with standard pre */
}

.copy-code-btn {
  background: transparent;
  border: none;
  color: #D4D4D4; /* neutral/300 */
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  transition: color 0.2s;
}

.copy-code-btn:hover {
  color: #ffffff;
}

.copy-code-btn svg {
  width: 10px;
  height: 10px;
}

.msg-bubble ul, .msg-bubble ol {
  margin: 10px 0 10px 20px;
}

.msg-bubble li {
  margin-bottom: 6px;
}

/* Markdown tables */
.msg-bubble .table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  margin: 8px 0;
}

.msg-bubble table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-main);
  font-size: 0.9em;
  line-height: 1.45;
}

.msg-bubble th,
.msg-bubble td {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  text-align: left;
  vertical-align: top;
}

.msg-bubble thead th {
  font-weight: 600;
  background: var(--bg-panel);
  white-space: nowrap;
}

/* Markdown links */
.msg-bubble a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  cursor: pointer;
  transition: color 0.15s ease, opacity 0.15s ease;
}

.message.assistant .msg-bubble a {
  color: var(--accent-primary);
}

.message.assistant .msg-bubble a:hover {
  color: #D9430F;
}

.message.user .msg-bubble a {
  color: #ffffff;
}

.message.user .msg-bubble a:hover {
  opacity: 0.8;
}

/* Chat error + retry */
.msg-error {
  color: var(--accent-red);
  font-weight: 500;
}

.msg-error-icon {
  width: 14px;
  height: 14px;
  vertical-align: middle;
  margin-right: 6px;
}

.msg-retry-actions {
  margin-top: 8px;
}

.msg-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--accent-red);
  border-radius: 6px;
  background: transparent;
  color: var(--accent-red);
  cursor: pointer;
  transition: all 0.2s;
}

.msg-retry-btn:hover {
  background: var(--accent-red);
  color: #ffffff;
}

.msg-retry-btn-icon,
.msg-retry-btn svg {
  width: 12px;
  height: 12px;
}

/* Text Selection */
::selection {
  background: var(--accent-soft);
  color: var(--text-main);
}

/* Bottom Chat Input Form Container */
.chat-input-container {
  padding: 24px 32px 32px 32px;
  background: var(--bg-primary);
  border-top: 1px solid transparent;
}


.chat-input-form {
  position: relative;
  display: flex;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 8px 12px;
  align-items: center;
  box-shadow: 0 4px 16px rgba(23, 23, 23, 0.05);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-form:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-input-form textarea {
  flex-grow: 1;
  background: transparent;
  border: none;
  padding: 8px 12px;
  font-size: 14px;
  height: auto;
  max-height: 120px;
  color: var(--text-main);
  outline: none;
}

.chat-input-form textarea:focus {
  border: none;
  box-shadow: none;
  background: transparent;
}

.chat-input-form button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: none;
  background: var(--accent-gradient);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-input-form button:hover:not(:disabled) {
  filter: brightness(1.08);
}

.chat-input-form button:disabled {
  background: var(--bg-panel);
  color: var(--text-muted);
  cursor: not-allowed;
}

.chat-input-form button svg {
  width: 16px;
  height: 16px;
}

/* ── Кнопка прикрепления файла (нейтральная, override send/stop) ── */

#attach-file-btn {
  background: var(--bg-panel);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

#attach-file-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-primary);
  filter: none;
}

#attach-file-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Чипы прикреплённых файлов ── */

.attachment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.attachment-chips[hidden] {
  display: none;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 4px 8px 4px 10px;
  font-family: var(--font-main);
  font-size: 12px;
  color: var(--text-main);
  max-width: 220px;
}

.attachment-chip svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.attachment-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.2s ease;
}

.attachment-chip-remove svg {
  width: 12px;
  height: 12px;
}

.attachment-chip-remove:hover {
  color: var(--accent-red);
}

/* ── Image attachment (vision-only models) ── */

#attach-image-btn {
  background: var(--bg-panel);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

#attach-image-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-primary);
  filter: none;
}

.image-preview {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 60px;
  margin-bottom: 8px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--bg-panel);
}

/* The unconditional `display` above beats the browser's own [hidden]{display:none} (author
   CSS always wins over the UA stylesheet, regardless of specificity) — this repo has hit
   that exact trap before on other elements. Without this, setting .hidden=true in JS updates
   the DOM attribute but the preview stays visually on screen, e.g. right after sending. */
.image-preview[hidden] {
  display: none;
}

/* ── Owner-only tool buttons (query_mdm_db/query_progress_db, read_file/edit_file) ── */

#owner-db-btn,
#owner-edit-btn {
  background: var(--bg-panel);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

#owner-db-btn:hover:not(:disabled),
#owner-edit-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-primary);
  filter: none;
}

/* Same [hidden] trap as .image-preview above — .chat-input-form button sets an
   unconditional display: flex, which beats the browser's own [hidden]{display:none}. */
#owner-db-btn[hidden],
#owner-edit-btn[hidden] {
  display: none;
}

.owner-tools-section[hidden] {
  display: none;
}

.owner-tool-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent-primary);
  background: var(--accent-soft, rgba(255, 90, 35, 0.12));
  border-radius: 10px;
  padding: 8px 10px;
}

.owner-tool-badge[hidden] {
  display: none;
}

.owner-tool-badge svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.image-preview img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  display: block;
  /* If the image ever fails to decode, hide it outright instead of showing a broken-image
     icon plus wrapped alt text spilling out of this 60x60 box (img.onerror in app.js). */
  color: transparent;
  font-size: 0;
}

.image-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.image-preview-remove svg {
  width: 10px;
  height: 10px;
}

.image-preview-remove:hover {
  color: var(--accent-red);
  border-color: var(--accent-red);
}

.msg-sent-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 12px;
  margin-bottom: 8px;
}

.stop-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: none;
  background: var(--accent-red);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.stop-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.stop-btn:active:not(:disabled) {
  filter: brightness(0.95);
}

.stop-btn[hidden] {
  display: none;
}

.stop-btn svg {
  width: 16px;
  height: 16px;
}

.input-disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Chat History Sidebar ───────────────────────────────────── */
.history-section {
  flex-shrink: 0;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.icon-btn svg {
  width: 14px;
  height: 14px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 170px;
  overflow-y: auto;
}

.history-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--bg-panel);
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  background: #E5E5E5; /* neutral/200 */
}

.history-item.active {
  border-color: var(--accent-primary);
  background: var(--accent-soft);
}

.history-item-info {
  flex-grow: 1;
  min-width: 0;
}

.history-item-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-date {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

.history-item-delete {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 6px;
  opacity: 0;
  transition: all 0.2s;
}

.history-item:hover .history-item-delete {
  opacity: 1;
}

.history-item-delete:hover {
  color: var(--accent-red);
  background: #fee2e2;
}

.history-item-delete svg {
  width: 12px;
  height: 12px;
}

/* ── Thinking / reasoning block ─────────────────────────────── */
.thinking-block {
  margin-bottom: 10px;
  border: 1px dashed var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-panel);
}

.thinking-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: var(--accent-primary);
  font-family: var(--font-main);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  cursor: pointer;
}

.thinking-toggle svg {
  width: 12px;
  height: 12px;
}

.thinking-toggle .chevron {
  margin-left: auto;
  transition: transform 0.2s;
}

.thinking-block.expanded .thinking-toggle .chevron {
  transform: rotate(180deg);
}

.thinking-body {
  padding: 0 12px 10px 12px;
  font-family: var(--font-code);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-muted);
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

.thinking-block:not(.expanded) .thinking-body {
  display: none;
}

/* ── Battle mode stage blocks ───────────────────────────────── */
.battle-stage {
  margin-bottom: 14px;
}

.battle-stage:last-child {
  margin-bottom: 0;
}

.battle-stage-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.battle-stage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.battle-stage.primary .battle-stage-dot  { background: var(--accent-secondary); }
.battle-stage.critic .battle-stage-dot   { background: var(--accent-primary); }
.battle-stage.revision .battle-stage-dot { background: #404040; } /* neutral/700 */

/* Shown first, above the (usually collapsed) discussion block below it. */
.battle-final {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.battle-final-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-green);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.battle-final-header svg {
  width: 13px;
  height: 13px;
}

.battle-final.revise .battle-final-header  { color: var(--accent-secondary); }
.battle-final.blocked .battle-final-header { color: var(--accent-red); }

/* ── Structured review card (verdict/findings — ported from claudex-loop) ──── */
.review-card {
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.45;
}

.review-verdict {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 6px;
}

.review-verdict svg { width: 14px; height: 14px; }

.review-card.approved .review-verdict { color: var(--accent-green); }
.review-card.revise .review-verdict   { color: var(--accent-secondary); }
.review-card.blocked .review-verdict  { color: var(--accent-red); }

.review-summary {
  color: var(--text-main);
  margin-bottom: 8px;
}

.review-findings {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.review-finding {
  border-left: 3px solid var(--border-color);
  padding: 4px 0 4px 10px;
}

.review-finding.severity-high   { border-left-color: var(--accent-red); }
.review-finding.severity-medium { border-left-color: var(--accent-secondary); }
.review-finding.severity-low    { border-left-color: var(--text-muted); }

.review-finding-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 2px;
}

.review-finding-severity {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.review-finding-path {
  font-family: var(--font-code);
  color: var(--text-main);
}

.review-finding-evidence {
  color: var(--text-main);
  margin-bottom: 2px;
}

.review-finding-fix {
  color: var(--text-muted);
}

.review-limitations {
  color: var(--text-muted);
  font-size: 11.5px;
  font-style: italic;
}

/* ── Battle mode discussion (collapsible draft/critique/revision exchange) ──── */
.battle-discussion {
  border: 1px dashed var(--border-color);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-panel);
}

.battle-discussion-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--accent-primary);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.battle-discussion-toggle svg {
  width: 14px;
  height: 14px;
}

.battle-discussion-toggle .chevron {
  margin-left: auto;
  transition: transform 0.2s;
}

.battle-discussion.expanded .battle-discussion-toggle .chevron {
  transform: rotate(180deg);
}

.battle-discussion-body {
  padding: 4px 14px 14px 14px;
  border-top: 1px solid var(--border-color);
}

.battle-discussion:not(.expanded) .battle-discussion-body {
  display: none;
}

/* ── MCP connectors ──────────────────────────────────────────── */
.mcp-providers {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mcp-provider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
}

.mcp-provider-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.mcp-provider-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.mcp-provider-dot.connected {
  background: var(--accent-green);
}

.mcp-connect-btn, .mcp-disconnect-btn {
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  background: #ffffff;
  color: var(--text-main);
  transition: all 0.2s;
}

.mcp-connect-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-soft);
}

.mcp-disconnect-btn:hover {
  border-color: #fecaca;
  color: var(--accent-red);
  background: #fef2f2;
}

.mcp-hint {
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 2px;
}

/* ── Settings page (settings.html) — MCP/memory/usage moved out of the chat
   sidebar so it doesn't get crowded; reuses .sidebar-section/.section-title/
   .mcp-*/.usage-* component styles above, just in a scrollable centered
   column instead of the fixed 320px sidebar. ─────────────────────────── */
.settings-body {
  overflow-y: auto;
  align-items: flex-start;
  height: auto;
  min-height: 100vh;
}

.settings-page {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 24px 64px;
  z-index: 1;
  position: relative;
}

.settings-header {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 36px;
}

.settings-back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
}

.settings-back-link:hover {
  color: var(--accent-primary);
}

.settings-back-link svg {
  width: 15px;
  height: 15px;
}

.settings-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
}

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

.memory-empty {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.memory-fact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
}

.memory-fact-text {
  font-size: 13px;
  line-height: 1.4;
}

.memory-fact-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.memory-fact-date {
  font-size: 10.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.memory-fact-delete {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.memory-fact-delete:hover {
  border-color: #fecaca;
  color: var(--accent-red);
  background: #fef2f2;
}

.memory-fact-delete svg {
  width: 14px;
  height: 14px;
}

/* ── Tool call block (MCP tool use inside a chat message) ────── */
.tool-call-block {
  margin-bottom: 10px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--accent-soft);
  font-size: 12px;
}

.tool-call-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--accent-primary);
  margin-bottom: 6px;
}

.tool-call-header svg {
  width: 13px;
  height: 13px;
}

.tool-call-args {
  font-family: var(--font-code);
  font-size: 11px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 6px;
}

.tool-call-result {
  font-family: var(--font-code);
  font-size: 11px;
  color: var(--text-main);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow-y: auto;
  border-top: 1px dashed rgba(255, 90, 35, 0.25);
  padding-top: 6px;
}

/* read_image/OCR gets its own accent (blue) so it visually reads as "this turn actually
   looked at an image", distinct from the brand-orange generic MCP tool-call blocks. */
.tool-call-block--ocr {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.35);
}

.tool-call-block--ocr .tool-call-header {
  color: #2563eb;
}

.tool-call-block--ocr .tool-call-result {
  border-top-color: rgba(59, 130, 246, 0.25);
}

/* Typing Indicator (Wait mode) */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 8px;
  align-items: center;
  justify-content: center;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent-primary);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}
