/* Deep Insights dashboard */

.deep-panel {
  position: relative;
  padding: 0.25rem 0 3rem;
  min-height: calc(100dvh - 2rem);
}

.deep-layout {
  display: block;
}

.deep-main {
  min-width: 0;
  transition: padding-right 0.22s ease;
}

.deep-panel.filters-open .deep-main {
  padding-right: 332px;
}

.deep-panel.filters-collapsed .deep-main {
  padding-right: 0;
}

@media (min-width: 769px) {
  .deep-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.65rem 0.75rem;
  }

  .deep-head-left {
    margin-bottom: 0;
  }

  .deep-kpis.deep-kpis-head,
  #deep-kpis.deep-kpis-head {
    min-width: 0;
    max-width: 100%;
    justify-self: stretch;
  }

  .deep-head-actions {
    justify-self: end;
    align-self: center;
  }
}

.deep-head-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.deep-sync-indicator {
  display: none;
  align-items: center;
  gap: 0.65rem;
  margin: -0.35rem 0 0.75rem;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: #bae6fd;
  font-size: 0.88rem;
  font-weight: 500;
}

.deep-sync-indicator-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(186, 230, 253, 0.25);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: deep-sync-spin 0.75s linear infinite;
  flex-shrink: 0;
}

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

.deep-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
  transition: padding-right 0.22s ease;
}

.deep-panel.filters-open .deep-head {
  padding-right: 332px;
}

.deep-panel.filters-collapsed .deep-head {
  padding-right: 0;
}

.deep-head-left {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  align-items: flex-start;
  margin-bottom: 0.35rem;
}

.deep-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.deep-track-select {
  min-width: 12rem;
}

.deep-current-pop {
  margin: 0;
  font-size: 0.82rem;
  color: #94a3b8;
  font-weight: 500;
}

/* .deep-rail-toggle chrome comes from shared app.css icon tokens */
.deep-rail-toggle svg {
  transition: transform 0.2s ease;
}

.deep-panel.filters-open .deep-head .deep-rail-toggle {
  display: none;
}

.deep-panel.filters-collapsed .deep-rail-toggle svg {
  transform: rotate(180deg);
}

