/* ────────────────────────────────────────────────
   Design system — 1eska.ru chat demo
   Палитра под бренд (мягкий зелёный) + нейтральные серые.
   ──────────────────────────────────────────────── */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-alt: #f4f6f8;
  --surface-muted: #eef1f4;
  --border: #e5e7eb;
  --border-strong: #cbd5e1;
  --border-focus: #10b981;
  --text: #0f172a;
  --text-body: #334155;
  --text-muted: #64748b;
  --text-soft: #94a3b8;

  --primary: #10b981;
  --primary-hover: #059669;
  --primary-soft: #d1fae5;
  --primary-softer: #ecfdf5;

  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --warning-border: #fde68a;
  --warning-text: #92400e;

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.10);

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

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-body);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

a { color: var(--primary-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; }
input, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }

/* ─── layout helpers ─── */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ─── header (общий) ─── */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  overflow: hidden;  /* не даём внутренностям вылезать за viewport */
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.brand .dot {
  width: 10px;
  height: 10px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.spacer { flex: 1; }

.topbar-link {
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.topbar-link:hover {
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
}

.topbar-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.topbar-field input {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 140px;
  font-size: 13px;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.topbar-field input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ─── status chip ─── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface-alt);
  color: var(--text-muted);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.chip.success { background: var(--primary-soft); color: var(--primary-hover); }
.chip.warning { background: var(--warning-soft); color: var(--warning-text); }
.chip.neutral { background: var(--surface-muted); color: var(--text-muted); }

.chip .pulse {
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  opacity: 0.9;
  animation: pulse 2s ease-in-out infinite;
}
.chip.neutral .pulse { animation: none; opacity: 0.6; }

@keyframes pulse {
  0%, 100% { opacity: 0.9; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.85); }
}

/* ─── buttons ─── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

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

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary { border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover:not(:disabled) { background: #fee2e2; }

.btn-warning { background: var(--warning-soft); color: var(--warning-text); border-color: var(--warning-border); }
.btn-warning:hover:not(:disabled) { background: #fde68a; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.btn-icon.btn-primary svg { stroke: white; }
.btn svg { display: block; }

/* ─── inputs / composer ─── */

.field {
  display: block;
  width: 100%;
  min-width: 0;   /* чтобы input корректно сжимался внутри flex-контейнера */
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

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

.composer {
  flex: 1;           /* занимает всё доступное пространство в flex-ряду */
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--border-focus);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  min-height: 22px;
  max-height: 140px;
  padding: 4px 0;
  color: var(--text);
}
.composer textarea::placeholder { color: var(--text-soft); }

/* ─── messages ─── */

.messages {
  padding: 20px 20px 12px;
  display: flex;
  flex-direction: column;
}

.messages-inner {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.msg {
  display: block;
  margin-bottom: 10px;
  animation: msgIn 0.2s ease-out;
  text-align: left;
}
.msg.me, .msg.user { text-align: right; }
.msg.system { text-align: center; }

.bubble {
  display: inline-flex;          /* ← inline для outer (sizes to content) + flex для inner (ignores whitespace between children) */
  flex-direction: column;
  vertical-align: top;
  text-align: left;
  max-width: 76%;
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble a, .msg-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.msg.bot .bubble a,
.msg.operator .bubble a,
.msg.m-bot .msg-bubble a,
.msg.m-client .msg-bubble a { color: var(--primary-hover); font-weight: 500; }
.msg.me .bubble a, .msg.user .bubble a,
.msg.m-op .msg-bubble a { color: white; font-weight: 500; }
.bubble > * { min-width: 0; }

/* Markdown-рендер сообщений LLM: настоящие p/ul/ol/li, не plain-text.
   Внутри пузыря — компактные отступы, без раздутий по высоте. */
.bubble .msg-text > * { margin: 0; padding: 0; }
.bubble .msg-text p { margin: 0 0 8px; }
.bubble .msg-text p:last-child { margin-bottom: 0; }
.bubble .msg-text ul,
.bubble .msg-text ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble .msg-text ul:last-child,
.bubble .msg-text ol:last-child { margin-bottom: 0; }
.bubble .msg-text li { margin: 1px 0; }
.bubble .msg-text strong { font-weight: 600; }
.bubble .msg-text code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
}
.bubble .msg-text h3,
.bubble .msg-text h4,
.bubble .msg-text h5 {
  margin: 6px 0 4px;
  font-size: 1em;
  font-weight: 600;
}
.msg.user .bubble .msg-text code,
.msg.me .bubble .msg-text code,
.msg.m-op .msg-bubble code {
  background: rgba(255, 255, 255, 0.22);
}

/* Аналогично для оператор-кабинета (.msg-bubble) */
.msg .msg-bubble > * { margin: 0; padding: 0; }
.msg .msg-bubble p { margin: 0 0 8px; }
.msg .msg-bubble p:last-child { margin-bottom: 0; }
.msg .msg-bubble ul,
.msg .msg-bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.msg .msg-bubble ul:last-child,
.msg .msg-bubble ol:last-child { margin-bottom: 0; }
.msg .msg-bubble li { margin: 1px 0; }
.msg .msg-bubble strong { font-weight: 600; }
.msg .msg-bubble code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
}
.msg .msg-bubble h3,
.msg .msg-bubble h4,
.msg .msg-bubble h5 {
  margin: 6px 0 4px;
  font-size: 1em;
  font-weight: 600;
}

.msg.bot .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.msg.user .bubble, .msg.me .bubble {
  background: var(--primary);
  color: white;
  border-top-right-radius: 4px;
}

.msg.operator .bubble {
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-top-left-radius: 4px;
  color: var(--warning-text);
}

.msg.system .bubble {
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  padding: 3px 10px;
  max-width: 90%;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 999px;
}

.msg .who {
  font-size: 11px;
  color: var(--text-soft);
  margin-bottom: 2px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.msg.user .who, .msg.me .who { color: rgba(255, 255, 255, 0.78); }
.msg.operator .who { color: #b45309; }

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

/* ─── empty states ─── */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 80px 24px;
  color: var(--text-soft);
  text-align: center;
}
.empty-icon {
  width: 44px;
  height: 44px;
  color: var(--text-soft);
  opacity: 0.55;
  margin-bottom: 4px;
}
.empty-title { font-size: 15px; color: var(--text-muted); font-weight: 500; }
.empty-sub { font-size: 13px; color: var(--text-soft); }

/* ─── scrollbar ─── */

.scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.scroll::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ─── tabs ─── */

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: var(--surface-alt); color: var(--text); }
.tab.active {
  background: var(--primary-softer);
  color: var(--primary-hover);
}

/* ─── list (handoffs sidebar) ─── */

.list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
.list-item {
  display: block;
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
  transition: background 0.15s, border-color 0.15s;
}
.list-item:hover { background: var(--surface-alt); }
.list-item.selected {
  background: var(--primary-softer);
  border-color: var(--primary-soft);
}

.list-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.list-item-id {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0;
}
.list-item-reason {
  font-size: 11px;
  padding: 1px 7px;
  background: var(--surface-muted);
  color: var(--text-muted);
  border-radius: 999px;
  font-weight: 500;
  min-width: 0;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-count {
  margin-left: auto;
  font-size: 11px;
  min-width: 20px;
  padding: 1px 7px;
  background: var(--primary);
  color: white;
  border-radius: 999px;
  text-align: center;
  font-weight: 600;
}
.list-item.closed .list-item-count { background: var(--text-soft); }

.list-item-preview {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.list-item-time {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 6px;
}

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

/* ─── misc utilities ─── */

.mono { font-family: var(--font-mono); }
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.meta {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}
.meta strong { color: var(--text); font-weight: 500; }
