/* ModelHub — минимализм, плоский дизайн.
   Токены темы задаются в :root / [data-theme]; система переключает data-theme.
   Адаптив: сетка сжимается на узких экранах (мобильные). */

:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222c;
  --border: #2a2f3a;
  --fg: #e6e8ee;
  --muted: #8b93a7;
  --accent: #4c8dff;
  --accent-fg: #ffffff;
  --danger: #ff5c5c;
  --warn: #ffb454;
  --ok: #4ade80;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter",
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --border: #d9dde5;
  --fg: #1a1d24;
  --muted: #5b6472;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1280px; margin: 0 auto; padding: 0 20px 60px; }

/* --- Шапка --- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 0; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand[role="button"] { cursor: pointer; user-select: none; border-radius: 6px; padding: 2px 4px; }
.brand[role="button"]:hover { background: var(--surface-2); }
.brand-logo { color: var(--accent); font-size: 20px; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav-btn {
  background: none; border: none; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-size: 14px; white-space: nowrap;
}
.nav-btn:hover { background: var(--surface-2); color: var(--fg); }
.nav-btn[data-active="true"] { background: var(--surface-2); color: var(--fg); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.user-chip .link-btn { color: var(--muted); background: none; border: none; cursor: pointer; font-size: 13px; }
.user-chip .link-btn:hover { color: var(--danger); }

.icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--fg);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 16px;
}

/* --- Карточки и формы --- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  margin-top: 16px;
}
h1 { font-size: 22px; margin: 18px 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 13px; }

.form { display: flex; flex-direction: column; gap: 14px; max-width: 360px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--fg);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; font-family: var(--font);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--fg);
  border-radius: 8px; padding: 9px 16px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.btn:hover { filter: brightness(1.08); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-ghost { background: none; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.error { color: var(--danger); font-size: 13px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.tabs { display: flex; gap: 6px; margin: 12px 0; }
.tab {
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
}
.tab[data-active="true"] { background: var(--surface-2); color: var(--fg); }

/* --- Фильтры --- */
.layout-filters { display: grid; grid-template-columns: 300px 1fr; gap: 20px; margin-top: 16px; align-items: start; }
.filters { position: sticky; top: 70px; }
.field { margin-bottom: 14px; }
.label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  border-radius: 20px; padding: 5px 12px; cursor: pointer; font-size: 13px;
}
.chip[data-on="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

/* --- Результаты --- */
.results { display: flex; flex-direction: column; gap: 12px; }

/* --- Фреймы с источниками (infinite scroll) --- */
.frames { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.frame {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.frame-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.frame-head h2 { margin: 0; font-size: 15px; }
.frame-count { font-size: 12px; color: var(--muted); }
.frame-scroll {
  overflow-y: auto; max-height: calc(100vh - 260px); min-height: 240px;
  padding: 8px;
}
.frame .model-row { border: none; border-bottom: 1px solid var(--border); border-radius: 0; margin: 0; }
.frame .model-row:last-child { border-bottom: none; }
.scroll-loader { text-align: center; padding: 12px; color: var(--muted); font-size: 12px; }

.empty { color: var(--muted); text-align: center; padding: 32px 16px; }
.model-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  transition: border-color .12s;
}
.model-row:hover { border-color: var(--accent); }
.model-title { font-weight: 600; }
.model-desc { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.model-meta { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.badge { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 11px; }

/* --- Описание модели (markdown) — контент не вылезает за карточку --- */
.desc { overflow-wrap: anywhere; word-break: break-word; line-height: 1.6; }
.desc pre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; max-width: 100%; white-space: pre;
}
.desc code {
  font-family: var(--mono); font-size: 12.5px; background: var(--surface-2);
  border-radius: 4px; padding: 1px 5px; overflow-wrap: anywhere; word-break: break-word;
}
.desc pre code { background: none; padding: 0; white-space: pre; }
.desc img { max-width: 100%; height: auto; }
.desc a { color: var(--accent); overflow-wrap: anywhere; word-break: break-all; }
.desc .table-wrap { overflow-x: auto; max-width: 100%; margin: 12px 0; }
.desc table { border-collapse: collapse; width: 100%; }
.desc th, .desc td { border: 1px solid var(--border); padding: 6px 10px; font-size: 12.5px; text-align: left; white-space: nowrap; }
.desc th { background: var(--surface-2); font-weight: 600; }
.desc blockquote {
  margin: 12px 0; padding: 8px 14px; border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--muted);
}
.desc h1, .desc h2, .desc h3, .desc h4 { margin: 18px 0 8px; line-height: 1.3; }
.desc h1 { font-size: 20px; } .desc h2 { font-size: 17px; }
.desc h3 { font-size: 15px; } .desc h4 { font-size: 14px; }
.desc ul, .desc ol { padding-left: 22px; margin: 8px 0; }
.desc li { overflow-wrap: anywhere; margin: 3px 0; }
.desc hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.desc details { margin: 8px 0; }

/* --- Прогресс-гистограмма --- */
.progress {
  height: 14px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 7px; overflow: hidden; position: relative;
}
.progress-fill {
  height: 100%; background: var(--accent); border-radius: 6px;
  transition: width .3s, background-color .3s; width: 0;
}
/* смена цвета по мере заполнения: 0-50% акцент, 50-85% жёлтый, 85-100% зелёный */
.progress-fill[data-stage="2"] { background: var(--warn); }
.progress-fill[data-stage="3"] { background: var(--ok); }
.progress-pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--fg);
  pointer-events: none;
}

