/* ByFly Agents — пульт управления агентами Cursor. Тёмная высокотехнологичная тема. */
:root {
  --bg: #070a10;
  --bg-2: #0b1019;
  --panel: rgba(19, 26, 40, 0.72);
  --panel-solid: #131a28;
  --stroke: rgba(120, 150, 200, 0.14);
  --stroke-2: rgba(120, 150, 200, 0.28);
  --txt: #e8edf6;
  --txt-dim: #8a97ad;
  --txt-faint: #5b6678;
  --accent: #4be3d0;
  --accent-2: #6d8cff;
  --violet: #b57bff;
  --grad: linear-gradient(120deg, #4be3d0, #6d8cff 55%, #b57bff);
  --ok: #37d67a;
  --warn: #ffb23e;
  --danger: #ff5c73;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  --radius: 16px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --sb-w: 340px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--txt);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Живой фон */
.aurora {
  position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
}
.aurora::before, .aurora::after {
  content: ""; position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%;
  filter: blur(120px); opacity: 0.35; animation: drift 26s ease-in-out infinite;
}
.aurora::before { background: radial-gradient(circle, #1f6d7a, transparent 60%); top: -20vmax; left: -10vmax; }
.aurora::after { background: radial-gradient(circle, #4b3a8f, transparent 60%); bottom: -20vmax; right: -10vmax; animation-delay: -12s; }
@keyframes drift { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(6vmax, 4vmax) scale(1.15); } }

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ── Экран входа ─────────────────────────────────────────── */
.login-wrap {
  position: relative; z-index: 1; height: 100%;
  display: grid; place-items: center; padding: 20px;
}
.login-card {
  width: min(420px, 94vw);
  background: var(--panel); backdrop-filter: blur(24px);
  border: 1px solid var(--stroke); border-radius: 22px;
  padding: 38px 32px; box-shadow: var(--shadow);
  animation: rise 0.5s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; background: var(--grad);
  display: grid; place-items: center; font-weight: 800; color: #06121a;
  box-shadow: 0 8px 26px rgba(75, 227, 208, 0.35);
}
.brand-title { font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: var(--txt-dim); margin-top: 2px; }
.login-card h1 { font-size: 22px; margin: 0 0 6px; font-weight: 700; }
.login-card p.lead { color: var(--txt-dim); font-size: 14px; margin: 0 0 22px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--txt-dim); margin-bottom: 8px; font-weight: 600; }
.phone-row { display: flex; gap: 10px; }
.cc-select {
  position: relative; flex: 0 0 auto;
}
.cc-btn {
  height: 52px; padding: 0 14px; border-radius: 13px;
  background: var(--bg-2); border: 1px solid var(--stroke-2); color: var(--txt);
  display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600;
}
.cc-menu {
  position: absolute; top: 58px; left: 0; z-index: 30; width: 260px; max-height: 300px; overflow: auto;
  background: var(--panel-solid); border: 1px solid var(--stroke-2); border-radius: 13px;
  box-shadow: var(--shadow); padding: 6px;
}
.cc-menu button {
  width: 100%; text-align: left; background: none; border: 0; color: var(--txt);
  padding: 10px 12px; border-radius: 9px; display: flex; gap: 10px; font-size: 14px;
}
.cc-menu button:hover { background: rgba(120,150,200,0.12); }
input, textarea, select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--stroke-2);
  color: var(--txt); border-radius: 13px; padding: 0 16px; height: 52px;
  font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(109,140,255,0.18); }
.otp-input { letter-spacing: 10px; text-align: center; font-family: var(--mono); font-size: 26px; }

.btn {
  width: 100%; height: 52px; border: 0; border-radius: 13px; font-size: 16px; font-weight: 700;
  color: #06121a; background: var(--grad); box-shadow: 0 10px 30px rgba(75,227,208,0.28);
  transition: transform .12s, filter .15s, opacity .15s; margin-top: 6px;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px) scale(.995); }
.btn[disabled] { opacity: .55; cursor: not-allowed; filter: grayscale(.3); }
.btn-ghost {
  background: transparent; color: var(--txt-dim); box-shadow: none; font-weight: 600;
  border: 1px solid var(--stroke-2);
}
.msg-line { font-size: 13px; margin-top: 14px; min-height: 18px; }
.msg-line.err { color: var(--danger); }
.msg-line.ok { color: var(--ok); }
.resend { margin-top: 16px; text-align: center; font-size: 13px; color: var(--txt-dim); }
.resend a { color: var(--accent); cursor: pointer; }

/* ── Приложение ──────────────────────────────────────────── */
.app { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: 60px; flex: 0 0 auto; display: flex; align-items: center; gap: 14px;
  padding: 0 18px; border-bottom: 1px solid var(--stroke); background: rgba(9,13,20,0.7);
  backdrop-filter: blur(20px);
}
.topbar .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
.topbar-title { font-weight: 700; font-size: 15px; }
.topbar-title small { display: block; color: var(--txt-faint); font-weight: 500; font-size: 11px; }
.spacer { flex: 1; }
.conn {
  display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--txt-dim);
  padding: 6px 11px; border-radius: 20px; border: 1px solid var(--stroke); background: var(--bg-2);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--txt-faint); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 rgba(55,214,122,.6); animation: pulse 1.8s infinite; }
