/* ============================================================
   SDA Manager — единая тёмная тема
   Подключайте этот файл во все шаблоны Flask:
   <link rel="stylesheet" href="{{ url_for('static', filename='css/theme.css') }}">
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap');

:root {
  /* — Поверхности — */
  --bg:            #0a0c10;
  --bg-grad-top:   #0c0f15;
  --surface:       #12151c;
  --surface-2:     #161a23;
  --surface-3:     #1b2029;
  --surface-hover: #1e2430;
  --inset:         #0d1015;

  /* — Границы — */
  --border:        #232936;
  --border-soft:   #1a1f2a;
  --border-strong: #2d3543;

  /* — Текст — */
  --text:          #e7ebf2;
  --text-2:        #9aa4b2;
  --text-3:        #5f6b7c;
  --text-on-accent:#ffffff;

  /* — Акцент (Steam blue) — */
  --accent:        #3b82f6;
  --accent-hover:  #4f8cff;
  --accent-press:  #2f6fe0;
  --accent-soft:   rgba(59,130,246,0.12);
  --accent-ring:   rgba(59,130,246,0.35);

  /* — Статусные цвета — */
  --ok:        #34d399;   /* успех / готово / работает */
  --ok-soft:   rgba(52,211,153,0.12);
  --warn:      #fbbf24;   /* в работе */
  --warn-soft: rgba(251,191,36,0.12);
  --err:       #f87171;   /* ошибка */
  --err-soft:  rgba(248,113,113,0.12);
  --idle:      #8b95a3;   /* ожидает / простой */
  --idle-soft: rgba(139,149,163,0.12);
  --info:      #60a5fa;
  --info-soft: rgba(96,165,250,0.12);

  /* — Радиусы — */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* — Тени — */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 24px -8px rgba(0,0,0,0.6);
  --shadow-lg: 0 24px 60px -20px rgba(0,0,0,0.7);
  --shadow-pop: 0 16px 40px -12px rgba(0,0,0,0.65);

  /* — Типографика — */
  --font: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --header-h: 60px;
}

/* ============================================================
   Базовые сбросы
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 78% -8%, rgba(59,130,246,0.06), transparent 60%),
    radial-gradient(900px 500px at 5% 0%, rgba(99,102,241,0.05), transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,h2,h3,h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 2px; }

::selection { background: var(--accent-soft); color: #fff; }

/* Скроллбары */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #3a4354; background-clip: padding-box; }

/* ============================================================
   Утилиты
   ============================================================ */