.dl-item { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.dl-item:last-child { border-bottom: none; }
.dl-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.dl-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; word-break: break-word; }
.dl-stats { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dl-done { color: var(--ok); }
.dl-error { color: var(--danger); font-weight: 600; }
.dl-cancelled { color: var(--warn); font-weight: 600; }
.dl-paused { color: var(--warn); font-weight: 600; }
.dl-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* --- Библиотека (аккордеон по моделям) --- */
.lib-group { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
.lib-group-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; cursor: pointer; background: var(--surface); user-select: none;
}
.lib-group-head:hover { background: var(--surface-2); }
.lib-group-head.open { background: var(--surface-2); }
.lib-caret { font-size: 12px; color: var(--muted); min-width: 12px; }
.lib-name { font-weight: 600; overflow-wrap: anywhere; word-break: break-word; flex: 1 1 auto; min-width: 120px; }
.lib-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.lib-group-head .btn { flex-shrink: 0; }
.lib-group-body { padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.lib-path { font-size: 12px; color: var(--muted); margin-bottom: 8px; word-break: break-all; font-family: var(--mono); }
.lib-files { display: flex; flex-direction: column; gap: 6px; }
.lib-file { padding: 6px 8px; background: var(--surface-2); border-radius: 6px; }
.lib-file-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.lib-file-name { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.lib-file-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.lib-file-path { font-size: 11px; color: var(--muted); font-family: var(--mono); word-break: break-all; margin-top: 2px; }

/* --- Таблицы --- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.status-ok { background: var(--ok); }
.status-degraded { background: var(--warn); }
.status-critical { background: var(--danger); }
.status-unknown { background: var(--muted); }

/* --- Логи --- */
.log-view {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-family: var(--mono); font-size: 12px; overflow-x: auto;
  max-height: 420px; overflow-y: auto; white-space: pre-wrap;
}
.log-controls { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.log-controls select { width: auto; }

/* --- Тосты --- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 12px 16px; box-shadow: var(--shadow); font-size: 14px;
  max-width: 340px; animation: slidein .2s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- Модальный диалог сохранения («Сохранить как…») --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 300; padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.45); width: 440px; max-width: 100%;
  display: flex; flex-direction: column; animation: modalpop .15s ease;
}
@keyframes modalpop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--border);
}
.modal-foot .btn { min-width: 96px; }

/* --- Invite-токен --- */
.token-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px;
}
.token-value {
  font-family: var(--mono); font-size: 13px; word-break: break-all;
  flex: 1; user-select: all;
}
.btn-sm { padding: 5px 10px; font-size: 12.5px; min-width: 0; }
.mono { font-family: var(--mono); font-size: 12px; }

/* --- Форма входа (auth) --- */
#view-login { max-width: none; padding: 0; }
.auth-shell {
  min-height: calc(100vh - 70px);
  display: grid; grid-template-columns: 1fr 1fr;
  margin: 0 -20px; /* растянуть на всю ширину контейнера */
}
/* брендовая панель */
.auth-hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  padding: 48px;
  background:
    radial-gradient(1200px 600px at -10% -20%, rgba(76,141,255,.28), transparent 60%),
    radial-gradient(900px 500px at 110% 120%, rgba(74,222,128,.18), transparent 55%),
    linear-gradient(160deg, var(--surface), var(--surface-2));
  border-right: 1px solid var(--border);
}
.auth-hero-inner { max-width: 420px; }
.auth-brand { font-size: 20px; margin-bottom: 32px; }
.auth-hero-title {
  font-size: 34px; line-height: 1.15; margin: 0 0 16px; font-weight: 750; letter-spacing: -.02em;
}
.auth-hero-sub { color: var(--muted); font-size: 15px; line-height: 1.6; margin: 0 0 28px; }
.auth-hero-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.auth-hero-points li { display: flex; align-items: center; gap: 10px; color: var(--fg); font-size: 14px; }
.auth-hero-points .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7cb3ff); flex: none;
}
/* панель формы */
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 32px; }
.auth-panel-inner { width: 100%; max-width: 380px; }
.auth-title { font-size: 24px; margin: 0 0 6px; font-weight: 700; letter-spacing: -.01em; }
.auth-panel-inner .muted { margin: 0 0 20px; }
.tabs-auth { margin: 0 0 22px; }
.tabs-auth .tab { flex: 1; text-align: center; }
.auth-form { max-width: none; gap: 16px; }
.field-input { display: flex; flex-direction: column; gap: 6px; }
.input-wrap {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 0 12px; transition: border-color .15s, box-shadow .15s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.input-icon { font-size: 15px; line-height: 1; opacity: .75; flex: none; }
.input-wrap input {
  border: none; background: none; padding: 12px 0; box-shadow: none;
  font-size: 15px; outline: none;
}
.btn-block { width: 100%; padding: 13px; font-size: 15px; font-weight: 600; }
.btn-primary { transition: background .15s, transform .05s; }
.btn-primary:active { transform: translateY(1px); }

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; margin: 0 -12px; }
  .auth-hero { display: none; }
  .auth-panel { padding: 32px 20px; min-height: calc(100vh - 70px); }
}

