/* ── Reset та базові змінні ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --accent: #4f8ef7;
  --accent-hover: #3a7af0;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --blue: #3b82f6;
  --gray: #64748b;
  --sidebar-w: 280px;
  --jira-w: 480px;
  --radius: 8px;
  --font: 'Inter', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ───────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar (Telegram) ───────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.sidebar-header .icon { font-size: 18px; }

#add-chat-form {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

#add-chat-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}

#add-chat-input:focus { border-color: var(--accent); }
#add-chat-input::placeholder { color: var(--text-muted); }

.btn-icon {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--accent-hover); }

#chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: var(--radius);
  margin: 2px 8px;
  transition: background .12s;
  gap: 10px;
}

.chat-item:hover { background: var(--surface2); }
.chat-item.active { background: var(--surface2); border-left: 3px solid var(--accent); }

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-avatar img, .msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.unread-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.btn-remove-chat {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s, color .15s;
}
.chat-item:hover .btn-remove-chat { opacity: 1; }
.btn-remove-chat:hover { color: var(--red); }

.btn-chat-type {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 3px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s, background .15s;
  flex-shrink: 0;
}
.chat-item:hover .btn-chat-type { opacity: 1; }
.btn-chat-type:hover { background: var(--surface2); }
.btn-chat-type.dev { opacity: 0.7; }
.chat-item:hover .btn-chat-type.dev { opacity: 1; }

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

/* ── Chat area ────────────────────────────────────────────────────── */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
}

#chat-title { font-size: 16px; font-weight: 600; flex: 1; }

.live-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--green);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.7); }
}

#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #0d1117;
}

.message {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: fadeIn .2s ease;
  padding: 2px 0;
}

.message.same-sender .msg-avatar { visibility: hidden; }

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

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}

.msg-body { flex: 1; min-width: 0; max-width: 75%; }

.msg-bubble {
  background: var(--surface2);
  border-radius: 16px 16px 16px 4px;
  padding: 8px 12px;
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--border);
}

.message.same-sender .msg-bubble {
  border-radius: 16px 16px 16px 4px;
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  padding-left: 4px;
}

.msg-sender {
  font-weight: 700;
  font-size: 12px;
  color: var(--accent);
}

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

.msg-text {
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  color: var(--text);
}

.msg-media-img {
  display: block;
  max-width: 280px;
  max-height: 320px;
  border-radius: 10px;
  margin-bottom: 4px;
  cursor: pointer;
  object-fit: cover;
}

.msg-media-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  padding: 4px 0;
}
.msg-media-doc:hover { text-decoration: underline; }

.msg-date-divider {
  text-align: center;
  margin: 12px 0 8px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-date-divider::before, .msg-date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Ask AI panel ────────────────────────────────────────────────── */
#ask-ai-panel {
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  max-height: 320px;
  display: flex;
  flex-direction: column;
}

.ask-ai-header {
  padding: 8px 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
.ask-ai-header:hover { color: var(--text); }

#ask-ai-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

#ask-ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
}

.ask-msg {
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 90%;
  word-break: break-word;
}
.ask-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-radius: 10px 10px 2px 10px;
}
.ask-msg.ai {
  background: var(--surface2);
  color: var(--text);
  align-self: flex-start;
  border: 1px solid var(--border);
  border-radius: 10px 10px 10px 2px;
}
.ask-msg.ai.loading { color: var(--text-muted); font-style: italic; }

.ask-ai-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
}

#ask-ai-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
#ask-ai-input:focus { border-color: var(--accent); }
#ask-ai-input::placeholder { color: var(--text-muted); }

#ask-ai-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}
#ask-ai-btn:hover { background: var(--accent-hover); }
#ask-ai-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── AI suggestion block ──────────────────────────────────────────── */
#ai-panel {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 14px 20px;
  flex-shrink: 0;
}

.ai-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-label .spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: none;
}
.ai-label.loading .spinner { display: block; }

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

#ai-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 42px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

#ai-text.muted { color: var(--text-muted); font-style: italic; }

.ai-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  padding: 6px 12px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-jira {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-jira.active { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }
.btn-jira.active:hover { background: #1e40af; }

.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Jira panel ───────────────────────────────────────────────────── */
#jira-panel {
  width: var(--jira-w);
  min-width: var(--jira-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .2s ease, min-width .2s ease;
}
#jira-panel.docs-mode {
  width: 420px;
  min-width: 420px;
}

.jira-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.jira-header-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.jira-header h2 { font-size: 15px; font-weight: 600; flex: 1; }

#jira-project-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

.jira-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: all .12s;
}
.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

