/* ─────────────────────────────────────────
   ДАШБОРД ( dashboard.css )
   ───────────────────────────────────────── */
#page-dashboard {
  flex-direction: column;
  gap: 24px;
}

/* Верхняя панель дашборда: периоды + кнопки действий */
.db-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  padding: 8px 16px;
}

.db-period-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--surface2);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.db-period-btn {
  padding: 6px 14px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--text3);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: none;
}

.db-period-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.db-period-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(var(--accent-rgb), 0.3);
}

.db-quick-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Сетка виджетов */
.db-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: min-content;
  grid-gap: 24px;
}

.db-widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px; /* Modern radius */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.db-widget:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  border-color: rgba(var(--accent-rgb), 0.3);
}

.db-widget.dragging {
  opacity: 0.5;
  transform: scale(0.98);
  z-index: 1000;
}

.db-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: move;
  position: relative;
  background: rgba(255, 255, 255, 0.01);
}

.db-wh-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.db-wh-remove {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s;
  color: var(--text3);
  font-size: 16px;
  background: var(--surface3);
}

.db-widget:hover .db-wh-remove {
  opacity: 0.6;
}

.db-wh-remove:hover {
  opacity: 1 !important;
  background: var(--danger);
  color: #fff;
}

/* Кнопка "Добавить" в топбаре */
.db-add-comp-btn {
  background: var(--surface2);
  color: var(--text) !important;
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
}

.db-add-comp-btn:hover {
  background: var(--surface3);
  border-color: rgba(var(--accent-rgb), 0.5);
}

.db-add-comp-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
  width: 240px;
  z-index: 200;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  display: none;
  flex-direction: column;
  gap: 4px;
  backdrop-filter: blur(20px);
}

.db-add-comp-menu.open {
  display: flex;
  animation: fade-in 0.2s ease-out;
}

.db-ac-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  transition: all 0.2s;
  color: var(--text2);
}

.db-ac-item:hover {
  background: var(--surface2);
  color: var(--text);
  transform: translateX(4px);
}

.db-ac-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.db-wh-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-transform: none !important; /* Less aggressive than uppercase */
  display: flex;
  align-items: center;
  gap: 12px;
}

.db-wh-title span {
  font-size: 16px;
  color: var(--accent);
}

.db-widget-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  cursor: pointer;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  transition: all 0.2s;
}

.db-widget-btn:hover {
  background: var(--surface3);
  color: var(--text);
}

.db-widget-content {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: auto;
}

/* Цвета выполнения KPI */
:root {
  --kpi-red: #ef4444;       /* < 50% */
  --kpi-orange: #f59e0b;    /* 50-99% */
  --kpi-green: #10b981;     /* 100% */
  --kpi-turquoise: #06b6d4; /* > 100% */
}

.db-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  width: 100%;
}

.db-kpi-card {
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.db-kpi-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; width: 4px; height: 100%;
  background: var(--kpi-color, var(--accent));
  opacity: 0.8;
}

.db-kpi-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  border-color: rgba(var(--accent-rgb), 0.2);
  background: rgba(255, 255, 255, 0.04);
}

.db-kc-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 16px;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.2s;
  color: var(--text3);
}

.db-kpi-card:hover .db-kc-remove {
  opacity: 1;
}

.db-kc-remove:hover {
  color: var(--danger);
}

.db-kc-icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  color: var(--kpi-color);
}

