/* ===========================================================================
   Agent Team Hub — дизайн-система (тёмная тема, без внешних зависимостей)
   =========================================================================== */

:root {
  --bg: #0b0f16;
  --bg-elev: #121826;
  --bg-elev-2: #172033;
  --line: #232f46;
  --line-soft: #1b2438;
  --text: #e8edf7;
  --muted: #8d9bb5;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --ok: #3ecf8e;
  --warn: #f5b544;
  --danger: #ff5f6d;
  --violet: #a78bfa;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", monospace;
}

* { box-sizing: border-box; }

/* ВАЖНО: атрибут hidden должен побеждать display из наших правил.
   Без этого .modal { display: grid } перебивает [hidden] → пустая модалка
   «Форма» навсегда висит поверх экрана и блокирует интерфейс. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 700px at 15% -10%, #16203a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
small, .small { font-size: 12.5px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
hr { border: none; border-top: 1px solid var(--line-soft); margin: 14px 0; }

/* ---------- Авторизация ---------- */

.auth-body { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.auth-card {
  width: min(420px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--accent), var(--violet));
  font-size: 21px;
}
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; margin-top: 4px; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  color: var(--text);
  font-family: inherit; font-size: 13.5px; font-weight: 550;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
.btn:hover { background: #1d2739; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #05101f; }
.btn.primary:hover { background: #62a0ff; }
.btn.danger { border-color: rgba(255, 95, 109, 0.5); color: var(--danger); }
.btn.danger:hover { background: rgba(255, 95, 109, 0.12); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; }

/* ---------- Каркас ---------- */

.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--line-soft);
  background: rgba(10, 14, 22, 0.75);
  backdrop-filter: blur(8px);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 0; height: 100vh;
}
.nav { display: grid; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 11px;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
  font-family: inherit; font-size: 13.5px; text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--bg-elev-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 0 0 1px rgba(79,140,255,0.35); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.live { display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.dot.on { background: var(--ok); box-shadow: 0 0 10px var(--ok); }

.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 5;
  background: rgba(11, 15, 22, 0.86);
  backdrop-filter: blur(8px);
}
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view { padding: 20px 22px 40px; }

/* ---------- Компоненты ---------- */

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card.tight { padding: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }

.stat { display: grid; gap: 4px; }
.stat .value { font-size: 26px; font-weight: 680; letter-spacing: -0.02em; }
.stat .label { font-size: 12.5px; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); white-space: nowrap;
}
.badge.queued { color: var(--accent); border-color: rgba(79,140,255,0.4); }
.badge.running { color: var(--warn); border-color: rgba(245,181,68,0.45); }
.badge.done, .badge.ok { color: var(--ok); border-color: rgba(62,207,142,0.4); }
.badge.failed, .badge.error { color: var(--danger); border-color: rgba(255,95,109,0.4); }
.badge.review, .badge.waiting { color: var(--violet); border-color: rgba(167,139,250,0.4); }
.badge.backlog, .badge.cancelled { color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { color: var(--muted); font-weight: 550; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
.table-wrap { overflow-x: auto; }

.kanban { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; align-items: start; }
.column { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.column h3 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.task-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
}
.task-card:hover { border-color: var(--accent); }
.task-card .title { font-size: 13.5px; font-weight: 560; margin-bottom: 6px; }
.task-card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.chat-wrap { display: grid; grid-template-columns: 280px 1fr; gap: 14px; min-height: 62vh; }
.thread-list { display: grid; gap: 6px; align-content: start; max-height: 70vh; overflow-y: auto; }
.thread {
  text-align: left; padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft); background: var(--bg-elev-2);
  color: var(--text); cursor: pointer; font-family: inherit;
}
.thread:hover { border-color: var(--accent); }
.thread.active { border-color: var(--accent); background: var(--accent-soft); }
.thread .snippet { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages { display: flex; flex-direction: column; gap: 10px; max-height: 62vh; overflow-y: auto; padding: 6px; }
.msg { max-width: 76%; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line-soft); background: var(--bg-elev-2); }
.msg.agent { align-self: flex-start; border-left: 3px solid var(--accent); }
.msg.user { align-self: flex-end; background: rgba(79,140,255,0.12); border-color: rgba(79,140,255,0.3); }
.msg.system { align-self: center; background: transparent; border-style: dashed; color: var(--muted); max-width: 90%; }
.msg .who { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.composer { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.composer textarea { min-height: 52px; }

.log { background: #070b12; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 10px; max-height: 320px; overflow: auto; white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; color: #c8d4ea; }

.empty { padding: 26px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .chat-wrap, .split { grid-template-columns: 1fr; }
}

/* ---------- Модальное окно / тосты ---------- */

.modal { position: fixed; inset: 0; background: rgba(3, 6, 12, 0.72); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-card { width: min(640px, 100%); max-height: 88vh; overflow: auto; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.modal-card header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: var(--bg-elev); }
.modal-body { padding: 16px; display: grid; gap: 12px; }
.modal-card footer { padding: 14px 16px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: var(--bg-elev); }

.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 90;
  padding: 11px 15px; border-radius: var(--radius-sm);
  background: var(--bg-elev-2); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 13.5px; max-width: 380px;
}
.toast.ok { border-color: rgba(62,207,142,0.5); }
.toast.err { border-color: rgba(255,95,109,0.5); }

.token-box { font-family: var(--mono); font-size: 12.5px; word-break: break-all; background: #070b12; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; }
