/**
 * Bharat Swasthya Setu — B2B portals (P5 + P7 polish)
 * MR field CRM + Distributor commerce. Depends on tokens.css.
 */

[data-portal="mr"],
[data-portal="distributor"] {
  font-family: var(--font-sans, "Plus Jakarta Sans", system-ui, sans-serif);
  color: var(--color-text-primary, #0f172a);
}

[data-portal="mr"] {
  --portal-accent: #1e88c7;
  --portal-accent-soft: rgba(2, 132, 199, 0.12);
}

[data-portal="distributor"] {
  --portal-accent: #0d9f6e;
  --portal-accent-soft: rgba(13, 159, 110, 0.12);
}

[data-portal="mr"] body,
body:has([data-portal="mr"]),
html[data-portal="mr"] body {
  background:
    radial-gradient(ellipse 55% 40% at 0% 0%, rgba(2, 132, 199, 0.08) 0%, transparent 55%),
    var(--color-bg-app, #f4f7fb);
}

[data-portal="distributor"] body,
html[data-portal="distributor"] body {
  background:
    radial-gradient(ellipse 55% 40% at 0% 0%, rgba(13, 159, 110, 0.08) 0%, transparent 55%),
    var(--color-bg-app, #f4f7fb);
}

html[data-portal="mr"] body,
html[data-portal="distributor"] body {
  font-family: var(--font-sans, "Plus Jakarta Sans", system-ui, sans-serif);
  color: var(--color-text-primary, #0f172a);
  min-height: 100vh;
}

/* ── Shell ── */
.b2b-shell-header {
  background: linear-gradient(
    135deg,
    var(--color-chrome) 0%,
    var(--color-chrome-deep) 100%
  );
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--color-chrome-text);
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-chrome-border);
  box-shadow: var(--shadow-2, 0 4px 16px rgba(15, 23, 42, 0.06));
  margin-bottom: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.b2b-shell-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.b2b-shell-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.b2b-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  font-size: 1.05rem;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.b2b-brand.bss-shell__brand {
  color: #fff;
}

.b2b-brand .bss-shell__brand-logo {
  width: 34px;
  height: 34px;
}

.b2b-brand .bss-shell__brand-name {
  max-width: min(240px, 40vw);
  color: inherit;
}

.b2b-brand .bss-shell__brand-sub {
  color: rgba(255, 255, 255, 0.62);
}

[data-portal="mr"] .b2b-brand {
  color: #fff;
}

[data-portal="distributor"] .b2b-brand {
  color: #fff;
}

.b2b-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.95rem;
  flex-shrink: 0;
}

[data-portal="mr"] .b2b-brand-mark {
  background: linear-gradient(135deg, #1e88c7, #3d63d6);
}

[data-portal="distributor"] .b2b-brand-mark {
  background: linear-gradient(135deg, #0d9f6e, #3d63d6);
}

.b2b-home-link {
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
}

.b2b-home-link:hover {
  color: #fff;
}

.b2b-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.b2b-nav a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  transition: background 120ms ease-out, color 120ms ease-out;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.b2b-nav a:hover,
.b2b-nav a.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

[data-portal="mr"] .b2b-nav a.active {
  background: rgba(56, 189, 248, 0.22);
}

[data-portal="distributor"] .b2b-nav a.active {
  background: rgba(52, 211, 153, 0.22);
}

.b2b-meta {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.8rem;
}

.b2b-logout-btn {
  color: #fff !important;
  border-color: rgba(255, 255, 255, 0.25) !important;
}

.b2b-logout-btn:hover {
  background: rgba(255, 255, 255, 0.1) !important;
}

.b2b-nav-toggle {
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  background: transparent;
  min-width: 44px;
  min-height: 44px;
}

.b2b-nav-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.b2b-mobile-nav {
  display: none;
  width: 100%;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin-top: 0.65rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.b2b-mobile-nav.open {
  display: flex;
}

.b2b-mobile-nav a {
  flex: 1 1 calc(50% - 0.25rem);
  text-align: center;
  padding: 0.65rem 0.4rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.b2b-mobile-nav a.active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

[data-portal="mr"] .b2b-mobile-nav a.active {
  background: rgba(56, 189, 248, 0.28);
}

[data-portal="distributor"] .b2b-mobile-nav a.active {
  background: rgba(52, 211, 153, 0.28);
}

.b2b-mobile-nav__meta {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0.15rem 0;
}

.b2b-main {
  padding-top: 0.25rem;
}

/* ── Metrics / target ring ── */
.b2b-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 1.25rem;
}

@media (max-width: 991.98px) {
  .b2b-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.b2b-metric {
  background: var(--color-bg-surface, #fff);
  border: 1px solid var(--color-border-subtle, #e2e8f0);
  border-radius: 16px;
  box-shadow: var(--shadow-2, 0 4px 16px rgba(15, 23, 42, 0.06));
  padding: 1rem;
  min-width: 0;
}

.b2b-metric__label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-tertiary, #94a3b8);
  margin-bottom: 4px;
}

.b2b-metric__value {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--color-text-primary, #0f172a);
}

.b2b-metric--ring {
  display: flex;
  align-items: center;
  gap: 12px;
}

.b2b-target-ring {
  --pct: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: conic-gradient(var(--portal-accent, #1e88c7) calc(var(--pct) * 1%), var(--color-bg-muted, #eef2f7) 0);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.b2b-target-ring::before {
  content: attr(data-label);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-bg-surface, #fff);
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--portal-accent, #1e88c7);
}

/* ── Calendar strip ── */
.b2b-cal {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 1.25rem;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.b2b-cal__day {
  flex: 0 0 72px;
  scroll-snap-align: start;
  text-align: center;
  padding: 10px 8px;
  border-radius: 12px;
  background: var(--color-bg-surface, #fff);
  border: 1px solid var(--color-border-subtle, #e2e8f0);
  box-shadow: var(--shadow-1);
  text-decoration: none;
  color: inherit;
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}

.b2b-cal__day.is-active,
.b2b-cal__day:hover {
  border-color: var(--portal-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--portal-accent) 20%, transparent);
}

.b2b-cal__dow {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

.b2b-cal__dom {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.b2b-cal__count {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--portal-accent);
}

/* ── Map + list ── */
.b2b-split {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.2fr);
  gap: 16px;
  margin-bottom: 1.25rem;
}

@media (max-width: 991.98px) {
  .b2b-split {
    grid-template-columns: 1fr;
  }
}

.b2b-map {
  position: relative;
  min-height: 280px;
  border-radius: 20px;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 40%, rgba(56, 189, 248, 0.25), transparent 45%),
    radial-gradient(circle at 70% 60%, rgba(13, 159, 110, 0.2), transparent 40%),
    linear-gradient(160deg, #0b1f3a 0%, #1246d6 55%, #0a3d32 100%);
  color: #fff;
  padding: 1.25rem;
  box-shadow: var(--shadow-3);
}

.b2b-map__title {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 12px;
}

.b2b-map__pins {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.b2b-map__pin {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.85rem;
}

.b2b-map__pin i {
  color: #7dd3fc;
  flex-shrink: 0;
}

.b2b-panel {
  background: var(--color-bg-surface, #fff);
  border: 1px solid var(--color-border-subtle, #e2e8f0);
  border-radius: 20px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.b2b-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  background: var(--color-bg-muted, #f8fafc);
}

.b2b-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* ── Visit cards ── */
.b2b-visit-card {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border-subtle);
  border-left: 3px solid transparent;
  transition: background 120ms ease-out;
}

.b2b-visit-card:last-child {
  border-bottom: none;
}

.b2b-visit-card:hover {
  background: var(--color-bg-muted, #f8fafc);
}

.b2b-visit-card--pending {
  border-left-color: #c9891c;
}

.b2b-visit-card--accepted {
  border-left-color: var(--portal-accent, #1e88c7);
}

.b2b-visit-card--declined {
  border-left-color: #ef4444;
}

.b2b-visit-card--rescheduled {
  border-left-color: #3b82f6;
}

/* ── Offer / enquiry ── */
.b2b-offer-card {
  border: 1px solid var(--color-border-subtle);
  border-radius: 16px;
  padding: 14px;
  background: var(--color-bg-surface);
  box-shadow: var(--shadow-1);
  margin-bottom: 12px;
  border-left: 3px solid var(--portal-accent, var(--color-accent-care));
}

.b2b-offer-card:last-child {
  margin-bottom: 0;
}

.b2b-enquiry {
  border-bottom: 1px solid var(--color-border-subtle);
  padding: 16px 18px;
  border-left: 3px solid transparent;
}

.b2b-enquiry:last-child {
  border-bottom: none;
}

.b2b-enquiry--new {
  border-left-color: var(--portal-accent, #0d9f6e);
  background: color-mix(in srgb, var(--portal-accent) 4%, transparent);
}

.b2b-enquiry--contacted {
  border-left-color: #3b82f6;
}

.b2b-enquiry--closed {
  border-left-color: var(--color-text-tertiary, #94a3b8);
  opacity: 0.92;
}

.b2b-enquiry__bubble {
  background: var(--color-bg-muted);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin: 10px 0;
  border: 1px solid transparent;
}

.b2b-enquiry__status {
  min-width: 7.5rem;
}

.b2b-enquiry__meta {
  font-size: 0.7rem;
  color: var(--color-text-tertiary, #94a3b8);
}

/* ── Modal polish ── */
.b2b-modal .modal-content {
  border: 1px solid var(--color-border-subtle);
  border-radius: 16px;
  overflow: hidden;
}

.b2b-modal .modal-header {
  background: var(--color-bg-muted, #f8fafc);
  border-bottom: 1px solid var(--color-border-subtle);
  color: var(--color-text-primary);
}

.b2b-modal .modal-title {
  font-weight: 800;
  letter-spacing: -0.02em;
}

.b2b-modal .modal-footer {
  background: var(--color-bg-muted, #f8fafc);
  border-top: 1px solid var(--color-border-subtle);
}

/* ── Compact density ── */
[data-density="compact"][data-portal="mr"] .b2b-metric,
[data-density="compact"][data-portal="distributor"] .b2b-metric {
  padding: 0.75rem;
}

[data-density="compact"][data-portal="mr"] .b2b-panel__head,
[data-density="compact"][data-portal="distributor"] .b2b-panel__head {
  padding: 10px 14px;
}

[data-density="compact"][data-portal="mr"] .b2b-visit-card,
[data-density="compact"][data-portal="distributor"] .b2b-enquiry {
  padding: 10px 14px;
}

[data-density="compact"][data-portal="mr"] .b2b-cal__day {
  flex-basis: 64px;
  padding: 8px 6px;
}

[data-density="compact"][data-portal="mr"] .b2b-shell-header,
[data-density="compact"][data-portal="distributor"] .b2b-shell-header {
  margin-bottom: 1rem;
}

/* ── Dark theme ── */
[data-theme="dark"][data-portal="mr"] body,
[data-theme="dark"][data-portal="distributor"] body,
html[data-theme="dark"][data-portal="mr"] body,
html[data-theme="dark"][data-portal="distributor"] body {
  background:
    radial-gradient(ellipse 55% 40% at 0% 0%, color-mix(in srgb, var(--portal-accent) 14%, transparent) 0%, transparent 55%),
    var(--color-bg-app, #0b1220);
}

[data-theme="dark"][data-portal="mr"] .b2b-metric,
[data-theme="dark"][data-portal="distributor"] .b2b-metric,
[data-theme="dark"][data-portal="mr"] .b2b-panel,
[data-theme="dark"][data-portal="distributor"] .b2b-panel,
[data-theme="dark"][data-portal="mr"] .b2b-cal__day,
[data-theme="dark"][data-portal="distributor"] .b2b-offer-card {
  background: var(--color-bg-elevated, #1e293b);
  border-color: var(--color-border-subtle);
}

[data-theme="dark"][data-portal="mr"] .b2b-panel__head,
[data-theme="dark"][data-portal="distributor"] .b2b-panel__head,
[data-theme="dark"][data-portal="mr"] .b2b-modal .modal-header,
[data-theme="dark"][data-portal="mr"] .b2b-modal .modal-footer {
  background: var(--color-bg-muted, #0f172a);
}

[data-theme="dark"][data-portal="mr"] .b2b-target-ring::before {
  background: var(--color-bg-elevated, #1e293b);
}

[data-theme="dark"][data-portal="mr"] .b2b-visit-card:hover,
[data-theme="dark"][data-portal="distributor"] .b2b-enquiry--new {
  background: color-mix(in srgb, var(--portal-accent) 10%, var(--color-bg-muted));
}

[data-theme="dark"][data-portal="distributor"] .b2b-enquiry__bubble {
  background: var(--color-bg-muted);
  color: var(--color-text-secondary);
}

[data-theme="dark"][data-portal="mr"] .b2b-metric__value,
[data-theme="dark"][data-portal="distributor"] .b2b-metric__value {
  color: var(--color-text-primary);
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .b2b-nav a,
  .b2b-cal__day,
  .b2b-visit-card,
  .b2b-mobile-nav.open {
    transition: none !important;
    animation: none !important;
  }
}

[data-theme="dark"][data-portal="mr"] .form-control,
[data-theme="dark"][data-portal="distributor"] .form-control,
[data-theme="dark"][data-portal="mr"] .form-select,
[data-theme="dark"][data-portal="distributor"] .form-select,
[data-theme="dark"][data-portal="mr"] textarea.form-control,
[data-theme="dark"][data-portal="distributor"] textarea.form-control {
  background: #121925 !important;
  border-color: rgba(148, 163, 184, 0.28) !important;
  color: #f8fafc !important;
  padding-left: 1rem !important;
  padding-right: 1rem !important;
}

[data-theme="dark"][data-portal="mr"] .form-control::placeholder,
[data-theme="dark"][data-portal="distributor"] .form-control::placeholder,
[data-theme="dark"][data-portal="mr"] textarea.form-control::placeholder,
[data-theme="dark"][data-portal="distributor"] textarea.form-control::placeholder {
  color: #d7e0eb !important;
  opacity: 1 !important;
}

[data-theme="dark"][data-portal="mr"] .form-label,
[data-theme="dark"][data-portal="distributor"] .form-label,
[data-theme="dark"][data-portal="mr"] .form-text,
[data-theme="dark"][data-portal="distributor"] .form-text,
[data-theme="dark"][data-portal="mr"] .text-muted,
[data-theme="dark"][data-portal="distributor"] .text-muted {
  color: #c5d0de !important;
}