.db-kc-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.db-kc-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.db-kc-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.db-kc-goal-text {
  font-size: 10px;
  font-weight: 700;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.db-kc-goal-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.db-kc-mini-bar-wrap {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
  overflow: hidden;
  margin-right: 8px;
}

.db-kc-mini-bar-fill {
  height: 100%;
  background: var(--status-color);
  box-shadow: 0 0 8px var(--status-color);
  transition: width 1s ease;
}

/* Метрики в таблице */
.db-table.detailed thead th {
  background: rgba(255, 255, 255, 0.01);
  font-size: 10px;
  color: var(--text3);
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.db-table.detailed tbody td {
  padding: 16px !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  font-size: 13px;
}

@keyframes db-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Метрики в таблице (Компактный стиль v5) */
.db-table.detailed {
  margin-top: 0;
  border-spacing: 0;
}

.db-metric-row {
  background: transparent;
}

.db-metric-row td {
  padding: 8px 10px !important;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.db-stage-name span {
  font-size: 14px;
  margin-right: 6px;
  filter: grayscale(0.5);
}

.db-stage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.db-conv-badge {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 9px;
  font-weight: 800;
  color: var(--accent);
}

.grey {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  opacity: 0.5;
  margin-left: 4px;
}

/* Виджеты: Расположение */
.db-widget[data-w="kpis"] { grid-column: span 12; }
.db-widget[data-w="dynamics"] { grid-column: span 8; height: 400px; }
.db-widget[data-w="sources"] { grid-column: span 4; height: 400px; }
.db-widget[data-w="funnel"] { grid-column: span 6; }
.db-widget[data-w="staff"] { grid-column: span 6; }

/* Адаптив для широких ноутбуков (<=1440px) */
@media (max-width: 1440px) {
  .db-widget[data-w="dynamics"] { grid-column: span 12; height: 350px; }
  .db-widget[data-w="sources"] { grid-column: span 12; height: 350px; }
}

/* Адаптив для стандартных ноутбуков (<=1280px) */
@media (max-width: 1280px) {
  .db-widget[data-w="funnel"] { grid-column: span 12; }
  .db-widget[data-w="staff"] { grid-column: span 12; }
}

/* Адаптив для планшетов и мобильных (<=1024px) */
@media (max-width: 1024px) {
  .db-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  .db-widget {
    width: 100% !important;
  }
  .db-widget[data-w="dynamics"], 
  .db-widget[data-w="sources"] { 
    height: 300px !important; 
  }
}

.db-chart-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* Легенда источников */
.db-source-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  padding-bottom: 8px;
}

.db-stage-name { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 13px; }
.db-legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  padding: 0 4px;
}

.db-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.db-legend-label {
  flex: 1;
  color: var(--text2);
}

.db-legend-val {
  font-weight: 700;
  color: var(--text);
}

.db-legend-pct {
  color: var(--text3);
  font-weight: 400;
  margin-left: 4px;
}

/* ─── Воронка (Funnel) ─── */
.db-funnel-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.db-funnel-step {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.db-funnel-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
}

.db-funnel-name i {
  font-style: normal;
  font-size: 14px;
}

.db-funnel-count {
  font-weight: 800;
  color: var(--text);
}

.db-funnel-drop {
  width: 45px;
  text-align: right;
  color: var(--text3);
  font-size: 10px;
  font-weight: 600;
}

.db-funnel-bar-wrap {
  height: 8px;
  background: var(--surface2);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}

.db-funnel-fill {
  height: 100%;
  border-radius: 14px;
  position: relative;
  transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.db-funnel-pct {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 8px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

/* Таблица сотрудников */
.db-staff-table-wrap {
  overflow-x: auto;
}

.db-staff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.db-staff-table th { padding: 14px 12px; font-size: 11px; text-align: left; color: var(--text3); font-weight: 600; border-bottom: 1px solid var(--border); }
.db-staff-table td { padding: 16px 12px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.db-staff-table tr:nth-child(even) { background: rgba(255,255,255,0.01); }
.db-staff-table tr:hover { background: rgba(255,255,255,0.03); }

/* Стили баров в ячейках */
.db-bar-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 100px;
}

.db-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 14px;
  overflow: hidden;
}

.db-bar-fill {
  height: 100%;
  border-radius: 14px;
}

.db-staff-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.db-staff-av {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 10px;
}

/* Функционал ресайза */
.db-widget-resize {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 10px;
  height: 10px;
  cursor: nwse-resize;
  border-right: 2px solid var(--border2);
  border-bottom: 2px solid var(--border2);
  opacity: 0.5;
}

/* Настройки KPI */
.db-kpi-settings-menu {
  position: absolute;
  top: 40px;
  right: 14px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 8px;
  z-index: 110;
  display: none;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
  min-width: 180px;
}

.db-kpi-settings-menu.open {
  display: flex;
}

.db-kpi-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.2s;
}

.db-kpi-opt:hover {
  background: var(--surface2);
}

.db-kpi-opt input {
  cursor: pointer;
}

/* Общие стили таблиц дашборда */
.db-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.db-table thead th { 
  padding: 16px 12px; 
  font-size: 11px; 
  color: var(--text3); 
  font-weight: 700; 
  text-transform: uppercase; 
  letter-spacing: 0.05em; 
  border-bottom: 1px solid var(--border); 
  text-align: left; 
}

.db-table tbody td { 
  padding: 18px 12px; 
  vertical-align: middle; 
  border-bottom: 1px solid rgba(255,255,255,0.03); 
  line-height: 1.5;
}

.db-table.detailed tbody td {
  padding: 10px 12px;
  line-height: 1.2;
}

.db-table tr:nth-child(even) { background: rgba(255,255,255,0.01); }
.db-table tr:hover { background: rgba(255,255,255,0.03); }

/* Специфичные фиксы для сотрудников */
.db-staff-table {
  width: 100%;
  border-collapse: collapse;
}
.db-staff-table th { padding: 16px 12px; font-size: 11px; text-align: left; color: var(--text3); font-weight: 600; border-bottom: 1px solid var(--border); }
.db-staff-table td { padding: 18px 12px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.db-staff-table tr:nth-child(even) { background: rgba(255,255,255,0.01); }
.db-staff-table tr:hover { background: rgba(255,255,255,0.03); }

.db-conv-stage {
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
}

.db-conv-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 10px var(--dot-color, rgba(0,0,0,0.1));
}

.db-conv-count {
  font-weight: 800;
  font-family: var(--mono);
  color: var(--accent);
  background: rgba(59, 130, 246, 0.05);
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
  min-width: 32px;
  text-align: center;
}

.db-conv-count.grey {
  color: var(--text3);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
}

.db-conv-pct {
  color: var(--text2);
  font-weight: 700;
  font-size: 10px;
  background: var(--surface2);
  padding: 4px 8px;
  border-radius: 6px;
}

.db-widget-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 4px;
  z-index: 100;
  display: none;
  flex-direction: column;
  min-width: 140px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.db-widget-menu.open {
  display: flex;
}

.db-menu-item {
  padding: 6px 12px;
  font-size: 11px;
  cursor: pointer;
  border-radius: 8px;
}

.db-menu-item:hover {
  background: var(--surface2);
}
/* ─── LIVE ACTIVITY FEED (V3) ─── */
.db-feed-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 500px;
  overflow-y: auto;
  padding-right: 8px;
}

