/* ─── Design tokens (маркетинговый стиль) ────────────────────── */
:root {
  --card-radius: 14px;
  --c-primary:   #0d9488;
  --c-primary-h: #0f766e;
  --c-accent:    #f97316;
  --c-indigo:    #6366f1;
  --c-blue:      #0ea5e9;
  --c-green:     #10b981;
  --c-red:       #ef4444;
  --c-amber:     #f59e0b;
  --c-violet:    #8b5cf6;
  --c-teal:      #14b8a6;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --text-primary: #1c1917;
  --text-muted:   #78716c;
  --bg-card:     #fff;
  --bg-subtle:   #fafaf9;
  --border:      #e7e5e4;
}

/* ─── Loading overlay ─────────────────────────────────────────── */
.app-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
}
.app-loading-overlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.app-loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: app-spin 0.8s linear infinite;
}
.app-loading-text {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-muted);
  margin: 0;
}
@keyframes app-spin {
  to { transform: rotate(360deg); }
}

/* ─── Base ───────────────────────────────────────────────────── */
body {
  font-family: var(--font-sans);
  font-size: .9375rem;
  line-height: 1.5;
  min-height: 100vh;
  color: var(--text-primary);
  background-color: var(--bg-subtle);
  background-image:
    radial-gradient(ellipse 70% 40% at 50% -15%, rgba(13,148,136,.06), transparent),
    radial-gradient(ellipse 50% 30% at 100% 100%, rgba(249,115,22,.04), transparent),
    radial-gradient(ellipse 40% 25% at 0% 90%, rgba(99,102,241,.04), transparent),
    linear-gradient(180deg, #fafaf9 0%, #f5f5f4 100%);
  background-attachment: fixed;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  background: var(--bg-card);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  transition: box-shadow .2s ease, border-color .2s ease;
}
.card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.06);
  border-color: rgba(13,148,136,.15);
}

/* ─── Navbar ─────────────────────────────────────────────────── */
.app-navbar {
  position: relative;
  z-index: 1030;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226,232,240,.8);
  min-height: 64px;
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 1rem;
  color: #0f172a;
  transition: opacity .2s;
}
.app-logo:hover {
  opacity: .9;
  color: #0f172a;
}
.app-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-teal));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(13,148,136,.25);
}
.app-logo-text {
  letter-spacing: -0.02em;
}

.app-navbar-toggler {
  border: none;
  padding: 8px;
  border-radius: 10px;
  transition: background .15s;
}
.app-navbar-toggler:hover {
  background: #f1f5f9;
}
.app-navbar-toggler:focus {
  box-shadow: none;
}

.app-nav-links {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin-right: auto;
}
@media (min-width: 992px) {
  .app-nav-links {
    flex-direction: row;
    align-items: center;
    gap: 4px;
  }
}

.app-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: .875rem;
  font-weight: 500;
  text-decoration: none;
  color: #64748b;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.app-nav-link:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.app-nav-link.active {
  background: rgba(13,148,136,.1);
  color: var(--c-primary-h);
}
.app-nav-icon {
  flex-shrink: 0;
  opacity: .85;
}
.app-nav-link.active .app-nav-icon {
  opacity: 1;
}

.app-nav-link-btn {
  border: none;
  background: transparent;
  cursor: pointer;
}

/* ─── User menu dropdown ─────────────────────────────────────── */
.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  background: rgba(248,250,252,.9);
  border: 1px solid rgba(226,232,240,.9);
  border-radius: 12px;
  font-size: .875rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  transition: all .2s ease;
}
.user-menu-trigger:hover {
  background: rgba(241,245,249,.95);
  border-color: rgba(203,213,225,.9);
  color: #0f172a;
}
.user-menu-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-teal));
  color: #fff;
  font-size: .875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-menu-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-menu-chevron {
  flex-shrink: 0;
  opacity: .6;
  transition: transform .2s;
}
.user-menu-trigger[aria-expanded="true"] .user-menu-chevron {
  transform: rotate(180deg);
}

