/* ===================================================
   1С Дашборд — главная таблица стилей
   Тёмная тема, компактные тайлы, tooltip, мобайл
   =================================================== */

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2a2d3d;
  --text:     #c9cdd8;
  --text-dim: #6b7280;
  --accent:   #3b82f6;

  /* Severity цвета */
  --ok:       #14532d;
  --ok-fg:    #4ade80;
  --info:     #1e3a5f;
  --info-fg:  #60a5fa;
  --warn:     #451a03;
  --warn-fg:  #fb923c;
  --error:    #450a0a;
  --error-fg: #f87171;
  --crit:     #3b0764;
  --crit-fg:  #e879f9;
  --err-load: #1f2937;
  --err-load-fg: #6b7280;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.4;
}

/* ===================================================
   Верхняя панель
   =================================================== */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.topbar__updated {
  font-size: 11px;
  color: var(--text-dim);
  flex: 1;
}

.topbar__build {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  font-family: monospace;
}

.topbar__webhook-warn {
  font-size: 10px;
  color: #f59e0b;
  white-space: nowrap;
  cursor: pointer;
}

.backend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  display: inline-block;
  flex-shrink: 0;
  transition: background 0.3s;
}
.backend-dot.ok  { background: var(--ok-fg); }
.backend-dot.err { background: var(--error-fg); }

.topbar__btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.topbar__btn:hover { border-color: var(--accent); color: var(--accent); }

/* ===================================================
   Баннер offline / ошибки
   =================================================== */

.status-banner {
  display: none;
  padding: 4px 10px;
  font-size: 11px;
  text-align: center;
}
.status-banner.offline  { display: block; background: #7c2d12; color: #fca5a5; }
.status-banner.updating { display: block; background: #1e3a5f; color: #93c5fd; }

/* ===================================================
   Сетка тайлов
   =================================================== */

.tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 5px;
  padding: 8px;
}

/* ===================================================
   Один тайл
   =================================================== */

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.15s, border-color 0.15s;
  min-height: 60px;
  overflow: hidden;
  user-select: none;
}

.tile:hover { filter: brightness(1.15); border-color: rgba(255,255,255,0.15); }
.tile:active { filter: brightness(0.9); }

/* Severity цвета тайлов */
.tile--ok    { background: var(--ok);    color: var(--ok-fg); }
.tile--info  { background: var(--info);  color: var(--info-fg); }
.tile--warn  { background: var(--warn);  color: var(--warn-fg); }
.tile--error { background: var(--error); color: var(--error-fg); }
.tile--crit  { background: var(--crit);  color: var(--crit-fg); }
.tile--load  { background: var(--err-load); color: var(--err-load-fg); }

/* Имя метрики */
.tile__name {
  font-size: 10px;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Счётчик / значение */
.tile__value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Подпись под счётчиком */
.tile__sub {
  font-size: 10px;
  opacity: 0.65;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Стрелка тренда */
.tile__trend {
  position: absolute;
  top: 5px;
  right: 6px;
  font-size: 11px;
  opacity: 0.7;
}

/* Пульсация для критических */
.tile--crit .tile__value,
.tile--error .tile__value {
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.65; }
}

/* ===================================================
   Tooltip (desktop hover)
   =================================================== */

.tooltip {
  position: fixed;
  z-index: 1000;
  background: #1e2130;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 240px;
  max-width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.12s;
}
.tooltip.visible { opacity: 1; }

.tooltip__title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: #e5e7eb;
}

.tooltip__row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px solid #2a2d3d;
  color: var(--text-dim);
}
.tooltip__row:last-child { border-bottom: none; }

.tooltip__row b {
  color: var(--text);
  font-weight: 500;
}

.tooltip__more {
  text-align: center;
  margin-top: 6px;
  font-size: 11px;
  color: var(--accent);
}

/* ===================================================
   Mobile popup (touch-tap)
   =================================================== */

.popup-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 500;
  align-items: flex-end;
  justify-content: center;
}
.popup-overlay.open { display: flex; }