/* --- Файловый менеджер (двухпанельный) --- */
.filemgr { display: grid; grid-template-columns: 1fr 52px 1fr; gap: 12px; align-items: start; }
.fpanel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; display: flex; flex-direction: column; }
.fpanel-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.fpanel-path { flex: 1; font-family: var(--mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fpanel-body { height: 420px; overflow-y: auto; padding: 6px; }
.fentry { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.fentry:hover { background: var(--surface-2); }
.fentry.selected { background: var(--accent); color: var(--accent-fg); }
.fentry.selected .fsize { color: var(--accent-fg); }
.fentry-up { color: var(--muted); }
.fico { flex-shrink: 0; }
.fname { flex: 1; overflow-wrap: anywhere; word-break: break-word; }
.fsize { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.filemgr-mid { display: flex; flex-direction: column; gap: 8px; justify-content: center; padding-top: 44px; }
.filemgr-mid .btn { width: 100%; }

/* --- Адаптив --- */
@media (max-width: 860px) {
  .layout-filters { grid-template-columns: 1fr; }
  .filters { position: static; }
  .frames { grid-template-columns: 1fr; }
  .frame-scroll { max-height: 420px; }
  .app { padding: 0 12px 40px; }

  /* меню сервиса — отдельной строкой на всю ширину, удобно нажимать */
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .nav-btn { padding: 10px 14px; min-height: 40px; font-size: 14px; }

  /* файловый менеджер — панели друг под другом */
  .filemgr { grid-template-columns: 1fr; }
  .filemgr-mid { flex-direction: row; padding-top: 0; justify-content: center; }
  .filemgr-mid .btn { width: auto; }
  .fpanel-body { height: 260px; }
}
@media (max-width: 480px) {
  .brand-name { display: none; }
  .row-between { flex-direction: column; align-items: flex-start; }
}
