.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px 20px;
  background: #fff;
}

.topbar.chat-mode {
  padding-bottom: 16px;
  border-bottom: 1px solid #eef2f7;
}

.title-group {
  min-width: 0;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 10px;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(var(--theme-primary-rgb, 58, 124, 165), 0.12), rgba(59, 130, 246, 0.08));
  color: var(--theme-primary-active);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.topbar h1 {
  color: #0f172a;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.2;
}

.topbar p {
  margin-top: 6px;
  max-width: 720px;
  color: #64748b;
  font-size: 14px;
  line-height: 1.5;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.range-combo {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.range-shell {
  height: 42px;
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid #d7e0ea;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.range-meta {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-right: 1px solid #e2e8f0;
  color: #334155;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.range-meta .mdi {
  color: var(--theme-primary);
}

.range-tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding-left: 3px;
}

.range-tabs button {
  height: 34px;
  min-width: 54px;
  padding: 0 14px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.range-tabs button:hover:not(.active) {
  background: #f1f5f9;
  color: #334155;
}

.range-tabs button.active {
  background: var(--theme-primary);
  color: #fff;
  box-shadow: 0 6px 14px rgba(var(--theme-primary-rgb, 58, 124, 165), .18);
}

.custom-range-wrap {
  position: relative;
}

.custom-range-btn {
  height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid #d7e0ea;
  border-radius: 4px;
  background: #fff;
  color: #334155;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.custom-range-btn:hover,
.custom-range-btn.active {
  border-color: rgba(var(--theme-primary-rgb, 58, 124, 165), .34);
  background: #f5fbff;
  color: var(--theme-primary-active);
}

.calendar-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 336px;
  z-index: 40;
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid #d7e0ea;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, .16);
}

.calendar-popover header,
.calendar-popover footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.calendar-popover header strong {
  color: #0f172a;
  font-size: 15px;
}

.calendar-popover header button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #64748b;
}

.date-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.date-fields label {
  display: grid;
  gap: 6px;
}

.date-fields span {
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
}

.date-fields input {
  width: 100%;
  height: 38px;
  padding: 0 9px;
  border: 1px solid #d7e0ea;
  border-radius: 4px;
  color: #0f172a;
  font-size: 13px;
}

.ghost-btn,
.apply-btn {
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 750;
}

.ghost-btn {
  border: 1px solid #d7e0ea;
  background: #fff;
  color: #334155;
}

.apply-btn {
  border: 0;
  background: var(--theme-primary);
  color: #fff;
}

.apply-btn:disabled {
  cursor: not-allowed;
  background: #cbd5e1;
}

.kpi-chips {
  display: flex;
  gap: 10px;
}

.detail-alert-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-alert-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  background: #fff7ed;
  color: #ea580c;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.detail-alert-pill i {
  font-size: 14px;
}

.detail-alert-pill.neutral {
  border-color: #d7e0ea;
  background: #f8fafc;
  color: #334155;
}

.detail-alert-pill.success {
  border-color: var(--success-line);
  background: var(--success-soft);
  color: var(--success);
}

.detail-alert-pill.danger {
  border-color: #fecaca;
  background: #fff1f2;
  color: #dc2626;
}

.topbar-toolset {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  min-width: 0;
}

.topbar-icon-btn {
  position: relative;
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #111827;
  font-size: 23px;
  line-height: 1;
  transition:
    color 160ms var(--ease),
    background 160ms var(--ease);
}

.topbar-icon-btn:hover {
  background: var(--theme-primary-light-9);
  color: var(--theme-primary-active);
}

.notification-badge {
  position: absolute;
  top: 2px;
  right: 1px;
  min-width: 13px;
  height: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 8px;
  font-weight: 850;
  line-height: 1;
  box-shadow: 0 5px 10px rgba(239, 68, 68, .22);
}

.company-switcher {
  max-width: min(220px, 28vw);
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 16px;
  border: 1px solid #edf1f5;
  border-radius: 999px;
  background: #fff;
  color: #111827;
  box-shadow:
    0 1px 2px rgba(15, 23, 42, .04),
    inset 0 1px 0 rgba(255, 255, 255, .92);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition:
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease),
    color 160ms var(--ease);
}

.company-switcher:hover {
  border-color: rgba(var(--theme-primary-rgb, 58, 124, 165), .26);
  color: var(--theme-primary-active);
  box-shadow: 0 6px 16px rgba(var(--theme-primary-rgb, 58, 124, 165), .08);
}

.company-switcher span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company-switcher .mdi {
  flex: 0 0 auto;
  color: #64748b;
  font-size: 16px;
}

.kpi-chip {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: 2px 10px;
  padding: 8px 16px;
  border-radius: 4px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--chip-color) 8%, #fff), color-mix(in srgb, var(--chip-color) 3%, #f8fafc));
  border: 1px solid color-mix(in srgb, var(--chip-color) 18%, #e2e8f0);
}

.chip-value {
  grid-row: 1 / 3;
  align-self: center;
  color: #0f172a;
  font-size: 22px;
  font-weight: 850;
  line-height: 1;
}

.chip-value small {
  font-size: 13px;
  font-weight: 700;
  margin-left: 2px;
}

.chip-label {
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
}

.chip-delta {
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
}

.chip-delta.up { color: var(--success); }
.chip-delta.down { color: #f59e0b; }

.topbar-spacer {
  flex: 1;
  min-width: 0;
}

.create-top-btn {
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: var(--theme-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(var(--theme-primary-rgb, 58, 124, 165), 0.18);
  white-space: nowrap;
}

.create-top-btn:hover {
  background: var(--theme-primary-active);
}

@media (max-width: 1120px) {
  .range-combo {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 960px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions,
  .search-wrap,
  .search-wrap.wide,
  .topbar-toolset,
  .detail-alert-strip,
  .month-chip,
  .qa-filter,
  .new-question-btn {
    width: 100%;
  }

  .range-combo {
    justify-content: stretch;
  }

  .topbar-toolset {
    justify-content: flex-end;
  }

  .range-shell {
    flex: 1;
  }

  .range-meta {
    flex: 1;
  }

  .custom-range-btn {
    width: 100%;
    justify-content: center;
  }

  .calendar-popover {
    right: auto;
    left: 0;
  }
}

@media (max-width: 760px) {
  .title-group {
    padding-right: 56px;
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 14px;
    padding: 16px 16px 14px;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .kpi-chips {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .kpi-chip {
    min-width: 118px;
    padding: 8px 12px;
  }

  .chip-label,
  .chip-delta {
    white-space: nowrap;
  }

  .topbar-toolset {
    gap: 10px;
  }

  .company-switcher {
    flex: 1 1 auto;
    max-width: none;
    justify-content: space-between;
  }

  .range-combo {
    display: grid;
    gap: 8px;
  }

  .range-shell {
    height: auto;
    display: grid;
    gap: 4px;
  }

  .range-meta {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid #e2e8f0;
    justify-content: center;
  }

  .range-tabs {
    width: 100%;
    padding-left: 0;
  }

  .range-tabs button {
    flex: 1;
    padding: 0 8px;
  }

  .calendar-popover {
    width: min(336px, calc(100vw - 32px));
  }

  .date-fields {
    grid-template-columns: 1fr;
  }
}
