/**
 * Screen Monitor — общие стили.
 * Подключение: index, upload, demo.
 */

/* ==========================================================================
   Переменные
   ========================================================================== */

:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --blue: #3b82f6;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   Базовые стили
   ========================================================================== */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ==========================================================================
   Боковая панель
   ========================================================================== */

.sidebar {
  width: 220px;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.25rem 1rem;
  margin-bottom: 0.5rem;
  text-decoration: none;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
}

.sidebar-logo:hover {
  color: var(--primary-hover);
}

.sidebar-logo-img {
  display: block;
  width: 112px !important;
  height: 112px !important;
  max-width: 112px !important;
  max-height: 112px !important;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-logo-name {
  font-weight: 600;
  font-size: 0.6875rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

/* Навигация */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  padding: 0.5rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  color: var(--text);
  background: var(--bg);
}

.sidebar-nav a.active {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
  border-left-color: var(--primary);
  font-weight: 500;
}

/* Футер сайдбара — только текст */
.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem 0;
}

.sidebar-footer-text {
  display: block;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.65rem;
  line-height: 1.3;
  color: var(--text-muted);
}

/* ==========================================================================
   Основная область
   ========================================================================== */

.main {
  flex: 1;
  padding: 1.5rem 2rem;
  overflow: auto;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* ==========================================================================
   Карточки
   ========================================================================== */

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
}

.card-body {
  padding: 1.25rem;
}

/* ==========================================================================
   Таблица статусов
   ========================================================================== */

.status-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.status-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 500;
}

.status-table td {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.status-table tr:hover {
  background: var(--bg);
}

/* ==========================================================================
   Бейджи
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-right: 0.25rem;
}

.badge-ok {
  background: #dcfce7;
  color: #166534;
}

.badge-defect {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-none {
  background: var(--bg);
  color: var(--text-muted);
}

.badge-pending {
  background: #fef3c7;
  color: #92400e;
}

.badge-fail {
  background: #fee2e2;
  color: #991b1b;
}

.badge-proc {
  background: #e0e7ff;
  color: #3730a3;
}

/* Панель мониторинга (index) */
.ops-banner {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.integration-banner {
  font-size: 0.9rem;
  color: var(--text);
  padding: 0.5rem 0;
}

.ops-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.ops-stat-pill {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
}

.ops-stat-pill .metric-value {
  font-size: 1.05rem;
}

.recent-table-wrap {
  overflow-x: auto;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
}

.pulse-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ==========================================================================
   Метрики (демо)
   ========================================================================== */

.metrics-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.metric {
  flex: 1;
  min-width: 120px;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.metric-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.metric-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.25rem;
}

.metric-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--primary);
}

.analysis-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.analysis-flags .badge {
  margin-right: 0;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}

/* ==========================================================================
   Формы и кнопки
   ========================================================================== */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group select {
  width: 100%;
  max-width: 280px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.04);
}

.drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.04);
}

.drop-zone input {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

/* ==========================================================================
   Превью и результат загрузки
   ========================================================================== */

.preview-area {
  background: #111;
  border-radius: var(--radius);
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  overflow: hidden;
  margin-top: 1rem;
}

.preview-area img {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
}

.result-panel {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
  font-size: 0.875rem;
}

.result-panel pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Результат на русском */
.result-ru {
  font-size: 0.9rem;
}

.result-ru-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.result-ru-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1.5rem;
  margin: 0 0 1rem;
}

.result-ru-dl dt {
  color: var(--text-muted);
  font-weight: 500;
}

.result-ru-dl dd {
  margin: 0;
  word-break: break-all;
}

.result-ru-subtitle {
  margin: 0.5rem 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.result-ru-muted {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.result-ru-list {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
}

.result-ru-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.result-ru-table th,
.result-ru-table td {
  padding: 0.4rem 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
}

.result-ru-table th {
  background: var(--bg);
  font-weight: 500;
  color: var(--text-muted);
}

.result-ru-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}

.error-msg {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* ==========================================================================
   Сетка и правые панели
   ========================================================================== */

.two-col {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
}

@media (max-width: 900px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

.right-panel .card {
  margin-bottom: 1rem;
}

/* ==========================================================================
   Пороги (слайдеры)
   ========================================================================== */

.threshold-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.threshold-card-header .btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.thresholds-card .threshold-row {
  margin-bottom: 0.75rem;
}

.thresholds-card .threshold-row:last-child {
  margin-bottom: 0;
}

.threshold-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.threshold-slider {
  flex: 1;
  min-width: 120px;
  max-width: 200px;
}

.threshold-value {
  font-weight: 600;
  min-width: 2ch;
}

/* ==========================================================================
   Индикатор загрузки (анализ кадра)
   ========================================================================== */

.upload-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.upload-loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: upload-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes upload-spin {
  to {
    transform: rotate(360deg);
  }
}

.upload-loading-text {
  font-weight: 500;
}

/* ==========================================================================
   Страница отчета кадра
   ========================================================================== */

.report-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr);
  gap: 1rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .report-layout {
    grid-template-columns: 1fr;
  }
}

.report-image-wrap {
  position: relative;
  background: #0f172a;
  border-radius: var(--radius);
  border: 1px solid #1e293b;
  overflow: hidden;
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.report-image-wrap img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 78vh;
  object-fit: contain;
}

.report-image-wrap canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.report-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.report-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
}

.report-class-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.25rem;
}

.report-boxes-table td,
.report-boxes-table th {
  padding: 0.5rem 0.65rem;
}
