/* Server Control — неоновая тёмная тема, мобильная вёрстка Mini App.
   Палитра подобрана под аватарку бота: синий и оранжевый на глубоком тёмном фоне.

   ВАЖНО про производительность. В прошлой версии темы использовались
   backdrop-filter на панелях и три размытых круга (filter: blur(70px)) на фоне.
   В WebView Telegram это пересчитывается на каждый кадр и роняет скролл и
   терминал в неиграбельные лаги. Здесь ни одного backdrop-filter и ни одного
   blur: объём и «свечение» набраны градиентами и box-shadow, которые
   композитор рисует один раз. */

:root {
  /* --- Поверхности (непрозрачные: прозрачность = лишний слой смешивания) --- */
  --bg:         #05070f;
  --bg-elev:    #121829;
  --bg-elev-2:  #1a2138;
  --bg-input:   #0a0e1a;
  --bg-solid:   #0b0f1c;

  --border:      #24304e;
  --border-soft: #1a2237;

  --text:      #c7d3ec;
  --text-dim:  #7385a6;
  --text-hi:   #ffffff;

  /* --- Неон --- */
  --neon:       #22e0ff;
  --neon-2:     #a86bff;
  --neon-3:     #ff8a1f;
  --accent:     #22e0ff;
  --accent-hi:  #6febff;
  --focus:      #22e0ff;

  --green:  #3ce6a0;
  --red:    #ff5c72;
  --yellow: #ffc53d;
  --blue:   #56b6ff;
  --purple: #c88bff;

  --glow-soft: 0 0 10px rgba(34, 224, 255, .3);
  --glow-neon: 0 0 14px rgba(34, 224, 255, .5);

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas,
          "Roboto Mono", "DejaVu Sans Mono", monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --topbar-h: 52px;
  --nav-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  color: var(--text);
  font-family: var(--ui); font-size: 15px; line-height: 1.45;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* Неоновое «зарево» — статичные градиенты прямо в фоне body.
   Рисуется один раз, в отличие от размытых слоёв поверх контента. */
body {
  display: flex; flex-direction: column; overflow: hidden;
  background:
    radial-gradient(120% 80% at 8% -10%,  rgba(26, 107, 255, .30) 0%, transparent 55%),
    radial-gradient(100% 70% at 105% 38%, rgba(143, 59, 255, .22) 0%, transparent 58%),
    radial-gradient(90%  60% at 20% 108%, rgba(255, 122, 24, .14) 0%, transparent 55%),
    var(--bg);
}

.hidden { display: none !important; }
/* На экране списка серверов нижней панели нет — обнуляем её высоту,
   чтобы кнопка «+» и тосты не висели над пустотой. */
body.no-nav { --nav-h: 0px; }
.mono { font-family: var(--mono); font-size: 13px; }
.grow { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Слой .glow-bg остался в разметке — держим его пустым и невидимым,
   чтобы не плодить лишних композиторских слоёв. */
.glow-bg { display: none; }

/* ---------------- Верхняя панель ---------------- */
#topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 10px 0;
  display: flex; align-items: center; gap: 9px;
  background: linear-gradient(180deg, #172037, #0e1425);
  border-bottom: 1px solid var(--border-soft);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset;
}

.brand-logo {
  width: 32px; height: 32px; flex: 0 0 auto; border-radius: 10px;
  padding: 1.5px; background: linear-gradient(135deg, var(--neon), var(--neon-2) 55%, var(--neon-3));
  box-shadow: var(--glow-soft);
}
.brand-logo img { width: 100%; height: 100%; border-radius: 8.5px; display: block; object-fit: cover; }

#title-wrap { flex: 1; min-width: 0; }
#title {
  font-size: 15.5px; font-weight: 700; letter-spacing: .2px; color: var(--text-hi);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#subtitle { font-family: var(--mono); font-size: 11px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  background: #1a2138; border: 1px solid var(--border-soft); color: var(--text);
  font-size: 20px; line-height: 1; padding: 6px 10px; border-radius: 10px;
  cursor: pointer; min-width: 36px;
}
.icon-btn:active { background: #24304e; color: var(--neon); }

/* ---------------- Основная область ---------------- */
#main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; }

#view-servers, #view-files { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---------------- Баннеры ---------------- */
.banner {
  padding: 9px 13px; font-size: 12.5px; font-family: var(--mono);
  border-bottom: 1px solid var(--border-soft);
}
.banner.info  { background: #10203a; color: var(--blue); }
.banner.warn  { background: #2b2413; color: var(--yellow); }
.banner.error { background: #2e1620; color: var(--red); }
.banner.ok    { background: #0f2b23; color: var(--green); }

/* ---------------- Список / карточки ---------------- */
.list { padding: 12px; display: flex; flex-direction: column; gap: 11px; }

.card {
  position: relative;
  background: linear-gradient(160deg, #1d2540, #10162a);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: flex; align-items: center; gap: 13px; cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 6px 16px rgba(0, 0, 0, .45);
}
.card::before {
  content: ""; position: absolute; left: 0; top: 14%; bottom: 14%; width: 2px;
  border-radius: 2px; background: linear-gradient(180deg, var(--neon), var(--neon-2));
}
.card:active { background: linear-gradient(160deg, #242e4f, #141b33); border-color: #2f6f8f; }

.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 650; color: var(--text-hi); font-size: 15.5px; letter-spacing: .2px; }
.card-sub { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; background: var(--text-dim); }
.status-dot.online  { background: var(--green);  box-shadow: 0 0 9px rgba(60, 230, 160, .85); }
.status-dot.offline { background: var(--red);    box-shadow: 0 0 9px rgba(255, 92, 114, .7); }
.status-dot.pending { background: var(--yellow); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.card-edit {
  background: #1a2138; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 10px; padding: 7px 10px; font-size: 13px; cursor: pointer;
}
.card-edit:active { background: #24304e; color: var(--text-hi); }

.empty { padding: 64px 24px; text-align: center; color: var(--text-dim); }
.empty-icon { font-size: 46px; color: var(--neon); opacity: .8; }
.empty-title { margin-top: 12px; font-size: 16.5px; color: var(--text); font-weight: 600; }
.empty-text { font-size: 13px; margin-top: 5px; }

/* ---------------- FAB ---------------- */
.fab {
  position: fixed; right: 18px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 18px);
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(145deg, #2ee7ff, #1a7bff 55%, #8f3bff);
  color: #04121a; border: none; font-size: 30px; line-height: 1;
  cursor: pointer; z-index: 30;
  box-shadow: 0 0 16px rgba(34, 224, 255, .5), 0 8px 20px rgba(0, 0, 0, .55),
              0 2px 0 rgba(255, 255, 255, .3) inset;
}
.fab:active { transform: translateY(2px); box-shadow: 0 0 10px rgba(34, 224, 255, .4), 0 3px 10px rgba(0, 0, 0, .5); }

/* ---------------- Кнопки и поля ---------------- */
.btn {
  background: linear-gradient(180deg, #2a3557, #171e33);
  color: var(--text);
  border: 1px solid var(--border); border-radius: 11px;
  padding: 10px 15px; font-size: 14px; font-family: var(--ui); font-weight: 550;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .08) inset, 0 4px 12px rgba(0, 0, 0, .4);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset; }
.btn.primary {
  background: linear-gradient(145deg, #2ee7ff, #1a7bff 60%, #7a3bff);
  border-color: #63d9f5; color: #04121a; font-weight: 700;
  box-shadow: 0 0 14px rgba(34, 224, 255, .4), 0 6px 16px rgba(0, 0, 0, .45),
              0 1px 0 rgba(255, 255, 255, .35) inset;
}
.btn.danger {
  color: #ffb3bd; border-color: #5e2a37;
  background: linear-gradient(180deg, #46202c, #2a1119);
}
.btn.small { padding: 7px 11px; font-size: 12.5px; border-radius: 9px; }
.btn:disabled { opacity: .4; cursor: default; box-shadow: none; transform: none; }

.input {
  width: 100%; background: var(--bg-input); color: var(--text-hi);
  border: 1px solid var(--border); border-radius: 11px;
  padding: 11px 12px; font-size: 15px; font-family: var(--ui);
  outline: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4) inset;
}
.input::placeholder { color: #55648a; }
.input:focus { border-color: var(--neon); box-shadow: 0 2px 6px rgba(0, 0, 0, .4) inset, var(--glow-soft); }
textarea.input { resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field > span {
  font-size: 11px; color: var(--neon); text-transform: uppercase;
  letter-spacing: .09em; font-weight: 600;
}
.field.port, .port-field { width: 110px; flex: 0 0 auto; }
.row { display: flex; gap: 10px; align-items: flex-start; }
.hint { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; line-height: 1.5; }

/* Спойлер «Дополнительно» в форме сервера. */
.advanced {
  margin: 2px 0 16px; border: 1px solid var(--border-soft); border-radius: 12px;
  background: #0d1424; overflow: hidden;
}
.advanced > summary {
  list-style: none; cursor: pointer; padding: 11px 14px;
  font-size: 13px; font-weight: 600; color: var(--text-dim);
  display: flex; align-items: center; gap: 8px;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::before { content: "▸"; color: var(--neon); font-size: 12px; display: inline-block; }
.advanced[open] > summary { color: var(--text); border-bottom: 1px solid var(--border-soft); }
.advanced[open] > summary::before { content: "▾"; }
.advanced-body { padding: 14px 14px 1px; }

.segmented {
  display: flex; border: 1px solid var(--border); border-radius: 11px; overflow: hidden;
  background: var(--bg-input);
}
.seg {
  flex: 1; background: transparent; color: var(--text-dim);
  border: none; padding: 10px 6px; font-size: 13.5px; font-family: var(--ui); cursor: pointer;
}
.seg.active {
  background: linear-gradient(145deg, #2ee7ff, #1a7bff 65%, #7a3bff);
  color: #04121a; font-weight: 700;
}

/* ---------------- Нижняя навигация ---------------- */
#bottomnav {
  flex: 0 0 auto;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: linear-gradient(0deg, #080c18, #131a2e);
  border-top: 1px solid var(--border-soft);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset;
}
.nav-btn {
  position: relative;
  flex: 1; background: transparent; border: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10.5px; cursor: pointer; padding: 0;
}
.nav-ico { font-size: 18px; line-height: 1; }
.nav-btn.active { color: var(--neon); }
.nav-btn.active::before {
  content: ""; position: absolute; top: 0; left: 50%; margin-left: -15px;
  width: 30px; height: 2.5px; border-radius: 0 0 3px 3px;
  background: linear-gradient(90deg, var(--neon), var(--neon-2));
  box-shadow: var(--glow-neon);
}
.nav-btn:disabled { opacity: .28; }

/* ---------------- Терминал ----------------
   Здесь всё максимально дёшево: сплошной фон, никаких теней и градиентов
   поверх канвы xterm — иначе каждый вывод строки заставляет перерисовывать слой. */
#term-host { flex: 1; min-height: 0; background: #05070f; padding: 6px 2px 0 8px; }
#term-host .xterm { height: 100%; }

/* ---------------- Файлы ---------------- */
.pathbar {
  flex: 0 0 auto; padding: 9px 13px; font-family: var(--mono); font-size: 12px;
  color: var(--neon); background: #0c1222;
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto; white-space: nowrap; scrollbar-width: none;
}
.pathbar::-webkit-scrollbar { display: none; }

.toolbar {
  flex: 0 0 auto; display: flex; gap: 7px; padding: 8px;
  overflow-x: auto; scrollbar-width: none;
  background: #101728; border-bottom: 1px solid var(--border-soft);
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar .btn { flex: 0 0 auto; }

#fs-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 0; gap: 0; }

.fs-row {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 13px; border-bottom: 1px solid var(--border-soft); cursor: pointer;
}
.fs-row:active { background: #16203a; }
.fs-ico { width: 18px; text-align: center; font-size: 14px; flex: 0 0 auto; }
.fs-ico.dir  { color: var(--yellow); }
.fs-ico.file { color: var(--text-dim); }
.fs-name { flex: 1; min-width: 0; font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-meta { font-family: var(--mono); font-size: 11px; color: var(--text-dim); flex: 0 0 auto; }
.fs-actions { display: flex; gap: 5px; flex: 0 0 auto; }
/* Стрелка у каталогов — подсказка, что внутрь можно зайти. */
.fs-chevron { flex: 0 0 auto; color: var(--neon); font-size: 17px; line-height: 1; opacity: .75; margin-left: 2px; }
.fs-act {
  background: #1a2138; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 9px; padding: 6px 9px; font-size: 12px; cursor: pointer;
}
.fs-act:active { background: #24304e; color: var(--text-hi); }

/* ---------------- Claude ---------------- */
.cl-bar {
  flex: 0 0 auto; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: #101728; border-bottom: 1px solid var(--border-soft);
}
.cl-place { font-size: 12px; color: var(--text-dim); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cl-output {
  flex: 1; min-height: 0; overflow-y: auto; padding: 12px 13px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}
.cl-msg { margin-bottom: 13px; }
/* Свой вопрос — «пузырём» справа, ответ — обычным текстом слева. */
.cl-msg.user {
  color: #04121a; background: linear-gradient(145deg, #2ee7ff, #1a7bff);
  padding: 9px 12px; border-radius: 14px 14px 4px 14px;
  margin-left: 18%; font-family: var(--ui); font-size: 14px; font-weight: 550;
}
.cl-msg.out { color: var(--text); }
.cl-msg.err { color: var(--red); }
.cl-msg.sys { color: var(--text-dim); font-size: 11.5px; text-align: center; }

/* «Claude думает…» — три точки и счётчик секунд. */
.cl-thinking {
  display: flex; align-items: center; gap: 9px; margin-bottom: 13px;
  color: var(--neon); font-family: var(--ui); font-size: 13.5px;
}
.cl-dots { display: inline-flex; gap: 4px; }
.cl-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--neon);
  animation: blink 1.2s ease-in-out infinite;
}
.cl-dots i:nth-child(2) { animation-delay: .2s; }
.cl-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
.cl-elapsed { color: var(--text-dim); font-family: var(--mono); font-size: 12px; }

/* Лента шагов: что Claude делает прямо сейчас. */
.cl-step {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px;
  padding-left: 10px; border-left: 2px solid var(--border);
  font-family: var(--ui); font-size: 12.5px;
}
.cl-step-name { color: var(--neon-2); flex: 0 0 auto; }
.cl-step-detail {
  color: var(--text-dim); font-family: var(--mono); font-size: 11.5px;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.cl-input-row {
  flex: 0 0 auto; display: flex; gap: 7px; padding: 9px;
  background: #101728; border-top: 1px solid var(--border-soft); align-items: flex-end;
}
.cl-input-row textarea { flex: 1; max-height: 140px; }
.cl-input-row .btn { padding: 11px 16px; }

/* ---------------- Модальные листы ---------------- */
#modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(3, 5, 12, .78); }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 92vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #1a2238, #0b0f1c);
  border-top: 1px solid #2b6f8c;
  border-radius: 20px 20px 0 0; padding-bottom: var(--safe-bottom);
  box-shadow: 0 -1px 0 rgba(255, 255, 255, .07) inset, 0 -12px 32px rgba(0, 0, 0, .6);
}
.sheet::before {
  content: ""; position: absolute; top: 8px; left: 50%; margin-left: -19px;
  width: 38px; height: 4px; border-radius: 3px;
  background: linear-gradient(90deg, var(--neon), var(--neon-2));
}
.sheet.full { top: 0; max-height: none; border-radius: 0; padding-top: var(--safe-top); }
.sheet.full::before { display: none; }
.sheet-head {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 18px 10px 13px 17px; border-bottom: 1px solid var(--border-soft);
  font-weight: 700; font-size: 15.5px; color: var(--text-hi); min-width: 0;
}
.sheet-head > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 17px; }
.sheet-foot {
  flex: 0 0 auto; display: flex; gap: 9px; padding: 13px 17px;
  border-top: 1px solid var(--border-soft);
}

#editor-host { flex: 1; min-height: 0; }

/* ---------------- Тост и лоадер ---------------- */
.toast {
  position: fixed; left: 50%; margin-left: -44vw; width: 88vw;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 22px);
  background: #202a44; color: var(--text-hi); border: 1px solid var(--border);
  padding: 11px 17px; border-radius: 13px; font-size: 13.5px; z-index: 80;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .6), 0 1px 0 rgba(255, 255, 255, .07) inset;
}
.toast.err { border-color: #6b2f3c; color: #ffb3bd; }
.toast.ok  { border-color: #2c6b52; color: var(--green); }

.loader {
  position: fixed; inset: 0; background: rgba(5, 7, 15, .6); z-index: 90;
  display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #24304e;
  border-top-color: var(--neon); border-right-color: var(--neon-2);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Экраны поуже — чуть плотнее */
@media (max-width: 360px) {
  html, body { font-size: 14px; }
  .nav-btn { font-size: 9.5px; }
  .list { padding: 10px; gap: 9px; }
}

/* Уважаем системную настройку «меньше движения». */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