#jira-tasks {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.jira-task {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  transition: border-color .15s, background .15s;
}
.jira-task:hover {
  border-color: var(--accent);
  background: rgba(79,142,247,.06);
}
.jira-task:hover { border-color: var(--accent); }

.task-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.task-key {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

.status-todo    { background: rgba(100,116,139,.25); color: #94a3b8; }
.status-inprogress { background: rgba(59,130,246,.2); color: #60a5fa; }
.status-review  { background: rgba(234,179,8,.2); color: #fbbf24; }
.status-done    { background: rgba(34,197,94,.15); color: #4ade80; }
.status-default { background: rgba(100,116,139,.2); color: var(--text-muted); }

.task-summary { font-size: 13px; line-height: 1.4; }

.task-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.task-due { color: var(--text-muted); }
.task-due.overdue { color: var(--red); font-weight: 600; }

/* ── Placeholder screens ──────────────────────────────────────────── */
.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}

.placeholder-icon { font-size: 48px; opacity: .3; }

/* ── Toast notifications ─────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  animation: slideIn .2s ease;
  max-width: 300px;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red); color: var(--red); }

@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; } }

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Connection status ───────────────────────────────────────────── */
#ws-status {
  position: fixed;
  bottom: 12px;
  right: 12px;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  z-index: 100;
  pointer-events: none;
}
#ws-status.connected { color: var(--green); border-color: var(--green); }
#ws-status.disconnected { color: var(--red); border-color: var(--red); }

/* ── Send button ─────────────────────────────────────────────────── */
.btn-send {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  border: none;
}
.btn-send:hover { opacity: .9; }

/* ── Search results ──────────────────────────────────────────────── */
.search-result { border-left: 3px solid var(--accent); margin-bottom: 6px; }
.search-result mark {
  background: rgba(79,142,247,.3);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
}

/* ── Label tags ──────────────────────────────────────────────────── */
.label-tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.label-tag.active {
  background: rgba(79,142,247,.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Chat header search ──────────────────────────────────────────── */
#chat-header { gap: 8px; flex-wrap: wrap; }
#search-bar { display: flex; align-items: center; }

/* ── Digest ──────────────────────────────────────────────────────── */
.digest-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-align: center;
}
.digest-section {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.digest-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
}
.digest-section-body {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Risks ───────────────────────────────────────────────────────── */
.risk-item {
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  border-left: 3px solid var(--border);
  background: var(--surface2);
}
.risk-item.risk-high   { border-left-color: var(--red); }
.risk-item.risk-medium { border-left-color: var(--yellow); }
.risk-item.risk-low    { border-left-color: var(--green); }

.risk-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.risk-badge { font-size: 11px; font-weight: 600; }
.risk-chat  { font-size: 10px; color: var(--text-muted); margin-left: auto; }
.risk-title { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.risk-explanation { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-bottom: 4px; }
.risk-mitigation   { font-size: 11px; color: var(--green); line-height: 1.4; }

/* ── Documents panel ─────────────────────────────────────────────── */
.doc-type-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.doc-type-tab {
  flex: 1;
  padding: 7px 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.doc-type-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.doc-template-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 7px 10px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
#doc-template-label {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}
.btn-upload {
  font-size: 11px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s;
}
.btn-upload:hover { border-color: var(--accent); color: var(--accent); }

.doc-hint {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(79,142,247,.07);
  border: 1px solid rgba(79,142,247,.2);
  border-radius: var(--radius);
  padding: 6px 10px;
  margin-bottom: 8px;
  line-height: 1.5;
}
.doc-hint code {
  background: rgba(79,142,247,.15);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 10px;
  color: var(--accent);
}

/* ── Перемикач режиму документа ─────────────────────────────────── */
.doc-mode-switch {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
  margin-bottom: 12px;
}

.doc-mode-btn {
  flex: 1;
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.doc-mode-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,.05);
}
.doc-mode-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(79,142,247,.35);
}

.doc-field {
  margin-bottom: 7px;
}
.doc-field label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.doc-field input,
.doc-field textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 9px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  font-family: var(--font);
  resize: vertical;
  transition: border-color .15s;
}
.doc-field input:focus,
.doc-field textarea:focus { border-color: var(--accent); }

.doc-field-row {
  display: flex;
  gap: 8px;
}
.doc-field-row > div { flex: 1; }

.doc-prefix {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) 0 0 var(--radius);
  padding: 6px 8px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1.5;
}

.doc-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin: 10px 0 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Duplicate warning ───────────────────────────────────────────── */
.duplicate-warning {
  font-size: 12px;
  color: var(--yellow);
  font-weight: 600;
  margin-bottom: 6px;
}
.duplicate-item {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 8px;
  background: var(--surface2);
  border-radius: 4px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Jira unavailable ────────────────────────────────────────────── */
.jira-unavailable {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── AI Analysis block ───────────────────────────────────────────── */
.ai-analysis {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 7px 10px;
  margin: 6px 10px;
  line-height: 1.5;
}
.ai-analysis .mood-icon { margin-right: 4px; }

/* ── Agent badges ────────────────────────────────────────────────── */
.agent-badges {
  display: flex;
  gap: 5px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.agent-confidence {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: help;
}

.agent-type {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(79,142,247,.15);
  color: var(--accent);
  border: 1px solid rgba(79,142,247,.3);
}

.agent-priority {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}
.agent-priority-p0 { background: rgba(239,68,68,.2); color: #ef4444; border: 1px solid rgba(239,68,68,.4); }
.agent-priority-p1 { background: rgba(249,115,22,.2); color: #f97316; border: 1px solid rgba(249,115,22,.4); }
.agent-priority-p2 { background: rgba(234,179,8,.2); color: #ca8a04; border: 1px solid rgba(234,179,8,.3); }
.agent-priority-p3 { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }

/* Jira кнопка — кольорова за типом рішення */
#btn-create-jira.jira-auto { background: rgba(34,197,94,.15); border-color: #22c55e; color: #22c55e; }
#btn-create-jira.jira-suggest { background: rgba(234,179,8,.12); border-color: #ca8a04; color: #ca8a04; }

/* ── Variant tabs ────────────────────────────────────────────────── */
.variant-tabs {
  display: flex;
  gap: 4px;
  padding: 4px 10px;
}
.variant-tab {
  flex: 1;
  padding: 5px 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.variant-tab:hover { color: var(--text); border-color: var(--accent); }
.variant-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Right panel tabs ────────────────────────────────────────────── */
.right-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.right-tab {
  flex: 1;
  padding: 8px 2px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.right-tab:hover { color: var(--text); }
.right-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

#right-jira { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
#right-memory { display: none; flex-direction: column; flex: 1; overflow: hidden; }

/* ── Memory header ───────────────────────────────────────────────── */
.memory-header {
  padding: 10px 12px 0;
  flex-shrink: 0;
}

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

.scope-btn {
  flex: 1;
  padding: 5px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scope-btn:hover { border-color: var(--accent); color: var(--accent); }
.scope-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.memory-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.memory-search-row input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  margin-bottom: 8px;
}
.memory-search-row input:focus { border-color: var(--accent); }

/* ── Memory item ─────────────────────────────────────────────────── */
.memory-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 12px;
}

.mem-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.mem-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.mem-decision   { background: #1e3a5f; color: #60a5fa; }
.mem-requirement { background: #1a3a2a; color: #4ade80; }
.mem-feedback   { background: #2d2a1a; color: #facc15; }
.mem-bug        { background: #3a1a1a; color: #f87171; }
.mem-blocker    { background: #3a1f1a; color: #fb923c; }
.mem-risk       { background: #2d1a3a; color: #c084fc; }
.mem-default    { background: var(--surface); color: var(--text-muted); }

.mem-chat { color: var(--text-muted); font-size: 10px; }
.mem-date { color: var(--text-muted); font-size: 10px; margin-left: auto; }

.mem-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.4;
}

.mem-content {
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 5px;
}

.mem-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.mem-tag {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  color: var(--text-muted);
}

.mem-jira-keys {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.mem-jira-key {
  font-size: 10px;
  color: var(--accent);
  cursor: pointer;
}

/* ── Кнопки дій на повідомленні ─────────────────────────────────── */
.msg-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
  margin-top: 2px;
}
.message:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: background .12s;
}
.msg-action-btn:hover { background: var(--surface2); }

/* ── Переклад і транскрипція ─────────────────────────────────────── */
.msg-translation {
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px dashed var(--border);
  margin-top: 5px;
  padding-top: 5px;
  font-style: italic;
}
.msg-transcription {
  font-size: 12px;
  color: var(--text);
  border-top: 1px dashed var(--border);
  margin-top: 5px;
  padding-top: 5px;
  line-height: 1.5;
}

/* ── Модальні вікна ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(3px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
}

/* ── Нагадування ─────────────────────────────────────────────────── */
.reminder-preset {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: all .12s;
}
.reminder-preset:hover { border-color: var(--accent); color: var(--accent); }

/* ── Картка клієнта ──────────────────────────────────────────────── */
.cc-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.cc-input {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 100%;
  font-family: inherit;
}
.cc-input:focus { border-color: var(--accent); }

/* ── Глобальний пошук ────────────────────────────────────────────── */
.global-search-result {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface2);
  cursor: pointer;
  transition: background .12s;
}
.global-search-result:hover { background: var(--surface); border: 1px solid var(--border); }
.gs-chat-name { font-size: 10px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.gs-sender    { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.gs-text      { font-size: 13px; color: var(--text); line-height: 1.4; }
.gs-text mark { background: rgba(79,142,247,.3); color: var(--accent); border-radius: 3px; padding: 0 2px; }

/* ── Search scope btn ────────────────────────────────────────────── */
.search-scope-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 3px 7px;
  transition: all .12s;
}
.search-scope-btn:hover { border-color: var(--accent); }

/* ══════════════════════════════════════════════════════════════════
   ── Мобільна адаптивність ─────────────────────────────────────────
   ══════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  :root {
    --sidebar-w: 100vw;
    --jira-w: 100vw;
  }

  #app {
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
    position: relative;
  }

  /* Sidebar — повний екран, ховається коли чат відкритий */
  #sidebar {
    width: 100vw;
    min-width: 100vw;
    height: 100dvh;
    position: absolute;
    top: 0; left: 0;
    z-index: 100;
    transition: transform .25s ease;
  }
  #sidebar.hidden { transform: translateX(-100%); }

  /* Chat area — повний екран */
  #chat-area {
    width: 100vw;
    height: 100dvh;
    position: absolute;
    top: 0; left: 0;
    z-index: 50;
    transform: translateX(100%);
    transition: transform .25s ease;
  }
  #chat-area.visible { transform: translateX(0); }

  /* Jira panel — слайдиться знизу */
  #jira-panel {
    width: 100vw;
    min-width: 100vw;
    height: 70dvh;
    position: fixed;
    bottom: 0; left: 0;
    z-index: 200;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform .3s ease;
    box-shadow: 0 -8px 32px rgba(0,0,0,.4);
  }
  #jira-panel.mobile-open { transform: translateY(0); }
  #jira-panel.docs-mode { width: 100vw; min-width: 100vw; }

  /* Кнопка "назад" в header чату */
  #chat-header {
    padding: 8px 12px;
    gap: 8px;
  }
  #btn-back-mobile {
    display: flex !important;
    align-items: center;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px 4px 0;
    flex-shrink: 0;
  }

  /* Мобільна нижня панель навігації */
  #mobile-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0;
    width: 100%;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 150;
    padding: 6px 0 env(safe-area-inset-bottom, 6px);
  }
  #mobile-nav button {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    padding: 6px 4px;
    transition: color .15s;
  }
  #mobile-nav button .nav-icon { font-size: 20px; }
  #mobile-nav button.active { color: var(--accent); }
  #mobile-nav button .nav-badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 18px);
    background: var(--red);
    color: #fff;
    border-radius: 999px;
    font-size: 9px;
    padding: 1px 5px;
    font-weight: 700;
  }

  /* Ховаємо десктопний контент що не потрібен на мобільному */
  #ask-ai-panel { display: none !important; }

  /* Більший шрифт для зручності */
  .msg-text { font-size: 15px; }
  .chat-name { font-size: 14px; }

  /* Відступ знизу для нижньої навігації */
  #messages-container { padding-bottom: 60px; }
  #ai-panel { padding-bottom: 60px; }
}

/* Десктоп — кнопка назад і мобільна навігація приховані */
#btn-back-mobile { display: none; }
#mobile-nav { display: none; }
