/* Vibor design system — shared with terotdel analytics */
:root {
  --bg: #f0f4f8;
  --card: #fff;
  --primary: #1e40af;
  --secondary: #3b82f6;
  --light: #dbeafe;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --positive: #059669;
  --negative: #dc2626;
  --warning: #d97706;
  --heatmap: #f97316;
  --violet: #7c3aed;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --shadow-sm: 0 2px 8px rgba(30, 64, 175, .06);
  --shadow-md: 0 8px 24px rgba(30, 64, 175, .12);
  --shadow-lg: 0 16px 40px rgba(30, 64, 175, .16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--text);
  line-height: 1.5;
  background: linear-gradient(145deg, #eef2f7 0%, #f0f4f8 40%, #e8eef6 100%);
  background-size: 200% 200%;
  animation: bgDrift 20s ease infinite;
  overflow-x: clip;
  min-height: 100vh;
}
@keyframes bgDrift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.container {
  max-width: 1480px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 20px;
  animation: fadeInUp 0.5s var(--ease-out);
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.app-header-main { display: flex; gap: 12px; min-width: 0; flex: 1; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), #1e3a8a);
  color: #fff; font-weight: 700; font-size: 0.7rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(30, 64, 175, .25);
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s;
}
@media (hover: hover) {
  .brand-icon:hover { transform: scale(1.06) rotate(-2deg); box-shadow: 0 8px 20px rgba(30, 64, 175, .35); }
}
.app-header h1 {
  font-size: 22px;
  color: var(--primary);
  line-height: 1.25;
  font-weight: 700;
}
.header-sub { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.45; }
.header-badges {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: flex-end; align-items: center;
}
.badge {
  background: var(--light); color: var(--primary);
  padding: 6px 14px; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s;
}
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
@media (hover: hover) {
  .badge:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
}

/* Period + mode switches */
.period-switch, .mode-switch {
  display: flex; gap: 4px; margin-bottom: 16px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 4px; width: 100%;
  box-shadow: var(--shadow-sm);
}
.period-switch { max-width: 420px; }
.mode-switch { margin-bottom: 20px; }
.period-btn, .mode-btn {
  flex: 1 1 0; min-width: 0; padding: 10px 8px;
  border: none; border-radius: 10px; background: transparent;
  cursor: pointer; font-family: inherit; font-size: 13px;
  font-weight: 600; color: var(--muted); text-align: center;
  line-height: 1.3;
  transition: transform 0.25s var(--ease-spring), background 0.2s, color 0.2s, box-shadow 0.25s;
}
.period-btn.active, .mode-btn.active {
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 14px rgba(30, 64, 175, .35);
  transform: scale(1.02);
}
.period-btn:hover:not(.active), .mode-btn:hover:not(.active) {
  background: var(--light); color: var(--primary); transform: translateY(-1px);
}
.mode-txt-short { display: none; }

/* Views */
.dashboard-view { display: none; min-width: 0; }
.dashboard-view.active { display: block; animation: fadeInUp 0.4s var(--ease-out); }
.view-desc { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.view-hidden { display: none !important; }

/* Hero KPI */
.overview-hero {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.hero-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
  transition: transform 0.35s var(--ease-spring), box-shadow 0.35s, border-color 0.25s;
  animation: fadeInUp 0.5s var(--ease-out) backwards;
}
.hero-card:nth-child(1) { animation-delay: 0.05s; }
.hero-card:nth-child(2) { animation-delay: 0.1s; }
.hero-card:nth-child(3) { animation-delay: 0.15s; }
.hero-card:nth-child(4) { animation-delay: 0.2s; }
.hero-card:nth-child(5) { animation-delay: 0.25s; }
@media (hover: hover) {
  .hero-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--secondary);
  }
}
.hero-card.accent {
  border-color: var(--primary);
  background: linear-gradient(160deg, #fff 0%, var(--light) 100%);
}
.hero-label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  font-weight: 600; margin-bottom: 8px;
}
.hero-value {
  font-size: 28px; font-weight: 700; color: var(--primary);
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.hero-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.kpi-trend { font-size: 11px; margin-top: 4px; font-weight: 600; }
.kpi-trend.up { color: var(--negative); }
.kpi-trend.down { color: var(--positive); }
.kpi-help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; margin-left: 4px; border-radius: 50%;
  font-size: 9px; font-weight: 700; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); cursor: help;
}

