:root {
  /* Luxury palette from reference: espresso, burgundy, taupe, linen, silver, ivory */
  --navy: #322D29;
  --navy-soft: #403A35;
  --teal: #72383D;
  --teal-dark: #5E2F34;
  --teal-soft: rgba(114, 56, 61, 0.10);
  --burgundy: #72383D;
  --taupe: #AC9C8D;
  --linen: #D1C7BD;
  --silver: #D9D9D9;
  --ivory: #EFE9E1;
  --steel: #8F8175;
  --muted: #AC9C8D;
  --line: rgba(172, 156, 141, 0.34);
  --line-soft: rgba(239, 233, 225, 0.82);
  --surface: rgba(255, 252, 247, 0.94);
  --canvas: #EFE9E1;
  --ink: #322D29;
  --shadow: 0 14px 42px rgba(50, 45, 41, 0.075);
  --shadow-hover: 0 24px 70px rgba(50, 45, 41, 0.14);
  --radius-lg: 26px;
  --radius-md: 20px;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -12%, rgba(114, 56, 61, 0.13), transparent 30%),
    radial-gradient(circle at 92% 0%, rgba(172, 156, 141, 0.22), transparent 28%),
    linear-gradient(180deg, #FBF8F3 0%, var(--canvas) 54%, #E6DDD4 100%);
  font-family: Inter, "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

button, select, input { font: inherit; }
button { cursor: pointer; }
svg { display: block; }

.app-shell { width: 100%; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: auto minmax(420px, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 66px;
  padding: 10px 24px;
  border-bottom: 1px solid rgba(172, 156, 141, 0.26);
  background: rgba(251, 248, 243, 0.86);
  backdrop-filter: blur(22px);
}

.brand-cluster, .profile-zone, .primary-action, .icon-button, .menu-button, .pill-nav, .segmented-control {
  display: flex;
  align-items: center;
}
.brand-cluster { gap: 12px; min-width: 210px; }
.menu-button {
  width: 38px;
  height: 38px;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  transition: transform 220ms var(--ease), box-shadow 220ms var(--ease), border-color 220ms var(--ease);
}
.menu-button:hover { transform: translateY(-1px) scale(1.015); border-color: rgba(15, 139, 141, 0.32); box-shadow: var(--shadow-hover); }
.menu-button span { display: block; width: 17px; height: 2px; border-radius: 999px; background: var(--navy); }
.brand-name { font-size: 18px; font-weight: 800; letter-spacing: -0.04em; color: var(--navy); }
.brand-caption { margin-top: -2px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: var(--steel); }

.pill-nav {
  justify-self: center;
  gap: 4px;
  padding: 5px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.035);
  overflow-x: auto;
  scrollbar-width: none;
}
.pill-nav::-webkit-scrollbar { display: none; }
.nav-item {
  border: 0;
  border-radius: 999px;
  padding: 8px 13px;
  background: transparent;
  color: var(--steel);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  transition: color 220ms var(--ease), background 220ms var(--ease), transform 220ms var(--ease), box-shadow 220ms var(--ease);
}
.nav-item:hover { color: var(--navy); transform: translateY(-1px); }
.nav-item.is-active { color: #fff; background: var(--navy); box-shadow: 0 10px 22px rgba(15, 23, 42, 0.16); }
.profile-zone { justify-content: flex-end; gap: 10px; }
.icon-button, .primary-action {
  height: 40px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(255, 255, 255, 0.88);
  color: var(--navy);
  transition: transform 220ms var(--ease), box-shadow 220ms var(--ease), border-color 220ms var(--ease), background 220ms var(--ease);
}
.icon-button { width: 40px; justify-content: center; border-radius: 14px; }
.primary-action { gap: 8px; border-radius: 999px; padding: 0 15px; font-size: 12px; font-weight: 850; }
.icon-button:hover, .primary-action:hover { transform: translateY(-1px) scale(1.012); border-color: rgba(15, 139, 141, 0.34); box-shadow: var(--shadow-hover); }
.icon-button svg, .primary-action svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.dashboard-shell {
  width: min(100%, 1560px);
  margin: 0 auto;
  padding: 16px 26px 34px;
  min-height: calc(100vh - 66px);
}
.command-center, .card, .kpi-card {
  border: 1px solid rgba(226, 232, 240, 0.8);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.command-center {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  border-radius: 26px;
}
.eyebrow, .section-label {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}
.command-center h1 {
  margin: 0;
  color: var(--navy);
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1;
  letter-spacing: -0.06em;
}
.lead { max-width: 780px; margin: 10px 0 0; color: var(--steel); font-size: 13px; line-height: 1.58; }
.filter-dock {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 9px;
  flex-wrap: wrap;
}
.filter-chip {
  display: grid;
  gap: 5px;
  min-width: 132px;
  color: var(--steel);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.filter-chip select, .reset-button {
  height: 38px;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 14px;
  color: var(--navy);
  background: rgba(255, 255, 255, 0.92);
  font-size: 12px;
  font-weight: 800;
  outline: none;
  transition: border-color 220ms var(--ease), box-shadow 220ms var(--ease), transform 220ms var(--ease);
}
.filter-chip select { padding: 0 12px; min-width: 132px; }
.filter-chip select:focus { border-color: rgba(15, 139, 141, 0.48); box-shadow: 0 0 0 4px rgba(15, 139, 141, 0.08); }
.reset-button { padding: 0 14px; color: #fff; background: var(--navy); }
.reset-button:hover { transform: translateY(-1px); box-shadow: 0 14px 28px rgba(15, 23, 42, 0.14); }

.view-page { display: none; }
.view-page.is-active { display: block; animation: viewIn 320ms var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.kpi-grid, .dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.kpi-grid { margin-top: 16px; }
.dashboard-grid { margin-top: 16px; }
.compact-view-grid { align-content: start; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.kpi-card {
  grid-column: span 3;
  min-height: 116px;
  padding: 16px;
  border-radius: 22px;
  transition: transform 240ms var(--ease), box-shadow 240ms var(--ease), border-color 240ms var(--ease);
}
.card {
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: transform 240ms var(--ease), box-shadow 240ms var(--ease), border-color 240ms var(--ease);
}
.card:hover, .kpi-card:hover { transform: translateY(-2px); border-color: rgba(15, 139, 141, 0.18); box-shadow: var(--shadow-hover); }
.kpi-top, .split-header, .product-row, .kol-row, .source-row, .platform-row, .quality-card, .marketing-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.card-header { display: flex; flex-direction: column; margin-bottom: 14px; }
.card-header h2 { margin: 0; color: var(--navy); font-size: 18px; line-height: 1.25; letter-spacing: -0.04em; }
.muted { margin: 4px 0 0; color: var(--steel); font-size: 12px; line-height: 1.52; }
.kpi-title { margin: 0; color: var(--steel); font-size: 11px; font-weight: 850; letter-spacing: 0.06em; text-transform: uppercase; }
.kpi-subtitle, .kpi-note { color: var(--steel); font-size: 11px; }
.kpi-value { margin-top: 12px; color: var(--navy); font-size: clamp(26px, 2.2vw, 36px); font-weight: 850; line-height: 1; letter-spacing: -0.06em; }
.kpi-delta { display: flex; align-items: center; gap: 7px; margin-top: 12px; color: var(--teal-dark); font-size: 11px; font-weight: 850; }
.delta-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); }
.metric-icon { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid rgba(226, 232, 240, 0.86); border-radius: 12px; background: rgba(248, 250, 252, 0.88); color: var(--teal-dark); }
.metric-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.compact-chart-card { min-height: 344px; }
.headline-metric { margin: -2px 0 10px; color: var(--navy); font-size: 38px; font-weight: 850; line-height: 0.98; letter-spacing: -0.07em; }
.growth-badge, .mini-badge {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}
.mini-badge { height: 27px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; }
.pulse-chart-wrap { height: 160px; width: 100%; }
.chart-svg { width: 100%; height: 100%; overflow: visible; }
.grid-line { stroke: var(--line-soft); stroke-width: 1; }
.axis-label { fill: #64748b; font-size: 10px; font-weight: 600; }
.y-label { fill: #94a3b8; font-size: 10px; font-weight: 600; }
.pulse-bar { fill: var(--teal); cursor: pointer; transform-box: fill-box; transform-origin: bottom; transition: fill 180ms var(--ease), opacity 180ms var(--ease), transform 240ms var(--ease); animation: barGrow 520ms var(--ease) both; }
.pulse-bar:hover { fill: var(--teal-dark); transform: scaleY(1.035); }

.donut-layout { display: grid; grid-template-columns: minmax(132px, 170px) 1fr; gap: 14px; align-items: center; }
.compact-donut .donut-wrap { min-height: 176px; }
.donut-wrap { position: relative; min-height: 190px; display: grid; place-items: center; }
.donut-center { position: absolute; text-align: center; pointer-events: none; }
.donut-center strong, .donut-center span { display: block; }
.donut-center strong { color: var(--navy); font-size: 19px; letter-spacing: -0.05em; }
.donut-center span { margin-top: 2px; color: var(--steel); font-size: 10px; font-weight: 750; }
.donut-segment { fill: none; stroke-width: 15; stroke-linecap: round; cursor: pointer; transform-origin: 50% 50%; transition: transform 240ms var(--ease), filter 240ms var(--ease), opacity 240ms var(--ease); }
.donut-segment:hover { transform: scale(1.04); filter: drop-shadow(0 8px 14px rgba(15, 23, 42, 0.12)); }
.platform-list, .marketing-stack, .product-list, .kol-list, .source-list, .insight-list, .mini-note-list, .decision-grid { display: grid; gap: 9px; }
.compact-list { gap: 8px; }
.relaxed-list { gap: 11px; }
.platform-row { gap: 12px; padding: 9px 0; border-bottom: 1px solid rgba(226, 232, 240, 0.62); }
.platform-row:last-child, .source-row:last-child { border-bottom: 0; }
.color-dot { width: 9px; height: 9px; flex: 0 0 auto; margin-top: 5px; border-radius: 50%; }
.platform-name, .product-name, .kol-name, .source-title, .marketing-label { color: var(--navy); font-size: 13px; font-weight: 850; }
.platform-meta, .product-meta, .kol-meta, .source-meta { margin-top: 3px; color: var(--steel); font-size: 11px; line-height: 1.42; }
.platform-value, .product-value, .kol-value, .marketing-value { color: var(--navy); font-size: 13px; font-weight: 850; white-space: nowrap; text-align: right; }
.marketing-value { font-size: 18px; letter-spacing: -0.04em; }

.insight-item, .marketing-item, .quality-card, .decision-card, .mini-note, .product-row, .kol-row, .source-row {
  position: relative;
  border: 1px solid rgba(226, 232, 240, 0.72);
  border-radius: 18px;
  background: rgba(248, 250, 252, 0.72);
  transition: transform 220ms var(--ease), background 220ms var(--ease), box-shadow 220ms var(--ease), border-color 220ms var(--ease);
}
.insight-item:hover, .marketing-item:hover, .product-row:hover, .kol-row:hover, .source-row:hover, .mini-note:hover, .decision-card:hover {
  transform: translateY(-2px) scale(1.006);
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(15, 139, 141, 0.18);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.075);
}
.insight-item { display: grid; grid-template-columns: 26px 1fr; gap: 11px; padding: 12px; cursor: pointer; }
.insight-index, .product-rank, .kol-rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 11px;
  color: var(--teal-dark);
  background: var(--teal-soft);
  font-size: 12px;
  font-weight: 900;
}
.insight-title { margin: 0; color: var(--navy); font-size: 12px; font-weight: 850; }
.insight-desc { margin: 4px 0 0; color: var(--steel); font-size: 11px; line-height: 1.48; }
.text-button { border: 0; padding: 0; background: transparent; color: var(--teal-dark); font-size: 12px; font-weight: 850; }
.segmented-control { gap: 4px; align-self: flex-start; padding: 4px; border: 1px solid rgba(226, 232, 240, 0.92); border-radius: 999px; background: rgba(248, 250, 252, 0.86); }
.segment { border: 0; border-radius: 999px; padding: 8px 12px; background: transparent; color: var(--steel); font-size: 12px; font-weight: 850; transition: color 220ms var(--ease), background 220ms var(--ease), transform 220ms var(--ease); }
.segment:hover { color: var(--navy); }
.segment.is-active { color: #fff; background: var(--navy); box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16); }
.trend-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.meta-pill { padding: 10px 12px; border: 1px solid rgba(226, 232, 240, 0.72); border-radius: 16px; background: rgba(248, 250, 252, 0.74); }
.meta-pill span, .meta-pill strong { display: block; }
.meta-pill span { color: var(--steel); font-size: 10px; font-weight: 850; text-transform: uppercase; letter-spacing: 0.06em; }
.meta-pill strong { margin-top: 4px; color: var(--navy); font-size: 16px; font-weight: 850; letter-spacing: -0.04em; }
.trend-chart-wrap { height: 292px; width: 100%; }
.trend-area { fill: url(#trendGradient); opacity: 0; animation: fadeUp 460ms var(--ease) 80ms both; }
.trend-line { fill: none; stroke: var(--teal); stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1200; stroke-dashoffset: 1200; animation: drawLine 880ms var(--ease) 120ms both; }
.trend-point { fill: #fff; stroke: var(--teal); stroke-width: 2.8; cursor: pointer; transition: r 180ms var(--ease), stroke 180ms var(--ease); }
.trend-point:hover { r: 7; stroke: var(--teal-dark); }
.trend-bar { fill: #80919f; cursor: pointer; transform-box: fill-box; transform-origin: bottom; animation: barGrow 560ms var(--ease) both; transition: fill 180ms var(--ease), transform 180ms var(--ease); }
.trend-bar:hover { fill: var(--navy-soft); transform: scaleY(1.025); }
.marketing-item { padding: 13px; cursor: pointer; }
.progress-track { overflow: hidden; height: 7px; margin-top: 11px; border-radius: 999px; background: #e9eef4; }
.progress-fill { height: 100%; width: var(--progress, 0%); border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--teal-dark)); animation: progressIn 700ms var(--ease) both; }
.product-row, .kol-row, .source-row { gap: 16px; padding: 12px; cursor: pointer; }
.product-main, .kol-main, .source-main { min-width: 0; flex: 1; }
.status-chip { display: inline-flex; align-items: center; height: 23px; padding: 0 9px; border-radius: 999px; color: var(--teal-dark); background: var(--teal-soft); font-size: 10px; font-weight: 850; white-space: nowrap; }
.quality-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.quality-card { flex-direction: column; min-height: 105px; padding: 13px; }
.quality-label { color: var(--steel); font-size: 11px; font-weight: 850; }
.quality-value { margin-top: 10px; color: var(--navy); font-size: 24px; font-weight: 850; line-height: 1; letter-spacing: -0.05em; }
.quality-note { margin-top: auto; color: var(--muted); font-size: 11px; }
.mini-note, .decision-card { padding: 14px; }
.mini-note strong, .decision-card strong { display:block; color: var(--navy); font-size: 13px; margin-bottom: 4px; }
.mini-note span, .decision-card span { color: var(--steel); font-size: 12px; line-height: 1.45; }
.decision-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.source-page-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.source-badge { flex: 0 0 auto; padding: 6px 9px; border-radius: 999px; color: var(--steel); background: rgba(248, 250, 252, 0.92); border: 1px solid rgba(226, 232, 240, 0.86); font-size: 11px; font-weight: 850; }
.source-row::after { content: "Open"; flex: 0 0 auto; padding: 6px 9px; border-radius: 999px; color: var(--teal-dark); background: var(--teal-soft); font-size: 10px; font-weight: 850; opacity: 0; transform: translateX(4px); transition: opacity 180ms var(--ease), transform 180ms var(--ease); }
.source-row:hover::after { opacity: 1; transform: translateX(0); }

.chart-tooltip { position: fixed; z-index: 80; pointer-events: none; min-width: 132px; padding: 10px 12px; border-radius: 13px; background: #0f172a; color: #fff; box-shadow: 0 18px 46px rgba(15, 23, 42, 0.22); opacity: 0; transform: translate3d(-50%, -8px, 0); transition: opacity 140ms var(--ease), transform 140ms var(--ease); }
.chart-tooltip.is-visible { opacity: 1; transform: translate3d(-50%, -14px, 0); }
.tooltip-title { color: #cbd5e1; font-size: 11px; font-weight: 700; }
.tooltip-value { margin-top: 3px; color: #fff; font-size: 13px; font-weight: 850; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 130; padding: 12px 16px; border-radius: 999px; background: var(--navy); color: #fff; font-size: 13px; font-weight: 850; box-shadow: 0 18px 44px rgba(15, 23, 42, 0.2); opacity: 0; transform: translateY(12px); transition: opacity 220ms var(--ease), transform 220ms var(--ease); }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.reveal { opacity: 0; transform: translateY(10px); animation: pageIn 360ms var(--ease) both; }
@keyframes pageIn { to { opacity: 1; transform: translateY(0); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes drawLine { to { stroke-dashoffset: 0; } }
@keyframes barGrow { from { transform: scaleY(0.12); opacity: 0.38; } to { transform: scaleY(1); opacity: 1; } }
@keyframes progressIn { from { width: 0; } to { width: var(--progress, 0%); } }

/* Premium Detail Modal */
.detail-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms var(--ease);
}
.detail-backdrop.is-open, .modal-backdrop.is-open { opacity: 1; pointer-events: auto; }
.detail-modal {
  position: relative;
  width: min(100%, 760px);
  max-height: min(86vh, 780px);
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.82);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 36px 120px rgba(15, 23, 42, 0.26);
  transform: translateY(18px) scale(0.985);
  transition: transform 280ms var(--ease);
}
.detail-backdrop.is-open .detail-modal { transform: translateY(0) scale(1); }
.detail-glow { position: absolute; inset: -30% auto auto -10%; width: 300px; height: 300px; border-radius: 999px; background: rgba(15, 139, 141, 0.11); filter: blur(18px); pointer-events: none; }
.detail-header, .modal-header, .modal-toolbar, .workspace-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.detail-header { position: relative; padding: 24px 26px 18px; border-bottom: 1px solid rgba(226, 232, 240, 0.72); }
.detail-header h2, .modal-header h2, .workspace-head h3 { margin: 0; color: var(--navy); letter-spacing: -0.04em; }
.detail-header h2 { margin-top: 3px; font-size: 26px; }
.detail-body { position: relative; padding: 22px 26px 26px; overflow: auto; max-height: 620px; }
.detail-metric-grid { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.detail-metric { padding: 14px; border: 1px solid rgba(226, 232, 240, 0.72); border-radius: 18px; background: rgba(248, 250, 252, 0.82); animation: fadeUp 360ms var(--ease) both; }
.detail-metric span { display:block; color: var(--steel); font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: 0.06em; }
.detail-metric strong { display:block; margin-top: 6px; color: var(--navy); font-size: 22px; letter-spacing: -0.05em; }
.detail-section { padding: 16px; border-radius: 20px; background: linear-gradient(180deg, rgba(248, 250, 252, 0.86), rgba(255,255,255,0.9)); border: 1px solid rgba(226, 232, 240, 0.72); }
.detail-section + .detail-section { margin-top: 12px; }
.detail-section h3 { margin:0 0 8px; color: var(--navy); font-size: 15px; }
.detail-section p, .detail-section li { color: var(--steel); font-size: 13px; line-height: 1.65; }
.detail-section ul { padding-left: 20px; margin: 8px 0 0; }
.modal-close { display: inline-grid; place-items: center; width: 42px; height: 42px; flex: 0 0 auto; border: 1px solid rgba(226, 232, 240, 0.9); border-radius: 15px; color: var(--navy); background: rgba(248, 250, 252, 0.86); transition: transform 220ms var(--ease), background 220ms var(--ease), box-shadow 220ms var(--ease); }
.modal-close:hover { transform: translateY(-1px); background: #fff; box-shadow: var(--shadow-hover); }
.modal-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

/* Source Mapping Modal + Excel Table Manager */
.source-modal {
  width: min(100%, 1240px);
  max-height: min(88vh, 900px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.82);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 36px 120px rgba(15, 23, 42, 0.24);
  transform: translateY(18px) scale(0.985);
  transition: transform 260ms var(--ease);
}
.modal-backdrop.is-open .source-modal { transform: translateY(0) scale(1); }
.modal-header { padding: 24px 26px 18px; border-bottom: 1px solid rgba(226, 232, 240, 0.72); }
.modal-header h2 { margin-top: 3px; font-size: 24px; }
.modal-toolbar { padding: 14px 26px; background: rgba(248, 250, 252, 0.7); border-bottom: 1px solid rgba(226, 232, 240, 0.72); }
.excel-status { display: inline-flex; align-items: center; min-height: 34px; padding: 8px 12px; border: 1px solid rgba(226, 232, 240, 0.86); border-radius: 999px; color: var(--steel); background: rgba(255, 255, 255, 0.72); font-size: 12px; font-weight: 850; }
.excel-status.is-live { color: var(--teal-dark); border-color: rgba(15, 139, 141, 0.24); background: var(--teal-soft); }
.modal-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.secondary-action { height: 40px; padding: 0 14px; border: 1px solid rgba(226, 232, 240, 0.94); border-radius: 999px; color: var(--navy); background: rgba(255, 255, 255, 0.92); font-size: 12px; font-weight: 850; transition: transform 220ms var(--ease), box-shadow 220ms var(--ease), border-color 220ms var(--ease); }
.secondary-action:hover, .modal-save-button:hover { transform: translateY(-1px); box-shadow: var(--shadow-hover); }
.modal-save-button { background: var(--navy); color: #fff; border-color: var(--navy); }
.modal-body { min-height: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.sheet-rail { overflow: auto; padding: 18px; border-right: 1px solid rgba(226, 232, 240, 0.72); background: rgba(248, 250, 252, 0.58); }
.sheet-button { width: 100%; display: grid; gap: 4px; margin-bottom: 9px; padding: 13px 14px; border: 1px solid transparent; border-radius: 18px; color: var(--steel); background: transparent; text-align: left; transition: background 220ms var(--ease), border-color 220ms var(--ease), transform 220ms var(--ease), color 220ms var(--ease); }
.sheet-button:hover { color: var(--navy); background: rgba(255, 255, 255, 0.74); transform: translateY(-1px); }
.sheet-button.is-active { color: var(--navy); border-color: rgba(15, 139, 141, 0.18); background: #fff; box-shadow: 0 10px 28px rgba(15, 23, 42, 0.055); }
.sheet-button strong { display: block; font-size: 13px; font-weight: 900; line-height: 1.25; }
.sheet-button span { display: block; color: var(--muted); font-size: 11px; font-weight: 750; }
.table-workspace { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); padding: 18px; }
.workspace-head { margin-bottom: 14px; }
.workspace-head h3 { font-size: 20px; }
.workspace-head p { margin: 5px 0 0; color: var(--steel); font-size: 12px; font-weight: 650; }
.table-search { display: grid; gap: 5px; min-width: 220px; color: var(--steel); font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: 0.06em; }
.table-search input { height: 40px; padding: 0 12px; border: 1px solid rgba(226, 232, 240, 0.94); border-radius: 14px; outline: none; color: var(--navy); background: rgba(248, 250, 252, 0.9); font: inherit; font-size: 13px; font-weight: 650; text-transform: none; letter-spacing: 0; transition: border-color 180ms var(--ease), background 180ms var(--ease), box-shadow 180ms var(--ease); }
.table-search input:focus { border-color: rgba(15, 139, 141, 0.42); background: #fff; box-shadow: 0 0 0 4px rgba(15, 139, 141, 0.08); }
.excel-table-wrap { min-height: 0; overflow: auto; border: 1px solid rgba(226, 232, 240, 0.84); border-radius: 22px; background: #fff; }
.excel-empty-state { display: grid; place-items: center; min-height: 260px; padding: 24px; text-align: center; color: var(--steel); }
.excel-empty-state strong { display: block; color: var(--navy); font-size: 18px; margin-bottom: 6px; }
.excel-data-table { width: 100%; min-width: 780px; border-collapse: separate; border-spacing: 0; }
.excel-data-table th, .excel-data-table td { border-bottom: 1px solid rgba(226, 232, 240, 0.72); padding: 10px; vertical-align: middle; text-align: left; }
.excel-data-table th { position: sticky; top: 0; z-index: 2; background: rgba(248, 250, 252, 0.98); color: var(--steel); font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.excel-data-table td { color: var(--navy); font-size: 12px; font-weight: 650; }
.excel-data-table tr:hover td { background: rgba(248, 250, 252, 0.56); }
.excel-cell-input { width: 100%; min-width: 120px; height: 36px; padding: 0 10px; border: 1px solid transparent; border-radius: 12px; color: var(--navy); background: transparent; font: inherit; font-size: 12px; font-weight: 650; transition: border-color 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease); }
.excel-cell-input:focus { outline: none; border-color: rgba(15, 139, 141, 0.32); background: #fff; box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.08); }
.excel-row-actions { width: 92px; text-align: right !important; white-space: nowrap; }
.delete-row-button { height: 32px; padding: 0 10px; border: 1px solid rgba(226, 232, 240, 0.9); border-radius: 999px; color: #b42318; background: #fff; font-size: 11px; font-weight: 850; transition: transform 180ms var(--ease), background 180ms var(--ease), box-shadow 180ms var(--ease); }
.delete-row-button:hover { transform: translateY(-1px); background: #fff5f5; box-shadow: 0 10px 24px rgba(180, 35, 24, 0.08); }

@media (max-width: 1360px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .pill-nav { justify-self: start; }
  .kpi-card { grid-column: span 6; }
  .span-3, .span-4, .span-5, .span-7, .span-8 { grid-column: span 12; }
  .compact-view-grid .span-4 { grid-column: span 4; }
  .compact-view-grid .span-5 { grid-column: span 5; }
  .compact-view-grid .span-7 { grid-column: span 7; }
  .compact-view-grid .span-8 { grid-column: span 8; }
}
@media (max-width: 1120px) {
  .topbar { grid-template-columns: 1fr auto; height: auto; min-height: 68px; }
  .pill-nav { grid-column: 1 / -1; justify-self: stretch; order: 3; }
  .dashboard-shell { padding: 14px 18px 30px; }
  .command-center { grid-template-columns: 1fr; }
  .filter-dock { justify-content: start; }
  .compact-view-grid .span-4, .compact-view-grid .span-5, .compact-view-grid .span-7, .compact-view-grid .span-8 { grid-column: span 12; }
  .donut-layout { grid-template-columns: 1fr; }
  .trend-meta, .quality-grid, .source-page-list, .decision-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 12px; gap: 10px; }
  .profile-zone .primary-action { display: none; }
  .dashboard-shell { padding: 12px 12px 28px; }
  .command-center, .card, .kpi-card { border-radius: 21px; }
  .command-center { padding: 16px; }
  .command-center h1 { font-size: 32px; }
  .lead { font-size: 12px; }
  .filter-dock { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .filter-chip, .filter-chip select { min-width: 0; width: 100%; }
  .reset-button { width: 100%; }
  .kpi-grid, .dashboard-grid { grid-template-columns: 1fr; gap: 12px; }
  .kpi-card, .span-3, .span-4, .span-5, .span-7, .span-8, .span-12, .compact-view-grid .span-4, .compact-view-grid .span-5, .compact-view-grid .span-7, .compact-view-grid .span-8 { grid-column: span 1; }
  .split-header, .detail-header, .modal-header, .modal-toolbar, .workspace-head { flex-direction: column; align-items: flex-start; }
  .segmented-control { width: 100%; overflow-x: auto; }
  .segment { flex: 1 0 auto; }
  .trend-meta, .quality-grid, .source-page-list, .decision-grid, .detail-metric-grid { grid-template-columns: 1fr; }
  .headline-metric { font-size: 34px; }
  .trend-chart-wrap { height: 250px; }
  .pulse-chart-wrap { height: 148px; }
  .detail-backdrop, .modal-backdrop { padding: 12px; }
  .detail-modal, .source-modal { max-height: 92vh; border-radius: 24px; }
  .modal-body { grid-template-columns: 1fr; }
  .sheet-rail { display: flex; gap: 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid rgba(226, 232, 240, 0.72); }
  .sheet-button { min-width: 190px; margin-bottom: 0; }
  .table-search, .modal-actions { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: 0.001ms !important; }
}
@media print {
  .topbar, .filter-dock, .toast, .modal-backdrop, .detail-backdrop { display:none !important; }
  body { background: #fff; }
  .dashboard-shell { padding: 0; }
  .view-page { display:block !important; page-break-after: always; }
  .card, .kpi-card, .command-center { box-shadow: none; }
}


/* Luxury palette refinement + richer motion layer */
.card,
.kpi-card,
.command-center {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.96), rgba(250, 246, 240, 0.92));
  border-color: rgba(172, 156, 141, 0.34);
  box-shadow: var(--shadow);
}

.card::before,
.kpi-card::before,
.command-center::before {
  content: "";
  position: absolute;
  inset: -1px;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at 18% 0%, rgba(114, 56, 61, 0.10), transparent 34%),
    linear-gradient(120deg, transparent 0%, rgba(255,255,255,0.38) 42%, transparent 72%);
  transform: translateX(-18px);
  transition: opacity 320ms var(--ease), transform 520ms var(--ease);
}

.card:hover::before,
.kpi-card:hover::before,
.command-center:hover::before {
  opacity: 1;
  transform: translateX(0);
}

.card > *, .kpi-card > *, .command-center > * { position: relative; z-index: 1; }

.nav-item.is-active,
.segment.is-active,
.primary-action,
.modal-save-button {
  background: linear-gradient(135deg, var(--navy), var(--burgundy));
  color: #fff;
  border-color: rgba(114, 56, 61, 0.34);
}

.nav-item:hover,
.segment:hover,
.text-button:hover,
.secondary-action:hover,
.icon-button:hover,
.menu-button:hover {
  border-color: rgba(114, 56, 61, 0.28) !important;
  box-shadow: 0 16px 46px rgba(50, 45, 41, 0.10);
}

.section-label,
.eyebrow {
  color: var(--burgundy);
  letter-spacing: 0.08em;
}

.growth-badge,
.mini-badge,
.status-chip {
  background: rgba(114, 56, 61, 0.09);
  color: var(--burgundy);
  border: 1px solid rgba(114, 56, 61, 0.16);
}

.pulse-bar { fill: var(--burgundy); }
.pulse-bar:hover { fill: var(--teal-dark); }
.color-dot { box-shadow: 0 0 0 4px rgba(172, 156, 141, 0.16); }
.progress-fill { background: linear-gradient(90deg, var(--burgundy), var(--taupe)); }

/* Premium detail/source modals: scroll safe, close button fixed top-right */
.detail-backdrop,
.modal-backdrop {
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(12px, 3vw, 28px);
  background:
    radial-gradient(circle at 50% 0%, rgba(114, 56, 61, 0.16), transparent 32%),
    rgba(50, 45, 41, 0.48);
  backdrop-filter: blur(18px);
}

.detail-modal,
.source-modal {
  border-color: rgba(172, 156, 141, 0.44);
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.98), rgba(239, 233, 225, 0.96));
  box-shadow: 0 38px 140px rgba(50, 45, 41, 0.30);
}

.detail-modal {
  width: min(100%, 920px);
  max-height: min(90dvh, 860px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.detail-header,
.modal-header {
  position: relative;
  padding-right: 86px !important;
  align-items: flex-start;
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 5;
  background: rgba(255, 252, 247, 0.92);
  border-color: rgba(172, 156, 141, 0.42);
  color: var(--navy);
}

.modal-close:hover {
  transform: translateY(-1px) scale(1.035) rotate(2deg);
  background: #fff;
  box-shadow: 0 16px 42px rgba(50, 45, 41, 0.14);
}

.detail-body {
  min-height: 0;
  max-height: none !important;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(114, 56, 61, 0.45) rgba(239, 233, 225, 0.55);
}

.detail-body::-webkit-scrollbar,
.excel-table-wrap::-webkit-scrollbar,
.sheet-rail::-webkit-scrollbar,
.modal-body::-webkit-scrollbar { width: 9px; height: 9px; }
.detail-body::-webkit-scrollbar-thumb,
.excel-table-wrap::-webkit-scrollbar-thumb,
.sheet-rail::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb { background: rgba(114, 56, 61, 0.42); border-radius: 999px; }
.detail-body::-webkit-scrollbar-track,
.excel-table-wrap::-webkit-scrollbar-track,
.sheet-rail::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track { background: rgba(239, 233, 225, 0.58); }

.detail-metric,
.detail-section,
.sheet-button.is-active,
.excel-data-table th {
  background: rgba(255, 252, 247, 0.78);
  border-color: rgba(172, 156, 141, 0.28);
}

.detail-section {
  animation: modalContentRise 420ms var(--ease) both;
}
.detail-section:nth-child(2) { animation-delay: 50ms; }
.detail-section:nth-child(3) { animation-delay: 100ms; }

.detail-glow {
  background:
    radial-gradient(circle, rgba(114, 56, 61, 0.17), transparent 62%),
    radial-gradient(circle at 60% 30%, rgba(172, 156, 141, 0.16), transparent 52%) !important;
  animation: premiumGlow 5.8s ease-in-out infinite alternate;
}

.kol-row,
.decision-card,
.product-row,
.marketing-item,
.insight-item {
  transform: translateZ(0);
}
.kol-row:hover,
.decision-card:hover,
.product-row:hover,
.marketing-item:hover,
.insight-item:hover {
  border-color: rgba(114, 56, 61, 0.30);
  background: linear-gradient(180deg, rgba(255,252,247,0.96), rgba(239,233,225,0.52));
}

@keyframes premiumGlow {
  from { transform: translate3d(0, 0, 0) scale(1); opacity: .72; }
  to { transform: translate3d(26px, 16px, 0) scale(1.08); opacity: 1; }
}

@keyframes modalContentRise {
  from { opacity: 0; transform: translateY(10px) scale(.992); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 720px) {
  .detail-backdrop,
  .modal-backdrop {
    align-items: flex-start;
    padding: 10px;
  }

  .detail-modal,
  .source-modal {
    width: 100%;
    height: calc(100dvh - 20px);
    max-height: none !important;
    border-radius: 22px;
  }

  .detail-header,
  .modal-header {
    display: block !important;
    padding: 18px 68px 14px 18px !important;
  }

  .modal-close {
    top: 14px;
    right: 14px;
    left: auto !important;
  }

  .detail-body {
    padding: 16px 18px 20px;
  }

  .source-modal {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .modal-toolbar {
    display: grid !important;
    gap: 10px;
    padding: 12px 18px;
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .modal-actions .modal-save-button { grid-column: 1 / -1; }

  .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 1fr);
  }

  .sheet-rail {
    max-height: 118px;
    padding: 12px;
  }

  .table-workspace {
    min-height: 420px;
    padding: 14px;
  }

  .excel-table-wrap {
    min-height: 300px;
  }
}


/* --------------------------------------------------------------------------
   iOS Liquid Glass Theme Refresh
   Palette: #E9E6E7 / #5E5653 / #6B7C98 / #7B7F8A / #AB978C
   Header brand cluster removed: center navigation remains the anchor.
---------------------------------------------------------------------------- */
:root {
  --navy: #5E5653;
  --navy-soft: rgba(94, 86, 83, 0.78);
  --teal: #6B7C98;
  --teal-dark: #53647D;
  --teal-soft: rgba(107, 124, 152, 0.12);
  --burgundy: #6B7C98;
  --taupe: #AB978C;
  --linen: #E9E6E7;
  --silver: #D8D6D7;
  --ivory: rgba(255, 255, 255, 0.70);
  --steel: #7B7F8A;
  --muted: #7B7F8A;
  --line: rgba(123, 127, 138, 0.24);
  --line-soft: rgba(233, 230, 231, 0.76);
  --surface: rgba(255, 255, 255, 0.58);
  --canvas: #E9E6E7;
  --ink: #312F31;
  --shadow: 0 18px 54px rgba(94, 86, 83, 0.10);
  --shadow-hover: 0 28px 78px rgba(94, 86, 83, 0.17);
}

html { background: #E9E6E7; }
body {
  background:
    radial-gradient(circle at 12% -8%, rgba(107, 124, 152, 0.28), transparent 34%),
    radial-gradient(circle at 88% 2%, rgba(171, 151, 140, 0.25), transparent 30%),
    radial-gradient(circle at 50% 108%, rgba(123, 127, 138, 0.16), transparent 34%),
    linear-gradient(135deg, #F3F1F2 0%, #E9E6E7 42%, #DFDDDF 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255,255,255,0.34) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.26) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.72), transparent 70%);
}

.topbar {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
  min-height: 58px;
  padding: 8px clamp(12px, 2vw, 24px);
  background: rgba(233, 230, 231, 0.54);
  border-bottom: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 10px 42px rgba(94, 86, 83, 0.08);
  -webkit-backdrop-filter: blur(28px) saturate(1.35);
  backdrop-filter: blur(28px) saturate(1.35);
}
.topbar::before {
  content: "";
  position: absolute;
  inset: 6px clamp(8px, 1.5vw, 18px);
  z-index: -1;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,.44), rgba(255,255,255,.16));
  border: 1px solid rgba(255,255,255,.42);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.68);
}
.brand-cluster,
.menu-button,
.brand-name,
.brand-caption { display: none !important; }

.pill-nav {
  grid-column: 2;
  justify-self: center;
  max-width: min(72vw, 760px);
  padding: 4px;
  gap: 3px;
  border: 1px solid rgba(255, 255, 255, 0.52);
  background: rgba(255, 255, 255, 0.34);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.62), 0 12px 36px rgba(94, 86, 83, 0.08);
  -webkit-backdrop-filter: blur(24px) saturate(1.35);
  backdrop-filter: blur(24px) saturate(1.35);
}
.nav-item {
  padding: 7px 13px;
  color: rgba(94, 86, 83, 0.74);
  font-size: 11px;
  letter-spacing: -0.01em;
}
.nav-item.is-active,
.segment.is-active,
.primary-action,
.modal-save-button {
  background: linear-gradient(135deg, #5E5653 0%, #6B7C98 100%) !important;
  color: #fff !important;
  box-shadow: 0 12px 30px rgba(107, 124, 152, 0.22), inset 0 1px 0 rgba(255,255,255,.24);
}
.nav-item:hover,
.segment:hover,
.text-button:hover,
.secondary-action:hover,
.icon-button:hover {
  border-color: rgba(107, 124, 152, 0.26) !important;
  box-shadow: 0 18px 48px rgba(107, 124, 152, 0.15) !important;
}
.profile-zone { grid-column: 3; justify-self: end; }
.icon-button,
.primary-action,
.filter-chip,
.reset-button,
.segmented-control,
.secondary-action,
.text-button {
  background: rgba(255,255,255,0.42);
  border-color: rgba(255,255,255,0.50);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  backdrop-filter: blur(18px) saturate(1.25);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.58), 0 10px 28px rgba(94, 86, 83, 0.06);
}

.dashboard-shell {
  width: min(100%, 1580px);
  padding: 14px clamp(12px, 2vw, 28px) 30px;
}
.command-center,
.card,
.kpi-card,
.detail-modal,
.source-modal {
  background: linear-gradient(180deg, rgba(255,255,255,.64), rgba(255,255,255,.34)) !important;
  border: 1px solid rgba(255,255,255,.46) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.62), var(--shadow) !important;
  -webkit-backdrop-filter: blur(28px) saturate(1.25);
  backdrop-filter: blur(28px) saturate(1.25);
}
.command-center {
  padding: 15px 18px;
  border-radius: 28px;
}
.command-center::after,
.card::after,
.kpi-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,.38), transparent 38%, rgba(107,124,152,.08));
  opacity: .78;
}
.card:hover,
.kpi-card:hover,
.command-center:hover {
  transform: translateY(-2px) scale(1.002);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72), var(--shadow-hover) !important;
}
.eyebrow,
.section-label { color: #6B7C98 !important; }
.lead,
.muted,
.platform-meta,
.product-meta,
.kol-meta,
.source-meta { color: #7B7F8A !important; }
.command-center h1,
.card h2,
.detail-header h2,
.modal-header h2,
.kpi-value,
.headline-metric { color: #312F31 !important; }
.growth-badge,
.mini-badge,
.status-chip,
.source-badge {
  background: rgba(107, 124, 152, 0.10) !important;
  color: #53647D !important;
  border: 1px solid rgba(107, 124, 152, 0.18) !important;
}

.pulse-bar { fill: #6B7C98 !important; }
.pulse-bar:hover { fill: #5E5653 !important; }
.grid-line { stroke: rgba(123, 127, 138, 0.18) !important; }
.axis-label,
.y-label { fill: #7B7F8A !important; font-weight: 500 !important; }
.progress-fill { background: linear-gradient(90deg, #6B7C98, #AB978C) !important; }
.color-dot { box-shadow: 0 0 0 4px rgba(107, 124, 152, 0.12) !important; }
.donut-segment { filter: drop-shadow(0 8px 16px rgba(94, 86, 83, 0.10)); transition: transform 260ms var(--ease), stroke-width 260ms var(--ease), filter 260ms var(--ease); }
.donut-segment:hover { stroke-width: 19; transform: translateY(-2px); filter: drop-shadow(0 12px 26px rgba(107, 124, 152, 0.22)); }

.detail-backdrop,
.modal-backdrop {
  background: rgba(94, 86, 83, 0.34) !important;
  -webkit-backdrop-filter: blur(26px) saturate(1.25);
  backdrop-filter: blur(26px) saturate(1.25);
}
.detail-modal,
.source-modal {
  border-radius: 30px;
  box-shadow: 0 44px 130px rgba(94, 86, 83, 0.30), inset 0 1px 0 rgba(255,255,255,.70) !important;
}
.detail-glow {
  background:
    radial-gradient(circle, rgba(107, 124, 152, 0.22), transparent 62%),
    radial-gradient(circle at 62% 28%, rgba(171, 151, 140, 0.20), transparent 52%) !important;
}
.modal-close {
  right: 18px !important;
  left: auto !important;
  background: rgba(255,255,255,0.54) !important;
  border-color: rgba(255,255,255,0.62) !important;
  color: #5E5653 !important;
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
  backdrop-filter: blur(18px) saturate(1.35);
}
.detail-body::-webkit-scrollbar-thumb,
.excel-table-wrap::-webkit-scrollbar-thumb,
.sheet-rail::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb { background: rgba(107, 124, 152, 0.42) !important; }
.detail-body::-webkit-scrollbar-track,
.excel-table-wrap::-webkit-scrollbar-track,
.sheet-rail::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track { background: rgba(233, 230, 231, 0.55) !important; }

.kol-row:hover,
.decision-card:hover,
.product-row:hover,
.marketing-item:hover,
.insight-item:hover,
.source-row:hover {
  border-color: rgba(107, 124, 152, 0.28) !important;
  background: linear-gradient(180deg, rgba(255,255,255,.64), rgba(233,230,231,.34)) !important;
  transform: translateY(-1px) scale(1.003);
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr auto !important;
    min-height: 56px;
    padding: 8px 12px;
  }
  .pill-nav {
    grid-column: 1 / 2;
    justify-self: center;
    width: min(100%, 720px);
    max-width: calc(100vw - 150px);
  }
  .profile-zone { grid-column: 2 / 3; }
  .dashboard-shell { padding: 12px 12px 24px; }
  .command-center { grid-template-columns: 1fr; gap: 12px; }
  .filter-dock { width: 100%; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; }
  .filter-chip { flex: 0 0 auto; min-width: 138px; }
}

@media (max-width: 760px) {
  .topbar {
    display: block !important;
    padding: 8px 8px 6px;
    min-height: 52px;
  }
  .topbar::before { inset: 5px 7px; }
  .pill-nav {
    width: 100%;
    max-width: 100%;
    justify-content: flex-start;
    padding: 4px;
    overflow-x: auto;
  }
  .nav-item { padding: 7px 11px; font-size: 11px; }
  .profile-zone { display: none !important; }
  .dashboard-shell { padding: 10px 8px 18px; }
  .command-center {
    padding: 14px;
    border-radius: 22px;
  }
  .command-center h1 { font-size: 25px; }
  .lead { font-size: 12px; line-height: 1.45; margin-top: 7px; }
  .filter-dock {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    overflow: visible;
  }
  .filter-chip { min-width: 0; height: 46px; }
  .filter-chip span { font-size: 9px; }
  .filter-chip select { font-size: 11px; }
  .reset-button { height: 46px; }
  .card, .kpi-card { border-radius: 22px; }
  .card { padding: 15px; }
  .kpi-card { padding: 14px; }
  .compact-chart-card { min-height: 292px; }
  .pulse-chart-wrap { height: 132px; }
  .trend-chart-wrap { height: 240px; }
  .headline-metric { font-size: 30px; }
  .detail-modal,
  .source-modal { border-radius: 24px !important; }
  .modal-close { top: 12px !important; right: 12px !important; }
}

@media (max-width: 420px) {
  .filter-dock { grid-template-columns: 1fr; }
  .nav-item { padding-inline: 10px; }
  .card-header { margin-bottom: 12px; }
  .detail-metric-grid { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   FINAL POLISH: muted liquid-glass palette + clean center nav + mobile footer
   Palette: #E9E6E7 / #5E5653 / #6B7C98 / #7B7F8A / #AB978C
---------------------------------------------------------------------------- */
:root {
  --navy: #2f3035 !important;
  --navy-soft: #5E5653 !important;
  --teal: #6B7C98 !important;
  --teal-dark: #5E5653 !important;
  --teal-soft: rgba(107, 124, 152, 0.12) !important;
  --burgundy: #5E5653 !important;
  --taupe: #AB978C !important;
  --linen: #E9E6E7 !important;
  --silver: #E9E6E7 !important;
  --ivory: #F7F5F5 !important;
  --steel: #7B7F8A !important;
  --muted: #7B7F8A !important;
  --line: rgba(123, 127, 138, 0.18) !important;
  --line-soft: rgba(233, 230, 231, 0.72) !important;
  --surface: rgba(255, 255, 255, 0.54) !important;
  --canvas: #E9E6E7 !important;
  --ink: #2f3035 !important;
  --shadow: 0 18px 60px rgba(94, 86, 83, 0.075) !important;
  --shadow-hover: 0 26px 84px rgba(94, 86, 83, 0.13) !important;
}

body {
  color: #2f3035 !important;
  background:
    radial-gradient(circle at 14% -10%, rgba(171, 151, 140, 0.26), transparent 34%),
    radial-gradient(circle at 84% 2%, rgba(107, 124, 152, 0.18), transparent 32%),
    linear-gradient(135deg, #F7F6F6 0%, #E9E6E7 46%, #DDDADB 100%) !important;
  font-family: Inter, "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
}
body::before {
  opacity: 0.45 !important;
  background-size: 90px 90px !important;
}

/* Clean desktop header: no double frame, no brand block, centered tabs only */
.topbar {
  position: sticky !important;
  top: 0 !important;
  z-index: 60 !important;
  display: grid !important;
  grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr) !important;
  min-height: 62px !important;
  padding: 10px clamp(16px, 2.6vw, 34px) !important;
  background: linear-gradient(180deg, rgba(247, 246, 246, 0.72), rgba(233, 230, 231, 0.38)) !important;
  border: 0 !important;
  box-shadow: none !important;
  -webkit-backdrop-filter: blur(22px) saturate(1.18) !important;
  backdrop-filter: blur(22px) saturate(1.18) !important;
}
.topbar::before,
.topbar::after { display: none !important; }
.brand-cluster,
.menu-button,
.brand-name,
.brand-caption { display: none !important; }

.pill-nav {
  grid-column: 2 !important;
  justify-self: center !important;
  width: auto !important;
  max-width: min(78vw, 760px) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
  padding: 5px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(255, 255, 255, 0.56) !important;
  background: linear-gradient(180deg, rgba(255,255,255,0.56), rgba(255,255,255,0.24)) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72), 0 12px 40px rgba(94,86,83,.075) !important;
  -webkit-backdrop-filter: blur(24px) saturate(1.25) !important;
  backdrop-filter: blur(24px) saturate(1.25) !important;
  overflow: visible !important;
}
.nav-item {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
  min-width: 74px !important;
  height: 36px !important;
  padding: 0 16px !important;
  border-radius: 999px !important;
  color: rgba(94, 86, 83, 0.74) !important;
  font-size: 12px !important;
  font-weight: 750 !important;
  letter-spacing: -0.015em !important;
  background: transparent !important;
  border: 1px solid transparent !important;
  box-shadow: none !important;
  transition: color 220ms var(--ease), background 220ms var(--ease), transform 220ms var(--ease), box-shadow 220ms var(--ease) !important;
}
.nav-item:hover {
  color: #5E5653 !important;
  transform: translateY(-1px) !important;
  background: rgba(255,255,255,.38) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.74) !important;
}
.nav-item.is-active {
  color: #fff !important;
  background: linear-gradient(135deg, #5E5653 0%, #6B7C98 100%) !important;
  box-shadow: 0 12px 32px rgba(107,124,152,.18), inset 0 1px 0 rgba(255,255,255,.25) !important;
}
.nav-icon { display: none; }
.nav-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.profile-zone {
  grid-column: 3 !important;
  justify-self: end !important;
}
.profile-zone .icon-button,
.profile-zone .primary-action {
  background: rgba(255,255,255,.42) !important;
  border: 1px solid rgba(255,255,255,.54) !important;
  color: #5E5653 !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.68), 0 10px 30px rgba(94,86,83,.06) !important;
}
.profile-zone .primary-action {
  color: #fff !important;
  background: linear-gradient(135deg, #5E5653, #6B7C98) !important;
}

/* Cleaner hero: single surface, less heavy text and less nested border feeling */
.dashboard-shell {
  width: min(100%, 1560px) !important;
  padding: 12px clamp(14px, 2vw, 30px) 34px !important;
}
.command-center {
  display: grid !important;
  grid-template-columns: minmax(260px, 1fr) minmax(420px, 0.92fr) !important;
  align-items: center !important;
  gap: 18px !important;
  padding: 18px 20px !important;
  border-radius: 28px !important;
  background: linear-gradient(180deg, rgba(255,255,255,.58), rgba(255,255,255,.30)) !important;
  border: 1px solid rgba(255,255,255,.48) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72), 0 18px 58px rgba(94,86,83,.075) !important;
  -webkit-backdrop-filter: blur(22px) saturate(1.18) !important;
  backdrop-filter: blur(22px) saturate(1.18) !important;
}
.command-center::after,
.card::after,
.kpi-card::after { opacity: .34 !important; }
.eyebrow,
.section-label {
  color: #6B7C98 !important;
  font-size: 11px !important;
  font-weight: 780 !important;
  letter-spacing: .085em !important;
}
.command-center h1 {
  margin-top: 6px !important;
  color: #2f3035 !important;
  font-size: clamp(28px, 2.4vw, 40px) !important;
  font-weight: 760 !important;
  letter-spacing: -0.055em !important;
  line-height: 1.04 !important;
}
.lead {
  max-width: 760px !important;
  margin-top: 8px !important;
  color: #7B7F8A !important;
  font-size: 13px !important;
  line-height: 1.58 !important;
  font-weight: 450 !important;
}
.filter-dock {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 10px !important;
  width: 100% !important;
  padding: 0 !important;
}
.filter-chip,
.reset-button {
  height: 52px !important;
  border-radius: 18px !important;
  background: linear-gradient(180deg, rgba(255,255,255,.62), rgba(255,255,255,.34)) !important;
  border: 1px solid rgba(255,255,255,.56) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72), 0 8px 24px rgba(94,86,83,.045) !important;
  color: #5E5653 !important;
}
.filter-chip span {
  color: #7B7F8A !important;
  font-weight: 760 !important;
  letter-spacing: .065em !important;
}
.filter-chip select {
  color: #4f5056 !important;
  font-weight: 650 !important;
}
.reset-button {
  color: #fff !important;
  font-weight: 760 !important;
  background: linear-gradient(135deg, rgba(94,86,83,.82), rgba(107,124,152,.82)) !important;
}

.card,
.kpi-card {
  background: linear-gradient(180deg, rgba(255,255,255,.58), rgba(255,255,255,.30)) !important;
  border: 1px solid rgba(255,255,255,.48) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.68), 0 16px 54px rgba(94,86,83,.07) !important;
}
.card h2,
.kpi-value,
.headline-metric,
.detail-header h2,
.modal-header h2 {
  color: #2f3035 !important;
  font-weight: 760 !important;
}
.muted,
.platform-meta,
.product-meta,
.kol-meta,
.source-meta,
.detail-section p,
.detail-section li { color: #7B7F8A !important; }
.growth-badge,
.mini-badge,
.status-chip,
.source-badge {
  background: rgba(107,124,152,.11) !important;
  color: #5c6e88 !important;
  border: 1px solid rgba(107,124,152,.16) !important;
}
.pulse-bar,
.trend-bar { fill: #6B7C98 !important; }
.pulse-bar:hover,
.trend-bar:hover { fill: #5E5653 !important; }
.progress-fill { background: linear-gradient(90deg, #6B7C98, #AB978C) !important; }
.grid-line { stroke: rgba(123,127,138,.16) !important; }
.axis-label,
.y-label { fill: #7B7F8A !important; font-weight: 500 !important; }

/* Responsive: convert the main navigation into a compact iOS-style bottom menu */
@media (max-width: 860px) {
  body {
    padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .topbar {
    position: fixed !important;
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 90 !important;
    display: block !important;
    min-height: 0 !important;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    background: transparent !important;
    border: 0 !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    pointer-events: none !important;
  }
  .profile-zone { display: none !important; }
  .pill-nav {
    pointer-events: auto !important;
    width: min(100%, 520px) !important;
    max-width: calc(100vw - 20px) !important;
    margin: 0 auto !important;
    display: grid !important;
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
    gap: 3px !important;
    padding: 7px !important;
    border-radius: 26px !important;
    background: linear-gradient(180deg, rgba(255,255,255,.72), rgba(255,255,255,.42)) !important;
    border: 1px solid rgba(255,255,255,.60) !important;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.78), 0 16px 54px rgba(94,86,83,.18) !important;
    -webkit-backdrop-filter: blur(26px) saturate(1.28) !important;
    backdrop-filter: blur(26px) saturate(1.28) !important;
    overflow: hidden !important;
  }
  .nav-item {
    min-width: 0 !important;
    width: 100% !important;
    height: 50px !important;
    padding: 0 4px !important;
    flex-direction: column !important;
    gap: 3px !important;
    border-radius: 20px !important;
    font-size: 9.5px !important;
    font-weight: 760 !important;
    letter-spacing: -0.025em !important;
    color: rgba(94,86,83,.66) !important;
  }
  .nav-icon {
    display: grid !important;
    place-items: center !important;
    color: currentColor !important;
  }
  .nav-icon svg {
    width: 18px !important;
    height: 18px !important;
  }
  .nav-label { line-height: 1 !important; }
  .nav-item.is-active {
    color: #fff !important;
    background: linear-gradient(135deg, #5E5653, #6B7C98) !important;
    box-shadow: 0 10px 24px rgba(107,124,152,.20), inset 0 1px 0 rgba(255,255,255,.24) !important;
  }

  .dashboard-shell {
    padding: 10px 10px 12px !important;
  }
  .command-center {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 14px !important;
    border-radius: 24px !important;
  }
  .command-center h1 {
    font-size: 25px !important;
    letter-spacing: -0.05em !important;
  }
  .lead {
    font-size: 12px !important;
    line-height: 1.45 !important;
    max-width: 100% !important;
  }
  .filter-dock {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 7px !important;
  }
  .filter-chip,
  .reset-button {
    min-width: 0 !important;
    height: 42px !important;
    border-radius: 15px !important;
    padding: 7px 9px !important;
  }
  .filter-chip span { font-size: 8.5px !important; }
  .filter-chip select { font-size: 11px !important; }
  .reset-button {
    grid-column: 1 / -1 !important;
    height: 40px !important;
  }
  .kpi-grid,
  .dashboard-grid,
  .compact-view-grid {
    gap: 10px !important;
  }
  .card { padding: 14px !important; border-radius: 22px !important; }
  .kpi-card { padding: 13px !important; border-radius: 20px !important; }
  .card-header { margin-bottom: 11px !important; }
  .card h2 { font-size: 17px !important; }
  .muted { font-size: 12px !important; }
  .compact-chart-card { min-height: 270px !important; }
  .pulse-chart-wrap { height: 124px !important; }
  .trend-chart-wrap { height: 230px !important; }
  .headline-metric { font-size: 28px !important; }
}

@media (max-width: 430px) {
  .dashboard-shell { padding-inline: 8px !important; }
  .pill-nav {
    width: calc(100vw - 14px) !important;
    max-width: calc(100vw - 14px) !important;
    padding: 6px !important;
    border-radius: 23px !important;
  }
  .nav-item {
    height: 47px !important;
    font-size: 8.8px !important;
    border-radius: 17px !important;
  }
  .nav-icon svg { width: 17px !important; height: 17px !important; }
  .filter-dock { grid-template-columns: 1fr 1fr !important; }
  .filter-chip:nth-child(3), .reset-button { grid-column: span 2 !important; }
  .command-center h1 { font-size: 23px !important; }
  .lead { display: none !important; }
}

/* --------------------------------------------------------------------------
   COMPACT FILTER + FOOTER MENU FIX
   - Remove hero description from visual flow
   - Flatten filter/dropdown surfaces so they do not look stacked
   - Add stronger separation for responsive bottom navigation
---------------------------------------------------------------------------- */
.lead,
#currentViewLead {
  display: none !important;
}

.command-center {
  grid-template-columns: minmax(230px, .76fr) minmax(520px, 1.24fr) !important;
  align-items: end !important;
  gap: 18px !important;
  padding: 18px 20px !important;
  border-radius: 26px !important;
  background: linear-gradient(180deg, rgba(255,255,255,.50), rgba(255,255,255,.26)) !important;
  border: 1px solid rgba(255,255,255,.58) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.70), 0 14px 44px rgba(94,86,83,.06) !important;
}

.view-title-block {
  min-width: 0 !important;
}

.command-center h1 {
  margin: 4px 0 0 !important;
  font-size: clamp(26px, 2.15vw, 36px) !important;
  line-height: 1.02 !important;
}

.eyebrow {
  margin-bottom: 0 !important;
  font-size: 10px !important;
  letter-spacing: .095em !important;
}

.filter-dock {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto !important;
  gap: 8px !important;
  align-items: end !important;
  width: 100% !important;
  padding: 8px !important;
  border-radius: 22px !important;
  background: rgba(255,255,255,.34) !important;
  border: 1px solid rgba(255,255,255,.48) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.60) !important;
  -webkit-backdrop-filter: blur(18px) saturate(1.12) !important;
  backdrop-filter: blur(18px) saturate(1.12) !important;
}

.filter-chip {
  display: grid !important;
  grid-template-rows: auto 34px !important;
  gap: 3px !important;
  min-width: 0 !important;
  height: auto !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  overflow: visible !important;
}

.filter-chip span {
  padding-left: 9px !important;
  color: rgba(94,86,83,.66) !important;
  font-size: 9px !important;
  line-height: 1 !important;
  font-weight: 760 !important;
  letter-spacing: .075em !important;
}

.filter-chip select {
  width: 100% !important;
  min-width: 0 !important;
  height: 34px !important;
  padding: 0 28px 0 11px !important;
  border-radius: 14px !important;
  border: 1px solid rgba(123,127,138,.18) !important;
  background: rgba(255,255,255,.76) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.82), 0 6px 16px rgba(94,86,83,.035) !important;
  color: #4f5056 !important;
  font-size: 12px !important;
  font-weight: 650 !important;
  outline: none !important;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease), background 180ms var(--ease), transform 180ms var(--ease) !important;
}

.filter-chip select:hover,
.filter-chip select:focus {
  background: rgba(255,255,255,.94) !important;
  border-color: rgba(107,124,152,.36) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.92), 0 0 0 4px rgba(107,124,152,.09), 0 10px 24px rgba(94,86,83,.05) !important;
}

.reset-button {
  align-self: end !important;
  width: auto !important;
  min-width: 104px !important;
  height: 34px !important;
  padding: 0 18px !important;
  border-radius: 14px !important;
  border: 1px solid rgba(107,124,152,.22) !important;
  background: linear-gradient(135deg, #6B7C98 0%, #5E5653 100%) !important;
  color: #fff !important;
  box-shadow: 0 10px 24px rgba(107,124,152,.17), inset 0 1px 0 rgba(255,255,255,.22) !important;
}
.reset-button:hover {
  transform: translateY(-1px) !important;
  box-shadow: 0 14px 30px rgba(107,124,152,.22), inset 0 1px 0 rgba(255,255,255,.26) !important;
}

@media (max-width: 1180px) {
  .command-center {
    grid-template-columns: 1fr !important;
    align-items: stretch !important;
    gap: 14px !important;
  }
  .filter-dock {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto !important;
  }
}

@media (max-width: 860px) {
  body::after {
    content: "";
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 118px;
    z-index: 82;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(233,230,231,0), rgba(233,230,231,.86) 48%, rgba(233,230,231,.98));
  }

  .topbar {
    z-index: 96 !important;
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .pill-nav {
    position: relative !important;
    z-index: 2 !important;
    border: 1px solid rgba(255,255,255,.74) !important;
    background: linear-gradient(180deg, rgba(255,255,255,.84), rgba(255,255,255,.52)) !important;
    box-shadow:
      0 -10px 34px rgba(94,86,83,.09),
      0 18px 58px rgba(47,48,53,.24),
      0 0 0 1px rgba(107,124,152,.06),
      inset 0 1px 0 rgba(255,255,255,.88) !important;
  }

  .pill-nav::before {
    content: "";
    position: absolute;
    inset: -10px -8px;
    z-index: -1;
    border-radius: 32px;
    background: radial-gradient(circle at 50% 0%, rgba(255,255,255,.72), transparent 58%);
    filter: blur(10px);
    opacity: .85;
  }

  .command-center {
    padding: 13px !important;
    gap: 10px !important;
    border-radius: 22px !important;
  }

  .command-center h1 {
    font-size: 24px !important;
  }

  .filter-dock {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    padding: 8px !important;
    border-radius: 20px !important;
  }

  .filter-chip {
    grid-template-rows: auto 32px !important;
    gap: 3px !important;
  }

  .filter-chip span {
    padding-left: 8px !important;
    font-size: 8px !important;
  }

  .filter-chip select {
    height: 32px !important;
    border-radius: 13px !important;
    font-size: 10.5px !important;
    padding-inline: 9px 25px !important;
  }

  .filter-chip:nth-child(3),
  .reset-button {
    grid-column: span 2 !important;
  }

  .reset-button {
    width: 100% !important;
    min-width: 0 !important;
    height: 34px !important;
    margin-top: 0 !important;
  }
}

@media (max-width: 430px) {
  .command-center {
    padding: 12px !important;
  }
  .command-center h1 {
    font-size: 22px !important;
  }
  .filter-dock {
    gap: 7px !important;
    padding: 7px !important;
  }
  .filter-chip select {
    font-size: 10px !important;
  }
  .pill-nav {
    box-shadow:
      0 -8px 28px rgba(94,86,83,.10),
      0 16px 50px rgba(47,48,53,.27),
      inset 0 1px 0 rgba(255,255,255,.88) !important;
  }
}

/* --------------------------------------------------------------------------
   RESPONSIVE FILTER COLLAPSE + COPY CLEANUP + BOTTOM NAV TAP FIX
   - Product/overview filters are collapsed on responsive to reduce scroll
   - Removes visual noise from helper labels/badges
   - Makes KOL and Source footer menu reliably tappable
---------------------------------------------------------------------------- */
.filter-toggle {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,.58);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.64), rgba(255,255,255,.36));
  color: #5E5653;
  font-size: 12px;
  font-weight: 760;
  letter-spacing: -0.01em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.76), 0 10px 24px rgba(94,86,83,.055);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  cursor: pointer;
  transition: transform 220ms var(--ease), box-shadow 220ms var(--ease), background 220ms var(--ease);
}
.filter-toggle:hover { transform: translateY(-1px); box-shadow: inset 0 1px 0 rgba(255,255,255,.84), 0 16px 34px rgba(94,86,83,.09); }
.filter-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform 240ms var(--ease); }
.command-center.is-filter-open .filter-toggle svg { transform: rotate(180deg); }

.card-header .mini-badge:empty { display: none !important; }
.card-header .muted { max-width: 42rem; }

@media (max-width: 860px) {
  .command-center {
    gap: 8px !important;
  }
  .filter-toggle {
    display: flex !important;
  }
  .filter-dock {
    max-height: 0 !important;
    opacity: 0 !important;
    transform: translateY(-4px) scale(.992) !important;
    overflow: hidden !important;
    pointer-events: none !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    border-width: 0 !important;
    margin-top: 0 !important;
    transition: max-height 280ms cubic-bezier(.25, 1, .5, 1), opacity 220ms var(--ease), transform 260ms var(--ease), padding 260ms var(--ease), border-width 260ms var(--ease) !important;
  }
  .command-center.is-filter-open .filter-dock {
    max-height: 240px !important;
    opacity: 1 !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
    padding: 8px !important;
    border-width: 1px !important;
  }

  body::after { z-index: 80 !important; }
  .topbar {
    z-index: 9999 !important;
    pointer-events: none !important;
    isolation: isolate !important;
  }
  .pill-nav {
    z-index: 10000 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    box-shadow:
      0 -12px 36px rgba(94,86,83,.13),
      0 20px 64px rgba(47,48,53,.28),
      0 0 0 1px rgba(255,255,255,.62),
      inset 0 1px 0 rgba(255,255,255,.9) !important;
  }
  .nav-item {
    position: relative !important;
    z-index: 10001 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
    -webkit-tap-highlight-color: transparent !important;
  }
  .nav-item * {
    pointer-events: none !important;
  }
  .nav-label {
    font-size: 8.8px !important;
    max-width: 100% !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
}

@media (max-width: 430px) {
  .filter-toggle {
    min-height: 38px;
    border-radius: 16px;
    font-size: 11px;
    padding-inline: 12px;
  }
  .command-center.is-filter-open .filter-dock {
    max-height: 260px !important;
  }
  .pill-nav {
    padding: 5px !important;
    gap: 2px !important;
  }
  .nav-item {
    height: 48px !important;
    padding-inline: 2px !important;
  }
}

/* Clean Source Manager refinement: demo-ready, no decorative icons, no one-column raw sheet look */
.source-modal {
  background: linear-gradient(180deg, rgba(250, 250, 250, .92), rgba(245, 244, 243, .86)) !important;
}
.modal-header .eyebrow,
.workspace-head .section-label {
  letter-spacing: .09em !important;
}
.excel-status {
  color: #5E5653 !important;
  background: rgba(255,255,255,.64) !important;
  border-color: rgba(123,127,138,.18) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72) !important;
}
.excel-status.is-live {
  color: #53647d !important;
  background: rgba(107,124,152,.10) !important;
  border-color: rgba(107,124,152,.18) !important;
}
.sheet-rail {
  background: linear-gradient(180deg, rgba(255,255,255,.36), rgba(233,230,231,.24)) !important;
}
.sheet-button {
  border-radius: 16px !important;
  padding: 12px 13px !important;
}
.sheet-button strong {
  font-weight: 760 !important;
  letter-spacing: -0.01em !important;
}
.sheet-button span {
  color: #7B7F8A !important;
  font-weight: 620 !important;
}
.sheet-button.is-active {
  border-color: rgba(107,124,152,.22) !important;
  background: rgba(255,255,255,.74) !important;
  box-shadow: 0 10px 28px rgba(94,86,83,.075), inset 0 1px 0 rgba(255,255,255,.84) !important;
}
.excel-table-wrap {
  border-color: rgba(123,127,138,.16) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72), 0 14px 40px rgba(94,86,83,.05) !important;
}
.excel-data-table th {
  background: rgba(250,250,250,.96) !important;
  color: #7B7F8A !important;
  font-weight: 720 !important;
  text-transform: none !important;
  letter-spacing: .01em !important;
}
.excel-data-table td {
  font-weight: 540 !important;
}
.excel-cell-input {
  font-weight: 540 !important;
  border-radius: 10px !important;
}
.excel-cell-input:hover {
  background: rgba(233,230,231,.22) !important;
}
.delete-row-button {
  color: #72383D !important;
  border-color: rgba(114,56,61,.16) !important;
}
.source-row::after { content: "Open" !important; }
@media (max-width: 860px) {
  .source-modal { max-height: 94vh !important; }
  .sheet-button { min-width: 178px !important; }
  .workspace-head h3 { font-size: 18px !important; }
}

/* Source Manager tab consistency polish */
.sheet-rail {
  padding: 18px 16px !important;
}
.sheet-button {
  position: relative;
  display: grid !important;
  gap: 4px !important;
  margin-bottom: 10px !important;
}
.sheet-button strong {
  font-size: 13px !important;
  color: #363332 !important;
}
.sheet-button span {
  font-size: 11px !important;
  color: #7B7F8A !important;
}
.sheet-button.is-active::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 14px;
  width: 3px;
  height: calc(100% - 28px);
  min-height: 18px;
  border-radius: 999px;
  background: #6B7C98;
  box-shadow: 0 0 14px rgba(107, 124, 152, .34);
}
.source-row::after {
  content: none !important;
}
.excel-modal-layout {
  grid-template-columns: minmax(210px, 250px) minmax(0, 1fr) !important;
}
@media (max-width: 860px) {
  .excel-modal-layout {
    grid-template-columns: 1fr !important;
  }
  .sheet-rail {
    display: grid !important;
    grid-auto-flow: column !important;
    grid-auto-columns: minmax(170px, 1fr) !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 12px !important;
  }
  .sheet-button {
    margin-bottom: 0 !important;
  }
}

/* Source page display fix: keep Source Mapping cards clean for demo */
.source-row::after {
  display: none !important;
  content: none !important;
}
.source-page-list {
  align-items: stretch;
}
.source-page-list .source-row {
  min-height: 68px;
}

/* Final content alignment polish: keep list content business-readable, not centered */
.insight-item,
.marketing-item,
.product-row,
.kol-row,
.source-row,
.platform-row,
.mini-note,
.decision-card,
.quality-card {
  text-align: left !important;
}

.insight-item > div:not(.insight-index),
.marketing-item > div,
.product-main,
.kol-main,
.source-main,
.mini-note strong,
.mini-note span,
.decision-card strong,
.decision-card span,
.product-name,
.product-meta,
.kol-name,
.kol-meta,
.source-title,
.source-meta,
.marketing-label,
.insight-title,
.insight-desc {
  text-align: left !important;
}

/* Keep number badges centered only inside the badge itself */
.insight-index,
.product-rank,
.kol-rank,
.metric-icon,
.donut-center {
  text-align: center !important;
}

/* Modern minimal Inventory Signal animation */
.inventory-signal-list {
  gap: 10px !important;
}

.inventory-signal-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: start;
  overflow: hidden;
}

.inventory-signal-dot {
  position: relative;
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: #6B7C98;
  box-shadow: 0 0 0 5px rgba(107, 124, 152, 0.10);
}

.inventory-signal-dot::before,
.inventory-signal-dot::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: inherit;
  border: 1px solid rgba(107, 124, 152, 0.26);
  opacity: 0;
  transform: scale(0.45);
  animation: inventoryPulse 2.4s cubic-bezier(0.25, 1, 0.5, 1) infinite;
}

.inventory-signal-dot::after {
  animation-delay: 1.1s;
}

.inventory-signal-dot.is-watch {
  background: #AB978C;
  box-shadow: 0 0 0 5px rgba(171, 151, 140, 0.13);
}

.inventory-signal-dot.is-watch::before,
.inventory-signal-dot.is-watch::after {
  border-color: rgba(171, 151, 140, 0.30);
}

.inventory-signal-dot.is-critical {
  background: #5E5653;
  box-shadow: 0 0 0 5px rgba(94, 86, 83, 0.12);
}

.inventory-signal-dot.is-critical::before,
.inventory-signal-dot.is-critical::after {
  border-color: rgba(94, 86, 83, 0.28);
}

.inventory-signal-item::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  opacity: 0;
  background: linear-gradient(180deg, rgba(107,124,152,0), rgba(107,124,152,.52), rgba(107,124,152,0));
  transform: translateY(-32%);
  animation: signalSweep 3.2s cubic-bezier(0.25, 1, 0.5, 1) infinite;
}

.inventory-signal-item:hover::before {
  opacity: 1;
}

@keyframes inventoryPulse {
  0% { opacity: 0; transform: scale(0.42); }
  28% { opacity: 0.78; }
  100% { opacity: 0; transform: scale(1.75); }
}

@keyframes signalSweep {
  0% { transform: translateY(-45%); opacity: 0; }
  22% { opacity: 0.55; }
  70% { opacity: 0.18; }
  100% { transform: translateY(45%); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .inventory-signal-dot::before,
  .inventory-signal-dot::after,
  .inventory-signal-item::before {
    animation: none !important;
  }
}

/* --------------------------------------------------------------------------
   FINAL UPDATE: theme switcher + Light / Warm / Charcoal Dark palettes
   - Export / Refresh buttons removed from top-right controls
   - Theme preference is persisted via localStorage in app.js
---------------------------------------------------------------------------- */
body[data-theme="warm"] {
  --navy: #2F3035 !important;
  --navy-soft: #5E5653 !important;
  --teal: #6B7C98 !important;
  --teal-dark: #5E5653 !important;
  --teal-soft: rgba(107, 124, 152, 0.13) !important;
  --taupe: #AB978C !important;
  --linen: #E9E6E7 !important;
  --silver: #D8D6D7 !important;
  --ivory: #F7F5F5 !important;
  --steel: #7B7F8A !important;
  --muted: #7B7F8A !important;
  --line: rgba(123, 127, 138, 0.18) !important;
  --line-soft: rgba(233, 230, 231, 0.72) !important;
  --surface: rgba(255, 255, 255, 0.56) !important;
  --canvas: #E9E6E7 !important;
  --ink: #2F3035 !important;
  --chart-1: #6B7C98;
  --chart-2: #5E5653;
  --chart-3: #AB978C;
  --chart-4: #7B7F8A;
  --chart-5: #D5CED0;
  --shadow: 0 18px 60px rgba(94, 86, 83, 0.075) !important;
  --shadow-hover: 0 26px 84px rgba(94, 86, 83, 0.13) !important;
  color: var(--ink) !important;
  background:
    radial-gradient(circle at 14% -10%, rgba(171, 151, 140, 0.26), transparent 34%),
    radial-gradient(circle at 84% 2%, rgba(107, 124, 152, 0.18), transparent 32%),
    linear-gradient(135deg, #F7F6F6 0%, #E9E6E7 46%, #DDDADB 100%) !important;
}

body[data-theme="light"] {
  --navy: #172033 !important;
  --navy-soft: #344054 !important;
  --teal: #2F7FE8 !important;
  --teal-dark: #1762C6 !important;
  --teal-soft: rgba(47, 127, 232, 0.12) !important;
  --taupe: #8AB8F5 !important;
  --linen: #EEF5FF !important;
  --silver: #DDE8F6 !important;
  --ivory: #FFFFFF !important;
  --steel: #607086 !important;
  --muted: #8493A8 !important;
  --line: rgba(90, 119, 160, 0.17) !important;
  --line-soft: rgba(238, 245, 255, 0.84) !important;
  --surface: rgba(255, 255, 255, 0.78) !important;
  --canvas: #F4F8FF !important;
  --ink: #172033 !important;
  --chart-1: #2F7FE8;
  --chart-2: #14A6A6;
  --chart-3: #7C8DB5;
  --chart-4: #94B8F2;
  --chart-5: #CBDCF7;
  --shadow: 0 18px 56px rgba(32, 84, 145, 0.08) !important;
  --shadow-hover: 0 28px 86px rgba(32, 84, 145, 0.15) !important;
  color: var(--ink) !important;
  background:
    radial-gradient(circle at 12% -10%, rgba(47, 127, 232, 0.22), transparent 34%),
    radial-gradient(circle at 90% 2%, rgba(20, 166, 166, 0.16), transparent 30%),
    linear-gradient(135deg, #FFFFFF 0%, #F4F8FF 46%, #EAF2FF 100%) !important;
}

body[data-theme="dark"] {
  --navy: #F1F3F5 !important;
  --navy-soft: #D6DBE0 !important;
  --teal: #86A5C8 !important;
  --teal-dark: #AB978C !important;
  --teal-soft: rgba(134, 165, 200, 0.14) !important;
  --taupe: #AB978C !important;
  --linen: #343941 !important;
  --silver: #4A515B !important;
  --ivory: #2E333A !important;
  --steel: #B4BEC9 !important;
  --muted: #9BA5B1 !important;
  --line: rgba(222, 228, 235, 0.13) !important;
  --line-soft: rgba(255, 255, 255, 0.08) !important;
  --surface: rgba(42, 47, 54, 0.74) !important;
  --canvas: #252A31 !important;
  --ink: #ECEFF2 !important;
  --chart-1: #86A5C8;
  --chart-2: #AB978C;
  --chart-3: #A9B2BE;
  --chart-4: #6E7F97;
  --chart-5: #454B54;
  --shadow: 0 18px 62px rgba(0, 0, 0, 0.18) !important;
  --shadow-hover: 0 30px 90px rgba(0, 0, 0, 0.26) !important;
  color: var(--ink) !important;
  background:
    radial-gradient(circle at 14% -10%, rgba(134, 165, 200, 0.18), transparent 34%),
    radial-gradient(circle at 88% 2%, rgba(171, 151, 140, 0.15), transparent 32%),
    linear-gradient(135deg, #30343B 0%, #252A31 52%, #20242B 100%) !important;
}

html[data-theme="light"] { background: #F4F8FF !important; }
html[data-theme="warm"] { background: #E9E6E7 !important; }
html[data-theme="dark"] { background: #252A31 !important; }

body[data-theme] .topbar {
  background: color-mix(in srgb, var(--canvas) 72%, transparent) !important;
  color: var(--ink) !important;
}
body[data-theme] .pill-nav,
body[data-theme] .theme-switcher,
body[data-theme] .command-center,
body[data-theme] .card,
body[data-theme] .kpi-card,
body[data-theme] .source-modal,
body[data-theme] .detail-modal {
  background: var(--surface) !important;
  border-color: var(--line) !important;
  box-shadow: var(--shadow) !important;
  color: var(--ink) !important;
}
body[data-theme] .card:hover,
body[data-theme] .kpi-card:hover,
body[data-theme] .theme-switcher:hover { box-shadow: var(--shadow-hover) !important; }

body[data-theme] h1,
body[data-theme] h2,
body[data-theme] h3,
body[data-theme] .brand-name,
body[data-theme] .source-title,
body[data-theme] .product-title,
body[data-theme] .kol-name,
body[data-theme] .metric-value,
body[data-theme] .headline-metric,
body[data-theme] .command-center h1 { color: var(--navy) !important; }
body[data-theme] .muted,
body[data-theme] .source-meta,
body[data-theme] .metric-label,
body[data-theme] .axis-label,
body[data-theme] .y-label { color: var(--steel) !important; fill: var(--steel) !important; }
body[data-theme] .section-label,
body[data-theme] .eyebrow { color: var(--teal) !important; }

body[data-theme] .nav-item { color: var(--steel) !important; }
body[data-theme] .nav-item:hover { color: var(--navy) !important; }
body[data-theme] .nav-item.is-active,
body[data-theme] .segment.is-active,
body[data-theme] .reset-button,
body[data-theme] .primary-action,
body[data-theme] .modal-save-button,
body[data-theme] .source-manage-button {
  color: #fff !important;
  background: linear-gradient(135deg, var(--teal-dark) 0%, var(--teal) 100%) !important;
  border-color: color-mix(in srgb, var(--teal) 38%, transparent) !important;
}

body[data-theme] .filter-chip select,
body[data-theme] .table-search input,
body[data-theme] .excel-cell-input,
body[data-theme] .secondary-action,
body[data-theme] .modal-close,
body[data-theme] .source-row,
body[data-theme] .product-row,
body[data-theme] .kol-row,
body[data-theme] .marketing-item,
body[data-theme] .insight-item,
body[data-theme] .decision-card,
body[data-theme] .note-item,
body[data-theme] .excel-data-table td,
body[data-theme] .excel-data-table th {
  background: color-mix(in srgb, var(--ivory) 76%, transparent) !important;
  border-color: var(--line) !important;
  color: var(--ink) !important;
}

body[data-theme] .excel-data-table thead th,
body[data-theme] .workspace-head,
body[data-theme] .modal-toolbar { background: color-mix(in srgb, var(--canvas) 62%, transparent) !important; }
body[data-theme] .grid-line { stroke: var(--line) !important; }
body[data-theme] .pulse-bar,
body[data-theme] .trend-bar { fill: var(--chart-1) !important; }
body[data-theme] .pulse-bar:hover,
body[data-theme] .trend-bar:hover { fill: var(--teal-dark) !important; }
body[data-theme] .progress-fill { background: linear-gradient(90deg, var(--chart-1), var(--chart-2)) !important; }
body[data-theme] .color-dot { background: var(--chart-1); }
body[data-theme] .chart-tooltip,
body[data-theme] .toast { background: color-mix(in srgb, var(--ink) 86%, #000 14%) !important; color: var(--canvas) !important; }
body[data-theme="dark"] .chart-tooltip,
body[data-theme="dark"] .toast { background: rgba(17, 20, 24, 0.92) !important; color: #F7F8FA !important; }

.theme-zone { display: flex !important; align-items: center !important; justify-content: flex-end !important; }
.theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(22px) saturate(1.16);
  backdrop-filter: blur(22px) saturate(1.16);
  box-shadow: var(--shadow);
}
.theme-option {
  min-width: 54px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--steel);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: -0.01em;
  transition: transform 220ms var(--ease), background 220ms var(--ease), color 220ms var(--ease), box-shadow 220ms var(--ease);
}
.theme-option:hover { transform: translateY(-1px); color: var(--navy); }
.theme-option.is-active {
  color: #fff !important;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal)) !important;
  box-shadow: 0 10px 22px color-mix(in srgb, var(--teal) 24%, transparent);
}
.theme-switcher-mobile { display: none; }

body[data-theme="dark"] .topbar,
body[data-theme="dark"] .pill-nav,
body[data-theme="dark"] .theme-switcher,
body[data-theme="dark"] .command-center,
body[data-theme="dark"] .card,
body[data-theme="dark"] .kpi-card,
body[data-theme="dark"] .source-modal,
body[data-theme="dark"] .detail-modal {
  -webkit-backdrop-filter: blur(26px) saturate(1.16) brightness(0.96) !important;
  backdrop-filter: blur(26px) saturate(1.16) brightness(0.96) !important;
}
body[data-theme="dark"] .filter-chip select,
body[data-theme="dark"] .table-search input,
body[data-theme="dark"] .excel-cell-input { color-scheme: dark; }
body[data-theme="dark"] .modal-backdrop,
body[data-theme="dark"] .detail-backdrop { background: rgba(18, 20, 24, 0.62) !important; }

@media (max-width: 860px) {
  .theme-zone { display: none !important; }
  .theme-switcher-mobile {
    position: fixed;
    right: 12px;
    bottom: calc(82px + env(safe-area-inset-bottom, 0px));
    z-index: 104;
    display: inline-flex !important;
    transform: translateZ(0);
  }
  .theme-switcher-mobile .theme-option {
    min-width: 32px;
    width: 32px;
    height: 30px;
    font-size: 10px;
  }
  body[data-theme="light"]::after {
    background: linear-gradient(180deg, rgba(244,248,255,0), rgba(244,248,255,.82) 48%, rgba(244,248,255,.96)) !important;
  }
  body[data-theme="warm"]::after {
    background: linear-gradient(180deg, rgba(233,230,231,0), rgba(233,230,231,.86) 48%, rgba(233,230,231,.98)) !important;
  }
  body[data-theme="dark"]::after {
    background: linear-gradient(180deg, rgba(37,42,49,0), rgba(37,42,49,.84) 48%, rgba(37,42,49,.96)) !important;
  }
  body[data-theme] .pill-nav {
    background: color-mix(in srgb, var(--surface) 86%, transparent) !important;
    border-color: color-mix(in srgb, var(--line) 80%, transparent) !important;
  }
}

/* --------------------------------------------------------------------------
   Dark Theme Readability Patch
   Purpose: charcoal dark that stays premium, readable, and keeps charts visible.
---------------------------------------------------------------------------- */
body[data-theme="dark"] {
  --navy: #F6F7F9 !important;
  --navy-soft: #E5E9EF !important;
  --teal: #9CBFE6 !important;
  --teal-dark: #7697BD !important;
  --teal-soft: rgba(156, 191, 230, 0.15) !important;
  --taupe: #C6AFA3 !important;
  --linen: #39414A !important;
  --silver: #56616D !important;
  --ivory: #363D46 !important;
  --steel: #C4CDD8 !important;
  --muted: #AAB4C0 !important;
  --line: rgba(218, 226, 236, 0.18) !important;
  --line-soft: rgba(218, 226, 236, 0.10) !important;
  --surface: rgba(51, 58, 67, 0.82) !important;
  --canvas: #2E343C !important;
  --ink: #EEF2F6 !important;
  --chart-1: #9CBFE6 !important;
  --chart-2: #C6AFA3 !important;
  --chart-3: #B6C2CF !important;
  --chart-4: #7F93AE !important;
  --chart-5: #4B5563 !important;
  --shadow: 0 18px 62px rgba(6, 10, 15, 0.24) !important;
  --shadow-hover: 0 30px 90px rgba(6, 10, 15, 0.34) !important;
  color: var(--ink) !important;
  background:
    radial-gradient(circle at 13% -12%, rgba(156, 191, 230, 0.16), transparent 34%),
    radial-gradient(circle at 88% 0%, rgba(198, 175, 163, 0.14), transparent 31%),
    linear-gradient(135deg, #353B44 0%, #2E343C 48%, #282E36 100%) !important;
}

html[data-theme="dark"] { background: #2E343C !important; }

body[data-theme="dark"] .topbar {
  background: rgba(44, 50, 58, 0.82) !important;
  border-bottom-color: rgba(225, 232, 240, 0.12) !important;
  box-shadow: 0 14px 48px rgba(4, 7, 12, 0.20) !important;
}

body[data-theme="dark"] .pill-nav,
body[data-theme="dark"] .theme-switcher,
body[data-theme="dark"] .command-center,
body[data-theme="dark"] .card,
body[data-theme="dark"] .kpi-card,
body[data-theme="dark"] .source-modal,
body[data-theme="dark"] .detail-modal {
  background: linear-gradient(180deg, rgba(57, 64, 74, 0.86), rgba(46, 53, 62, 0.80)) !important;
  border-color: rgba(224, 232, 242, 0.14) !important;
  box-shadow: var(--shadow) !important;
}

body[data-theme="dark"] .command-center {
  background:
    linear-gradient(180deg, rgba(62, 70, 81, 0.90), rgba(47, 54, 63, 0.84)),
    radial-gradient(circle at 96% 0%, rgba(156, 191, 230, 0.12), transparent 36%) !important;
}

body[data-theme="dark"] h1,
body[data-theme="dark"] h2,
body[data-theme="dark"] h3,
body[data-theme="dark"] .command-center h1,
body[data-theme="dark"] .card-header h2,
body[data-theme="dark"] .kpi-value,
body[data-theme="dark"] .headline-metric,
body[data-theme="dark"] .quality-value,
body[data-theme="dark"] .platform-value,
body[data-theme="dark"] .product-value,
body[data-theme="dark"] .kol-value,
body[data-theme="dark"] .marketing-value,
body[data-theme="dark"] .source-title,
body[data-theme="dark"] .platform-name,
body[data-theme="dark"] .product-name,
body[data-theme="dark"] .kol-name,
body[data-theme="dark"] .marketing-label,
body[data-theme="dark"] .insight-title,
body[data-theme="dark"] .mini-note strong,
body[data-theme="dark"] .decision-card strong,
body[data-theme="dark"] .detail-metric strong,
body[data-theme="dark"] .detail-section h3 {
  color: #F7F9FC !important;
  text-shadow: none !important;
}

body[data-theme="dark"] .muted,
body[data-theme="dark"] .lead,
body[data-theme="dark"] .kpi-subtitle,
body[data-theme="dark"] .kpi-note,
body[data-theme="dark"] .kpi-title,
body[data-theme="dark"] .source-meta,
body[data-theme="dark"] .platform-meta,
body[data-theme="dark"] .product-meta,
body[data-theme="dark"] .kol-meta,
body[data-theme="dark"] .insight-desc,
body[data-theme="dark"] .detail-section p,
body[data-theme="dark"] .detail-section li,
body[data-theme="dark"] .quality-note,
body[data-theme="dark"] .quality-label,
body[data-theme="dark"] .mini-note span,
body[data-theme="dark"] .decision-card span,
body[data-theme="dark"] .detail-metric span,
body[data-theme="dark"] .metric-label,
body[data-theme="dark"] .axis-label,
body[data-theme="dark"] .y-label {
  color: #C7D0DB !important;
  fill: #C7D0DB !important;
}

body[data-theme="dark"] .section-label,
body[data-theme="dark"] .eyebrow,
body[data-theme="dark"] .kpi-delta,
body[data-theme="dark"] .text-button {
  color: #AFCDF0 !important;
}

body[data-theme="dark"] .pill-nav,
body[data-theme="dark"] .theme-switcher {
  background: rgba(43, 49, 58, 0.88) !important;
  border-color: rgba(224, 232, 242, 0.16) !important;
}
body[data-theme="dark"] .nav-item,
body[data-theme="dark"] .theme-option {
  color: #D2D9E2 !important;
}
body[data-theme="dark"] .nav-item:hover,
body[data-theme="dark"] .theme-option:hover {
  color: #FFFFFF !important;
  background: rgba(156, 191, 230, 0.10) !important;
}
body[data-theme="dark"] .nav-item.is-active,
body[data-theme="dark"] .theme-option.is-active,
body[data-theme="dark"] .segment.is-active,
body[data-theme="dark"] .reset-button,
body[data-theme="dark"] .modal-save-button,
body[data-theme="dark"] .source-manage-button {
  color: #17202A !important;
  background: linear-gradient(135deg, #D7E8FB 0%, #9CBFE6 100%) !important;
  border-color: rgba(215, 232, 251, 0.52) !important;
  box-shadow: 0 12px 28px rgba(156, 191, 230, 0.22) !important;
}

body[data-theme="dark"] .filter-dock {
  padding: 6px !important;
  border: 1px solid rgba(224, 232, 242, 0.12) !important;
  border-radius: 22px !important;
  background: rgba(36, 42, 50, 0.56) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06) !important;
}
body[data-theme="dark"] .filter-chip {
  color: #B9C5D2 !important;
}
body[data-theme="dark"] .filter-chip select {
  height: 38px !important;
  color: #F5F8FB !important;
  background: rgba(55, 63, 73, 0.95) !important;
  border-color: rgba(224, 232, 242, 0.18) !important;
  box-shadow: none !important;
  outline: none !important;
}
body[data-theme="dark"] .filter-chip select:hover,
body[data-theme="dark"] .filter-chip select:focus {
  border-color: rgba(156, 191, 230, 0.55) !important;
  box-shadow: 0 0 0 4px rgba(156, 191, 230, 0.10) !important;
}
body[data-theme="dark"] .filter-chip select option {
  background: #303741 !important;
  color: #F5F8FB !important;
}

body[data-theme="dark"] .source-row,
body[data-theme="dark"] .product-row,
body[data-theme="dark"] .kol-row,
body[data-theme="dark"] .marketing-item,
body[data-theme="dark"] .insight-item,
body[data-theme="dark"] .decision-card,
body[data-theme="dark"] .note-item,
body[data-theme="dark"] .detail-metric,
body[data-theme="dark"] .detail-section,
body[data-theme="dark"] .sheet-button.is-active,
body[data-theme="dark"] .excel-data-table td,
body[data-theme="dark"] .excel-data-table th {
  background: rgba(61, 69, 80, 0.68) !important;
  border-color: rgba(224, 232, 242, 0.13) !important;
  color: #EEF2F6 !important;
}
body[data-theme="dark"] .source-row:hover,
body[data-theme="dark"] .product-row:hover,
body[data-theme="dark"] .kol-row:hover,
body[data-theme="dark"] .marketing-item:hover,
body[data-theme="dark"] .insight-item:hover,
body[data-theme="dark"] .decision-card:hover {
  background: linear-gradient(180deg, rgba(73, 83, 97, 0.82), rgba(58, 66, 77, 0.74)) !important;
  border-color: rgba(156, 191, 230, 0.26) !important;
}

body[data-theme="dark"] .progress-track {
  background: rgba(226, 232, 240, 0.16) !important;
}
body[data-theme="dark"] .progress-fill {
  background: linear-gradient(90deg, #9CBFE6, #C6AFA3) !important;
}
body[data-theme="dark"] .grid-line {
  stroke: rgba(226, 232, 240, 0.13) !important;
}
body[data-theme="dark"] .pulse-bar,
body[data-theme="dark"] .trend-bar {
  fill: #9CBFE6 !important;
}
body[data-theme="dark"] .pulse-bar:hover,
body[data-theme="dark"] .trend-bar:hover {
  fill: #D7E8FB !important;
}
body[data-theme="dark"] .trend-line {
  stroke: #9CBFE6 !important;
}
body[data-theme="dark"] .trend-point {
  fill: #303741 !important;
  stroke: #D7E8FB !important;
}
body[data-theme="dark"] .donut-center strong {
  color: #F7F9FC !important;
}
body[data-theme="dark"] .donut-center span {
  color: #C7D0DB !important;
}
body[data-theme="dark"] .chart-tooltip,
body[data-theme="dark"] .toast {
  background: rgba(18, 22, 28, 0.96) !important;
  color: #F7F9FC !important;
  border: 1px solid rgba(255,255,255,0.10) !important;
}

@media (max-width: 860px) {
  body[data-theme="dark"]::after {
    background: linear-gradient(180deg, rgba(46,52,60,0), rgba(46,52,60,.82) 42%, rgba(46,52,60,.98)) !important;
  }
  body[data-theme="dark"] .theme-switcher-mobile,
  body[data-theme="dark"] .mobile-tabbar {
    background: rgba(43, 49, 58, 0.90) !important;
    border-color: rgba(224, 232, 242, 0.18) !important;
    box-shadow: 0 -18px 46px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255,255,255,0.07) !important;
  }
}

/* --------------------------------------------------------------------------
   Final Dark Header + Filter Polish
   Fixes heavy nested borders in the command center and improves contrast.
---------------------------------------------------------------------------- */
body[data-theme="dark"] {
  --dark-bg-0: #252B33;
  --dark-bg-1: #2C333C;
  --dark-bg-2: #333B46;
  --dark-bg-3: #3C4652;
  --dark-text-strong: #F8FAFC;
  --dark-text: #E5EBF3;
  --dark-text-muted: #B9C4D1;
  --dark-accent: #B7D4F4;
  --dark-accent-2: #8FB2D8;
  --dark-border: rgba(230, 238, 248, 0.14);
  --dark-border-strong: rgba(230, 238, 248, 0.22);
}

body[data-theme="dark"] .command-center {
  grid-template-columns: minmax(280px, 0.9fr) minmax(520px, 1.25fr) !important;
  align-items: center !important;
  gap: clamp(18px, 3vw, 34px) !important;
  padding: 18px clamp(18px, 2.2vw, 28px) !important;
  background:
    linear-gradient(135deg, rgba(61, 70, 82, 0.90), rgba(45, 53, 63, 0.90)),
    radial-gradient(circle at 95% 15%, rgba(183, 212, 244, 0.12), transparent 30%) !important;
  border: 1px solid rgba(230, 238, 248, 0.15) !important;
  box-shadow:
    0 20px 70px rgba(5, 10, 16, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.07) !important;
}

body[data-theme="dark"] .command-center::after {
  opacity: 0.24 !important;
  background: linear-gradient(135deg, rgba(255,255,255,0.10), transparent 45%, rgba(183,212,244,0.06)) !important;
}

body[data-theme="dark"] .view-title-block {
  min-width: 0;
}

body[data-theme="dark"] .command-center h1 {
  color: var(--dark-text-strong) !important;
  letter-spacing: -0.055em !important;
}

body[data-theme="dark"] .command-center .eyebrow {
  color: #AFCDF0 !important;
  opacity: 0.95 !important;
}

body[data-theme="dark"] .filter-dock {
  justify-content: flex-end !important;
  align-items: end !important;
  display: grid !important;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) minmax(104px, auto) !important;
  gap: 10px !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  min-width: min(100%, 720px);
}

body[data-theme="dark"] .filter-chip {
  min-width: 0 !important;
  gap: 4px !important;
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  color: #AEBACA !important;
  letter-spacing: 0.075em !important;
}

body[data-theme="dark"] .filter-chip span {
  padding-left: 2px;
  color: #9FAABD !important;
  font-size: 9px !important;
  line-height: 1 !important;
  opacity: 0.86;
}

body[data-theme="dark"] .filter-chip select {
  width: 100% !important;
  min-width: 0 !important;
  height: 44px !important;
  padding: 0 38px 0 14px !important;
  border-radius: 14px !important;
  color: #F8FAFC !important;
  background:
    linear-gradient(180deg, rgba(61, 71, 83, 0.98), rgba(48, 57, 68, 0.98)) !important;
  border: 1px solid rgba(230, 238, 248, 0.20) !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 10px 28px rgba(5, 10, 16, 0.16) !important;
  font-weight: 750 !important;
  letter-spacing: -0.01em !important;
  text-transform: none !important;
}

body[data-theme="dark"] .filter-chip select:hover {
  border-color: rgba(183, 212, 244, 0.42) !important;
  background:
    linear-gradient(180deg, rgba(70, 81, 94, 0.98), rgba(54, 64, 76, 0.98)) !important;
}

body[data-theme="dark"] .filter-chip select:focus {
  border-color: rgba(183, 212, 244, 0.62) !important;
  box-shadow:
    0 0 0 4px rgba(183, 212, 244, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 14px 32px rgba(5, 10, 16, 0.20) !important;
}

body[data-theme="dark"] .reset-button {
  align-self: end !important;
  height: 44px !important;
  min-width: 106px !important;
  padding: 0 18px !important;
  border-radius: 16px !important;
  color: #172331 !important;
  background: linear-gradient(135deg, #DBECFF 0%, #A8C8EA 100%) !important;
  border: 1px solid rgba(219, 236, 255, 0.58) !important;
  box-shadow:
    0 14px 34px rgba(168, 200, 234, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.48) !important;
  font-weight: 850 !important;
}

body[data-theme="dark"] .reset-button:hover {
  transform: translateY(-1px) !important;
  box-shadow:
    0 18px 42px rgba(168, 200, 234, 0.30),
    inset 0 1px 0 rgba(255, 255, 255, 0.55) !important;
}

body[data-theme="dark"] .kpi-card,
body[data-theme="dark"] .card {
  background: linear-gradient(180deg, rgba(50, 58, 68, 0.90), rgba(42, 49, 58, 0.88)) !important;
  border-color: rgba(230, 238, 248, 0.13) !important;
}

body[data-theme="dark"] .kpi-value,
body[data-theme="dark"] .headline-metric,
body[data-theme="dark"] .marketing-value,
body[data-theme="dark"] .platform-value,
body[data-theme="dark"] .product-value,
body[data-theme="dark"] .kol-value {
  color: #F8FAFC !important;
  opacity: 1 !important;
}

body[data-theme="dark"] .kpi-title,
body[data-theme="dark"] .section-label {
  color: #9FC2EA !important;
}

body[data-theme="dark"] .muted,
body[data-theme="dark"] .kpi-subtitle,
body[data-theme="dark"] .kpi-note,
body[data-theme="dark"] .platform-meta,
body[data-theme="dark"] .product-meta,
body[data-theme="dark"] .kol-meta,
body[data-theme="dark"] .insight-desc {
  color: #C8D2DE !important;
}

@media (max-width: 1120px) {
  body[data-theme="dark"] .command-center {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  body[data-theme="dark"] .filter-dock {
    width: 100% !important;
    min-width: 0 !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  body[data-theme="dark"] .reset-button {
    grid-column: span 2 !important;
    width: 100% !important;
  }
}

@media (max-width: 560px) {
  body[data-theme="dark"] .command-center {
    padding: 15px !important;
    border-radius: 22px !important;
  }

  body[data-theme="dark"] .filter-dock {
    grid-template-columns: 1fr !important;
    gap: 9px !important;
  }

  body[data-theme="dark"] .reset-button {
    grid-column: auto !important;
  }

  body[data-theme="dark"] .filter-chip select,
  body[data-theme="dark"] .reset-button {
    height: 42px !important;
  }
}

/* --- Dark theme elevation refresh: clearer hierarchy and less sunken look --- */
html[data-theme="dark"] { background: #242B34 !important; }
body[data-theme="dark"] {
  background:
    radial-gradient(circle at 8% 0%, rgba(120, 154, 196, 0.16), transparent 22%),
    radial-gradient(circle at 92% 4%, rgba(198, 175, 163, 0.12), transparent 22%),
    linear-gradient(180deg, #242B34 0%, #20262E 48%, #1C222A 100%) !important;
  color: #F3F6FA !important;
}
body[data-theme="dark"] .dashboard-shell {
  padding-top: 18px !important;
}
body[data-theme="dark"] .topbar {
  background: rgba(34, 41, 49, 0.82) !important;
  border-bottom-color: rgba(214, 224, 236, 0.10) !important;
  box-shadow: 0 12px 40px rgba(5, 10, 18, 0.22) !important;
}
body[data-theme="dark"] .pill-nav,
body[data-theme="dark"] .theme-switcher {
  background: rgba(41, 49, 59, 0.88) !important;
  border-color: rgba(214, 224, 236, 0.12) !important;
  box-shadow: 0 10px 26px rgba(3, 8, 14, 0.14) !important;
}
body[data-theme="dark"] .command-center,
body[data-theme="dark"] .card,
body[data-theme="dark"] .kpi-card,
body[data-theme="dark"] .source-modal,
body[data-theme="dark"] .detail-modal {
  background: linear-gradient(180deg, rgba(50, 59, 70, 0.94), rgba(41, 49, 59, 0.92)) !important;
  border-color: rgba(214, 224, 236, 0.12) !important;
  box-shadow: 0 18px 44px rgba(6, 10, 18, 0.18) !important;
}
body[data-theme="dark"] .command-center {
  background:
    radial-gradient(circle at 100% 0%, rgba(137, 174, 216, 0.10), transparent 28%),
    linear-gradient(180deg, rgba(58, 67, 79, 0.96), rgba(45, 53, 64, 0.94)) !important;
}
body[data-theme="dark"] h1,
body[data-theme="dark"] h2,
body[data-theme="dark"] h3,
body[data-theme="dark"] .command-center h1,
body[data-theme="dark"] .card-header h2,
body[data-theme="dark"] .kpi-value,
body[data-theme="dark"] .headline-metric,
body[data-theme="dark"] .quality-value,
body[data-theme="dark"] .platform-value,
body[data-theme="dark"] .product-value,
body[data-theme="dark"] .kol-value,
body[data-theme="dark"] .marketing-value,
body[data-theme="dark"] .source-title,
body[data-theme="dark"] .platform-name,
body[data-theme="dark"] .product-name,
body[data-theme="dark"] .kol-name,
body[data-theme="dark"] .marketing-label,
body[data-theme="dark"] .insight-title,
body[data-theme="dark"] .mini-note strong,
body[data-theme="dark"] .decision-card strong,
body[data-theme="dark"] .detail-metric strong,
body[data-theme="dark"] .detail-section h3,
body[data-theme="dark"] .note-item strong,
body[data-theme="dark"] .insight-item strong,
body[data-theme="dark"] .inventory-title {
  color: #F6F8FC !important;
}
body[data-theme="dark"] .muted,
body[data-theme="dark"] .lead,
body[data-theme="dark"] .kpi-subtitle,
body[data-theme="dark"] .kpi-note,
body[data-theme="dark"] .kpi-title,
body[data-theme="dark"] .source-meta,
body[data-theme="dark"] .platform-meta,
body[data-theme="dark"] .product-meta,
body[data-theme="dark"] .kol-meta,
body[data-theme="dark"] .insight-desc,
body[data-theme="dark"] .detail-section p,
body[data-theme="dark"] .detail-section li,
body[data-theme="dark"] .quality-note,
body[data-theme="dark"] .quality-label,
body[data-theme="dark"] .mini-note span,
body[data-theme="dark"] .decision-card span,
body[data-theme="dark"] .detail-metric span,
body[data-theme="dark"] .metric-label,
body[data-theme="dark"] .axis-label,
body[data-theme="dark"] .y-label,
body[data-theme="dark"] .note-item p,
body[data-theme="dark"] .insight-item p {
  color: #D7E0EA !important;
  opacity: 1 !important;
}
body[data-theme="dark"] .section-label,
body[data-theme="dark"] .eyebrow,
body[data-theme="dark"] .kpi-delta,
body[data-theme="dark"] .text-button {
  color: #9FC1E9 !important;
}
body[data-theme="dark"] .source-row,
body[data-theme="dark"] .product-row,
body[data-theme="dark"] .kol-row,
body[data-theme="dark"] .marketing-item,
body[data-theme="dark"] .insight-item,
body[data-theme="dark"] .decision-card,
body[data-theme="dark"] .note-item,
body[data-theme="dark"] .detail-metric,
body[data-theme="dark"] .detail-section,
body[data-theme="dark"] .sheet-button,
body[data-theme="dark"] .excel-data-table td,
body[data-theme="dark"] .excel-data-table th,
body[data-theme="dark"] .source-status-chip {
  background: rgba(92, 104, 118, 0.34) !important;
  border-color: rgba(214, 224, 236, 0.14) !important;
  color: #F3F6FA !important;
}
body[data-theme="dark"] .insight-item,
body[data-theme="dark"] .note-item,
body[data-theme="dark"] .decision-card,
body[data-theme="dark"] .inventory-card,
body[data-theme="dark"] .budget-card,
body[data-theme="dark"] .marketing-item {
  background: linear-gradient(180deg, rgba(96, 108, 122, 0.30), rgba(81, 92, 105, 0.34)) !important;
  border: 1px solid rgba(216, 226, 238, 0.14) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04) !important;
}
body[data-theme="dark"] .source-row:hover,
body[data-theme="dark"] .product-row:hover,
body[data-theme="dark"] .kol-row:hover,
body[data-theme="dark"] .marketing-item:hover,
body[data-theme="dark"] .insight-item:hover,
body[data-theme="dark"] .decision-card:hover,
body[data-theme="dark"] .sheet-button:hover {
  background: linear-gradient(180deg, rgba(113, 127, 144, 0.34), rgba(93, 105, 119, 0.38)) !important;
  border-color: rgba(159, 193, 233, 0.28) !important;
}
body[data-theme="dark"] .sheet-button.is-active {
  background: linear-gradient(180deg, rgba(120, 138, 160, 0.40), rgba(99, 115, 132, 0.46)) !important;
  border-color: rgba(174, 202, 234, 0.26) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06) !important;
}
body[data-theme="dark"] .filter-dock {
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
body[data-theme="dark"] .filter-chip {
  gap: 6px !important;
  color: #AEBCCD !important;
}
body[data-theme="dark"] .filter-chip select {
  height: 42px !important;
  background: rgba(57, 66, 78, 0.96) !important;
  border: 1px solid rgba(214, 224, 236, 0.14) !important;
  color: #F7FAFD !important;
  box-shadow: 0 8px 18px rgba(6, 10, 18, 0.10) !important;
}
body[data-theme="dark"] .filter-chip select:hover,
body[data-theme="dark"] .filter-chip select:focus {
  background: rgba(63, 73, 86, 0.98) !important;
  border-color: rgba(159, 193, 233, 0.36) !important;
  box-shadow: 0 0 0 4px rgba(159, 193, 233, 0.10) !important;
}
body[data-theme="dark"] .reset-button,
body[data-theme="dark"] .modal-save-button,
body[data-theme="dark"] .source-manage-button {
  color: #13202B !important;
  background: linear-gradient(135deg, #DCEBFC 0%, #AAC4E4 100%) !important;
  border: 1px solid rgba(220, 235, 252, 0.34) !important;
}
body[data-theme="dark"] .progress-track {
  background: rgba(233, 239, 247, 0.18) !important;
}
body[data-theme="dark"] .progress-fill {
  background: linear-gradient(90deg, #AFC8E5, #D2B7AA) !important;
}
body[data-theme="dark"] .donut-center,
body[data-theme="dark"] .donut-center strong,
body[data-theme="dark"] .donut-center span {
  color: #F5F8FC !important;
}
body[data-theme="dark"] .source-modal .modal-toolbar,
body[data-theme="dark"] .source-modal .modal-header,
body[data-theme="dark"] .detail-modal .modal-header {
  background: rgba(47, 55, 66, 0.92) !important;
  border-color: rgba(214,224,236,0.12) !important;
}
body[data-theme="dark"] .excel-data-table {
  background: rgba(53, 61, 72, 0.90) !important;
}
body[data-theme="dark"] .excel-data-table th {
  background: rgba(82, 93, 107, 0.58) !important;
  color: #F7F9FC !important;
}
body[data-theme="dark"] .excel-data-table td {
  background: rgba(73, 84, 97, 0.48) !important;
}
body[data-theme="dark"] .excel-cell-input {
  background: rgba(62, 72, 84, 0.92) !important;
  color: #F7F9FC !important;
  border-color: rgba(214,224,236,0.14) !important;
}
body[data-theme="dark"] .chart-tooltip,
body[data-theme="dark"] .toast {
  background: rgba(18, 23, 30, 0.97) !important;
  border: 1px solid rgba(214,224,236,0.12) !important;
}
body[data-theme="dark"] .inventory-signal-dot,
body[data-theme="dark"] .signal-dot,
body[data-theme="dark"] .inventory-dot {
  box-shadow: 0 0 0 6px rgba(159,193,233,0.10), 0 0 18px rgba(159,193,233,0.18) !important;
}

/* --- Dark theme palette refresh based on new reference --- */
body[data-theme="dark"] {
  --dark-ink: #F4F8FC;
  --dark-muted: #C2D0E0;
  --dark-accent-soft: #88B2DD;
  --dark-accent: #5FA6E3;
  --dark-surface: #37455E;
  --dark-base: #0F1724;
  --dark-base-deep: #0B1220;
  --dark-line: rgba(160, 186, 214, 0.18);
  background:
    radial-gradient(circle at 12% 0%, rgba(136, 178, 221, 0.16), transparent 24%),
    radial-gradient(circle at 82% 4%, rgba(95, 166, 227, 0.12), transparent 22%),
    linear-gradient(180deg, #111927 0%, #0F1724 48%, #0B1220 100%) !important;
  color: var(--dark-ink) !important;
}
html[data-theme="dark"] { background: #0F1724 !important; }
body[data-theme="dark"] .topbar {
  background: rgba(17, 25, 39, 0.84) !important;
  border-bottom-color: rgba(136, 178, 221, 0.10) !important;
  box-shadow: 0 12px 40px rgba(2, 7, 14, 0.28) !important;
}
body[data-theme="dark"] .pill-nav,
body[data-theme="dark"] .theme-switcher {
  background: rgba(24, 34, 49, 0.82) !important;
  border-color: rgba(136, 178, 221, 0.12) !important;
  box-shadow: 0 10px 26px rgba(2, 7, 14, 0.18) !important;
}
body[data-theme="dark"] .nav-item,
body[data-theme="dark"] .theme-option {
  color: #D6E0EB !important;
}
body[data-theme="dark"] .nav-item.is-active,
body[data-theme="dark"] .theme-option.is-active,
body[data-theme="dark"] .segment.is-active {
  color: #0D1724 !important;
  background: linear-gradient(135deg, #8AB4E0 0%, #5FA6E3 100%) !important;
  border-color: rgba(138, 180, 224, 0.26) !important;
  box-shadow: 0 12px 28px rgba(95, 166, 227, 0.28) !important;
}
body[data-theme="dark"] .command-center,
body[data-theme="dark"] .card,
body[data-theme="dark"] .kpi-card,
body[data-theme="dark"] .source-modal,
body[data-theme="dark"] .detail-modal {
  background: linear-gradient(180deg, rgba(55, 69, 94, 0.88), rgba(34, 46, 66, 0.94)) !important;
  border-color: rgba(136, 178, 221, 0.12) !important;
  box-shadow: 0 18px 44px rgba(2, 7, 14, 0.20) !important;
}
body[data-theme="dark"] .command-center {
  background:
    radial-gradient(circle at 92% 0%, rgba(95, 166, 227, 0.14), transparent 28%),
    linear-gradient(180deg, rgba(56, 71, 96, 0.92), rgba(39, 51, 72, 0.96)) !important;
}
body[data-theme="dark"] h1,
body[data-theme="dark"] h2,
body[data-theme="dark"] h3,
body[data-theme="dark"] .command-center h1,
body[data-theme="dark"] .card-header h2,
body[data-theme="dark"] .kpi-value,
body[data-theme="dark"] .headline-metric,
body[data-theme="dark"] .quality-value,
body[data-theme="dark"] .platform-value,
body[data-theme="dark"] .product-value,
body[data-theme="dark"] .kol-value,
body[data-theme="dark"] .marketing-value,
body[data-theme="dark"] .source-title,
body[data-theme="dark"] .platform-name,
body[data-theme="dark"] .product-name,
body[data-theme="dark"] .kol-name,
body[data-theme="dark"] .marketing-label,
body[data-theme="dark"] .insight-title,
body[data-theme="dark"] .mini-note strong,
body[data-theme="dark"] .decision-card strong,
body[data-theme="dark"] .detail-metric strong,
body[data-theme="dark"] .detail-section h3,
body[data-theme="dark"] .note-item strong,
body[data-theme="dark"] .inventory-title {
  color: var(--dark-ink) !important;
}
body[data-theme="dark"] .muted,
body[data-theme="dark"] .lead,
body[data-theme="dark"] .kpi-subtitle,
body[data-theme="dark"] .kpi-note,
body[data-theme="dark"] .kpi-title,
body[data-theme="dark"] .source-meta,
body[data-theme="dark"] .platform-meta,
body[data-theme="dark"] .product-meta,
body[data-theme="dark"] .kol-meta,
body[data-theme="dark"] .insight-desc,
body[data-theme="dark"] .detail-section p,
body[data-theme="dark"] .detail-section li,
body[data-theme="dark"] .quality-note,
body[data-theme="dark"] .quality-label,
body[data-theme="dark"] .mini-note span,
body[data-theme="dark"] .decision-card span,
body[data-theme="dark"] .detail-metric span,
body[data-theme="dark"] .metric-label,
body[data-theme="dark"] .axis-label,
body[data-theme="dark"] .y-label,
body[data-theme="dark"] .note-item p,
body[data-theme="dark"] .insight-item p {
  color: var(--dark-muted) !important;
}
body[data-theme="dark"] .section-label,
body[data-theme="dark"] .eyebrow,
body[data-theme="dark"] .kpi-delta,
body[data-theme="dark"] .text-button {
  color: var(--dark-accent-soft) !important;
}
body[data-theme="dark"] .filter-dock {
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
body[data-theme="dark"] .filter-chip {
  color: #BED0E3 !important;
}
body[data-theme="dark"] .filter-chip select {
  background: rgba(24, 35, 50, 0.88) !important;
  border: 1px solid rgba(136, 178, 221, 0.16) !important;
  color: #F4F8FC !important;
  box-shadow: 0 8px 18px rgba(2, 7, 14, 0.12) !important;
}
body[data-theme="dark"] .filter-chip select:hover,
body[data-theme="dark"] .filter-chip select:focus {
  background: rgba(28, 40, 57, 0.94) !important;
  border-color: rgba(95, 166, 227, 0.38) !important;
  box-shadow: 0 0 0 4px rgba(95, 166, 227, 0.10) !important;
}
body[data-theme="dark"] .reset-button,
body[data-theme="dark"] .modal-save-button,
body[data-theme="dark"] .source-manage-button {
  color: #0E1724 !important;
  background: linear-gradient(135deg, #8AB4E0 0%, #5FA6E3 100%) !important;
  border: 1px solid rgba(138, 180, 224, 0.26) !important;
  box-shadow: 0 12px 28px rgba(95, 166, 227, 0.24) !important;
}
body[data-theme="dark"] .source-row,
body[data-theme="dark"] .product-row,
body[data-theme="dark"] .kol-row,
body[data-theme="dark"] .marketing-item,
body[data-theme="dark"] .insight-item,
body[data-theme="dark"] .decision-card,
body[data-theme="dark"] .note-item,
body[data-theme="dark"] .detail-metric,
body[data-theme="dark"] .detail-section,
body[data-theme="dark"] .sheet-button,
body[data-theme="dark"] .excel-data-table td,
body[data-theme="dark"] .excel-data-table th,
body[data-theme="dark"] .source-status-chip {
  background: rgba(70, 85, 113, 0.34) !important;
  border-color: var(--dark-line) !important;
  color: var(--dark-ink) !important;
}
body[data-theme="dark"] .insight-item,
body[data-theme="dark"] .note-item,
body[data-theme="dark"] .decision-card,
body[data-theme="dark"] .inventory-card,
body[data-theme="dark"] .budget-card,
body[data-theme="dark"] .marketing-item {
  background: linear-gradient(180deg, rgba(94, 116, 150, 0.30), rgba(69, 85, 112, 0.34)) !important;
  border: 1px solid rgba(136, 178, 221, 0.14) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04) !important;
}
body[data-theme="dark"] .source-row:hover,
body[data-theme="dark"] .product-row:hover,
body[data-theme="dark"] .kol-row:hover,
body[data-theme="dark"] .marketing-item:hover,
body[data-theme="dark"] .insight-item:hover,
body[data-theme="dark"] .decision-card:hover,
body[data-theme="dark"] .sheet-button:hover {
  background: linear-gradient(180deg, rgba(110, 136, 174, 0.32), rgba(77, 97, 128, 0.38)) !important;
  border-color: rgba(95, 166, 227, 0.26) !important;
}
body[data-theme="dark"] .sheet-button.is-active {
  background: linear-gradient(180deg, rgba(95, 166, 227, 0.26), rgba(72, 91, 121, 0.46)) !important;
  border-color: rgba(138, 180, 224, 0.28) !important;
}
body[data-theme="dark"] .progress-track {
  background: rgba(214, 227, 241, 0.18) !important;
}
body[data-theme="dark"] .progress-fill {
  background: linear-gradient(90deg, #88B2DD, #5FA6E3) !important;
}
body[data-theme="dark"] .pulse-bar,
body[data-theme="dark"] .trend-bar {
  fill: #5FA6E3 !important;
}
body[data-theme="dark"] .pulse-bar:hover,
body[data-theme="dark"] .trend-bar:hover {
  fill: #8AB4E0 !important;
}
body[data-theme="dark"] .trend-line {
  stroke: #8AB4E0 !important;
}
body[data-theme="dark"] .trend-point {
  fill: #1B2838 !important;
  stroke: #8AB4E0 !important;
}
body[data-theme="dark"] .grid-line {
  stroke: rgba(136, 178, 221, 0.14) !important;
}
body[data-theme="dark"] .source-modal .modal-toolbar,
body[data-theme="dark"] .source-modal .modal-header,
body[data-theme="dark"] .detail-modal .modal-header {
  background: rgba(34, 46, 66, 0.90) !important;
  border-color: rgba(136, 178, 221, 0.12) !important;
}
body[data-theme="dark"] .excel-data-table {
  background: rgba(42, 54, 75, 0.92) !important;
}
body[data-theme="dark"] .excel-data-table th {
  background: rgba(81, 101, 133, 0.56) !important;
  color: #F5F8FC !important;
}
body[data-theme="dark"] .excel-data-table td {
  background: rgba(65, 80, 107, 0.42) !important;
}
body[data-theme="dark"] .excel-cell-input {
  background: rgba(27, 40, 56, 0.92) !important;
  color: #F5F8FC !important;
  border-color: rgba(136, 178, 221, 0.14) !important;
}
body[data-theme="dark"] .chart-tooltip,
body[data-theme="dark"] .toast {
  background: rgba(12, 19, 30, 0.97) !important;
  border: 1px solid rgba(136, 178, 221, 0.12) !important;
  color: #F5F8FC !important;
}
body[data-theme="dark"] .inventory-signal-dot,
body[data-theme="dark"] .signal-dot,
body[data-theme="dark"] .inventory-dot {
  box-shadow: 0 0 0 6px rgba(95, 166, 227, 0.10), 0 0 18px rgba(95, 166, 227, 0.20) !important;
}


/* --- Dark theme card background fix: remove light rgba surfaces that sink white text --- */
body[data-theme="dark"] {
  --dark-card-bg: linear-gradient(180deg, rgba(46, 61, 84, 0.88), rgba(26, 39, 58, 0.94));
  --dark-card-bg-soft: linear-gradient(180deg, rgba(58, 76, 102, 0.46), rgba(39, 55, 78, 0.52));
  --dark-panel-bg: rgba(19, 30, 46, 0.76);
  --dark-panel-bg-strong: rgba(26, 40, 59, 0.92);
  --dark-field-bg: rgba(15, 26, 42, 0.86);
  --dark-text: #F5F9FE;
  --dark-text-soft: #D7E5F4;
}

/* Main glass surfaces */
body[data-theme="dark"] .card,
body[data-theme="dark"] .kpi-card,
body[data-theme="dark"] .command-center,
body[data-theme="dark"] .source-modal,
body[data-theme="dark"] .detail-modal,
body[data-theme="dark"] .modal-body,
body[data-theme="dark"] .modal-content {
  background: var(--dark-card-bg) !important;
  border-color: rgba(139, 183, 225, 0.16) !important;
}

/* Inner list/cards that previously used rgba(248,250,252,.72) */
body[data-theme="dark"] .insight-item,
body[data-theme="dark"] .note-item,
body[data-theme="dark"] .decision-card,
body[data-theme="dark"] .inventory-card,
body[data-theme="dark"] .budget-card,
body[data-theme="dark"] .marketing-item,
body[data-theme="dark"] .source-row,
body[data-theme="dark"] .product-row,
body[data-theme="dark"] .kol-row,
body[data-theme="dark"] .quality-card,
body[data-theme="dark"] .metric-card,
body[data-theme="dark"] .detail-metric,
body[data-theme="dark"] .detail-section,
body[data-theme="dark"] .sheet-button,
body[data-theme="dark"] .source-status-chip,
body[data-theme="dark"] .platform-row,
body[data-theme="dark"] .channel-row {
  background: var(--dark-card-bg-soft) !important;
  border-color: rgba(139, 183, 225, 0.16) !important;
  color: var(--dark-text) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.045), 0 10px 24px rgba(0,0,0,0.08) !important;
}

/* Remove accidental light panels inside dark mode */
body[data-theme="dark"] [style*="rgba(248, 250, 252"],
body[data-theme="dark"] [style*="rgba(248,250,252"],
body[data-theme="dark"] [style*="#f8fafc"],
body[data-theme="dark"] [style*="#F8FAFC"] {
  background: var(--dark-card-bg-soft) !important;
  color: var(--dark-text) !important;
}

/* Table and editable inputs */
body[data-theme="dark"] .excel-data-table,
body[data-theme="dark"] .table-panel,
body[data-theme="dark"] .excel-table-wrap {
  background: var(--dark-panel-bg) !important;
  border-color: rgba(139, 183, 225, 0.16) !important;
}

body[data-theme="dark"] .excel-data-table th {
  background: rgba(74, 97, 128, 0.62) !important;
  color: #F7FBFF !important;
  border-color: rgba(139, 183, 225, 0.16) !important;
}

body[data-theme="dark"] .excel-data-table td {
  background: rgba(36, 52, 74, 0.56) !important;
  color: #F4F8FC !important;
  border-color: rgba(139, 183, 225, 0.12) !important;
}

body[data-theme="dark"] .excel-cell-input,
body[data-theme="dark"] .table-search input,
body[data-theme="dark"] input,
body[data-theme="dark"] select {
  background: var(--dark-field-bg) !important;
  color: #F7FBFF !important;
  border-color: rgba(139, 183, 225, 0.18) !important;
}

/* Text readability on dark surfaces */
body[data-theme="dark"] .insight-title,
body[data-theme="dark"] .note-item strong,
body[data-theme="dark"] .inventory-card strong,
body[data-theme="dark"] .budget-card strong,
body[data-theme="dark"] .marketing-item strong,
body[data-theme="dark"] .source-row strong,
body[data-theme="dark"] .product-row strong,
body[data-theme="dark"] .kol-row strong,
body[data-theme="dark"] .detail-metric strong,
body[data-theme="dark"] .detail-section h3 {
  color: var(--dark-text) !important;
}

body[data-theme="dark"] .insight-desc,
body[data-theme="dark"] .note-item p,
body[data-theme="dark"] .inventory-card p,
body[data-theme="dark"] .budget-card p,
body[data-theme="dark"] .marketing-item p,
body[data-theme="dark"] .source-meta,
body[data-theme="dark"] .product-meta,
body[data-theme="dark"] .kol-meta,
body[data-theme="dark"] .detail-section p {
  color: var(--dark-text-soft) !important;
  opacity: 1 !important;
}

/* Hover states with blue highlight instead of pale cards */
body[data-theme="dark"] .insight-item:hover,
body[data-theme="dark"] .note-item:hover,
body[data-theme="dark"] .decision-card:hover,
body[data-theme="dark"] .inventory-card:hover,
body[data-theme="dark"] .budget-card:hover,
body[data-theme="dark"] .marketing-item:hover,
body[data-theme="dark"] .source-row:hover,
body[data-theme="dark"] .product-row:hover,
body[data-theme="dark"] .kol-row:hover,
body[data-theme="dark"] .sheet-button:hover {
  background: linear-gradient(180deg, rgba(77, 104, 139, 0.54), rgba(48, 69, 98, 0.60)) !important;
  border-color: rgba(95, 166, 227, 0.30) !important;
}

/* If any generic helper class still produces light cards in dark mode */
body[data-theme="dark"] .glass,
body[data-theme="dark"] .glass-card,
body[data-theme="dark"] .soft-card,
body[data-theme="dark"] .surface-card,
body[data-theme="dark"] .row-card {
  background: var(--dark-card-bg-soft) !important;
  color: var(--dark-text) !important;
}


/* --- Dark mode removed: keep only Light / Warm themes --- */
.theme-option[data-theme-option="dark"] { display: none !important; }
.two-theme-switcher { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.theme-switcher .theme-option { min-width: 58px; }
.theme-switcher-mobile.two-theme-switcher { width: auto; }
.theme-switcher-mobile.two-theme-switcher .theme-option { min-width: 42px; }
html[data-theme="dark"],
body[data-theme="dark"] { color-scheme: light; }

/* In case old localStorage applies dark before JS migration, immediately render as warm surfaces. */
body[data-theme="dark"] {
  color: var(--ink) !important;
  background:
    radial-gradient(circle at 10% -12%, rgba(107, 124, 152, 0.10), transparent 30%),
    radial-gradient(circle at 92% 0%, rgba(171, 151, 140, 0.18), transparent 28%),
    linear-gradient(180deg, #FBF8F3 0%, #E9E6E7 54%, #D7D2D0 100%) !important;
}


/* --- KPI responsive 2-column fix --- */
/* Keep executive KPI cards compact and readable on tablet/mobile. */
.kpi-card,
.kpi-card * {
  min-width: 0;
}

.kpi-card {
  overflow: hidden;
}

.kpi-title,
.kpi-subtitle,
.kpi-note,
.kpi-delta {
  overflow-wrap: normal;
  word-break: keep-all;
  text-wrap: balance;
}

.kpi-title {
  white-space: nowrap;
  letter-spacing: 0.055em;
}

.kpi-value {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  line-height: 0.96;
}

.kpi-subtitle,
.kpi-note {
  line-height: 1.35;
}

/* Tablet and mobile: force 2 columns for the 4 primary KPI cards */
@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  .kpi-card {
    grid-column: span 1 !important;
    min-height: 106px !important;
    padding: 13px 12px !important;
    border-radius: 18px !important;
  }

  .kpi-title {
    font-size: 9px !important;
    line-height: 1.1 !important;
  }

  .kpi-subtitle {
    font-size: 10px !important;
    line-height: 1.25 !important;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .kpi-value {
    font-size: clamp(24px, 8.6vw, 34px) !important;
    letter-spacing: -0.065em !important;
    margin-top: 12px !important;
  }

  .kpi-note,
  .kpi-delta {
    font-size: 10px !important;
    line-height: 1.25 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .kpi-icon {
    width: 30px !important;
    height: 30px !important;
    border-radius: 12px !important;
  }

  .kpi-icon svg {
    width: 14px !important;
    height: 14px !important;
  }
}

/* Very small phones: stay 2 columns but tighten text more */
@media (max-width: 430px) {
  .kpi-grid {
    gap: 8px !important;
  }

  .kpi-card {
    min-height: 98px !important;
    padding: 11px 10px !important;
    border-radius: 16px !important;
  }

  .kpi-title {
    font-size: 8.5px !important;
    letter-spacing: 0.045em !important;
  }

  .kpi-value {
    font-size: clamp(21px, 8vw, 29px) !important;
  }

  .kpi-subtitle,
  .kpi-note,
  .kpi-delta {
    font-size: 9px !important;
  }

  .kpi-icon {
    width: 27px !important;
    height: 27px !important;
  }
}

/* Extra narrow devices: keep layout stable and avoid broken words */
@media (max-width: 360px) {
  .kpi-card {
    min-height: 94px !important;
    padding: 10px 9px !important;
  }

  .kpi-title {
    font-size: 8px !important;
  }

  .kpi-value {
    font-size: 22px !important;
  }

  .kpi-subtitle {
    display: none !important;
  }
}


/* --- Responsive modal footer overlap fix --- */
/* Modal/backdrop must always sit above the mobile footer navigation. */
.modal-backdrop,
.detail-backdrop {
  z-index: 20000 !important;
}

.modal-backdrop.is-open,
.detail-backdrop.is-open {
  pointer-events: auto !important;
}

.source-modal,
.detail-modal {
  position: relative;
  z-index: 20001 !important;
}

/* Hide the responsive bottom menu while any modal is open. */
@media (max-width: 860px) {
  body.modal-is-open .topbar {
    opacity: 0 !important;
    visibility: hidden !important;
    transform: translateY(18px) !important;
    pointer-events: none !important;
    transition: opacity 180ms var(--ease), transform 180ms var(--ease), visibility 180ms var(--ease) !important;
  }

  body.modal-is-open .pill-nav,
  body.modal-is-open .nav-item {
    pointer-events: none !important;
  }

  body.modal-is-open {
    padding-bottom: 0 !important;
  }

  .modal-backdrop,
  .detail-backdrop {
    padding: 10px !important;
    align-items: center !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
  }

  .source-modal,
  .detail-modal {
    width: min(100%, 720px) !important;
    max-height: calc(100dvh - 20px) !important;
    border-radius: 22px !important;
  }

  .source-modal {
    grid-template-rows: auto auto minmax(0, 1fr) !important;
  }

  .detail-body {
    max-height: calc(100dvh - 180px) !important;
    overflow-y: auto !important;
    padding-bottom: max(22px, env(safe-area-inset-bottom, 0px)) !important;
  }

  .modal-body {
    min-height: 0 !important;
    overflow: hidden !important;
  }

  .table-workspace,
  .excel-table-wrap,
  .sheet-rail {
    min-height: 0 !important;
  }

  .modal-close {
    position: relative !important;
    z-index: 20002 !important;
  }
}

/* Extra small screens: keep source manager usable without footer collision. */
@media (max-width: 560px) {
  .modal-backdrop,
  .detail-backdrop {
    padding: 8px !important;
  }

  .source-modal,
  .detail-modal {
    max-height: calc(100dvh - 16px) !important;
    border-radius: 20px !important;
  }

  .modal-header,
  .detail-header {
    padding: 16px !important;
  }

  .modal-toolbar {
    padding: 10px 14px !important;
  }
}


/* --- Responsive modal close button position + cache-bust release --- */
/* Keep close button visible at the top-right on small screens. */
.modal-header,
.detail-header,
.source-modal,
.detail-modal {
  position: relative;
}

.modal-close,
.detail-close,
button[aria-label="Close modal"],
button[aria-label="Close detail"] {
  flex: 0 0 auto;
}

@media (max-width: 860px) {
  .source-modal .modal-header,
  .detail-modal .detail-header,
  .detail-modal .modal-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 20004 !important;
    padding-right: 62px !important;
    backdrop-filter: blur(18px) !important;
  }

  .source-modal .modal-close,
  .detail-modal .modal-close,
  .detail-modal .detail-close,
  button[aria-label="Close modal"],
  button[aria-label="Close detail"] {
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    left: auto !important;
    z-index: 20005 !important;
    width: 40px !important;
    height: 40px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 999px !important;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .source-modal .modal-title,
  .detail-modal .modal-title,
  .detail-modal .detail-title {
    max-width: calc(100% - 54px) !important;
  }
}

@media (max-width: 480px) {
  .source-modal .modal-header,
  .detail-modal .detail-header,
  .detail-modal .modal-header {
    padding-right: 58px !important;
  }

  .source-modal .modal-close,
  .detail-modal .modal-close,
  .detail-modal .detail-close,
  button[aria-label="Close modal"],
  button[aria-label="Close detail"] {
    top: 10px !important;
    right: 10px !important;
    width: 38px !important;
    height: 38px !important;
  }
}


/* --- Light theme modal tone fix: separate Light from Warm --- */
body[data-theme="light"] {
  --light-modal-bg: rgba(255, 255, 255, 0.94);
  --light-modal-bg-solid: #FFFFFF;
  --light-modal-panel: rgba(248, 250, 252, 0.88);
  --light-modal-panel-strong: rgba(241, 245, 249, 0.96);
  --light-modal-line: rgba(148, 163, 184, 0.22);
  --light-modal-ink: #0F172A;
  --light-modal-muted: #64748B;
  --light-modal-accent: #2563EB;
  --light-modal-accent-soft: rgba(37, 99, 235, 0.10);
}

/* Modal shell */
body[data-theme="light"] .source-modal,
body[data-theme="light"] .detail-modal {
  background:
    radial-gradient(circle at 100% 0%, rgba(59, 130, 246, 0.08), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.96)) !important;
  border-color: var(--light-modal-line) !important;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.16) !important;
  color: var(--light-modal-ink) !important;
}

/* Backdrop */
body[data-theme="light"] .modal-backdrop,
body[data-theme="light"] .detail-backdrop {
  background:
    radial-gradient(circle at 50% 0%, rgba(37, 99, 235, 0.10), transparent 40%),
    rgba(15, 23, 42, 0.34) !important;
}

/* Header and toolbar */
body[data-theme="light"] .source-modal .modal-header,
body[data-theme="light"] .detail-modal .modal-header,
body[data-theme="light"] .detail-modal .detail-header,
body[data-theme="light"] .source-modal .modal-toolbar {
  background: rgba(255, 255, 255, 0.86) !important;
  border-color: var(--light-modal-line) !important;
  color: var(--light-modal-ink) !important;
  backdrop-filter: blur(18px) !important;
}

/* Modal text */
body[data-theme="light"] .source-modal h1,
body[data-theme="light"] .source-modal h2,
body[data-theme="light"] .source-modal h3,
body[data-theme="light"] .detail-modal h1,
body[data-theme="light"] .detail-modal h2,
body[data-theme="light"] .detail-modal h3,
body[data-theme="light"] .modal-title,
body[data-theme="light"] .detail-title,
body[data-theme="light"] .detail-metric strong,
body[data-theme="light"] .detail-section h3,
body[data-theme="light"] .sheet-title,
body[data-theme="light"] .source-title {
  color: var(--light-modal-ink) !important;
}

body[data-theme="light"] .source-modal p,
body[data-theme="light"] .detail-modal p,
body[data-theme="light"] .source-modal span,
body[data-theme="light"] .detail-modal span,
body[data-theme="light"] .source-modal .muted,
body[data-theme="light"] .detail-modal .muted,
body[data-theme="light"] .sheet-meta,
body[data-theme="light"] .detail-section p,
body[data-theme="light"] .detail-section li,
body[data-theme="light"] .detail-metric span {
  color: var(--light-modal-muted) !important;
}

/* Inner panels / rows */
body[data-theme="light"] .source-modal .sheet-button,
body[data-theme="light"] .source-modal .detail-section,
body[data-theme="light"] .detail-modal .detail-section,
body[data-theme="light"] .detail-modal .detail-metric,
body[data-theme="light"] .source-status-chip {
  background: var(--light-modal-panel) !important;
  border-color: var(--light-modal-line) !important;
  color: var(--light-modal-ink) !important;
}

body[data-theme="light"] .source-modal .sheet-button:hover,
body[data-theme="light"] .detail-modal .detail-section:hover,
body[data-theme="light"] .detail-modal .detail-metric:hover {
  background: #FFFFFF !important;
  border-color: rgba(37, 99, 235, 0.26) !important;
}

body[data-theme="light"] .source-modal .sheet-button.is-active {
  background: linear-gradient(180deg, #FFFFFF, rgba(239, 246, 255, 0.96)) !important;
  border-color: rgba(37, 99, 235, 0.34) !important;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.10) !important;
}

/* Search / input / select inside modal */
body[data-theme="light"] .source-modal input,
body[data-theme="light"] .source-modal select,
body[data-theme="light"] .source-modal .table-search input,
body[data-theme="light"] .source-modal .excel-cell-input {
  background: #FFFFFF !important;
  border-color: rgba(148, 163, 184, 0.28) !important;
  color: var(--light-modal-ink) !important;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.045) !important;
}

body[data-theme="light"] .source-modal input:focus,
body[data-theme="light"] .source-modal select:focus,
body[data-theme="light"] .source-modal .table-search input:focus,
body[data-theme="light"] .source-modal .excel-cell-input:focus {
  border-color: rgba(37, 99, 235, 0.44) !important;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.10) !important;
}

/* Excel table */
body[data-theme="light"] .source-modal .excel-table-wrap,
body[data-theme="light"] .source-modal .table-panel,
body[data-theme="light"] .source-modal .excel-data-table {
  background: #FFFFFF !important;
  border-color: var(--light-modal-line) !important;
}

body[data-theme="light"] .source-modal .excel-data-table th {
  background: #F1F5F9 !important;
  color: #334155 !important;
  border-color: rgba(148, 163, 184, 0.22) !important;
}

body[data-theme="light"] .source-modal .excel-data-table td {
  background: #FFFFFF !important;
  color: #0F172A !important;
  border-color: rgba(148, 163, 184, 0.16) !important;
}

body[data-theme="light"] .source-modal .excel-data-table tr:hover td {
  background: #F8FAFC !important;
}

/* Buttons */
body[data-theme="light"] .source-modal .modal-save-button,
body[data-theme="light"] .detail-modal .modal-save-button,
body[data-theme="light"] .source-modal .source-manage-button {
  color: #FFFFFF !important;
  background: linear-gradient(135deg, #2563EB, #0EA5E9) !important;
  border-color: rgba(37, 99, 235, 0.30) !important;
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.22) !important;
}

body[data-theme="light"] .source-modal .modal-close,
body[data-theme="light"] .detail-modal .modal-close,
body[data-theme="light"] .detail-modal .detail-close,
body[data-theme="light"] button[aria-label="Close modal"],
body[data-theme="light"] button[aria-label="Close detail"] {
  background: rgba(255, 255, 255, 0.92) !important;
  color: #0F172A !important;
  border-color: rgba(148, 163, 184, 0.24) !important;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.10) !important;
}

/* Mobile modal in Light */
@media (max-width: 860px) {
  body[data-theme="light"] .source-modal .modal-header,
  body[data-theme="light"] .detail-modal .detail-header,
  body[data-theme="light"] .detail-modal .modal-header {
    background: rgba(255, 255, 255, 0.92) !important;
  }
}


/* --- Advanced Analytics: Top SKU, Customer Retention, Province Intelligence --- */
.advanced-card {
  position: relative;
  overflow: hidden;
}

.advanced-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 96% 0%, rgba(107, 124, 152, 0.10), transparent 30%);
  opacity: 0.8;
}

.compact-segment {
  min-width: fit-content;
  flex-wrap: nowrap;
}

.advanced-list {
  display: grid;
  gap: 10px;
}

.analytics-context {
  margin-bottom: 2px;
  color: var(--steel);
  font-size: 12px;
  font-weight: 700;
}

.analytics-context strong {
  color: var(--navy);
  font-weight: 850;
}

.analytics-row {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  text-align: left;
  padding: 12px 13px;
  border: 1px solid rgba(172, 156, 141, 0.22);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.54);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
  transition: transform 220ms var(--ease), border-color 220ms var(--ease), background 220ms var(--ease), box-shadow 220ms var(--ease);
}

.analytics-row:hover {
  transform: translateY(-1px);
  border-color: rgba(107, 124, 152, 0.34);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 14px 32px rgba(50, 45, 41, 0.08);
}

.rank-badge {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(107, 124, 152, 0.11);
  color: var(--navy);
  font-size: 12px;
  font-weight: 850;
}

.analytics-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.analytics-main strong {
  color: var(--navy);
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.analytics-main span {
  color: var(--steel);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.analytics-metrics {
  min-width: 104px;
  display: grid;
  gap: 2px;
  text-align: right;
}

.analytics-metrics strong {
  color: var(--navy);
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.analytics-metrics span {
  color: var(--steel);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.retention-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.retention-metric {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid rgba(172, 156, 141, 0.22);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.54);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
}

.retention-metric span {
  color: var(--steel);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.retention-metric strong {
  color: var(--navy);
  font-size: clamp(18px, 2.2vw, 26px);
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.retention-metric small {
  color: var(--steel);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  padding: 16px;
  border: 1px dashed rgba(172, 156, 141, 0.34);
  border-radius: 18px;
  color: var(--steel);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

/* Light theme: keep analytics crisp and bright */
body[data-theme="light"] .analytics-row,
body[data-theme="light"] .retention-metric {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(148, 163, 184, 0.22);
}

body[data-theme="light"] .analytics-row:hover {
  background: #FFFFFF;
  border-color: rgba(37, 99, 235, 0.24);
  box-shadow: 0 16px 36px rgba(37, 99, 235, 0.08);
}

body[data-theme="light"] .rank-badge {
  background: rgba(37, 99, 235, 0.10);
  color: #1E40AF;
}

/* Responsive compact layout */
@media (max-width: 1100px) {
  .retention-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .advanced-card.span-6 {
    grid-column: span 12;
  }
}

@media (max-width: 760px) {
  .compact-segment {
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
  }

  .analytics-row {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
    padding: 11px;
  }

  .analytics-metrics {
    grid-column: 2 / -1;
    min-width: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    gap: 10px;
  }

  .analytics-main strong,
  .analytics-main span,
  .analytics-metrics strong,
  .analytics-metrics span {
    white-space: nowrap;
  }

  .retention-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .retention-metric {
    padding: 11px;
    border-radius: 16px;
  }
}

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

  .retention-metric strong {
    font-size: 18px;
  }

  .retention-metric span,
  .retention-metric small {
    font-size: 9px;
  }
}


/* --- iPad / tablet Source Manager modal layout fix --- */
/* The old desktop split layout squeezed tabs and table on iPad. */
@media (min-width: 641px) and (max-width: 1180px) {
  .source-modal {
    width: min(96vw, 980px) !important;
    max-height: calc(100dvh - 28px) !important;
    display: grid !important;
    grid-template-rows: auto auto minmax(0, 1fr) !important;
    overflow: hidden !important;
  }

  .source-modal .modal-header {
    padding: 18px 22px !important;
  }

  .source-modal .modal-toolbar {
    display: grid !important;
    grid-template-columns: 1fr auto auto auto !important;
    gap: 10px !important;
    align-items: center !important;
    padding: 12px 22px !important;
  }

  .source-modal .source-status-chip {
    min-width: 0 !important;
    max-width: 100% !important;
    white-space: normal !important;
    line-height: 1.25 !important;
  }

  .source-modal .modal-body {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  .source-modal .sheet-rail {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: row !important;
    gap: 10px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 12px 18px !important;
    border-right: 0 !important;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18) !important;
    scrollbar-width: thin !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .source-modal .sheet-rail::-webkit-scrollbar {
    height: 6px !important;
  }

  .source-modal .sheet-rail::-webkit-scrollbar-thumb {
    border-radius: 999px !important;
    background: rgba(107, 124, 152, 0.36) !important;
  }

  .source-modal .sheet-button {
    flex: 0 0 clamp(155px, 24vw, 210px) !important;
    width: clamp(155px, 24vw, 210px) !important;
    min-height: 76px !important;
    max-height: 88px !important;
    padding: 12px !important;
    border-radius: 18px !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    text-align: left !important;
    overflow: hidden !important;
  }

  .source-modal .sheet-button strong,
  .source-modal .sheet-title {
    display: block !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    font-size: 13px !important;
    line-height: 1.2 !important;
  }

  .source-modal .sheet-button span,
  .source-modal .sheet-meta {
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    white-space: normal !important;
    font-size: 11px !important;
    line-height: 1.25 !important;
  }

  .source-modal .table-workspace {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    padding: 16px 18px 18px !important;
  }

  .source-modal .table-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 280px) !important;
    gap: 12px !important;
    align-items: start !important;
  }

  .source-modal .table-title h2 {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .source-modal .table-search {
    min-width: 0 !important;
    width: 100% !important;
  }

  .source-modal .table-search input {
    width: 100% !important;
  }

  .source-modal .excel-table-wrap {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .source-modal .excel-data-table {
    min-width: 820px !important;
  }
}

/* Smaller tablets and large phones: keep tabs as horizontal chips and stack toolbar buttons. */
@media (max-width: 760px) {
  .source-modal .modal-toolbar {
    grid-template-columns: 1fr 1fr !important;
    gap: 9px !important;
  }

  .source-modal .source-status-chip {
    grid-column: 1 / -1 !important;
  }

  .source-modal .modal-toolbar button {
    width: 100% !important;
    min-height: 40px !important;
  }

  .source-modal .table-header {
    grid-template-columns: 1fr !important;
  }

  .source-modal .sheet-button {
    flex-basis: 150px !important;
    width: 150px !important;
    min-height: 72px !important;
  }
}

/* Phone: make modal even more compact, prevent horizontal layout collision. */
@media (max-width: 520px) {
  .source-modal {
    width: calc(100vw - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
  }

  .source-modal .sheet-rail {
    padding: 10px 12px !important;
    gap: 8px !important;
  }

  .source-modal .sheet-button {
    flex-basis: 136px !important;
    width: 136px !important;
    min-height: 68px !important;
    padding: 10px !important;
  }

  .source-modal .table-workspace {
    padding: 14px 12px 16px !important;
  }

  .source-modal .excel-data-table {
    min-width: 760px !important;
  }
}


/* --- Toast above modal/backdrop layer fix --- */
/* Modal/backdrop currently uses very high z-index; toast must be higher and global. */
.toast,
.toast-container,
#toast,
#toastContainer {
  position: fixed !important;
  z-index: 30050 !important;
  pointer-events: none !important;
  isolation: isolate !important;
}

.toast {
  right: 24px !important;
  bottom: 24px !important;
  top: auto !important;
  left: auto !important;
  max-width: min(420px, calc(100vw - 32px)) !important;
  pointer-events: auto !important;
  transform: translateZ(0) !important;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.22) !important;
}

/* When a modal is open, move toast to top-right so it doesn't hide modal action buttons. */
body.modal-is-open .toast,
body.modal-is-open #toast {
  top: 18px !important;
  right: 18px !important;
  bottom: auto !important;
  left: auto !important;
  z-index: 30050 !important;
}

/* Keep toast visible above source/detail modal in every viewport. */
.modal-backdrop,
.detail-backdrop {
  z-index: 20000 !important;
}

.source-modal,
.detail-modal {
  z-index: 20001 !important;
}

/* Tablet/mobile: place toast below the modal close button area but still above modal content. */
@media (max-width: 860px) {
  body.modal-is-open .toast,
  body.modal-is-open #toast {
    top: 64px !important;
    right: 12px !important;
    left: 12px !important;
    bottom: auto !important;
    width: auto !important;
    max-width: none !important;
    border-radius: 18px !important;
    z-index: 30050 !important;
  }

  .toast {
    right: 12px !important;
    left: 12px !important;
    bottom: max(88px, calc(env(safe-area-inset-bottom, 0px) + 78px)) !important;
    width: auto !important;
    max-width: none !important;
  }
}

/* Small phones: compact toast height to avoid covering too much modal content. */
@media (max-width: 480px) {
  body.modal-is-open .toast,
  body.modal-is-open #toast {
    top: 58px !important;
    font-size: 12px !important;
    padding: 11px 13px !important;
  }
}


/* --- Responsive Source Modal UX redesign --- */
/* Goal: no cramped text, no long tab scrolling, clean demo-ready mobile modal. */

.mobile-sheet-picker {
  display: none;
}

@media (max-width: 760px) {
  .source-modal {
    width: calc(100vw - 18px) !important;
    max-height: calc(100dvh - 18px) !important;
    border-radius: 22px !important;
    overflow: hidden !important;
  }

  .source-modal .modal-header {
    min-height: auto !important;
    padding: 15px 58px 12px 16px !important;
    border-bottom: 1px solid rgba(148, 163, 184, 0.16) !important;
  }

  .source-modal .modal-header .eyebrow,
  .source-modal .section-label {
    margin-bottom: 4px !important;
    font-size: 9px !important;
    letter-spacing: 0.10em !important;
  }

  .source-modal .modal-header h2,
  .source-modal .modal-title,
  .source-modal h1 {
    max-width: 100% !important;
    font-size: clamp(20px, 5.6vw, 24px) !important;
    line-height: 1.08 !important;
    letter-spacing: -0.045em !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .source-modal .modal-header p,
  .source-modal .modal-subtitle {
    margin-top: 5px !important;
    max-width: 100% !important;
    font-size: 11px !important;
    line-height: 1.35 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .source-modal .modal-close {
    top: 12px !important;
    right: 12px !important;
    width: 38px !important;
    height: 38px !important;
  }

  /* Toolbar: compact command zone */
  .source-modal .modal-toolbar {
    display: grid !important;
    grid-template-columns: 1fr auto auto auto !important;
    gap: 7px !important;
    align-items: center !important;
    padding: 10px 12px !important;
  }

  .source-modal .source-status-chip {
    min-width: 0 !important;
    max-width: 100% !important;
    height: 38px !important;
    padding: 0 12px !important;
    border-radius: 999px !important;
    display: flex !important;
    align-items: center !important;
    font-size: 10px !important;
    line-height: 1.15 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .source-modal .source-status-chip::before {
    content: "Excel Source";
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .source-modal .source-status-chip > * {
    display: none !important;
  }

  .source-modal .modal-toolbar button {
    width: auto !important;
    min-width: 42px !important;
    height: 38px !important;
    padding: 0 11px !important;
    border-radius: 999px !important;
    font-size: 0 !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  .source-modal .modal-toolbar button::after {
    font-size: 11px !important;
    font-weight: 850 !important;
  }

  .source-modal .modal-toolbar button:nth-of-type(1)::after {
    content: "Reload";
  }

  .source-modal .modal-toolbar button:nth-of-type(2)::after {
    content: "Add";
  }

  .source-modal .modal-toolbar button:nth-of-type(3)::after {
    content: "Save";
  }

  /* Replace long tab rail with one clean picker */
  .source-modal .modal-body {
    grid-template-rows: auto minmax(0, 1fr) !important;
  }

  .source-modal .mobile-sheet-picker {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 10px !important;
    padding: 10px 12px !important;
    border-bottom: 1px solid rgba(148, 163, 184, 0.16) !important;
    background: rgba(248, 250, 252, 0.42) !important;
  }

  .source-modal .mobile-sheet-picker-label {
    font-size: 10px !important;
    font-weight: 850 !important;
    letter-spacing: 0.08em !important;
    text-transform: uppercase !important;
    color: var(--steel, #64748b) !important;
    white-space: nowrap !important;
  }

  .source-modal .mobile-sheet-picker-select {
    width: 100% !important;
    min-width: 0 !important;
    height: 40px !important;
    padding: 0 12px !important;
    border-radius: 14px !important;
    border: 1px solid rgba(148, 163, 184, 0.24) !important;
    background: rgba(255, 255, 255, 0.88) !important;
    color: var(--navy, #0f172a) !important;
    font-size: 12px !important;
    font-weight: 800 !important;
    outline: none !important;
  }

  .source-modal .sheet-rail {
    display: none !important;
  }

  .source-modal .table-workspace {
    padding: 12px !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  .source-modal .table-header {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    margin-bottom: 10px !important;
  }

  .source-modal .table-title h2,
  .source-modal .table-workspace h2 {
    font-size: 19px !important;
    line-height: 1.12 !important;
    letter-spacing: -0.04em !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .source-modal .table-title p,
  .source-modal .table-workspace .muted,
  .source-modal .table-workspace p {
    font-size: 11px !important;
    line-height: 1.35 !important;
  }

  .source-modal .table-search {
    width: 100% !important;
  }

  .source-modal .table-search label {
    display: none !important;
  }

  .source-modal .table-search input {
    height: 40px !important;
    width: 100% !important;
    font-size: 12px !important;
    border-radius: 14px !important;
  }

  .source-modal .excel-table-wrap {
    max-height: calc(100dvh - 330px) !important;
    overflow: auto !important;
    border-radius: 18px !important;
  }

  .source-modal .excel-data-table {
    min-width: 720px !important;
  }

  .source-modal .excel-data-table th {
    font-size: 10px !important;
    padding: 10px !important;
    white-space: nowrap !important;
  }

  .source-modal .excel-data-table td {
    padding: 7px !important;
  }

  .source-modal .excel-cell-input {
    min-height: 34px !important;
    padding: 0 10px !important;
    font-size: 12px !important;
    border-radius: 10px !important;
  }
}

/* Very small phones: use two-row toolbar so text never wraps badly. */
@media (max-width: 430px) {
  .source-modal .modal-toolbar {
    grid-template-columns: 1fr 1fr 1fr !important;
  }

  .source-modal .source-status-chip {
    grid-column: 1 / -1 !important;
  }

  .source-modal .modal-toolbar button {
    width: 100% !important;
  }

  .source-modal .mobile-sheet-picker {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }

  .source-modal .mobile-sheet-picker-label {
    font-size: 9px !important;
  }

  .source-modal .excel-table-wrap {
    max-height: calc(100dvh - 365px) !important;
  }
}

/* Light theme support for the mobile picker */
body[data-theme="light"] .source-modal .mobile-sheet-picker {
  background: rgba(248, 250, 252, 0.76) !important;
}

body[data-theme="light"] .source-modal .mobile-sheet-picker-select {
  background: #ffffff !important;
  border-color: rgba(148, 163, 184, 0.26) !important;
  color: #0f172a !important;
}

/* Warm theme support for the mobile picker */
body[data-theme="warm"] .source-modal .mobile-sheet-picker,
body:not([data-theme]) .source-modal .mobile-sheet-picker {
  background: rgba(239, 233, 225, 0.48) !important;
}


/* --- Desktop analytics layout fix --- */
/* Prevent Customer / Province / Top SKU sections from inheriting compact mobile widths on desktop. */
@media (min-width: 1025px) {
  .dashboard-shell {
    width: min(100%, 1560px) !important;
  }

  .view-page.is-active {
    width: 100% !important;
  }

  .view-page.is-active > .dashboard-grid,
  .view-page.is-active > .kpi-grid,
  .dashboard-grid,
  .kpi-grid {
    width: 100% !important;
    grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
    align-items: stretch !important;
  }

  /* New analytics sections added for customers / provinces / SKU should be full-card desktop surfaces. */
  .customer-retention-card,
  .province-intelligence-card,
  .top-sku-card,
  .customer-analytics-card,
  .province-analytics-card,
  .sku-analytics-card,
  .retention-card,
  .geo-card,
  .analytics-card {
    min-width: 0 !important;
    width: 100% !important;
    max-width: none !important;
  }

  /* If these cards are inside generic card grids, force usable desktop spans. */
  .dashboard-grid > .customer-retention-card,
  .dashboard-grid > .customer-analytics-card,
  .dashboard-grid > .retention-card {
    grid-column: span 6 !important;
  }

  .dashboard-grid > .province-intelligence-card,
  .dashboard-grid > .province-analytics-card,
  .dashboard-grid > .geo-card {
    grid-column: span 6 !important;
  }

  .dashboard-grid > .top-sku-card,
  .dashboard-grid > .sku-analytics-card {
    grid-column: span 8 !important;
  }

  /* Any card that contains Top 5 province ranking should not collapse into a narrow column. */
  .card:has(.province-list),
  .card:has(.province-rank),
  .card:has(.province-item),
  .card:has(.customer-retention-grid),
  .card:has(.retention-metrics),
  .card:has(.top-sku-table),
  .card:has(.sku-ranking) {
    min-width: 0 !important;
    width: 100% !important;
  }

  .dashboard-grid > .card:has(.province-list),
  .dashboard-grid > .card:has(.province-rank),
  .dashboard-grid > .card:has(.province-item),
  .dashboard-grid > .card:has(.customer-retention-grid),
  .dashboard-grid > .card:has(.retention-metrics) {
    grid-column: span 6 !important;
  }

  .dashboard-grid > .card:has(.top-sku-table),
  .dashboard-grid > .card:has(.sku-ranking) {
    grid-column: span 8 !important;
  }

  /* Ranking rows should use horizontal desktop layout, not narrow stacked mobile layout. */
  .province-item,
  .customer-item,
  .retention-item,
  .sku-row,
  .top-sku-row {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
  }

  .province-list,
  .customer-list,
  .top-sku-list,
  .sku-ranking,
  .retention-list {
    width: 100% !important;
    max-width: none !important;
  }

  /* Customer KPI mini-cards: use grid instead of squeezing into tiny cards. */
  .customer-retention-grid,
  .retention-metrics,
  .province-summary-grid,
  .sku-summary-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 12px !important;
    width: 100% !important;
  }

  .customer-retention-grid > *,
  .retention-metrics > *,
  .province-summary-grid > *,
  .sku-summary-grid > * {
    min-width: 0 !important;
    width: 100% !important;
  }

  /* Prevent text from stacking character-by-character in narrow accidental cards. */
  .customer-retention-card h2,
  .province-intelligence-card h2,
  .top-sku-card h2,
  .customer-analytics-card h2,
  .province-analytics-card h2,
  .sku-analytics-card h2,
  .retention-card h2,
  .geo-card h2,
  .analytics-card h2 {
    white-space: normal !important;
    text-wrap: balance !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
  }
}

/* Medium desktop / laptop: keep 2-column analytics instead of compressed thin columns. */
@media (min-width: 861px) and (max-width: 1280px) {
  .dashboard-grid {
    grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
  }

  .dashboard-grid > .customer-retention-card,
  .dashboard-grid > .province-intelligence-card,
  .dashboard-grid > .top-sku-card,
  .dashboard-grid > .customer-analytics-card,
  .dashboard-grid > .province-analytics-card,
  .dashboard-grid > .sku-analytics-card,
  .dashboard-grid > .retention-card,
  .dashboard-grid > .geo-card,
  .dashboard-grid > .analytics-card {
    grid-column: span 6 !important;
  }
}

/* Mobile keeps compact, but cards should never become ultra-thin columns. */
@media (max-width: 860px) {
  .customer-retention-card,
  .province-intelligence-card,
  .top-sku-card,
  .customer-analytics-card,
  .province-analytics-card,
  .sku-analytics-card,
  .retention-card,
  .geo-card,
  .analytics-card {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    grid-column: span 12 !important;
  }

  .customer-retention-grid,
  .retention-metrics,
  .province-summary-grid,
  .sku-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* Hard fallback for cards accidentally inserted outside dashboard grid. */
#salesView .card,
#productsView .card,
.view-page[data-view="sales"] .card,
.view-page[data-view="products"] .card {
  min-width: 0;
}


/* --- Source Manager modal surface polish --- */
/* Fix harsh toolbar/workspace/table-header blocks and make them feel like modern liquid glass. */

body[data-theme] .source-modal .modal-toolbar,
body[data-theme] .source-modal .workspace-head,
body[data-theme] .source-modal .table-header {
  border-color: rgba(148, 163, 184, 0.14) !important;
  box-shadow: none !important;
}

body[data-theme] .source-modal .modal-toolbar {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

body[data-theme] .source-modal .modal-toolbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.38), rgba(255,255,255,0.10)),
    radial-gradient(circle at 92% 0%, rgba(107,124,152,0.10), transparent 32%);
}

body[data-theme] .source-modal .table-workspace {
  background:
    radial-gradient(circle at 96% 0%, rgba(107,124,152,0.055), transparent 34%),
    linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0.06)) !important;
}

body[data-theme] .source-modal .table-header,
body[data-theme] .source-modal .workspace-head {
  background: transparent !important;
}

body[data-theme] .source-modal .excel-table-wrap {
  border: 1px solid rgba(148, 163, 184, 0.16) !important;
  border-radius: 22px !important;
  background: rgba(255, 255, 255, 0.46) !important;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.58),
    0 18px 42px rgba(15, 23, 42, 0.055) !important;
  overflow: auto !important;
}

body[data-theme] .source-modal .excel-data-table {
  border-collapse: separate !important;
  border-spacing: 0 !important;
  background: transparent !important;
}

body[data-theme] .source-modal .excel-data-table thead th,
body[data-theme] .source-modal .excel-data-table th {
  position: sticky !important;
  top: 0 !important;
  z-index: 3 !important;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.88), rgba(248,250,252,0.72)) !important;
  color: #475569 !important;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.72) !important;
  backdrop-filter: blur(16px) !important;
}

body[data-theme] .source-modal .excel-data-table td {
  background: rgba(255,255,255,0.50) !important;
  border-bottom: 1px solid rgba(148, 163, 184, 0.11) !important;
}

/* Light theme: cleaner, brighter and less warm */
body[data-theme="light"] .source-modal .modal-toolbar {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.86), rgba(248,250,252,0.78)) !important;
  border-top: 1px solid rgba(148, 163, 184, 0.13) !important;
  border-bottom: 1px solid rgba(148, 163, 184, 0.13) !important;
}

body[data-theme="light"] .source-modal .table-workspace {
  background:
    radial-gradient(circle at 98% 0%, rgba(59,130,246,0.055), transparent 34%),
    linear-gradient(180deg, rgba(255,255,255,0.76), rgba(248,250,252,0.62)) !important;
}

body[data-theme="light"] .source-modal .excel-table-wrap {
  background: rgba(255,255,255,0.82) !important;
  border-color: rgba(148,163,184,0.18) !important;
}

body[data-theme="light"] .source-modal .excel-data-table thead th,
body[data-theme="light"] .source-modal .excel-data-table th {
  background:
    linear-gradient(180deg, rgba(248,250,252,0.96), rgba(241,245,249,0.88)) !important;
  color: #334155 !important;
}

body[data-theme="light"] .source-modal .excel-data-table td {
  background: rgba(255,255,255,0.88) !important;
}

body[data-theme="light"] .source-modal .excel-data-table tr:hover td {
  background: rgba(239,246,255,0.74) !important;
}

/* Warm theme: keep luxury warm tone but make the surface smooth, not blocky */
body[data-theme="warm"] .source-modal .modal-toolbar,
body:not([data-theme]) .source-modal .modal-toolbar {
  background:
    linear-gradient(180deg, rgba(251,248,243,0.78), rgba(239,233,225,0.58)) !important;
  border-top: 1px solid rgba(172,156,141,0.16) !important;
  border-bottom: 1px solid rgba(172,156,141,0.16) !important;
}

body[data-theme="warm"] .source-modal .table-workspace,
body:not([data-theme]) .source-modal .table-workspace {
  background:
    radial-gradient(circle at 98% 0%, rgba(171,151,140,0.075), transparent 34%),
    linear-gradient(180deg, rgba(251,248,243,0.58), rgba(239,233,225,0.42)) !important;
}

body[data-theme="warm"] .source-modal .excel-table-wrap,
body:not([data-theme]) .source-modal .excel-table-wrap {
  background: rgba(255,252,247,0.64) !important;
  border-color: rgba(172,156,141,0.18) !important;
}

body[data-theme="warm"] .source-modal .excel-data-table thead th,
body[data-theme="warm"] .source-modal .excel-data-table th,
body:not([data-theme]) .source-modal .excel-data-table thead th,
body:not([data-theme]) .source-modal .excel-data-table th {
  background:
    linear-gradient(180deg, rgba(255,252,247,0.92), rgba(239,233,225,0.76)) !important;
  color: #5E5653 !important;
  border-bottom-color: rgba(172,156,141,0.18) !important;
}

body[data-theme="warm"] .source-modal .excel-data-table td,
body:not([data-theme]) .source-modal .excel-data-table td {
  background: rgba(255,252,247,0.58) !important;
}

body[data-theme="warm"] .source-modal .excel-data-table tr:hover td,
body:not([data-theme]) .source-modal .excel-data-table tr:hover td {
  background: rgba(239,233,225,0.58) !important;
}

/* Inputs should feel embedded in the table, not like heavy blocks */
body[data-theme] .source-modal .excel-cell-input {
  border-radius: 12px !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.42) !important;
}

body[data-theme="light"] .source-modal .excel-cell-input {
  background: rgba(255,255,255,0.94) !important;
  border-color: rgba(148,163,184,0.22) !important;
}

body[data-theme="warm"] .source-modal .excel-cell-input,
body:not([data-theme]) .source-modal .excel-cell-input {
  background: rgba(255,252,247,0.82) !important;
  border-color: rgba(172,156,141,0.20) !important;
}

/* Toolbar buttons alignment / cleaner rhythm */
body[data-theme] .source-modal .modal-toolbar button {
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.06) !important;
}

@media (max-width: 760px) {
  body[data-theme] .source-modal .modal-toolbar {
    background:
      linear-gradient(180deg, rgba(255,255,255,0.74), rgba(255,255,255,0.36)) !important;
  }

  body[data-theme] .source-modal .table-workspace {
    background: rgba(255,255,255,0.10) !important;
  }

  body[data-theme] .source-modal .excel-table-wrap {
    border-radius: 18px !important;
  }
}


/* --- Source modal toolbar cleanup: remove source chip and align actions --- */
.source-modal .source-status-chip,
.source-modal [data-source-status],
.source-modal .excel-source-chip {
  display: none !important;
}

/* Desktop/tablet toolbar: actions align cleanly to the right */
.source-modal .modal-toolbar {
  display: flex !important;
  justify-content: flex-end !important;
  align-items: center !important;
  gap: 10px !important;
  min-height: 64px !important;
  padding: 12px 22px !important;
}

.source-modal .modal-toolbar button {
  flex: 0 0 auto !important;
  height: 42px !important;
  padding: 0 18px !important;
  border-radius: 999px !important;
  white-space: nowrap !important;
}

/* Make the primary save button visually balanced but not oversized */
.source-modal .modal-save-button,
.source-modal button[data-action="save-excel"],
.source-modal .save-excel-button {
  min-width: 128px !important;
}

/* Medium screens: keep buttons compact and avoid wrapping */
@media (max-width: 900px) {
  .source-modal .modal-toolbar {
    justify-content: flex-end !important;
    gap: 8px !important;
    min-height: 58px !important;
    padding: 10px 14px !important;
  }

  .source-modal .modal-toolbar button {
    height: 40px !important;
    padding: 0 13px !important;
    font-size: 12px !important;
  }

  .source-modal .modal-save-button,
  .source-modal button[data-action="save-excel"],
  .source-modal .save-excel-button {
    min-width: 112px !important;
  }
}

/* Mobile: 3 equal action buttons, no source chip, no text collision */
@media (max-width: 640px) {
  .source-modal .modal-toolbar {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
    padding: 10px 12px !important;
    min-height: auto !important;
  }

  .source-modal .modal-toolbar button {
    width: 100% !important;
    min-width: 0 !important;
    height: 40px !important;
    padding: 0 8px !important;
    font-size: 0 !important;
    overflow: hidden !important;
  }

  .source-modal .modal-toolbar button::after {
    font-size: 11px !important;
    font-weight: 850 !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  .source-modal .modal-toolbar button:nth-of-type(1)::after {
    content: "Reload";
  }

  .source-modal .modal-toolbar button:nth-of-type(2)::after {
    content: "Add";
  }

  .source-modal .modal-toolbar button:nth-of-type(3)::after {
    content: "Save";
  }
}

/* Extra small: keep button rhythm without text breaking */
@media (max-width: 380px) {
  .source-modal .modal-toolbar {
    gap: 6px !important;
    padding: 9px 10px !important;
  }

  .source-modal .modal-toolbar button {
    height: 38px !important;
    border-radius: 14px !important;
  }

  .source-modal .modal-toolbar button::after {
    font-size: 10px !important;
  }
}


/* --- Source Manager toolbar HARD FIX --- */
/* Hide source file chip regardless of exact generated class/name. */
.source-modal .modal-toolbar .is-source-chip-hidden,
.source-modal .modal-toolbar [aria-hidden="true"].is-source-chip-hidden,
.source-modal .modal-toolbar .source-status-chip,
.source-modal .modal-toolbar .source-chip,
.source-modal .modal-toolbar .excel-source-chip,
.source-modal .modal-toolbar [data-source-status] {
  display: none !important;
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
}

/* Desktop/tablet: only action buttons remain, aligned right. */
.source-modal .modal-toolbar {
  display: flex !important;
  flex-wrap: nowrap !important;
  justify-content: flex-end !important;
  align-items: center !important;
  gap: 10px !important;
  min-height: 64px !important;
  padding: 12px 22px !important;
}

.source-modal .modal-toolbar button {
  position: relative !important;
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 108px !important;
  max-width: none !important;
  height: 42px !important;
  padding: 0 18px !important;
  border-radius: 999px !important;
  white-space: nowrap !important;
  line-height: 1 !important;
  text-align: center !important;
}

.source-modal .modal-toolbar .toolbar-save-button,
.source-modal .modal-toolbar button:is([class*="save"], [data-action*="save"]) {
  min-width: 132px !important;
}

/* iPad / responsive: reliable two-row command layout */
@media (max-width: 760px) {
  .source-modal .modal-toolbar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    grid-template-areas:
      "reload add"
      "save save" !important;
    gap: 8px !important;
    padding: 10px 12px !important;
    min-height: auto !important;
    align-items: stretch !important;
  }

  .source-modal .modal-toolbar .toolbar-reload-button {
    grid-area: reload !important;
  }

  .source-modal .modal-toolbar .toolbar-add-button {
    grid-area: add !important;
  }

  .source-modal .modal-toolbar .toolbar-save-button {
    grid-area: save !important;
  }

  .source-modal .modal-toolbar button {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 40px !important;
    padding: 0 10px !important;
    border-radius: 999px !important;
    font-size: 0 !important;
    overflow: hidden !important;
  }

  .source-modal .modal-toolbar button::after {
    display: inline-block !important;
    font-size: 11px !important;
    font-weight: 850 !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  .source-modal .modal-toolbar .toolbar-reload-button::after {
    content: "Reload" !important;
  }

  .source-modal .modal-toolbar .toolbar-add-button::after {
    content: "Add" !important;
  }

  .source-modal .modal-toolbar .toolbar-save-button::after {
    content: "Save to Excel" !important;
  }
}

/* Very small screens: tighter but still clean */
@media (max-width: 420px) {
  .source-modal .modal-toolbar {
    gap: 7px !important;
    padding: 9px 10px !important;
  }

  .source-modal .modal-toolbar button {
    height: 38px !important;
    border-radius: 15px !important;
  }

  .source-modal .modal-toolbar button::after {
    font-size: 10px !important;
  }
}


/* --- Excel table rounded viewport fix --- */
/* The table/header backgrounds were visually escaping the rounded container. */
.source-modal .excel-table-wrap,
.source-modal .table-panel,
.source-modal .table-scroll,
.source-modal .excel-table-scroll {
  border-radius: 24px !important;
  overflow: auto !important;
  clip-path: inset(0 round 24px) !important;
  background-clip: padding-box !important;
  isolation: isolate !important;
}

.source-modal .excel-table-wrap {
  border: 1px solid rgba(148, 163, 184, 0.16) !important;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.54),
    0 18px 42px rgba(15, 23, 42, 0.055) !important;
}

/* Keep table background transparent so the rounded wrapper is visible */
.source-modal .excel-data-table {
  border-collapse: separate !important;
  border-spacing: 0 !important;
  background: transparent !important;
}

/* Top corners */
.source-modal .excel-data-table thead tr:first-child th:first-child,
.source-modal .excel-data-table tr:first-child th:first-child {
  border-top-left-radius: 24px !important;
}

.source-modal .excel-data-table thead tr:first-child th:last-child,
.source-modal .excel-data-table tr:first-child th:last-child {
  border-top-right-radius: 24px !important;
}

/* Bottom corners for visible last row */
.source-modal .excel-data-table tbody tr:last-child td:first-child {
  border-bottom-left-radius: 24px !important;
}

.source-modal .excel-data-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: 24px !important;
}

/* Avoid square background blocks at the table edges */
.source-modal .excel-data-table th,
.source-modal .excel-data-table td {
  background-clip: padding-box !important;
}

/* Make the bottom scrollbar feel integrated with rounded container */
.source-modal .excel-table-wrap::-webkit-scrollbar,
.source-modal .table-scroll::-webkit-scrollbar,
.source-modal .excel-table-scroll::-webkit-scrollbar {
  height: 10px !important;
  width: 10px !important;
}

.source-modal .excel-table-wrap::-webkit-scrollbar-track,
.source-modal .table-scroll::-webkit-scrollbar-track,
.source-modal .excel-table-scroll::-webkit-scrollbar-track {
  background: transparent !important;
  margin: 18px !important;
}

.source-modal .excel-table-wrap::-webkit-scrollbar-thumb,
.source-modal .table-scroll::-webkit-scrollbar-thumb,
.source-modal .excel-table-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px !important;
  border: 3px solid transparent !important;
  background-clip: padding-box !important;
  background-color: rgba(107, 124, 152, 0.36) !important;
}

/* Light / Warm theme refinement */
body[data-theme="light"] .source-modal .excel-table-wrap {
  background: rgba(255, 255, 255, 0.88) !important;
  border-color: rgba(148, 163, 184, 0.18) !important;
}

body[data-theme="warm"] .source-modal .excel-table-wrap,
body:not([data-theme]) .source-modal .excel-table-wrap {
  background: rgba(255, 252, 247, 0.66) !important;
  border-color: rgba(172, 156, 141, 0.20) !important;
}

/* Responsive keeps slightly smaller radius to match modal scale */
@media (max-width: 760px) {
  .source-modal .excel-table-wrap,
  .source-modal .table-panel,
  .source-modal .table-scroll,
  .source-modal .excel-table-scroll {
    border-radius: 18px !important;
    clip-path: inset(0 round 18px) !important;
  }

  .source-modal .excel-data-table thead tr:first-child th:first-child,
  .source-modal .excel-data-table tr:first-child th:first-child {
    border-top-left-radius: 18px !important;
  }

  .source-modal .excel-data-table thead tr:first-child th:last-child,
  .source-modal .excel-data-table tr:first-child th:last-child {
    border-top-right-radius: 18px !important;
  }

  .source-modal .excel-data-table tbody tr:last-child td:first-child {
    border-bottom-left-radius: 18px !important;
  }

  .source-modal .excel-data-table tbody tr:last-child td:last-child {
    border-bottom-right-radius: 18px !important;
  }
}
