/* ============================================================
   chart.css — диаграмма столбиками (ВЕРТИКАЛЬНАЯ) + линия порога
   ============================================================ */

.chart-wrap {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 4px 20px;
  min-height: 0;
  height: 100%;
}

.chart-header {
  text-align: center;
  margin-bottom: 4px;
  flex-shrink: 0;
}
.chart-title {
  font-size: 22px;
  font-weight: 700;
  color: #1e293b;
  letter-spacing: 0.5px;
}
.chart-sub {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

/* Панель управления */
.chart-toolbar {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: 0 1px 3px rgba(15,23,42,.05);
  flex-shrink: 0;
}
.chart-toolbar .ct-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chart-toolbar .ct-field label {
  font-size: 11px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}
.chart-toolbar input[type="text"],
.chart-toolbar input[type="number"] {
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  outline: none;
  color: #1e293b;
  min-width: 90px;
}
.chart-toolbar input:focus { border-color: #7c3aed; background: #fff; }
.chart-toolbar input.t-wide { min-width: 260px; }
.chart-toolbar input.t-num  { min-width: 80px; }

.chart-status {
  margin-left: auto;
  font-size: 12px;
  color: #16a34a;
  padding: 6px 12px;
  background: #dcfce7;
  border-radius: 8px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .2s;
}
.chart-status.show { opacity: 1; }
.chart-status.error { color: #b91c1c; background: #fee2e2; }

/* Редактор строк */
.chart-editor {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.chart-editor-row {
  display: grid;
  grid-template-columns: 28px 1fr 130px 70px 32px;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background .12s;
}
.chart-editor-row:hover { background: #f8fafc; }
.chart-editor-row.dragging { opacity: .5; }
.chart-editor-row.drag-over { background: #ede9fe; }

.chart-editor-row .cr-handle {
  cursor: grab;
  color: #cbd5e1;
  font-size: 16px;
  text-align: center;
  user-select: none;
}
.chart-editor-row .cr-handle:active { cursor: grabbing; }

.chart-editor-row input {
  padding: 6px 9px;
  font: inherit;
  font-size: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  outline: none;
  color: #1e293b;
  width: 100%;
}
.chart-editor-row input:focus { border-color: #7c3aed; }

.chart-editor-row .cr-color {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
}

.chart-editor-row .cr-del {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: #fee2e2;
  color: #b91c1c;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-editor-row .cr-del:hover { background: #fca5a5; }

.chart-editor-row.footer-row {
  background: #eff6ff;
  border: 1px dashed #93c5fd;
  margin-top: 6px;
}
.chart-editor-row.footer-row:hover { background: #dbeafe; }
.chart-editor-row.footer-row input { border-color: #93c5fd; }

.chart-editor-actions {
  display: flex;
  gap: 10px;
  padding: 10px 8px 4px;
  border-top: 1px solid #f1f5f9;
  margin-top: 4px;
}

/* Контейнер диаграммы */
.chart-view {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(15,23,42,.05);
  min-height: 0;
  overflow: auto;
}

/* Полоса столбиков */
.chart-bars {
  --bars-pad-x: 8px;
  --bars-pad-y-top: 24px;
  --bars-pad-y-bottom: 8px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  min-height: 240px;
  height: 100%;
  padding: var(--bars-pad-y-top) var(--bars-pad-x) var(--bars-pad-y-bottom);
  box-sizing: border-box;
  position: relative;
}

.chart-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 0;
  min-width: 60px;
  max-width: 160px;
  height: 100%;
  gap: 6px;
}

.chart-bar-value {
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  white-space: nowrap;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.chart-bar-column {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
  min-height: 40px;
  border-bottom: 1px solid #e2e8f0;
}

.chart-bar-fill {
  width: 100%;
  height: 0;
  border-radius: 6px 6px 0 0;
  transition: height .65s cubic-bezier(.22, 1, .36, 1),
              background-color .35s;
  min-height: 2px;
}

.chart-bar-label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
  max-width: 100%;
  flex-shrink: 0;
}

.chart-bar-item.footer .chart-bar-value {
  color: #1d4ed8;
  font-size: 17px;
}
.chart-bar-item.footer .chart-bar-label {
  color: #1d4ed8;
  font-weight: 700;
}

.chart-empty {
  padding: 60px 40px;
  text-align: center;
  color: #94a3b8;
  font-style: italic;
  font-size: 15px;
}

/* Превью в админке */
.chart-view.chart-view-preview .chart-bars {
  --bars-pad-x: 4px;
  --bars-pad-y-top: 16px;
  --bars-pad-y-bottom: 4px;
  min-height: 160px;
  gap: 8px;
}
.chart-view.chart-view-preview .chart-bar-item { min-width: 50px; max-width: 120px; }
.chart-view.chart-view-preview .chart-bar-value { font-size: 12px; }
.chart-view.chart-view-preview .chart-bar-label { font-size: 11px; }

/* ============================================================
   ЛИНИЯ ПОРОГА — ОДНА на весь блок, позиционируется из JS в px
   ============================================================ */
.chart-threshold-line {
  position: absolute;
  left: var(--bars-pad-x);
  right: var(--bars-pad-x);
  height: 0;
  border-top: 2px solid #dc2626;
  pointer-events: none;
  z-index: 3;
}

.chart-threshold-label {
  position: absolute;
  left: 50%;
  top: -12px;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 700;
  color: #dc2626;
  background: rgba(255, 255, 255, .95);
  padding: 2px 10px;
  border-radius: 4px;
  border: 1px solid rgba(220, 38, 38, .45);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  white-space: nowrap;
  line-height: 1.4;
}

/* Тёмная тема админки */
body.dark .chart-title { color: #e5e7eb; }
body.dark .chart-sub { color: #6b7280; }
body.dark .chart-toolbar { background: #23232a; border-color: #2f2f3a; }
body.dark .chart-toolbar .ct-field label { color: #94a3b8; }
body.dark .chart-toolbar input { background: #1a1d24; color: #e5e7eb; border-color: #2f2f3a; }
body.dark .chart-toolbar input:focus { border-color: #a78bfa; background: #0f1115; }
body.dark .chart-status { background: #14261a; color: #4ade80; }
body.dark .chart-status.error { background: #2a1414; color: #f87171; }

body.dark .chart-editor { background: #23232a; border-color: #2f2f3a; }
body.dark .chart-editor-row:hover { background: #1a1d24; }
body.dark .chart-editor-row.drag-over { background: #2a1f4a; }
body.dark .chart-editor-row input { background: #1a1d24; color: #e5e7eb; border-color: #2f2f3a; }
body.dark .chart-editor-row input:focus { border-color: #a78bfa; }
body.dark .chart-editor-row .cr-handle { color: #4b5563; }
body.dark .chart-editor-row .cr-del { background: #2a1414; color: #f87171; }
body.dark .chart-editor-row .cr-del:hover { background: #7f1d1d; }
body.dark .chart-editor-row.footer-row { background: #1e293b; border-color: #1e40af; }
body.dark .chart-editor-row.footer-row input { border-color: #1e40af; }
body.dark .chart-editor-actions { border-top-color: #2f2f3a; }

body.dark .chart-view { background: #23232a; border-color: #2f2f3a; }
body.dark .chart-bar-column { border-bottom-color: #2f2f3a; }
body.dark .chart-bar-value { color: #e5e7eb; }
body.dark .chart-bar-label { color: #cbd5e1; }
body.dark .chart-bar-item.footer .chart-bar-value { color: #93c5fd; }
body.dark .chart-bar-item.footer .chart-bar-label { color: #93c5fd; }
body.dark .chart-empty { color: #4b5563; }
body.dark .chart-threshold-label {
  background: #1a1d24;
  border-color: #7f1d1d;
}

/* Ночной режим ТВ */
body.night .chart-title { color: #e5e7eb; }
body.night .chart-sub { color: #6b7280; }
body.night .chart-view { background: #23232a; border-color: #2f2f3a; }
body.night .chart-bar-column { border-bottom-color: #2f2f3a; }
body.night .chart-bar-value { color: #e5e7eb; }
body.night .chart-bar-label { color: #cbd5e1; }
body.night .chart-bar-item.footer .chart-bar-value { color: #93c5fd; }
body.night .chart-bar-item.footer .chart-bar-label { color: #93c5fd; }
body.night .chart-threshold-label {
  background: #1a1d24;
  border-color: #7f1d1d;
}

/* ТВ */
body.tv-page .chart-wrap {
  height: calc(100vh - 100px);
  padding: 0 20px 20px;
  gap: 10px;
}
body.tv-page .chart-toolbar { display: none; }
body.tv-page .chart-header { padding: 4px 0 0; flex-shrink: 0; }
body.tv-page .chart-title { font-size: 36px; letter-spacing: 1px; }
body.tv-page .chart-sub   { font-size: 14px; }

body.tv-page .chart-view {
  flex: 1;
  min-height: 0;
  padding: 16px 32px 20px;
  border-radius: 18px;
}

body.tv-page .chart-bars {
  --bars-pad-x: 20px;
  --bars-pad-y-top: 30px;
  --bars-pad-y-bottom: 8px;
  min-height: 0;
  gap: 22px;
}

body.tv-page .chart-bar-item {
  min-width: 80px;
  max-width: 220px;
  gap: 10px;
}

body.tv-page .chart-bar-value { font-size: 26px; font-weight: 800; }
body.tv-page .chart-bar-label { font-size: 20px; }
body.tv-page .chart-bar-column { min-height: 60px; border-bottom-width: 2px; }
body.tv-page .chart-bar-fill { border-radius: 8px 8px 0 0; }
body.tv-page .chart-bar-item.footer .chart-bar-value { font-size: 28px; }
body.tv-page .chart-bar-item.footer .chart-bar-label { font-size: 22px; }

body.tv-page .chart-threshold-line { border-top-width: 3px; }
body.tv-page .chart-threshold-label {
  font-size: 16px;
  padding: 4px 12px;
  top: -16px;
}

/* Мобильная */
@media (max-width: 900px) {
  .chart-bars { --bars-pad-x: 4px; padding-top: 16px; padding-bottom: 4px; gap: 6px; }
  .chart-bar-item { min-width: 40px; }
  .chart-bar-value { font-size: 11px; }
  .chart-bar-label { font-size: 10px; }

  .chart-editor-row { grid-template-columns: 24px 1fr 90px 60px 28px; gap: 4px; }
  .chart-toolbar { gap: 8px; padding: 10px 12px; }
  .chart-toolbar input.t-wide { min-width: 160px; }

  body.tv-page .chart-bars { gap: 8px; }
  body.tv-page .chart-bar-value { font-size: 16px; }
  body.tv-page .chart-bar-label { font-size: 13px; }
}


/* ============================================================
   Блок «Google Sheets» в админке
   ============================================================ */
.chart-gsheet-block {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 16px;
  margin-top: 12px;
}
body.dark .chart-gsheet-block {
  background: #23232a;
  border-color: #2f2f3a;
}
body.dark .chart-gsheet-block input {
  background: #1a1d24 !important;
  color: #e5e7eb !important;
  border-color: #2f2f3a !important;
}
body.dark .chart-gsheet-block label {
  color: #94a3b8 !important;
}