/* Panels */
.panel-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.32s var(--ease-spring), box-shadow 0.32s, border-color 0.25s;
}
@media (hover: hover) {
  .panel-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: rgba(59, 130, 246, 0.35);
  }
}
.panel-card.accent-border { border: 2px solid var(--primary); }
.panel-card.heatmap-border { border: 2px solid var(--heatmap); }
.panel-title {
  font-size: 15px; font-weight: 700; color: var(--primary); margin-bottom: 4px;
}
.panel-desc { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.section-label {
  font-size: 14px; font-weight: 600; margin: 20px 0 12px;
  padding-bottom: 6px; border-bottom: 2px solid var(--light);
  color: var(--primary);
}
.section-label:first-child { margin-top: 0; }

.overview-two {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-bottom: 20px; min-width: 0;
}
.summary-panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
  transition: transform 0.32s var(--ease-spring), box-shadow 0.32s, border-color 0.25s;
}
@media (hover: hover) {
  .summary-panel:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: rgba(59, 130, 246, 0.3);
  }
}
.summary-panel h3 { font-size: 13px; font-weight: 600; margin-bottom: 12px; color: var(--primary); }

/* Nav cards */
.overview-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.nav-card {
  background: var(--card); border: 2px solid var(--border);
  border-radius: 12px; padding: 16px;
  cursor: pointer; text-align: left; font-family: inherit; color: inherit;
  transition: transform 0.3s var(--ease-spring), border-color 0.25s, box-shadow 0.3s;
}
@media (hover: hover) {
  .nav-card:hover {
    border-color: var(--secondary);
    transform: translateY(-4px) scale(1.02);
    box-shadow: var(--shadow-md);
  }
  .nav-card:hover .nav-card-arrow { transform: translateX(5px); }
}
.nav-card-title { font-size: 14px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.nav-card-desc { font-size: 12px; color: var(--muted); }
.nav-card-arrow {
  font-size: 11px; color: var(--secondary); font-weight: 600; margin-top: 10px;
  display: inline-block; transition: transform 0.25s;
}

/* Tiles (departments) — 4 в ряд, крупные карточки */
.tile-grid { display: grid; gap: 20px; margin-bottom: 28px; }
.tile-grid.deputies { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile {
  background: var(--card); border: 2px solid var(--border);
  border-radius: 16px; padding: 24px 22px;
  cursor: pointer; text-align: left; font-family: inherit; color: inherit; width: 100%;
  min-height: 188px;
  display: flex; flex-direction: column;
  transition: transform 0.35s var(--ease-spring), border-color 0.25s, box-shadow 0.35s;
  animation: fadeInUp 0.45s var(--ease-out) backwards;
}
.tile:nth-child(1) { animation-delay: 0.04s; }
.tile:nth-child(2) { animation-delay: 0.08s; }
.tile:nth-child(3) { animation-delay: 0.12s; }
.tile:nth-child(4) { animation-delay: 0.16s; }
.tile:nth-child(5) { animation-delay: 0.2s; }
.tile:nth-child(6) { animation-delay: 0.24s; }
.tile:nth-child(7) { animation-delay: 0.28s; }
.tile:nth-child(8) { animation-delay: 0.32s; }
@media (hover: hover) {
  .tile:hover {
    transform: translateY(-8px) scale(1.02);
    border-color: var(--secondary);
    box-shadow: var(--shadow-lg);
  }
  .tile:hover .tile-bar-fill { filter: brightness(1.08); }
}
.tile.selected {
  border-color: var(--primary);
  background: linear-gradient(160deg, #fff 0%, var(--light) 100%);
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
}
.tile-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); font-weight: 700; margin-bottom: 8px;
}
.tile-title { font-size: 18px; font-weight: 700; color: var(--primary); margin-bottom: 12px; line-height: 1.3; }
.tile-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex: 1; }
.tile-stat {
  background: var(--bg); border-radius: 10px; padding: 12px 14px;
  border: 1px solid transparent;
  transition: background 0.25s, border-color 0.25s, transform 0.25s var(--ease-spring);
}
@media (hover: hover) {
  .tile:hover .tile-stat { border-color: rgba(59, 130, 246, 0.15); }
  .tile-stat:hover { background: var(--light); transform: scale(1.03); }
}
.tile-stat-label { font-size: 11px; color: var(--muted); }
.tile-stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.tile-bar { height: 6px; background: var(--border); border-radius: 3px; margin-top: 14px; overflow: hidden; }
.tile-bar-fill { height: 100%; border-radius: 3px; transform-origin: left; transition: filter 0.25s, width 0.4s var(--ease-out); }