.dot.warn { background: var(--warn); }
.dot.dead { background: var(--danger); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(55,214,122,.5);} 70%{ box-shadow: 0 0 0 7px rgba(55,214,122,0);} 100%{ box-shadow:0 0 0 0 rgba(55,214,122,0);} }
.user-chip {
  display: flex; align-items: center; gap: 9px; padding: 5px 6px 5px 12px; border-radius: 22px;
  border: 1px solid var(--stroke); background: var(--bg-2); cursor: pointer; font-size: 13px;
}
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--grad); color:#06121a;
  display: grid; place-items: center; font-weight: 800; font-size: 13px; }

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

/* Сайдбар */
.sidebar {
  width: var(--sb-w); flex: 0 0 var(--sb-w); border-right: 1px solid var(--stroke);
  display: flex; flex-direction: column; min-height: 0; background: rgba(9,13,20,0.5);
}
.sb-head { padding: 14px; display: flex; flex-direction: column; gap: 12px; border-bottom: 1px solid var(--stroke); }
.sb-actions { display: flex; gap: 10px; }
.mini-btn {
  flex: 1; height: 40px; border-radius: 11px; border: 1px solid var(--stroke-2);
  background: var(--bg-2); color: var(--txt); font-weight: 600; font-size: 13px;
  display: flex; align-items: center; justify-content: center; gap: 7px; transition: background .15s, border-color .15s;
}
.mini-btn:hover { border-color: var(--accent-2); background: rgba(109,140,255,0.1); }
.mini-btn.primary { background: var(--grad); color: #06121a; border: 0; }
.search { position: relative; }
.search input { height: 42px; padding-left: 38px; font-size: 14px; }
.search svg { position: absolute; left: 12px; top: 12px; opacity: .5; }

.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
  padding: 12px 13px; border-radius: 13px; cursor: pointer; margin-bottom: 4px;
  border: 1px solid transparent; transition: background .12s, border-color .12s; position: relative;
}
.chat-item:hover { background: rgba(120,150,200,0.07); }
.chat-item.active { background: rgba(109,140,255,0.13); border-color: rgba(109,140,255,0.4); }
.ci-top { display: flex; align-items: center; gap: 8px; }
.ci-name { font-weight: 600; font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-time { font-size: 11px; color: var(--txt-faint); flex: 0 0 auto; }
.ci-sub { font-size: 12px; color: var(--txt-dim); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-badges { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.badge {
  font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 7px; letter-spacing: .3px;
  text-transform: uppercase; border: 1px solid transparent;
}
.badge.mode { color: var(--accent-2); background: rgba(109,140,255,0.12); }
.badge.attn { color: var(--warn); background: rgba(255,178,62,0.14); border-color: rgba(255,178,62,0.35); animation: blink 1.4s infinite; }
.badge.run { color: var(--ok); background: rgba(55,214,122,0.14); }
.badge.plan { color: var(--violet); background: rgba(181,123,255,0.14); }
@keyframes blink { 50% { opacity: .5; } }
.unread-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; box-shadow: 0 0 8px var(--accent); }

/* Основная область */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main-head {
  height: 58px; flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 0 18px;
  border-bottom: 1px solid var(--stroke); background: rgba(9,13,20,0.4);
}
.back-btn { display: none; background: none; border: 0; color: var(--txt); font-size: 22px; padding: 4px 8px; }
.mh-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mh-status { font-size: 12px; color: var(--txt-dim); display: flex; align-items: center; gap: 7px; margin-top: 2px; }
.mh-status .spin { width: 12px; height: 12px; border: 2px solid var(--stroke-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stream { flex: 1; overflow-y: auto; padding: 22px clamp(14px, 5vw, 60px); display: flex; flex-direction: column; gap: 16px; scroll-behavior: smooth; }
.bubble { max-width: 780px; width: fit-content; animation: rise .3s ease; }
.bubble.user { align-self: flex-end; }
.bubble.agent { align-self: flex-start; }
.bubble .who { font-size: 11px; color: var(--txt-faint); margin-bottom: 5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
.bubble.user .who { text-align: right; }
.bubble .body {
  padding: 13px 16px; border-radius: 15px; font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word;
}
.bubble.user .body { background: linear-gradient(135deg, rgba(109,140,255,0.22), rgba(75,227,208,0.16)); border: 1px solid rgba(109,140,255,0.3); border-bottom-right-radius: 5px; }
.bubble.agent .body { background: var(--panel); border: 1px solid var(--stroke); border-bottom-left-radius: 5px; }
.bubble .body code { font-family: var(--mono); font-size: 13px; background: rgba(0,0,0,0.35); padding: 1px 5px; border-radius: 5px; }
.bubble .body pre { font-family: var(--mono); font-size: 12.5px; background: #05070c; border: 1px solid var(--stroke); border-radius: 10px; padding: 12px; overflow-x: auto; }
.thinking {
  align-self: flex-start; max-width: 780px; font-size: 12.5px; color: var(--txt-dim);
  border-left: 2px solid var(--violet); padding: 4px 0 4px 12px; opacity: .85; font-style: italic; white-space: pre-wrap;
}
.thinking summary { cursor: pointer; color: var(--violet); font-style: normal; font-weight: 600; }

.empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--txt-faint); padding: 30px; }
.empty .big { font-size: 46px; margin-bottom: 14px; opacity: .5; }

/* Композер */
.composer { flex: 0 0 auto; padding: 14px clamp(12px, 4vw, 40px) 18px; border-top: 1px solid var(--stroke); background: rgba(9,13,20,0.6); }
.composer-inner { max-width: 900px; margin: 0 auto; background: var(--panel); border: 1px solid var(--stroke-2); border-radius: 18px; padding: 12px 14px; transition: border-color .15s; }
.composer-inner:focus-within { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(109,140,255,0.15); }
.composer textarea {
  border: 0; background: transparent; padding: 4px 4px 8px; min-height: 26px; max-height: 200px; height: auto;
  resize: none; font-size: 15px; line-height: 1.5;
}
.composer textarea:focus { box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: 10px; }
.model-pick {
  height: 36px; padding: 0 12px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--stroke-2);
  color: var(--txt); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 7px; max-width: 60vw;
}
.model-pick .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.composer .spacer { flex: 1; }
.send-btn {
  width: 46px; height: 46px; border-radius: 13px; border: 0; background: var(--grad); color: #06121a;
  display: grid; place-items: center; box-shadow: 0 8px 22px rgba(75,227,208,0.3); transition: transform .1s, filter .15s;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:active { transform: scale(.94); }
.send-btn[disabled] { opacity: .5; cursor: not-allowed; }
.send-btn.stop { background: linear-gradient(135deg, #ff5c73, #ff2d55); box-shadow: 0 8px 22px rgba(255,45,85,0.3); }

/* Тосты */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast { background: var(--panel-solid); border: 1px solid var(--stroke-2); color: var(--txt); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: rise .3s ease; max-width: 90vw; }
.toast.err { border-color: rgba(255,92,115,0.5); }
.toast.ok { border-color: rgba(55,214,122,0.5); }

/* Модалка (выбор модели, меню) */
.sheet-bg { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); display: grid; place-items: center; animation: rise .2s ease; }
.sheet { width: min(440px, 92vw); max-height: 76vh; overflow: auto; background: var(--panel-solid); border: 1px solid var(--stroke-2); border-radius: 18px; box-shadow: var(--shadow); padding: 10px; }
.sheet h3 { margin: 8px 12px 12px; font-size: 15px; }
.sheet .opt { padding: 13px 14px; border-radius: 11px; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.sheet .opt:hover { background: rgba(120,150,200,0.1); }
.sheet .opt.cur { background: rgba(75,227,208,0.12); color: var(--accent); font-weight: 600; }
.sheet .opt .check { margin-left: auto; color: var(--accent); }
.menu { position: absolute; top: 54px; right: 16px; z-index: 92; width: 220px; background: var(--panel-solid); border: 1px solid var(--stroke-2); border-radius: 13px; box-shadow: var(--shadow); padding: 6px; }
.menu button { width: 100%; text-align: left; background: none; border: 0; color: var(--txt); padding: 11px 13px; border-radius: 9px; font-size: 14px; display: flex; gap: 10px; align-items: center; }
.menu button:hover { background: rgba(120,150,200,0.1); }
.menu .who { padding: 10px 13px; border-bottom: 1px solid var(--stroke); margin-bottom: 4px; }
.menu .who b { display: block; font-size: 14px; }
.menu .who span { font-size: 12px; color: var(--txt-dim); font-family: var(--mono); }

.skeleton { padding: 8px; }
.sk-line { height: 58px; border-radius: 13px; margin-bottom: 6px; background: linear-gradient(90deg, rgba(120,150,200,0.06), rgba(120,150,200,0.13), rgba(120,150,200,0.06)); background-size: 200% 100%; animation: sheen 1.3s infinite; }
@keyframes sheen { to { background-position: -200% 0; } }

/* ── Адаптив: планшет и телефон ─────────────────────────── */
@media (max-width: 900px) { :root { --sb-w: 300px; } }
@media (max-width: 720px) {
  .body { position: relative; }
  .sidebar { position: absolute; inset: 0; width: 100%; flex: none; z-index: 5; transition: transform .28s cubic-bezier(.2,.8,.2,1); }
  .main { position: absolute; inset: 0; z-index: 6; transition: transform .28s cubic-bezier(.2,.8,.2,1); transform: translateX(100%); }
  .app.show-chat .main { transform: translateX(0); }
  .app.show-chat .sidebar { transform: translateX(-24%); }
  .back-btn { display: block; }
  .topbar-title small { display: none; }
  .conn .label { display: none; }
  .bubble { max-width: 88%; }
  .model-pick .lbl { max-width: 130px; }
}
@media (max-width: 400px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .user-chip .uname { display: none; }
}