.mono { font-family: var(--mono); font-feature-settings: 'zero' 1; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.t-ok { color: var(--ok); }
.t-warn { color: var(--warn); }
.t-err { color: var(--err); }
.t-idle { color: var(--idle); }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-20 { gap: 20px; }
.grow { flex: 1; }
.hide { display: none !important; }

.kbd {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
}

/* ============================================================
   Бренд / логотип
   ============================================================ */
.brand { display: inline-flex; align-items: center; gap: 11px; user-select: none; }
.brand__mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(155deg, #2563eb, #1e40af);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25), 0 4px 12px -3px rgba(37,99,235,0.55);
  flex: none;
}
.brand__mark svg { width: 18px; height: 18px; display: block; }
.brand__name { font-weight: 600; font-size: 15.5px; letter-spacing: -0.02em; color: var(--text); }
.brand__name b { font-weight: 600; color: #fff; }
.brand__name span { color: var(--accent-hover); }
.brand__sub { font-size: 11px; color: var(--text-3); font-family: var(--mono); letter-spacing: 0.02em; }

/* ============================================================
   Кнопки
   ============================================================ */
.btn {
  --bh: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--bh);
  padding: 0 15px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px; font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s ease, border-color .14s ease, transform .08s ease, box-shadow .14s ease, color .14s ease;
}
.btn:hover { background: var(--surface-hover); border-color: #38414f; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.btn--primary {
  background: var(--accent); border-color: transparent; color: var(--text-on-accent);
  box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset, 0 6px 16px -8px var(--accent-ring);
}
.btn--primary:hover { background: var(--accent-hover); border-color: transparent; }
.btn--primary:active { background: var(--accent-press); }

.btn--ok    { background: var(--ok-soft);   border-color: rgba(52,211,153,0.3);  color: var(--ok); }
.btn--ok:hover { background: rgba(52,211,153,0.18); }
.btn--danger{ background: var(--err-soft);  border-color: rgba(248,113,113,0.3); color: var(--err); }
.btn--danger:hover { background: rgba(248,113,113,0.18); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.btn--lg { --bh: 46px; padding: 0 22px; font-size: 15px; border-radius: var(--r-md); }
.btn--sm { --bh: 30px; padding: 0 10px; font-size: 12.5px; gap: 6px; border-radius: var(--r-xs); }
.btn--icon { --bh: 32px; width: 32px; padding: 0; }
.btn--block { width: 100%; }

/* ============================================================
   Поля ввода
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 7px; }
.label { font-size: 12.5px; font-weight: 500; color: var(--text-2); letter-spacing: -0.005em; }
.hint  { font-size: 12px; color: var(--text-3); }

.input, .textarea, .select {
  width: 100%;
  font-family: inherit; font-size: 13.5px; color: var(--text);
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #0f131a;
}
.input--mono { font-family: var(--mono); letter-spacing: 0.01em; }
.textarea { resize: vertical; min-height: 96px; line-height: 1.55; }
.textarea--mono { font-family: var(--mono); font-size: 12.5px; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239aa4b2' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  padding-right: 34px; cursor: pointer;
}

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 40px; }
.input-group__btn {
  position: absolute; right: 5px;
  display: grid; place-items: center; width: 30px; height: 30px;
  border: none; background: transparent; color: var(--text-3); cursor: pointer; border-radius: 6px;
}
.input-group__btn:hover { color: var(--text); background: var(--surface-2); }
.input-group__btn svg { width: 16px; height: 16px; }

/* Переключатель */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; gap: 10px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 38px; height: 22px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  transition: background .16s ease, border-color .16s ease; flex: none; position: relative;
}
.switch__track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 999px; background: #cdd4de;
  transition: transform .16s cubic-bezier(.4,.1,.2,1), background .16s ease;
}
.switch input:checked + .switch__track { background: var(--accent); border-color: transparent; }
.switch input:checked + .switch__track::after { transform: translateX(16px); background: #fff; }
.switch__label { font-size: 13px; color: var(--text); }

/* ============================================================
   Карточки / панели
   ============================================================ */
.card {
  background: linear-gradient(180deg, var(--surface), var(--surface) 40%, #11141b);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.card__title { font-size: 13.5px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 9px; }
.card__title .dot-ic { width: 16px; height: 16px; color: var(--text-2); }
.card__body { padding: 18px; }

/* ============================================================
   Бейджи статусов
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 23px; padding: 0 9px 0 8px;
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500; letter-spacing: -0.005em;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 999px; background: currentColor; flex: none; }
.badge--ok   { color: var(--ok);   background: var(--ok-soft);   border-color: rgba(52,211,153,0.22); }
.badge--warn { color: var(--warn); background: var(--warn-soft); border-color: rgba(251,191,36,0.22); }
.badge--err  { color: var(--err);  background: var(--err-soft);  border-color: rgba(248,113,113,0.22); }
.badge--idle { color: var(--idle); background: var(--idle-soft); border-color: rgba(139,149,163,0.22); }
.badge--info { color: var(--info); background: var(--info-soft); border-color: rgba(96,165,250,0.22); }
.badge--ghost{ color: var(--text-2); background: var(--surface-3); border-color: var(--border); }
.badge--ghost::before { display: none; }

/* Пульсирующий бейдж работы */
.badge--warn.is-live::before { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* Индикатор статуса воркера */
.worker-status {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px 0 11px;
  border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--border);
}
.worker-status__led { width: 8px; height: 8px; border-radius: 999px; background: var(--idle); flex: none; }
.worker-status.is-running { color: var(--ok); border-color: rgba(52,211,153,0.25); background: var(--ok-soft); }
.worker-status.is-running .worker-status__led { background: var(--ok); box-shadow: 0 0 0 0 rgba(52,211,153,0.5); animation: ring 1.6s ease-out infinite; }
.worker-status.is-idle { color: var(--text-2); }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,0.5);} 70%{ box-shadow: 0 0 0 6px rgba(52,211,153,0);} 100%{ box-shadow: 0 0 0 0 rgba(52,211,153,0);} }

/* ============================================================
   Шапка приложения
   ============================================================ */
.appbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; gap: 22px;
  padding: 0 22px;
  background: rgba(10,12,16,0.78);
  backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border-soft);
}
.appbar__nav { display: flex; align-items: center; gap: 3px; }
.navlink {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 13px;
  border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 500; color: var(--text-2);
  transition: background .14s ease, color .14s ease;
}
.navlink svg { width: 16px; height: 16px; }
.navlink:hover { color: var(--text); background: var(--surface-2); }
.navlink.is-active { color: var(--text); background: var(--surface-3); }
.navlink__badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 600; font-family: var(--mono);
  border-radius: 999px; background: var(--accent); color: #fff;
}

/* ============================================================
   Контейнеры контента
   ============================================================ */
.page { max-width: 1320px; margin: 0 auto; padding: 26px 22px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; }
.page-sub { font-size: 13px; color: var(--text-2); margin-top: 3px; }

