/* ============================================================
   Дашборд банных заходов — дизайн-токены и компоненты
   ============================================================ */

:root {
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --text: #1B2A44;
  --text-secondary: #5B6B85;
  --border: #DCE3EE;
  --accent: #2553A0;
  --accent-dark: #1B3E7A;
  --accent-soft: #E8EEF9;
  --event: #E4572E;
  --event-soft: #FDEAE3;

  --temp-1: #E4572E;
  --temp-2: #F2994A;
  --temp-3: #C23616;
  --temp-4: #F7B267;

  --hum-1: #2553A0;
  --hum-2: #56A0D3;
  --hum-3: #173F73;
  --hum-4: #8FC1E3;

  --dew-1: #2E7D6B;
  --dew-2: #6BBF9A;
  --dew-3: #1F5C4F;
  --dew-4: #A8DDC3;

  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow-card: 0 1px 2px rgba(27, 42, 68, .06), 0 6px 20px rgba(27, 42, 68, .07);
  --shadow-pop: 0 8px 28px rgba(27, 42, 68, .18);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.tabular { font-variant-numeric: tabular-nums; }

h1, .h1 { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2, .h2 { font-size: 20px; font-weight: 600; margin: 0; }
.text-secondary-custom { color: var(--text-secondary); }

a { color: var(--accent); }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
}

.app-header .brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex: none;
}

.app-header .brand-date {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ---------- Layout ---------- */
.dashboard-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 992px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .session-sidebar { display: none; }
  .mobile-select-wrap { display: block !important; }
}

.mobile-select-wrap { display: none; margin-bottom: 16px; }

/* ---------- Sidebar ---------- */
.session-sidebar {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 104px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 8px;
}

.session-sidebar .sidebar-title {
  padding: 10px 10px 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-secondary);
  font-weight: 600;
}

.session-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}

.session-card:hover { background: var(--bg); }

.session-card.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.session-card .badge-num {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.session-card.no-log .badge-num { background: var(--text-secondary); }

.session-card .card-body-text { min-width: 0; flex: 1; }

.session-card .card-aroma {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-card .card-meta {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-card .no-log-pill {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 7px;
  display: inline-block;
  margin-top: 3px;
}

/* ---------- Main panel ---------- */
.main-panel { min-width: 0; }

.session-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.session-heading .meta-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.meta-chip {
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 18px 12px;
}

.chart-canvas-wrap {
  position: relative;
  height: 500px;
  width: 100%;
  transition: opacity .25s ease;
}

.chart-canvas-wrap.fading { opacity: 0; }

/* ---------- Event pins ---------- */
.pins-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.event-pin-line {
  position: absolute;
  top: 8px;
  bottom: 28px;
  width: 0;
  border-left: 1.5px dashed rgba(228, 87, 46, .55);
  pointer-events: none;
}

.event-pin {
  position: absolute;
  top: 0;
  transform: translate(-50%, -100%);
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  transform-origin: bottom center;
  background: var(--event);
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(228, 87, 46, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  cursor: pointer;
  pointer-events: auto;
  transition: transform .12s ease, box-shadow .12s ease;
}

.event-pin i { transform: rotate(45deg); }
.event-pin { transform: translate(-50%, -100%) rotate(-45deg); }

.event-pin:hover, .event-pin:focus-visible, .event-pin.pin-active {
  transform: translate(-50%, -108%) rotate(-45deg) scale(1.12);
  box-shadow: 0 4px 12px rgba(228, 87, 46, .55);
  outline: none;
}

.event-pin.pin-start { background: var(--accent); box-shadow: 0 2px 6px rgba(37, 83, 160, .45); }
.event-pin.pin-end { background: var(--text-secondary); box-shadow: 0 2px 6px rgba(91, 107, 133, .45); }

/* ---------- Legend chips ---------- */
.legend-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 2px 4px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

@media (max-width: 768px) {
  .legend-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .legend-chip { flex: none; }
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 20px;
  padding: 5px 11px 5px 8px;
  cursor: pointer;
  user-select: none;
  transition: opacity .15s ease, border-color .15s ease;
}

.legend-chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.legend-chip.off { opacity: .4; }
.legend-chip.off .dot { background: transparent !important; border: 1.5px solid currentColor; }

.legend-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  align-self: center;
  padding: 0 2px;
  flex: none;
}

/* ---------- Popover (desktop) ---------- */
.event-popover {
  position: absolute;
  z-index: 30;
  width: 280px;
  max-width: 80vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: 14px 14px 12px;
  display: none;
}

.event-popover.show { display: block; }

.event-popover .pop-time {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.event-popover .pop-title {
  font-size: 14.5px;
  font-weight: 700;
  margin: 2px 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.event-popover .pop-close {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}

/* ---------- Empty / loading / error states ---------- */
.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 28px;
  text-align: center;
}

.empty-state .empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.empty-state .demo-chart-preview {
  max-width: 420px;
  margin: 20px auto 0;
  position: relative;
}

.skeleton-block {
  height: 500px;
  border-radius: var(--radius-md);
  background: linear-gradient(100deg, #EEF1F6 30%, #F7F9FC 50%, #EEF1F6 70%);
  background-size: 240% 100%;
  animation: skeleton-shimmer 1.3s ease-in-out infinite;
}

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

.error-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--event);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.error-card .error-icon { color: var(--event); font-size: 20px; margin-top: 2px; }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
}

/* ---------- Mobile bottom sheet ---------- */
.event-offcanvas .offcanvas-header { border-bottom: 1px solid var(--border); }
.event-offcanvas { border-top-left-radius: 16px; border-top-right-radius: 16px; }

@media (max-width: 768px) {
  .chart-card { padding: 14px 12px 10px; }
  .chart-canvas-wrap { height: 380px; }
}

.fade-swap { animation: fade-in .28s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .fade-swap, .chart-canvas-wrap, .skeleton-block, .event-pin { animation: none !important; transition: none !important; }
}