.db-feed-item {
  display: flex;
  gap: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  transition: all 0.3s ease;
  animation: slideInRight 0.4s ease forwards;
}

.db-feed-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateX(4px);
}

.db-feed-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.db-feed-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.db-feed-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.db-feed-user {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
}

.db-feed-time {
  font-size: 10px;
  color: var(--text3);
  font-weight: 600;
}

.db-feed-text {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text2);
}

.db-feed-lead {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(59, 130, 246, 0.1);
  padding: 4px 10px;
  border-radius: 20px;
  width: fit-content;
  transition: all 0.2s;
}

.db-feed-lead:hover {
  background: var(--accent);
  color: #fff;
}

/* Animations */
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Scrollbar for feed */
.db-feed-container::-webkit-scrollbar { width: 4px; }
.db-feed-container::-webkit-scrollbar-track { background: transparent; }
.db-feed-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

/* Dashboard V3 Glassmorphism Tweak */
.db-widget {
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ─── DATE PICKER ─── */
.db-date-picker-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.db-dp-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.db-dp-group label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.db-date-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.db-date-input:hover {
  border-color: rgba(var(--accent-rgb), 0.5);
  background: var(--surface3);
}

.db-date-input::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: 0.6;
  cursor: pointer;
}

#dbApplyCustom {
    padding: 6px 14px;
}

@media (max-width: 1024px) {
  .db-date-picker-wrap {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    width: 100%;
    justify-content: space-between;
    margin-top: 8px;
  }
}