.user-menu-dropdown {
  border: none;
  border-radius: 14px;
  padding: 6px;
  min-width: 200px;
  box-shadow: 0 10px 40px rgba(0,0,0,.12), 0 4px 12px rgba(99,102,241,.08);
  z-index: 1060;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: .875rem;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s;
  text-align: left;
}
.user-menu-item:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.user-menu-item-logout:hover {
  background: #fef2f2;
  color: #dc2626;
}

/* ─── Password modal (modern) ─────────────────────────────────── */
.password-modal-content {
  border: none;
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,.25);
  overflow: hidden;
}

.password-modal-header {
  position: relative;
  padding: 1.75rem 1.5rem 1rem;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid rgba(226,232,240,.8);
}

.password-modal-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-teal));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.password-modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 .25rem;
  letter-spacing: -0.02em;
}

.password-modal-subtitle {
  font-size: .8125rem;
  color: #64748b;
  margin: 0;
}

.password-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.password-modal-close:hover {
  background: rgba(0,0,0,.06);
  color: #64748b;
}

.password-modal-body {
  padding: 1.5rem 1.5rem 1.75rem;
}

.password-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.password-form-group {
  position: relative;
}

.password-input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  font-size: .9375rem;
  color: #0f172a;
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
}
.password-input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}
.password-input::placeholder {
  color: transparent;
}

.password-label {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: .9375rem;
  color: #94a3b8;
  pointer-events: none;
  transition: all .2s ease;
}
.password-input:focus ~ .password-label,
.password-input:not(:placeholder-shown) ~ .password-label {
  top: -9px;
  transform: none;
  left: 12px;
  font-size: .75rem;
  color: var(--c-primary);
  background: #fff;
  padding: 0 4px;
}

.password-hint {
  display: block;
  font-size: .75rem;
  color: #94a3b8;
  margin-top: 6px;
  margin-left: 4px;
}

.password-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  margin-top: .5rem;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-teal));
  color: #fff;
  font-size: .9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
  box-shadow: 0 4px 14px rgba(13,148,136,.3);
}
.password-submit-btn:hover {
  opacity: .95;
  transform: translateY(-1px);
}
.password-submit-btn:active {
  transform: translateY(0);
}

.app-user-name {
  font-size: .8125rem;
  font-weight: 500;
  color: #64748b;
  max-width: 140px;
}

.app-nav-right {
  position: relative;
  z-index: 1020;
}
@media (min-width: 992px) {
  .app-nav-right {
    border-left: 1px solid rgba(226,232,240,.8);
    padding-left: 1rem;
    margin-left: .5rem;
  }
}

/* ─── Main content ───────────────────────────────────────────── */
.app-main {
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

/* ─── Page title ─────────────────────────────────────────────── */
.app-page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 1.25rem;
  line-height: 1.3;
}

/* Кнопка выхода */
.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: .8125rem;
  font-weight: 500;
  color: #475569;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.btn-logout:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

/* ─── Period bar ─────────────────────────────────────────────── */
.period-bar {
  border-radius: var(--card-radius);
  border: 1px solid var(--border);
  background: var(--bg-card) !important;
}
.period-bar .btn {
  font-size: .8125rem;
  font-weight: 500;
  border-radius: 10px;
  transition: all .15s ease;
}
.period-bar .btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
}
.period-bar .btn-primary:hover {
  background: var(--c-primary-h);
  border-color: var(--c-primary-h);
}
.period-bar .btn-outline-secondary {
  border-color: var(--border);
  color: var(--text-muted);
}
.period-bar .btn-outline-secondary:hover {
  background: var(--bg-subtle);
  border-color: var(--c-primary);
  color: var(--c-primary);
}
.period-date-input {
  width: 145px;
  border-radius: 10px;
  border-color: var(--border);
}
.period-date-input:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(13,148,136,.12);
}
.period-bar .badge {
  background: var(--bg-subtle) !important;
  border-color: var(--border) !important;
  color: var(--text-primary) !important;
  font-weight: 600;
}