/* ============================================================
   Метрики
   ============================================================ */
.metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 13px; margin-bottom: 20px; }
.metric {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 15px 16px 14px;
  transition: border-color .16s ease, transform .12s ease;
}
.metric:hover { border-color: var(--border-strong); }
.metric__top { display: flex; align-items: center; justify-content: space-between; }
.metric__ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.metric__ic svg { width: 16px; height: 16px; }
.metric__label { font-size: 12px; color: var(--text-2); font-weight: 500; margin-top: 12px; }
.metric__value { font-size: 27px; font-weight: 600; letter-spacing: -0.02em; font-family: var(--mono); margin-top: 2px; line-height: 1; }
.metric__delta { font-size: 11.5px; margin-top: 7px; color: var(--text-3); }
.metric__bar { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; opacity: .6; }

.metric.is-total .metric__ic { background: var(--accent-soft); color: var(--accent-hover); }
.metric.is-total .metric__bar { background: var(--accent); }
.metric.is-idle  .metric__ic { background: var(--idle-soft); color: var(--idle); }
.metric.is-idle  .metric__bar { background: var(--idle); }
.metric.is-work  .metric__ic { background: var(--warn-soft); color: var(--warn); }
.metric.is-work  .metric__bar { background: var(--warn); }
.metric.is-done  .metric__ic { background: var(--ok-soft); color: var(--ok); }
.metric.is-done  .metric__bar { background: var(--ok); }
.metric.is-err   .metric__ic { background: var(--err-soft); color: var(--err); }
.metric.is-err   .metric__bar { background: var(--err); }

/* ============================================================
   Таблица
   ============================================================ */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  text-align: left; font-weight: 500; font-size: 11.5px; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--text-3); padding: 10px 14px; white-space: nowrap;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; white-space: nowrap; }
.table tbody tr { transition: background .1s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { font-family: var(--mono); color: var(--text-2); }
.cell-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: var(--r-xs); border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-2); cursor: pointer; transition: all .12s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-hover); }
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn.is-accent { color: var(--accent-hover); border-color: rgba(59,130,246,0.3); background: var(--accent-soft); }
.icon-btn.is-accent:hover { background: rgba(59,130,246,0.2); }

/* Тулбар таблицы */
.toolbar { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); }
.search .input { padding-left: 34px; height: 36px; }
.seg { display: inline-flex; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button {
  height: 28px; padding: 0 11px; border: none; background: transparent; color: var(--text-2);
  font-size: 12.5px; font-weight: 500; font-family: inherit; border-radius: 5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: all .12s ease; white-space: nowrap;
}
.seg button .cnt { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.seg button:hover { color: var(--text); }
.seg button.is-active { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-sm); }
.seg button.is-active .cnt { color: var(--text-2); }

/* ============================================================
   Лог-консоль
   ============================================================ */
.console {
  font-family: var(--mono); font-size: 12px; line-height: 1.7;
  background: var(--inset); border-radius: var(--r-sm);
  padding: 12px 14px; height: 230px; overflow-y: auto;
  border: 1px solid var(--border-soft);
}
.log-line { display: flex; gap: 10px; padding: 1px 0; }
.log-line__t { color: var(--text-3); flex: none; }
.log-line__tag { flex: none; width: 54px; font-weight: 500; }
.log-line__msg { color: var(--text-2); word-break: break-word; }
.log-line.is-ok   .log-line__tag { color: var(--ok); }
.log-line.is-warn .log-line__tag { color: var(--warn); }
.log-line.is-err  .log-line__tag { color: var(--err); }
.log-line.is-info .log-line__tag { color: var(--info); }
.log-line.is-err  .log-line__msg { color: #f3b4b4; }

/* ============================================================
   Авторизация / центрированные страницы
   ============================================================ */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 384px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 32px;
}

/* ============================================================
   Адаптив
   ============================================================ */
@media (max-width: 1080px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric.is-total { grid-column: span 2; }
}
@media (max-width: 820px) {
  .appbar__nav { display: none; }
  .page { padding: 18px 14px 48px; }
}
@media (max-width: 560px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric.is-total { grid-column: span 2; }
  .auth-card { padding: 24px; }
}

/* Меню-бургер для мобильной навигации */
.menu-toggle { display: none; }
@media (max-width: 820px) {
  .menu-toggle { display: inline-grid; }
}

/* Скрытая мобильная навигация (выпадающая) */
.mobile-nav {
  display: none; position: fixed; inset: var(--header-h) 0 auto 0; z-index: 29;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px; flex-direction: column; gap: 2px;
}
.mobile-nav.is-open { display: flex; }
.mobile-nav .navlink { height: 42px; }
