/**
 * Company Analytics — token-baserad basstil (dashboard-aligned)
 * Ingen lila AI-gradient. Används med company-theme-tokens.css
 */

/* Samma bakgrund som övriga företagssidor (följer theme-tokens i dark mode) */
body.company-page {
  background: var(--company-bg-subtle, #f8fafc) !important;
  background-color: var(--company-bg-subtle, #f8fafc) !important;
  background-image: none !important;
  color: var(--company-text, #0f172a);
}

.analytics-page {
  max-width: var(--arv-shell-max, 1600px);
  margin: 0 auto;
  padding: 5.5rem 1.25rem 6rem;
  color: var(--company-text, #0f172a);
  background: transparent;
  min-height: 100vh;
}

.analytics-hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  margin-bottom: 1.5rem;
  padding: 1.75rem 1.5rem 1.5rem;
  border-radius: 1rem;
  border: 1px solid var(--company-border, #e2e8f0);
  background: var(--company-bg, #fff);
}

.analytics-hero--bg {
  min-height: 15.5rem;
  padding: 2rem 1.75rem 1.75rem;
  display: flex;
  align-items: center;
  background: transparent;
}

.analytics-hero--bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background-color: #e8edf2;
  background-image: url('/images/company-analytics-hero-bg.jpg?v=20260823');
  background-size: cover;
  background-position: right center;
  background-repeat: no-repeat;
  filter: grayscale(100%);
  z-index: 0;
}

.analytics-hero--bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    rgba(248, 250, 252, 0.97) 0%,
    rgba(248, 250, 252, 0.92) 28%,
    rgba(248, 250, 252, 0.55) 52%,
    rgba(248, 250, 252, 0.12) 72%,
    rgba(248, 250, 252, 0.02) 100%
  );
  z-index: 1;
}

.analytics-hero__content {
  position: relative;
  z-index: 2;
  max-width: min(34rem, 100%);
}

.analytics-hero h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 2.5vw, 1.875rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--company-text, #0f172a);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.analytics-hero h1 i {
  color: var(--company-text-muted, #64748b);
  font-size: 0.9em;
}

.analytics-hero p {
  margin: 0;
  color: var(--company-text-muted, #64748b);
  font-size: 0.95rem;
  line-height: 1.45;
  max-width: 32rem;
}

.analytics-note {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--company-border, #e2e8f0);
  color: var(--company-text-muted, #64748b);
  font-size: 0.75rem;
  font-weight: 500;
  backdrop-filter: blur(6px);
}

/* Plan banner */
.analytics-plan-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  padding: 0.9rem 1.1rem;
  background: var(--company-bg, #fff);
  border: 1px solid var(--company-border, #e2e8f0);
  border-radius: 12px;
}

.analytics-plan-banner strong {
  display: block;
  font-size: 0.95rem;
  color: var(--company-text, #0f172a);
}

.analytics-plan-banner span {
  font-size: 0.85rem;
  color: var(--company-text-muted, #64748b);
}

.analytics-plan-banner .btn-upgrade {
  appearance: none;
  border: 1px solid var(--company-cta, #0f172a);
  background: var(--company-cta, #0f172a);
  color: #fff;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.analytics-plan-banner .btn-upgrade:hover {
  background: var(--company-cta-hover, #1e293b);
}

/* Time selector */
.time-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding: 0.5rem;
  background: var(--company-bg, #fff);
  border: 1px solid var(--company-border, #e2e8f0);
  border-radius: 12px;
}

.time-selector--in-hero {
  margin: 1.1rem 0 0;
  margin-bottom: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.time-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--company-text-muted, #64748b);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.time-btn:hover:not(:disabled) {
  background: var(--company-bg-subtle, #f8fafc);
  color: var(--company-text, #0f172a);
}

.time-btn.active {
  background: var(--company-cta, #0f172a);
  color: #fff;
}

.time-btn:disabled,
.time-btn.is-locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.time-selector-mobile {
  display: none;
  width: 100%;
  min-height: 44px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 500;
  border: 1px solid var(--company-border, #e2e8f0);
  border-radius: 10px;
  background: var(--company-bg, #fff);
  color: var(--company-text, #0f172a);
}

/* KPI cards */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--company-bg, #fff);
  border: 1px solid var(--company-border, #e2e8f0);
  border-radius: 14px;
  padding: 1.1rem 1.15rem;
  position: relative;
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.stat-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--company-bg-subtle, #f8fafc);
  color: var(--company-text, #0f172a);
  border: 1px solid var(--company-border, #e2e8f0);
  font-size: 0.95rem;
}

.stat-trend {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--company-bg-subtle, #f8fafc);
  color: var(--company-text-muted, #64748b);
}

.stat-trend.trend-up {
  color: var(--company-success, #10b981);
  background: #ecfdf5;
}

.stat-trend.trend-down {
  color: var(--company-danger, #ef4444);
  background: #fef2f2;
}

.stat-number {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: 0.25rem;
}

.stat-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--company-text, #0f172a);
}

.stat-change {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--company-text-muted, #64748b);
}

/* Charts */
.charts-section {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.chart-card,
.performance-card,
.insights-section,
.export-section {
  background: var(--company-bg, #fff);
  border: 1px solid var(--company-border, #e2e8f0);
  border-radius: 14px;
  padding: 1.15rem;
  position: relative;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.chart-title,
.performance-title,
.insights-title,
.export-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--company-text, #0f172a);
}

.chart-actions {
  display: flex;
  gap: 0.35rem;
}

.chart-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--company-border, #e2e8f0);
  background: var(--company-bg, #fff);
  border-radius: 10px;
  cursor: pointer;
  color: var(--company-text-muted, #64748b);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chart-btn:hover {
  color: var(--company-text, #0f172a);
  border-color: #cbd5e1;
}

.chart-container {
  position: relative;
  height: 280px;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.35rem;
  text-align: center;
  color: var(--company-text-muted, #64748b);
  font-size: 0.9rem;
  padding: 1rem;
  z-index: 2;
  background: color-mix(in srgb, var(--company-bg, #fff) 92%, transparent);
  border-radius: 10px;
}

.chart-empty.is-visible {
  display: flex;
}

.chart-empty strong {
  color: var(--company-text, #0f172a);
}

/* Performance */
.performance-section {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.performance-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.performance-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--company-text, #0f172a);
}

.performance-bar {
  background: var(--company-bg-subtle, #f8fafc);
  border: 1px solid var(--company-border, #e2e8f0);
  border-radius: 999px;
  height: 8px;
  margin-bottom: 0.65rem;
  overflow: hidden;
}

.performance-fill {
  background: var(--company-cta, #0f172a);
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

.performance-details {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--company-text-muted, #64748b);
}

/* Insights */
.insights-section {
  margin-bottom: 1.5rem;
}

.insights-header {
  margin-bottom: 1rem;
}

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

.insight-card {
  background: var(--company-bg-subtle, #f8fafc);
  border: 1px solid var(--company-border, #e2e8f0);
  border-left: 3px solid var(--company-cta, #0f172a);
  border-radius: 12px;
  padding: 1rem;
}

.insight-card.success {
  border-left-color: var(--company-success, #10b981);
}

.insight-card.warning {
  border-left-color: var(--company-warning, #ca8a04);
}

.insight-card.info {
  border-left-color: #64748b;
}

.insight-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.insight-icon {
  color: var(--company-text-muted, #64748b);
}

.insight-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.insight-description {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--company-text-muted, #64748b);
}

.insight-action {
  appearance: none;
  border: 1px solid var(--company-border, #e2e8f0);
  background: var(--company-bg, #fff);
  color: var(--company-text, #0f172a);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 40px;
}

.insight-action:hover {
  border-color: #cbd5e1;
}

.insights-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--company-text-muted, #64748b);
  font-size: 0.9rem;
}

/* Export */
.export-section {
  margin-bottom: 1rem;
}

.export-description {
  margin: 0.4rem 0 1rem;
  color: var(--company-text-muted, #64748b);
  font-size: 0.9rem;
}

.export-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.export-btn {
  appearance: none;
  border: 1px solid var(--company-border, #e2e8f0);
  background: var(--company-bg, #fff);
  color: var(--company-text, #0f172a);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.export-btn-primary {
  background: var(--company-cta, #0f172a);
  border-color: var(--company-cta, #0f172a);
  color: #fff;
}

.export-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Locked overlay */
.analytics-lock-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.25rem;
  text-align: center;
  background: rgba(248, 250, 252, 0.94);
  backdrop-filter: blur(4px);
  border-radius: 14px;
  cursor: pointer;
}

.analytics-lock-overlay i {
  font-size: 1.5rem;
  color: var(--company-text-muted, #64748b);
}

.analytics-lock-overlay h4 {
  margin: 0;
  font-size: 1rem;
}

.analytics-lock-overlay p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--company-text-muted, #64748b);
}

.analytics-lock-overlay .btn-upgrade {
  margin-top: 0.35rem;
}

/* Upgrade modal */
.analytics-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.analytics-modal {
  width: min(520px, 100%);
  background: var(--company-bg, #fff);
  border-radius: 16px;
  border: 1px solid var(--company-border, #e2e8f0);
  padding: 1.35rem;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
}

.analytics-modal h3 {
  margin: 0 0 0.4rem;
  font-size: 1.2rem;
}

.analytics-modal p {
  margin: 0 0 1rem;
  color: var(--company-text-muted, #64748b);
  font-size: 0.9rem;
  line-height: 1.45;
}

.analytics-modal-actions {
  display: flex;
  gap: 0.6rem;
}

.analytics-modal-actions button {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--company-border, #e2e8f0);
  background: var(--company-bg-subtle, #f8fafc);
  color: var(--company-text, #0f172a);
}

.analytics-modal-actions .btn-primary {
  flex: 1.4;
  background: var(--company-cta, #0f172a);
  border-color: var(--company-cta, #0f172a);
  color: #fff;
}

@media (max-width: 1023px) {
  .stats-overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .charts-section,
  .performance-section,
  .insights-grid,
  .export-buttons {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .analytics-page {
    padding: 5rem 1rem calc(5.5rem + env(safe-area-inset-bottom));
  }

  .analytics-hero--bg {
    min-height: 0;
    padding: 1.25rem 1.1rem 1.15rem;
  }

  .analytics-hero--bg::before {
    background-position: 72% center;
    opacity: 0.55;
  }

  .analytics-hero--bg::after {
    background: linear-gradient(
      180deg,
      rgba(248, 250, 252, 0.94) 0%,
      rgba(248, 250, 252, 0.9) 55%,
      rgba(248, 250, 252, 0.82) 100%
    );
  }

  .analytics-hero__content {
    max-width: 100%;
  }

  .time-btn {
    display: none;
  }

  .time-selector {
    display: block;
    padding: 0.75rem;
  }

  .time-selector-mobile {
    display: block;
  }

  .time-selector-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--company-text-muted, #64748b);
    margin-bottom: 0.4rem;
  }
}

@media (min-width: 769px) {
  .time-selector-label {
    display: none;
  }
}

/* Dark mode hero */
html.dark-mode .analytics-hero--bg::after,
body.dark-mode .analytics-hero--bg::after {
  background: linear-gradient(
    100deg,
    rgba(15, 23, 42, 0.96) 0%,
    rgba(15, 23, 42, 0.9) 30%,
    rgba(15, 23, 42, 0.55) 55%,
    rgba(15, 23, 42, 0.2) 75%,
    rgba(15, 23, 42, 0.08) 100%
  );
}

html.dark-mode .analytics-note,
body.dark-mode .analytics-note,
html.dark-mode .time-selector--in-hero,
body.dark-mode .time-selector--in-hero {
  background: rgba(30, 41, 59, 0.92);
  border-color: #334155;
}

html.dark-mode .analytics-hero,
body.dark-mode .analytics-hero {
  border-color: #334155;
}