/* Detail panel */
.detail-panel {
  display: none; background: var(--card); border: 2px solid var(--primary);
  border-radius: 16px; padding: 24px; margin-bottom: 24px;
  box-shadow: var(--shadow-lg);
}
.detail-panel.visible { display: block; animation: slideIn 0.35s var(--ease-out); }
.detail-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.detail-title { font-size: 22px; font-weight: 700; color: var(--primary); }
.detail-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.close-btn {
  background: var(--secondary); color: #fff; border: none;
  padding: 8px 18px; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-family: inherit; flex-shrink: 0;
  transition: transform 0.25s var(--ease-spring), background 0.2s, box-shadow 0.25s;
}
.close-btn:hover { background: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(30,64,175,.3); }

/* Charts */
.chart-box {
  background: var(--bg); border-radius: 10px; padding: 14px;
  min-width: 0; width: 100%;
  transition: box-shadow 0.3s, border-color 0.25s;
  border: 1px solid transparent;
}
@media (hover: hover) {
  .chart-box:hover {
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.12);
  }
}
.chart-box-sm { height: 240px; min-height: 200px; }
.chart-box-md { height: 280px; min-height: 240px; }
.chart-box-lg { height: 320px; min-height: 260px; }
.charts-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-bottom: 20px; min-width: 0;
}
.chart-title { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: var(--text); }

/* Tables */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--border); border-radius: 10px;
  -webkit-overflow-scrolling: touch; max-width: 100%;
  scrollbar-gutter: stable;
  transition: box-shadow 0.3s, border-color 0.25s, transform 0.3s var(--ease-spring);
}
@media (hover: hover) {
  .table-wrap:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(59, 130, 246, 0.25);
    transform: translateY(-2px);
  }
}
.table-wrap.table-scroll-y {
  max-height: min(420px, 58vh);
  overflow: auto;
}
.table-wrap.table-scroll-y .data-table thead th {
  position: sticky; top: 0; z-index: 2;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .12);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; background: var(--card); }
