:root {
  --bg: #f4f6f8; --panel: #ffffff; --border: #dde3ea; --text: #1c2733;
  --muted: #6b7a8c; --accent: #2563eb; --accent-dark: #1d4ed8;
  --green: #16a34a; --red: #dc2626; --yellow: #d97706;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); height: 100vh; overflow: hidden;
}
button {
  font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: var(--panel); border-radius: 8px; padding: 8px 14px;
}
button.icon-btn { width: 34px; height: 34px; padding: 0; flex: 0 0 34px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  font: inherit; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; width: 100%; background: #fff; color: var(--text);
}
.hidden { display: none !important; }

/* Вход */
#login-view {
  height: 100vh; display: flex; align-items: center; justify-content: center;
}
#login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 32px; width: 340px; display: flex; flex-direction: column; gap: 12px;
}
#login-box h1 { font-size: 18px; }
#login-error { color: var(--red); font-size: 13px; min-height: 16px; }

/* Основной вид */
#app-view { display: flex; height: 100vh; }
#sidebar {
  width: 280px; min-width: 280px; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  transition: width .2s ease, min-width .2s ease, transform .2s ease;
}
#app-view.sidebar-collapsed #sidebar { width: 0; min-width: 0; overflow: hidden; border-right: 0; }
#sidebar header {
  padding: 14px; border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center; justify-content: space-between;
}
#sidebar header .who { font-size: 13px; color: var(--muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
#manager-filter-wrap { padding: 10px 14px; border-bottom: 1px solid var(--border); }
#manager-filter { font-size: 13px; }
#chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.chat-item:hover { background: #f0f4f9; }
.chat-item.active { background: #e8effc; }
.chat-item-main { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.chat-item-text { min-width: 0; flex: 1; }
.chat-item .t { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .d { font-size: 11px; color: var(--muted); }
.chat-owner-line { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-actions { display: flex; gap: 4px; opacity: .35; }
.chat-item:hover .chat-actions { opacity: 1; }
.chat-actions button { width: 26px; height: 26px; padding: 0; font-size: 13px; }
.chat-item.editing { background: #f8fbff; }
.chat-item.editing .t { white-space: normal; overflow: visible; }
.chat-title-input {
  height: 28px; padding: 4px 7px; border-radius: 6px; font-size: 13px;
}
.chat-header-input {
  width: min(520px, 70vw); height: 34px; padding: 5px 8px; font-weight: 600;
}
.rename-error {
  color: var(--red); font-size: 11px; font-weight: 500; margin-top: 4px; white-space: normal;
}
.status-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px;
  background: #cbd5e1; box-shadow: 0 0 0 3px rgba(203, 213, 225, .28);
}
.status-dot.running { background: var(--accent); animation: pulse-dot 2.2s ease-in-out infinite; }
.status-dot.done { background: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, .18); }
.status-dot.needs-human { background: var(--yellow); box-shadow: 0 0 0 3px rgba(217, 119, 6, .18); }
@keyframes pulse-dot {
  0%, 100% { opacity: .45; box-shadow: 0 0 0 2px rgba(37, 99, 235, .16); }
  50% { opacity: 1; box-shadow: 0 0 0 6px rgba(37, 99, 235, .08); }
}
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #eef2f7;
  color: var(--muted); white-space: nowrap;
}
.badge.run { background: #fff7e6; color: var(--yellow); }
.badge.done { background: #e9f9ef; color: var(--green); }
#sidebar footer { padding: 10px 14px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; }
#sidebar footer button { flex: 1; font-size: 13px; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#collapsed-rail {
  position: absolute; left: 12px; top: 12px; z-index: 10;
}
#chat-header {
  padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
  font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.owner-pill {
  display: inline-flex; margin-left: 8px; padding: 2px 8px; border-radius: 999px;
  background: #eef2f7; color: var(--muted); font-size: 12px; font-weight: 500;
}
#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex;
  flex-direction: column; gap: 12px; }
.msg { max-width: 76%; padding: 10px 14px; border-radius: 12px; font-size: 14px;
  white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff;
  border-bottom-right-radius: 4px; }
.msg.system { align-self: flex-start; background: var(--panel);
  border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .time { display: block; font-size: 10px; opacity: .6; margin-top: 4px; }
.msg .file-link { display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; padding: 8px 12px; background: #e9f9ef; border-radius: 8px;
  color: var(--green); text-decoration: none; font-weight: 600; }

/* Подтверждение позиций */
.confirm-box { align-self: stretch; max-width: 100%; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.confirm-box h4 { font-size: 14px; margin-bottom: 8px; }
.confirm-box .warn { color: var(--red); font-size: 13px; margin: 6px 0; }
.confirm-box table { width: 100%; border-collapse: collapse; font-size: 13px; }
.confirm-box th, .confirm-box td { border: 1px solid var(--border); padding: 5px 8px;
  text-align: left; }
.confirm-box th { background: #f0f4f9; }
.confirm-box tr.invalid td { background: #fdecea; }
.confirm-box input { padding: 3px 6px; border-radius: 5px; }
.confirm-box .row-note { font-size: 11px; color: var(--yellow); }
.confirm-actions { display: flex; gap: 10px; margin-top: 10px; align-items: center;
  flex-wrap: wrap; }
.confirm-actions label { font-size: 13px; display: flex; gap: 6px; align-items: center; }

/* Прогресс */
.progress-box { align-self: flex-start; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px;
  font-size: 13px; min-width: 320px; }
.progress-box .bar { height: 6px; background: #eef2f7; border-radius: 3px;
  margin: 8px 0; overflow: hidden; }
.progress-box .bar div { height: 100%; background: var(--accent); transition: width .4s; }
.progress-box .pl { color: var(--muted); margin-top: 2px; }

#composer { padding: 14px 20px; background: var(--panel);
  border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-end; }
#composer textarea { resize: none; max-height: 140px; min-height: 42px; }
#empty-state { flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px; }

/* Админка */
.admin-body { overflow: auto; padding: 24px; height: 100vh; }
.admin-wrap { max-width: 1100px; margin: 0 auto; }
.admin-wrap h1 { font-size: 20px; margin-bottom: 16px; }
.tabs { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; margin-bottom: 16px; }
.card h3 { font-size: 15px; margin-bottom: 10px; }
.card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.card th, .card td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; }
.card th { background: #f0f4f9; }
.status-ok { color: var(--green); font-weight: 600; }
.status-bad { color: var(--red); font-weight: 600; }
.status-unknown { color: var(--muted); }
.card textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.form-row { display: flex; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 140px; }
.msg-note { font-size: 13px; margin-top: 8px; min-height: 16px; }
.msg-note.ok { color: var(--green); }
.msg-note.err { color: var(--red); white-space: pre-wrap; }
.shot { max-width: 100%; border: 1px solid var(--border); border-radius: 8px;
  margin-top: 10px; }
pre.log { background: #101418; color: #cfe3f5; padding: 12px; border-radius: 8px;
  font-size: 11px; overflow: auto; max-height: 400px; }

/* ==================================================================
   Плавность: мгновенный отклик, мягкие переходы, честные индикаторы.
   Никакой анимации дольше 0.25 с — интерфейс должен казаться быстрым,
   а не «красиво тормозить».
   ================================================================== */

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* появление сообщения */
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.msg.appear { animation: msg-in .22s ease-out; }

/* своё сообщение, пока сервер не подтвердил */
.msg.pending { opacity: .62; }
.msg.pending .msg-state { display: block; font-size: 10px; margin-top: 4px; opacity: .8; }
.msg .msg-state { display: none; }
.msg.failed { background: var(--red); }
.msg.failed .msg-state { display: block; font-size: 11px; margin-top: 4px; }

/* «агент печатает» */
.msg.typing { display: flex; gap: 5px; align-items: center; padding: 14px 16px; }
.msg.typing .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: typing-bounce 1.3s ease-in-out infinite;
}
.msg.typing .dot:nth-child(2) { animation-delay: .18s; }
.msg.typing .dot:nth-child(3) { animation-delay: .36s; }
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* кнопка отправки: состояние ожидания вместо «мёртвого» клика */
#btn-send { transition: background .15s ease, transform .12s ease, opacity .15s ease; }
#btn-send:active:not(:disabled) { transform: scale(.94); }
#btn-send.sending { position: relative; color: transparent; }
#btn-send.sending::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* переходы между чатами и наведение */
.chat-item { transition: background .15s ease; }
.chat-item.active { box-shadow: inset 3px 0 0 var(--accent); }
#messages { scroll-behavior: smooth; }
button:not(:disabled):active { transform: scale(.97); }
button { transition: background .15s ease, border-color .15s ease, transform .12s ease; }

/* прогресс прогона: полоса «дышит», пока идёт работа */
.progress-box { animation: msg-in .22s ease-out; }
.progress-box .bar div { transition: width .5s ease; }
.progress-box.active .bar { position: relative; overflow: hidden; }
.progress-box.active .bar::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .5), transparent);
  animation: sheen 1.6s linear infinite;
}
@keyframes sheen { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* мягкое сворачивание боковой панели */
#sidebar { transition: width .22s ease, min-width .22s ease; }
#collapsed-rail { animation: msg-in .2s ease-out; }

/* скелет загрузки списка чатов */
.chat-skeleton { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-skeleton span {
  display: block; height: 10px; border-radius: 5px; margin-bottom: 6px;
  background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite;
}
.chat-skeleton span:last-child { width: 55%; margin-bottom: 0; }
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