/* ─── KPI cards ──────────────────────────────────────────────── */
.kpi-card {
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  border-radius: 4px 0 0 4px;
  background: var(--kpi-color, var(--c-primary));
}
.kpi-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--kpi-color, var(--c-primary)) 14%, white);
  color: var(--kpi-color, var(--c-primary));
}
.kpi-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text-primary);
}
.kpi-sub {
  font-size: .75rem;
  color: #9ca3af;
  margin-top: 4px;
}
.kpi-sub strong {
  color: #374151;
}
.kpi-compare {
  margin-top: 2px;
}
.metric-tooltip {
  cursor: help;
  opacity: 0.6;
  font-size: 0.75em;
  margin-left: 2px;
}
.metric-tooltip:hover {
  opacity: 1;
}

/* ─── Chart cards ────────────────────────────────────────────── */
.chart-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}
.chart-subtitle {
  font-size: .75rem;
  color: var(--text-muted);
}

/* ─── Funnel ─────────────────────────────────────────────────── */
.funnel-bar-wrap {
  height: 8px;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}
.funnel-bar {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--c-primary), var(--c-teal));
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.funnel-rate {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--c-primary), var(--c-teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.funnel-step {
  font-size: .8125rem;
  color: var(--text-muted);
}
.funnel-step strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ─── Events list ────────────────────────────────────────────── */
.event-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.event-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.event-label {
  flex: 1;
  font-size: .875rem;
  color: var(--text-primary);
  min-width: 0;
}
.event-code {
  font-size: .7rem;
  color: var(--text-muted);
}
.event-count {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}
.event-bar {
  width: 120px;
  flex-shrink: 0;
}

/* ─── Bot pills (dashboard) ──────────────────────────────────── */
.bot-pills-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bot-pills-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: .8125rem;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  width: fit-content;
}
.bot-pills-toggle:hover {
  background: #f3f4f6;
  color: #374151;
  border-color: #d1d5db;
}
.bot-pills-toggle-icon {
  font-size: .7rem;
  opacity: .8;
}
.bot-pills-panel {
  padding-top: 4px;
}
.bot-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.bot-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font-size: .8125rem;
  color: #374151;
  text-decoration: none;
  transition: all .2s cubic-bezier(.4,0,.2,1);
  min-width: 0;
}
.bot-pill:hover {
  border-color: var(--bot-color, #6366f1);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--bot-color, #6366f1) 12%, transparent);
  transform: translateY(-1px);
}
.bot-pill.active {
  color: var(--bot-color, #6366f1);
  border-color: var(--bot-color, #6366f1);
  background: color-mix(in srgb, var(--bot-color, #6366f1) 6%, white);
  font-weight: 600;
}
.bot-pill-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--bot-color, #6366f1), color-mix(in srgb, var(--bot-color, #6366f1) 70%, black));
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--bot-color, #6366f1) 35%, transparent);
}
.bot-pill-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.bot-pill-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  line-height: 1.2;
}
.bot-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .02em;
  vertical-align: middle;
}
.bot-status-badge-deleted {
  background: rgba(239, 68, 68, .14);
  color: #b91c1c;
  border: 1px solid rgba(239, 68, 68, .25);
}
.bot-pill-handle {
  font-size: .7rem;
  color: #9ca3af;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bot-pill.active .bot-pill-handle {
  color: color-mix(in srgb, var(--bot-color, #6366f1) 70%, #9ca3af);
}
.bot-pill.is-deleted {
  border-color: #fecaca;
  background: linear-gradient(135deg, #fff1f2 0%, #fff 100%);
}
.bot-pill.is-deleted .bot-pill-avatar {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  box-shadow: 0 1px 3px rgba(239, 68, 68, .35);
}
.bot-pill.is-deleted .bot-pill-name::before {
  content: "⚠ ";
  color: #dc2626;
}
.bot-pill.is-deleted .bot-pill-handle {
  color: #dc2626;
  font-weight: 600;
}
.bot-pill-check {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bot-color, #6366f1);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
}

/* ─── Bot selector ────────────────────────────────────────────── */
.bot-selector-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-size: .875rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.bot-selector-trigger:hover {
  background: linear-gradient(135deg, #ccfbf1 0%, #99f6e4 100%);
  border-color: #5eead4;
  color: var(--c-primary-h);
  box-shadow: 0 2px 8px rgba(13,148,136,.15);
}
.bot-selector-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--bot-color, #6366f1);
  color: #fff;
  font-size: .875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px color-mix(in srgb, var(--bot-color, #6366f1) 40%, transparent);
}
.bot-selector-label {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bot-selector-chevron {
  flex-shrink: 0;
  opacity: .6;
  transition: transform .2s;
}
.bot-selector-trigger[aria-expanded="true"] .bot-selector-chevron {
  transform: rotate(180deg);
}

.bot-selector-menu {
  border: none;
  border-radius: 14px;
  padding: 6px;
  min-width: 220px;
  box-shadow: 0 10px 40px rgba(0,0,0,.12), 0 4px 12px rgba(99,102,241,.08);
  z-index: 1060;
}

.bot-selector-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: #374151;
  font-size: .875rem;
  transition: all .15s ease;
}
.bot-selector-item:hover {
  background: #f8fafc;
  color: #111827;
}
.bot-selector-item.active {
  background: rgba(13,148,136,.1);
  color: var(--c-primary-h);
}
.bot-selector-item-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bot-color, #6366f1);
  color: #fff;
  font-size: .9375rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.bot-selector-item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bot-selector-item-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bot-selector-item-meta {
  font-size: .7rem;
  color: #9ca3af;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bot-selector-item.active .bot-selector-item-meta {
  color: var(--c-primary-h);
}
.bot-selector-item.is-deleted {
  background: linear-gradient(135deg, #fff1f2 0%, #fff 100%);
  border: 1px solid #fecaca;
}
.bot-selector-item.is-deleted .bot-selector-item-avatar {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
}
.bot-selector-item.is-deleted .bot-selector-item-name::before {
  content: "⚠ ";
  color: #dc2626;
}
.bot-selector-item.is-deleted .bot-selector-item-meta {
  color: #dc2626;
  font-weight: 600;
}
.bot-selector-check {
  flex-shrink: 0;
  color: var(--c-primary);
}

/* ─── Bot indicator (legacy) ──────────────────────────────────── */
.bot-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #22c55e;
  flex-shrink: 0;
}

canvas {
  max-width: 100%;
}

/* ─── Bootstrap overrides (маркетинговый стиль) ───────────────── */
.btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
}
.btn-primary:hover {
  background: var(--c-primary-h);
  border-color: var(--c-primary-h);
}

.table {
  --bs-table-border-color: var(--border);
}
.table thead th {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom-width: 1px;
}

.alert {
  border-radius: 12px;
  border: none;
}
.alert-success {
  background: rgba(16,185,129,.12);
  color: #047857;
}
.alert-danger {
  background: rgba(239,68,68,.1);
  color: #b91c1c;
}

/* ─── Mobile (≤ 575px) ───────────────────────────────────────── */
@media (max-width: 575px) {
  /* Меньше отступы у карточек */
  .card-body {
    padding: 1rem;
  }

  /* KPI — уменьшаем число */
  .kpi-value {
    font-size: 1.625rem;
  }
  .kpi-icon {
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
  }

  /* Period bar — датапикеры на всю ширину */
  .period-date-input {
    width: 100%;
    flex: 1 1 120px;
  }

  /* Скрываем прогресс-бар в event-row на очень узких экранах */
  .event-bar {
    display: none;
  }

  /* Funnel rate чуть меньше */
  .funnel-rate {
    font-size: 1.75rem;
  }

  /* Charts — уменьшаем высоту */
  canvas[height="110"] {
    height: 180px !important;
  }
  canvas[height="120"] {
    height: 180px !important;
  }

  /* Navbar collapse — добавляем разделитель */
  #navMain {
    border-top: 1px solid rgba(226,232,240,.6);
    margin-top: 8px;
    padding-top: 8px;
  }
  .app-nav-link {
    width: 100%;
    padding: 10px 14px;
  }
}

/* ─── Tablet (576–991px) ─────────────────────────────────────── */
@media (min-width: 576px) and (max-width: 991px) {
  .period-date-input {
    width: 130px;
  }
  .event-bar {
    width: 80px;
  }
}

/* ─── Рассылки (таблица кампаний) ─────────────────────────────── */
.mailings-table-card {
  border-radius: var(--card-radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}
.mailings-table-card .table-responsive {
  max-height: none;
}
.mailings-table {
  margin: 0;
  font-size: 0.875rem;
}
.mailings-table thead th {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: linear-gradient(180deg, #fafaf9 0%, #f5f5f4 100%);
  border-bottom: 1px solid var(--border);
  padding-top: 1rem;
  padding-bottom: 1rem;
  white-space: nowrap;
}
.mailings-table tbody tr {
  border-bottom: 1px solid rgba(231, 229, 228, 0.9);
  transition: background-color 0.15s ease;
}
.mailings-table tbody tr:hover {
  background: rgba(13, 148, 136, 0.04);
}
.mailings-table tbody tr:last-child {
  border-bottom: none;
}
.mailings-table tbody td {
  vertical-align: middle;
  padding-top: 0.95rem;
  padding-bottom: 0.95rem;
}
.mailings-id {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.mailings-campaign-head {
  padding: 0.5rem 0.65rem 0.55rem 0.75rem;
  margin-bottom: 0.6rem;
  background: linear-gradient(
    135deg,
    rgba(13, 148, 136, 0.09),
    rgba(99, 102, 241, 0.05)
  );
  border: 1px solid rgba(13, 148, 136, 0.16);
  border-radius: 10px;
  border-left: 4px solid var(--c-primary);
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
}
.mailings-campaign-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  line-height: 1.35;
}
.mailings-time-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.35rem;
}
.mailings-time-kind {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  width: fit-content;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  line-height: 1.2;
}
.mailings-time-kind--start {
  color: #0d9488;
  background: rgba(13, 148, 136, 0.12);
}
.mailings-time-kind--plan {
  color: #b45309;
  background: rgba(245, 158, 11, 0.14);
}
.mailings-time-block {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  line-height: 1.25;
}
.mailings-time-clock {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.mailings-time-sub {
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}
.mailings-time-follow {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(231, 229, 228, 0.95);
}
.mailings-time-follow + .mailings-time-follow--duration {
  border-top: none;
  margin-top: 0.35rem;
  padding-top: 0;
}
.mailings-time-kind--end {
  color: #57534e;
  background: rgba(245, 245, 244, 0.95);
}
.mailings-time-kind--duration {
  color: #44403c;
  background: rgba(231, 229, 228, 0.35);
}
.mailings-time-clock--compact {
  font-size: 0.9375rem;
}
.mailings-duration-val {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #44403c;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  background: linear-gradient(180deg, #fafaf9, #f5f5f4);
  border: 1px solid rgba(231, 229, 228, 0.95);
  display: inline-block;
}
.mailings-duration-val--running {
  color: #1d4ed8;
  background: linear-gradient(180deg, #eff6ff, #e0e7ff);
  border-color: rgba(59, 130, 246, 0.28);
}
.mailings-duration-empty {
  color: #a8a29e;
  font-weight: 500;
}
.mailings-time-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: #57534e;
  background: rgba(245, 245, 244, 0.95);
  border: 1px solid rgba(231, 229, 228, 0.8);
  border-radius: 8px;
  padding: 0.25rem 0.55rem;
  width: fit-content;
  max-width: 100%;
  line-height: 1.35;
}
.mailings-time-chip--schedule::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-amber);
  flex-shrink: 0;
}
.mailings-time-chip--start::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-primary);
  flex-shrink: 0;
}
.mailings-time-end {
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: #44403c;
  line-height: 1.45;
}
.mailings-time-end--empty {
  color: #a8a29e;
  font-weight: 500;
}
.mailings-col-bots {
  vertical-align: top;
  min-width: 0;
  max-width: 18rem;
}
.mailings-col-bots-head abbr {
  text-decoration: none;
  border-bottom: 1px dotted rgba(120, 113, 108, 0.45);
  cursor: help;
}
.mailings-bots-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.35rem 0.4rem;
  max-width: 100%;
}
.mailings-bot-chip {
  display: inline-block;
  max-width: 100%;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
  padding: 0.28rem 0.55rem;
  border-radius: 8px;
  color: #57534e;
  background: rgba(245, 245, 244, 0.95);
  border: 1px solid rgba(231, 229, 228, 0.95);
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.mailings-bot-chip--current {
  color: var(--c-primary-h);
  background: rgba(13, 148, 136, 0.11);
  border-color: rgba(13, 148, 136, 0.28);
  font-weight: 600;
}
.mailings-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
}
.mailings-status--completed {
  background: linear-gradient(180deg, #ecfdf5, #d1fae5);
  color: #047857;
  border-color: rgba(16, 185, 129, 0.25);
}
.mailings-status--scheduled {
  background: linear-gradient(180deg, #fffbeb, #fef3c7);
  color: #b45309;
  border-color: rgba(245, 158, 11, 0.3);
}
.mailings-status--running {
  background: linear-gradient(180deg, #eff6ff, #dbeafe);
  color: #1d4ed8;
  border-color: rgba(59, 130, 246, 0.28);
}
.mailings-status--draft {
  background: #f5f5f4;
  color: var(--text-muted);
  border-color: var(--border);
}
.mailings-metric {
  font-variant-numeric: tabular-nums;
  color: #44403c;
}
.mailings-metric--accent {
  font-weight: 700;
  color: var(--text-primary);
}
.mailings-metric--fail {
  color: #dc2626;
  font-weight: 600;
}
.mailings-delivery {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.mailings-delivery-track {
  flex: 1;
  min-width: 48px;
  height: 7px;
  border-radius: 999px;
  background: #e7e5e4;
  overflow: hidden;
}
.mailings-delivery-fill {
  height: 100%;
  border-radius: inherit;
  min-width: 2px;
  transition: width 0.35s ease;
}
.mailings-delivery-pct {
  font-size: 0.8125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 2.5rem;
  text-align: right;
}
.mailings-empty {
  padding: 3rem 2rem !important;
  text-align: center;
  background: linear-gradient(180deg, rgba(250, 250, 249, 0.6), #fff);
}
.mailings-empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.12), rgba(99, 102, 241, 0.08));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  border: 1px solid rgba(231, 229, 228, 0.9);
}
.mailings-empty-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}
.mailings-empty-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 320px;
  margin: 0 auto;
}
@media (max-width: 767px) {
  .mailings-table thead th {
    font-size: 0.625rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    white-space: normal;
    line-height: 1.25;
    vertical-align: bottom;
  }
  .mailings-table thead th .metric-tooltip {
    vertical-align: 0.05em;
  }
  .mailings-table tbody td {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  .mailings-table tbody td.mailings-col-bots {
    max-width: none;
    min-width: 9.5rem;
  }
  .mailings-bots-wrap {
    gap: 0.3rem;
  }
  .mailings-bot-chip {
    font-size: 0.6875rem;
    padding: 0.22rem 0.45rem;
    border-radius: 6px;
  }
  .mailings-table .mailings-delivery {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
  }
  .mailings-table .mailings-delivery-pct {
    text-align: left;
    min-width: 0;
  }
  .mailings-table .mailings-delivery-track {
    min-width: 0;
    width: 100%;
  }
  .mailings-status {
    font-size: 0.6875rem;
    padding: 0.28rem 0.5rem;
    white-space: normal;
    text-align: center;
    max-width: 7.5rem;
  }
}

/* ─── AI insights report (Markdown → HTML) ─────────────────────── */
.ai-insights-toolbar {
  background: linear-gradient(180deg, rgba(250, 250, 249, 0.95), #fff);
  border-color: var(--border) !important;
}
.ai-insights-body {
  background: #fff;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.ai-insights-report {
  font-size: 0.96875rem;
  line-height: 1.7;
  color: var(--text-primary);
  max-width: 48rem;
  margin: 0 auto;
}
.ai-insights-report h2 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 2rem;
  margin-bottom: 0.85rem;
  padding: 0.35rem 0 0.5rem 0.85rem;
  border-left: 4px solid var(--c-primary);
  border-bottom: none;
  color: #0f766e;
  scroll-margin-top: 5.5rem;
}
.ai-insights-report h2:first-child {
  margin-top: 0;
}
.ai-insights-report h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.55rem;
  color: #292524;
  scroll-margin-top: 5rem;
}
.ai-insights-report h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 1.15rem;
  margin-bottom: 0.45rem;
}
.ai-insights-report ul,
.ai-insights-report ol {
  padding-left: 1.35rem;
  margin-bottom: 0.9rem;
}
.ai-insights-report li {
  margin-bottom: 0.35rem;
}
.ai-insights-report li::marker {
  color: var(--c-primary);
}
.ai-insights-report ul ul,
.ai-insights-report ol ol,
.ai-insights-report ul ol,
.ai-insights-report ol ul {
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
}
.ai-insights-report p {
  margin-bottom: 0.85rem;
}
.ai-insights-report p:last-child {
  margin-bottom: 0;
}
.ai-insights-report strong {
  font-weight: 600;
  color: #1c1917;
}
.ai-insights-report a {
  color: var(--c-primary-h);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ai-insights-report a:hover {
  color: var(--c-primary);
}
.ai-insights-report hr {
  border: 0;
  height: 1px;
  margin: 1.75rem 0;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.ai-insights-report blockquote {
  margin: 1rem 0 1.25rem;
  padding: 0.65rem 1rem 0.65rem 1rem;
  border-left: 3px solid var(--c-amber);
  background: rgba(245, 158, 11, 0.08);
  border-radius: 0 10px 10px 0;
  color: #57534e;
  font-size: 0.9em;
}
.ai-insights-report blockquote p:last-child {
  margin-bottom: 0;
}
.ai-insights-report code {
  font-size: 0.88em;
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  background: rgba(13, 148, 136, 0.08);
  color: #0f766e;
  padding: 0.12em 0.4em;
  border-radius: 5px;
  border: 1px solid rgba(13, 148, 136, 0.15);
}
.ai-insights-report pre {
  background: linear-gradient(165deg, #1c1917 0%, #292524 100%);
  color: #e7e5e4;
  padding: 1.1rem 1.15rem;
  border-radius: 12px;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.55;
  margin-bottom: 1.15rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.ai-insights-report pre code {
  background: transparent;
  border: 0;
  color: inherit;
  padding: 0;
  font-size: inherit;
}
.ai-insights-report table {
  width: 100%;
  min-width: 280px;
  font-size: 0.875rem;
  margin-bottom: 1.15rem;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.ai-insights-report thead th {
  background: linear-gradient(180deg, #fafaf9, #f5f5f4);
}
.ai-insights-report tbody tr:nth-child(even) {
  background: rgba(250, 250, 249, 0.65);
}
.ai-insights-report th,
.ai-insights-report td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
}
.ai-insights-report th:last-child,
.ai-insights-report td:last-child {
  border-right: none;
}
.ai-insights-report tbody tr:last-child td {
  border-bottom: none;
}
.ai-insights-report th {
  font-weight: 600;
  color: #44403c;
}

@media print {
  .app-navbar,
  .app-loading-overlay,
  .ai-insights-no-print,
  .bot-pills-wrap,
  #passwordModal {
    display: none !important;
  }
  body {
    background: #fff !important;
  }
  .app-main {
    padding: 0.5rem 1rem !important;
    max-width: 100% !important;
  }
  .ai-insights-card {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
  }
  .ai-insights-toolbar {
    display: none !important;
  }
  .ai-insights-body {
    padding: 1rem !important;
  }
  .ai-insights-report {
    max-width: none;
    font-size: 11pt;
    line-height: 1.5;
  }
  .ai-insights-report h2 {
    scroll-margin-top: 0;
    border-left-color: #0d9488;
    page-break-after: avoid;
  }
  .ai-insights-report pre {
    white-space: pre-wrap;
    word-break: break-word;
  }
}