/* Small collapse bar at the top of the filters drawer (mirrors the sidebar toggle). */
.drawer-collapse-btn {
  width: 100%;
  padding: 0.35rem;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.drawer-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.drawer-collapse-btn svg {
  width: 16px;
  height: 16px;
}

.deep-kpis {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0.85rem 0.65rem;
  margin: 0.4rem 0 1.35rem;
  align-items: start;
  justify-items: center;
}

.deep-kpis-head {
  flex: 1;
  margin: 0 0.5rem;
  min-width: 0;
  gap: 0.5rem 0.4rem;
}

.deep-kpis-head .deep-kpi {
  max-width: 96px;
}

.deep-kpis-head .deep-kpi-label {
  font-size: 0.68rem;
  min-height: 1.45rem;
  margin-bottom: 0;
  color: #94a3b8;
}

.deep-kpis-head .deep-kpi-delta {
  font-size: 0.57rem;
  margin-top: 0;
  min-height: 0.85rem;
}

.deep-kpi {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  width: 100%;
  max-width: 96px;
}

.deep-kpis-head .deep-kpi-ring {
  width: clamp(48px, 4.5vw, 64px);
  height: clamp(48px, 4.5vw, 64px);
}

.deep-kpis-head .deep-kpi-value {
  font-size: clamp(0.56rem, 0.68vw, 0.72rem);
  color: #e2e8f0;
}

.deep-kpi-label {
  font-size: 0.68rem;
  font-weight: 500;
  color: #94a3b8;
  text-align: center;
  line-height: 1.2;
  min-height: 1.45rem;
  margin: 0;
  width: 100%;
}

.deep-kpi-ring {
  width: clamp(48px, 4.5vw, 64px);
  height: clamp(48px, 4.5vw, 64px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, rgba(56, 189, 248, 0.22), rgba(8, 20, 32, 0.95));
  border: 1px solid rgba(56, 189, 248, 0.25);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.deep-kpi-value {
  font-size: clamp(0.56rem, 0.68vw, 0.72rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #e2e8f0;
  line-height: 1.1;
  text-align: center;
}

.deep-kpi-delta {
  font-size: 0.57rem;
  font-weight: 500;
  min-height: 0.85rem;
  margin-top: 0;
}

.deep-kpi-delta.up { color: #4ade80; }
.deep-kpi-delta.down { color: #f87171; }
.deep-kpi-delta.flat { color: #94a3b8; }

.deep-select,
.deep-source-select,
.deep-dropdown-btn {
  appearance: none;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(56, 189, 248, 0.35);
  border-radius: 999px;
  color: var(--text);
  padding: 0.45rem 2rem 0.45rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M6 9l6 6 6-6' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

.deep-source-select {
  width: 100%;
  font-size: 0.82rem;
  padding-right: 1.8rem;
}

.deep-filters-drawer {
  position: fixed;
  top: 1rem;
  right: 0;
  bottom: 0;
  width: 320px;
  z-index: 40;
  overflow: auto;
  padding: 0.6rem 0.85rem 1.25rem;
  box-sizing: border-box;
  transform: translateX(0);
  transition: transform 0.22s ease;
  background: rgba(4, 10, 18, 0.96);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px 0 0 0;
}

.deep-filters-drawer.collapsed {
  transform: translateX(110%);
}

.deep-filters-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.deep-filter-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.deep-chart-filter-label {
  font-size: 0.72rem;
  color: #94a3b8;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0.04em;
}

.deep-periods.filter-drawer-periods {
  /* Period row layout — see app.css .filter-drawer-periods */
}

.deep-period-btn {
  /* Drawer overrides — see app.css .filter-drawer-periods .period-btn */
}

.deep-calendar-block .range-picker-popover {
  position: static;
  width: 100%;
  box-shadow: none;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 0.75rem 0.7rem 0.6rem;
}

.deep-dropdown {
  position: relative;
}

.deep-dropdown-btn {
  width: 100%;
  text-align: left;
  padding-right: 2rem;
}

.deep-dropdown-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.45rem);
  background: #0b1c28;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 0.7rem 0.85rem;
  z-index: 60;
}

.deep-dropdown-panel .check-row {
  padding: 0.25rem 0;
}

.deep-compare-card {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
}

.deep-compare-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.deep-switch {
  position: relative;
  width: 46px;
  height: 26px;
  display: inline-block;
}

.deep-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.deep-switch-ui {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  cursor: pointer;
  transition: background 0.2s ease;
}

.deep-switch-ui::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}

.deep-switch input:checked + .deep-switch-ui {
  background: #22c55e;
}

.deep-switch input:checked + .deep-switch-ui::after {
  transform: translateX(20px);
}

.deep-compare-controls {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.deep-vs {
  text-align: center;
  font-style: italic;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
}

.deep-status {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  opacity: 0.5;
  text-align: right;
}


.deep-tables {
  margin-bottom: 1rem;
}

.deep-table-card {
  background: linear-gradient(145deg, rgba(11, 28, 40, 0.95), rgba(6, 14, 22, 0.98));
  border: 1px solid rgba(56, 189, 248, 0.12);
  border-radius: 14px;
  padding: 0.85rem 0.85rem 1.15rem;
}

.deep-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.deep-card-head-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.deep-metric-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.15rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
}

.deep-metric-mode-toggle--stack {
  flex-direction: column;
  align-items: stretch;
  border-radius: 10px;
  gap: 0.1rem;
  padding: 0.12rem;
}

.deep-metric-mode-toggle--stack .deep-mode-btn {
  padding: 0.22rem 0.5rem;
  font-size: 0.66rem;
}

.deep-metric-mode-toggle.hidden {
  display: none;
}

.deep-mode-btn {
  border: none;
  background: transparent;
  color: #94a3b8;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.deep-mode-btn.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.deep-mode-btn:hover:not(.active) {
  color: #cbd5e1;
}

.deep-table-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #e2e8f0;
}

.deep-mini-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #cbd5e1;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.deep-table-wrap {
  overflow: auto;
  padding: 0.45rem 0 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.deep-data-table {
  min-width: 680px;
  width: 100%;
  table-layout: fixed;
}

.deep-data-table th:first-child {
  width: auto;
}

.deep-data-table th,
.deep-data-table td {
  padding: 0.36rem 0.45rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.deep-data-table th {
  color: #94a3b8;
  font-weight: 500;
  font-size: 0.72rem;
  padding-bottom: 0.55rem;
  vertical-align: bottom;
}

.deep-data-table td {
  font-size: calc(0.66rem - 1px);
}

.deep-data-table th.num,
.deep-data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.deep-data-table tbody tr:nth-child(odd) {
  background: rgba(255, 255, 255, 0.02);
}

.deep-data-table tbody tr.row-total {
  background: rgba(56, 189, 248, 0.08);
  font-weight: 600;
}

.deep-charts-section {
  margin-bottom: 1.25rem;
}

.deep-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.deep-charts-grid .deep-widget {
  min-width: 0;
}

.deep-widget {
  background: linear-gradient(160deg, rgba(11, 28, 40, 0.92), rgba(4, 10, 18, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 0.8rem 0.8rem 0.55rem;
  min-height: 220px;
}

.deep-widget-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
  min-width: 0;
}

.deep-widget-head h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.deep-widget-head .deep-metric-mode-toggle,
.deep-widget-head .deep-widget-mode-toggle {
  flex: 0 0 auto;
  max-width: 46%;
}

.deep-widget h3 {
  margin: 0 0 0.45rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: #94a3b8;
}

.deep-widget-head + .deep-chart-wrap {
  margin-top: 0;
}

@media (min-width: 769px) {
  .deep-kpi-popularity {
    display: none;
  }
}

.deep-chart-canvas {
  display: block;
  width: 100%;
  height: 180px;
}

.deep-chart-wrap {
  position: relative;
}

.deep-chart-wrap canvas {
  cursor: crosshair;
}

.deep-chart-wrap canvas.deep-chart-brushing {
  cursor: col-resize;
  touch-action: none;
}

.deep-chart-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  transform: translate(-50%, -100%);
  background: rgba(8, 20, 30, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 10px;
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
  color: #fff;
  white-space: nowrap;
  width: max-content;
  min-width: 110px;
  max-width: min(260px, 90vw);
  box-sizing: border-box;
  word-break: normal;
  overflow-wrap: normal;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (max-width: 768px) {
  .deep-chart-tooltip {
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .deep-widget-head {
    align-items: center;
  }

  .deep-widget-head .deep-metric-mode-toggle--stack {
    flex-direction: row;
    max-width: none;
    border-radius: 999px;
    gap: 0.1rem;
    padding: 0.12rem;
  }

  .deep-widget-head .deep-metric-mode-toggle--stack .deep-mode-btn {
    padding: 0.2rem 0.45rem;
    font-size: 0.62rem;
    white-space: nowrap;
  }
}

.deep-chart-tooltip .tip-date {
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.75rem;
}

.deep-chart-tooltip .tip-value {
  font-weight: 600;
  margin-top: 0.15rem;
}

.deep-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  margin-top: 0.4rem;
  font-size: 0.72rem;
  color: #94a3b8;
}

.deep-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
  user-select: none;
  background: transparent;
  color: inherit;
  font: inherit;
}

.deep-legend-item.off {
  opacity: 0.45;
}

.deep-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.deep-popularity-track {
  color: #94a3b8;
  font-weight: 500;
  font-size: 0.85em;
}

.deep-chart-hint {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: #94a3b8;
  text-align: center;
}

@media (max-width: 1280px) {
  .deep-head {
    flex-wrap: wrap;
  }

  .deep-kpis-head {
    order: 3;
    flex-basis: 100%;
    margin: 0.4rem 0 0;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 1100px) {
  .deep-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .deep-filters-drawer {
    width: min(100%, 340px);
  }
}

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

  .deep-filters-drawer {
    width: 100%;
  }
}

/* Затемнение под панелью фильтров — только на мобильных. */
.deep-drawer-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .deep-head {
    position: relative;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    padding-right: 0 !important;
  }

  .deep-panel.filters-open .deep-main,
  .deep-panel.filters-collapsed .deep-main {
    padding-right: 0 !important;
  }

  .deep-head-left {
    width: 100%;
    align-items: stretch;
  }

  .deep-sync-indicator {
    display: none !important;
  }

  /* Заголовок уехал в верхнюю полосу, страница начинается с выбора трека */
  .deep-title {
    display: none;
  }

  .deep-head-left .app-select-wrap,
  .deep-track-select {
    width: 100%;
    min-width: 0;
    display: block;
  }

  .deep-current-pop {
    display: none;
  }

  .deep-kpi-popularity {
    display: flex;
  }

  /* KPI — горизонтальный слайдер: помещается ~2.5 кружка, остальное скроллится */
  .deep-kpis-head {
    display: flex;
    flex-wrap: nowrap;
    flex: none;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x mandatory;
    gap: 0.6rem;
    margin: 0.35rem 0 0;
    padding-bottom: 0.35rem;
  }

  .deep-kpis-head::-webkit-scrollbar {
    display: none;
  }

  .deep-kpis-head .deep-kpi {
    flex: 0 0 25%;
    max-width: none;
    scroll-snap-align: start;
  }

  .deep-kpis-head .deep-kpi-ring {
    width: min(20vw, 74px);
    height: min(20vw, 74px);
  }

  .deep-kpis-head .deep-kpi-value {
    font-size: 0.67rem;
  }

  .deep-kpis-head .deep-kpi-label {
    font-size: 0.57rem;
    min-height: 1.1rem;
  }

  .deep-kpis-head .deep-kpi-delta {
    font-size: 0.57rem;
  }

  /* Таблица — горизонтальный скролл, колонки не разъезжаются */
  .deep-data-table {
    font-size: 0.8rem;
    min-width: 720px;
    width: 720px;
    table-layout: fixed;
  }

  .deep-data-table th,
  .deep-data-table td {
    padding: 0.45rem 0.55rem;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: none;
  }

  .deep-table-wrap {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .deep-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    z-index: 39;
    display: none;
  }

  /* На мобильных drawer только по body.deep-filters-open, не от filters-open в HTML */
  .deep-filters-drawer {
    transform: translateX(110%);
  }

  body.deep-filters-open .deep-filters-drawer {
    transform: translateX(0);
  }

  body.deep-filters-open .deep-drawer-backdrop {
    display: block;
  }

  .deep-panel.filters-open .deep-drawer-backdrop {
    display: none;
  }

  .deep-filters-drawer {
    top: 1rem;
    height: calc(100dvh - 1rem);
    border-radius: 18px 18px 0 0;
    background: #060d16;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding: 0.6rem 7% 1.25rem 0.85rem;
  }

  .deep-filters-panel .drawer-collapse-btn {
    padding: 0.6rem;
    margin-bottom: 0.15rem;
  }

  .deep-filters-panel .drawer-collapse-btn svg {
    width: 20px;
    height: 20px;
  }
}