.data-table th {
  background: var(--primary); color: #fff; padding: 9px 10px;
  text-align: left; white-space: nowrap; font-weight: 600;
}
.data-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}
.data-table tbody tr:hover td { background: var(--light); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tfoot td { background: var(--light); font-weight: 700; }

/* Tension */
.tension-low { background: #d1fae5; color: #065f46; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.tension-medium { background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.tension-high { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.tension-row-high td { background: rgba(254, 226, 226, 0.45); }
.tension-row-medium td { background: rgba(254, 243, 199, 0.35); }
.tension-row-low td { background: rgba(209, 250, 229, 0.2); }
.tension-scale { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 11px; color: var(--muted); margin-bottom: 12px; }
.tension-scale span { display: inline-flex; align-items: center; gap: 4px; }
.tension-scale i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }

/* Status */
.status-critical { background: #fef2f2; border: 1px solid #fecaca; border-radius: 12px; }
.status-warning { background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; }
.status-ok { background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 12px; }
.status-box {
  display: none; border-radius: 12px; padding: 14px 16px;
  font-size: 13px; margin-bottom: 16px; line-height: 1.5;
}
.status-box.visible { display: block; animation: fadeInUp 0.35s var(--ease-out); }
.status-box.ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.status-box.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.status-box.err { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* Upload */
.upload-zone {
  display: block; width: 100%; box-sizing: border-box;
  border: 2px dashed var(--border); border-radius: 14px; padding: 28px 20px;
  text-align: center; background: var(--bg); cursor: pointer;
  transition: border-color 0.3s, background 0.3s, transform 0.3s var(--ease-spring), box-shadow 0.3s;
  margin-bottom: 16px;
}
.upload-zone:hover {
  border-color: var(--secondary); background: var(--light);
  transform: translateY(-3px); box-shadow: var(--shadow-md);
}
.upload-title { font-size: 15px; font-weight: 600; color: var(--primary); margin-bottom: 6px; }
.upload-sub { font-size: 13px; color: var(--muted); }
.upload-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; justify-content: center; }

/* Buttons */
.btn-action {
  border: none; border-radius: 8px; padding: 9px 16px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; background: var(--primary); color: #fff;
  transition: transform 0.25s var(--ease-spring), background 0.2s, box-shadow 0.25s;
}
.btn-action:hover { background: #1e3a8a; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(30,64,175,.25); }
.btn-action.secondary { background: var(--light); color: var(--primary); }
.btn-action.secondary:hover { background: #bfdbfe; }
.btn-action.heatmap { background: var(--heatmap); }
.btn-action.heatmap:hover { background: #ea580c; }

/* AI block */
.ai-block { border-left: 4px solid var(--violet); }
.ai-help-panel {
  font-size: 13px; color: var(--text); line-height: 1.5;
  padding: 12px 14px; border-radius: 10px;
  background: #f5f3ff; border: 1px solid #ddd6fe; margin-bottom: 14px;
}
.ai-help-btn {
  font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  border: 1px solid #c4b5fd; background: #ede9fe; color: #5b21b6; cursor: pointer;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s, background 0.2s;
}
@media (hover: hover) {
  .ai-help-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.2);
    background: #ddd6fe;
  }
}
.priority-high { border-left: 4px solid var(--negative); }
.priority-medium { border-left: 4px solid var(--warning); }
.priority-low { border-left: 4px solid var(--positive); }

/* Filters */
.filter-select {
  font-size: 13px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--card); color: var(--text); font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s var(--ease-spring);
}
.filter-select:focus { outline: none; border-color: var(--secondary); box-shadow: 0 0 0 3px var(--light); }
@media (hover: hover) {
  .filter-select:hover { border-color: var(--secondary); transform: translateY(-1px); }
}
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }

/* Loading */
#loading-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(240, 244, 248, 0.92);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
#loading-overlay.hidden { display: none; }
.loader-spin {
  width: 40px; height: 40px; border: 4px solid var(--light);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto;
}
.loader-text { margin-top: 16px; color: var(--muted); font-weight: 500; font-size: 14px; text-align: center; }

/* Utilities */
.hidden { display: none !important; }
.tabular-nums { font-variant-numeric: tabular-nums; }
.delta-pos { color: var(--positive); font-weight: 600; }
.delta-neg { color: var(--negative); font-weight: 600; }
.no-print {}
.fade-section { opacity: 1; transform: translateY(0); }
.fade-section.animate-in { opacity: 0; transform: translateY(12px); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.insight-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tag {
  display: inline-block; padding: 4px 10px; border-radius: 8px;
  font-size: 12px; font-weight: 600; background: var(--light); color: var(--primary);
}
.tag-heatmap { background: #ffedd5; color: #9a3412; }
.kpi-legend {
  font-size: 12px; color: var(--muted); line-height: 1.45;
  padding: 10px 14px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border); margin-bottom: 16px;
}
.message-card {
  padding: 12px 14px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border); font-size: 13px;
  transition: transform 0.28s var(--ease-spring), box-shadow 0.28s, border-color 0.25s, background 0.25s;
}
@media (hover: hover) {
  .message-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-sm);
    border-color: rgba(59, 130, 246, 0.35);
    background: #fff;
  }
}
.status-neg-chart { height: 56px; margin-top: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  body { animation: none; background: var(--bg); }
}

@media (max-width: 1200px) {
  .tile-grid.deputies { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .overview-hero { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
  .overview-hero { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-two, .charts-row, .grid-2 { grid-template-columns: 1fr; }
  .overview-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-grid.deputies { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .container { padding: 12px; }
  .app-header h1 { font-size: 18px; }
  .mode-txt-long { display: none; }
  .mode-txt-short { display: inline; }
  .overview-hero { grid-template-columns: 1fr; }
  .hero-value { font-size: 22px; }
  .overview-nav { grid-template-columns: 1fr; }
  .tile-grid.deputies { grid-template-columns: 1fr; }
  .tile { min-height: 0; padding: 20px 18px; }
  .tile-title { font-size: 16px; }
  .tile-stat-value { font-size: 16px; }
  .detail-panel { padding: 14px; }
  .period-switch { max-width: 100%; }
}