.popup {
  background: #1e2130;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  width: 100%;
  max-height: 70vh;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.popup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.popup__title { font-weight: 600; font-size: 15px; }

.popup__close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

/* ===================================================
   Страница детализации
   =================================================== */

.detail-page { padding: 12px; }

.detail-page h1 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.back-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }

.problems-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.problems-table th {
  text-align: left;
  padding: 5px 8px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.problems-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #1f2937;
  vertical-align: top;
}
.problems-table tr:last-child td { border-bottom: none; }

.solutions {
  margin-top: 16px;
  background: var(--surface);
  border-radius: 8px;
  padding: 12px;
}
.solutions h2 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.solutions li {
  color: var(--text-dim);
  margin-left: 16px;
  margin-bottom: 4px;
  font-size: 12px;
}

/* ===================================================
   Severity-бейджи
   =================================================== */

.sev { display: inline-block; border-radius: 3px; padding: 1px 5px; font-size: 10px; font-weight: 600; }
.sev-0 { background: #374151; color: #9ca3af; }
.sev-1 { background: var(--info);  color: var(--info-fg); }
.sev-2 { background: #1c3a1c; color: #86efac; }
.sev-3 { background: var(--warn);  color: var(--warn-fg); }
.sev-4 { background: var(--error); color: var(--error-fg); }
.sev-5 { background: var(--crit);  color: var(--crit-fg); }

/* ===================================================
   Попап настроек
   =================================================== */

.settings-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 600;
  align-items: center;
  justify-content: center;
}
.settings-overlay.open { display: flex; }

.settings-modal {
  background: #1e2130;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  min-width: 280px;
  max-width: 340px;
  width: 90%;
}

.settings-modal h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.settings-field {
  margin-bottom: 14px;
}

.settings-field label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settings-field input[type=number] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 14px;
}
.settings-field input[type=number]:focus {
  outline: none;
  border-color: var(--accent);
}

.settings-hint {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 3px;
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  justify-content: flex-end;
}

.settings-actions button {
  border-radius: 5px;
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.settings-actions .btn-cancel { background: none; color: var(--text-dim); }
.settings-actions .btn-cancel:hover { border-color: var(--text-dim); }
.settings-actions .btn-save   { background: var(--accent); color: #fff; border-color: var(--accent); }
.settings-actions .btn-save:hover { background: #2563eb; }

/* ===================================================
   Кнопка действия "Исправить"
   =================================================== */

.fix-block {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 16px;
  flex-wrap: wrap;
}

.fix-btn {
  background: #1d4ed8;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.fix-btn:hover:not(:disabled) { background: #2563eb; }
.fix-btn:disabled { background: #374151; color: #6b7280; cursor: default; }

.fix-status { font-size: 12px; color: var(--text-dim); }
.fix-status--ok  { color: var(--ok-fg); }
.fix-status--err { color: var(--error-fg); }

/* ===================================================
   Skeleton (загрузка)
   =================================================== */

.skeleton {
  border-radius: 6px;
  background: linear-gradient(90deg, #1f2937 25%, #2d3748 50%, #1f2937 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  min-height: 60px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===================================================
   Адаптив (мобайл)
   =================================================== */

@media (max-width: 480px) {
  /* Запрет горизонтального скролла */
  html, body { overflow-x: hidden; max-width: 100vw; }

  /* Компактный topbar: скрываем второстепенное */
  .topbar { gap: 5px; padding: 5px 6px; }
  .topbar__build { display: none; }
  .topbar__updated { font-size: 10px; min-width: 0; }
  .topbar__title { font-size: 12px; }
  .btn-label { display: none; }          /* тексты кнопок — только иконки */

  .topbar__btn { padding: 3px 6px; font-size: 13px; }

  /* Тайлы */
  .tiles-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 4px; padding: 6px; }
  .tile { min-height: 54px; }
  .tile__value { font-size: 18px; }

  /* Страница детализации */
  .detail-page { padding: 8px; }
  .detail-page h1 { font-size: 14px; }

  /* Таблица — горизонтальный скролл внутри контейнера */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  .problems-table { font-size: 11px; min-width: max-content; }
  .problems-table th,
  .problems-table td { padding: 4px 6px; white-space: nowrap; }
}
