:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --pos: #15803d;
  --pos-bg: #dcfce7;
  --neg: #b91c1c;
  --neg-bg: #fee2e2;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, 0.18);
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 1760px;
  margin: 0 auto;
  padding: 16px 20px 48px;
}

/* HEADER */
.top-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-badge {
  background: linear-gradient(135deg, #1d4ed8, #0f172a);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 8px 12px;
  border-radius: 10px;
  white-space: nowrap;
}

.app-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.app-subtitle {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.unit-switch-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.segmented {
  display: inline-flex;
  background: var(--surface-alt);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover {
  background: var(--surface-alt);
  border-color: var(--primary);
}

.icon-sm {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* MACRO KPI BAR */
.macro-kpi-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-size: 20px;
  font-weight: 800;
  font-family: var(--font-mono);
  margin-top: 4px;
  color: var(--text);
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* TABS */
.main-tabs {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.22);
}

/* TOOLBAR & CRM SNI SEARCH INPUT */
.toolbar-panel {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-box-wrap {
  width: 100%;
}

.crm-search-container {
  position: relative;
  display: flex;
  align-items: center;
}

.crm-sni-search-input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f8fafc;
  padding: 9px 34px 9px 14px;
  font-size: 12px;
  font-weight: 700;
  color: #1e293b;
  outline: none;
  transition: all 0.15s;
}

.crm-sni-search-input::placeholder {
  color: #94a3b8;
  font-weight: 600;
}

.crm-sni-search-input:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.search-clear-btn {
  position: absolute;
  right: 10px;
  border: 0;
  background: #e2e8f0;
  color: #475569;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.ctrl-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-item label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.select-ctrl {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
}

.select-ctrl:focus {
  border-color: var(--primary);
}

.ctrl-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.btn-mini {
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-mini:hover {
  background: #e2e8f0;
}

.btn-mini.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* TABLE CONTAINER */
.tab-content {
  margin-top: 12px;
}

.table-info-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.table-scroll-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  padding: 10px 10px;
  text-align: right;
  font-size: 11px;
  font-weight: 800;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  user-select: none;
}

.data-table thead th.col-left {
  text-align: left;
}

.data-table thead th.sortable {
  cursor: pointer;
}

.data-table thead th.sortable:hover {
  background: #f1f5f9;
  color: var(--primary);
}

.data-table thead th.sorted {
  color: var(--primary);
  background: #eff6ff;
}

.data-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  text-align: right;
  font-family: var(--font-mono);
  white-space: nowrap;
  vertical-align: middle;
}

.data-table tbody td.col-left {
  text-align: left;
  font-family: var(--font-sans);
  white-space: normal;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.data-table tbody tr.row-section {
  background: #fcfdff;
  font-weight: 700;
}

.data-table tbody tr.row-section:hover {
  background: #f0f7ff;
}

/* SNI TREE INDENTATION & CHEVRON (like CRM sni-tree) */
.tree-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 320px;
  max-width: 540px;
}

.tree-chevron-btn {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: all 0.12s;
}

.tree-chevron-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.tree-chevron-spacer {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: inline-block;
}

.chevron-svg {
  width: 12px;
  height: 12px;
  transition: transform 0.15s ease;
}

.chevron-svg.open {
  transform: rotate(90deg);
}

.sni-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  flex-shrink: 0;
}

.sni-badge.lvl-section {
  background: #1e293b;
  color: #fff;
  border-color: #1e293b;
}

.sni-badge.lvl-division {
  background: #dbeafe;
  color: #1e40af;
}

.industry-name-link {
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}

.industry-name-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.btn-drill-group {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.btn-drill {
  border: 1px solid var(--primary-border);
  background: var(--primary-soft);
  color: var(--primary);
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0.92;
  transition: all 0.12s;
  white-space: nowrap;
}

.btn-drill:hover {
  opacity: 1;
  background: var(--primary);
  color: #fff;
}

.btn-drill.btn-drill-fast {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #15803d;
}

.btn-drill.btn-drill-fast:hover {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

/* COLUMN HEADER HELP BADGE & FLOATING NOVICE TOOLTIP */
.th-with-help {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.th-help-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e2e8f0;
  color: #475569;
  font-size: 9.5px;
  font-weight: 800;
  font-family: var(--font-sans);
  line-height: 1;
  flex-shrink: 0;
  transition: all 0.12s;
}

th:hover .th-help-dot {
  background: var(--primary);
  color: #fff;
}

.fin-tooltip-popover {
  position: fixed;
  z-index: 9999;
  width: 340px;
  max-width: 92vw;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 18px 36px -8px rgba(15, 23, 42, 0.45);
  pointer-events: none;
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.45;
  text-align: left;
}

.fin-tooltip-title {
  font-size: 12.5px;
  font-weight: 800;
  color: #60a5fa;
  margin-bottom: 5px;
}

.fin-tooltip-body {
  color: #e2e8f0;
  margin-bottom: 6px;
}

.fin-tooltip-formula {
  background: rgba(255, 255, 255, 0.08);
  border-left: 3px solid #38bdf8;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 11px;
  color: #bae6fd;
  font-family: var(--font-mono);
}

/* VALUE FORMATTING & BADGES */
.val-pos {
  color: var(--pos);
}

.val-neg {
  color: var(--neg);
}

.val-muted {
  color: var(--text-soft);
}

.pill-growth {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}

.pill-growth.pos {
  background: var(--pos-bg);
  color: var(--pos);
}

.pill-growth.neg {
  background: var(--neg-bg);
  color: var(--neg);
}

.pill-growth.neutral {
  background: #f1f5f9;
  color: #475569;
}

.share-bar-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.share-bar {
  width: 44px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.share-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
}

.sparkline-svg {
  vertical-align: middle;
}

/* TAB 2: FAST GROWING INDUSTRIES CHART */
.growth-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.chart-card-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.section-subtitle {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.chart-mode-btns {
  display: flex;
  gap: 6px;
}

.chart-canvas-wrap {
  width: 100%;
  height: 300px;
  background: #fcfdff;
  border: 1px solid #f1f5f9;
  border-radius: 12px;
  padding: 8px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-alt);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--border);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* MODAL / DRAWER FOR INDUSTRY DRILLDOWN */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  justify-content: flex-end;
}

.modal-drawer {
  position: relative;
  width: var(--modal-width, min(1440px, 96vw));
  min-width: min(600px, 92vw);
  max-width: 100vw;
  height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  padding-left: 12px;
}

.modal-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 14px;
  z-index: 80;
  cursor: ew-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(90deg, #dbeafe 0%, #eff6ff 100%);
  border-right: 2px solid #93c5fd;
  border-left: 1px solid #60a5fa;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.modal-resize-handle:hover,
.modal-resize-handle.dragging {
  background: var(--primary);
  border-right-color: var(--primary);
}

.resize-grip-dots {
  background: #2563eb;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  padding: 14px 2px;
  border-radius: 6px;
  letter-spacing: -2px;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

.modal-resize-handle:hover .resize-grip-dots,
.modal-resize-handle.dragging .resize-grip-dots {
  background: #1e40af;
  color: #ffffff;
}

body.resizing-modal {
  cursor: ew-resize !important;
  user-select: none !important;
}

.modal-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.breadcrumb-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.crumb-btn {
  border: 0;
  background: var(--surface-alt);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  cursor: pointer;
}

.crumb-btn:hover {
  text-decoration: underline;
}

.modal-heading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sni-pill-lg {
  background: #1d4ed8;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 8px;
}

#modalIndustryName {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.level-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 6px;
}

.modal-close-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.modal-close-btn:hover {
  background: #fee2e2;
  color: #b91c1c;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.industry-overview-grid {
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 14px;
}

.ind-kpi-column {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.ind-chart-column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
}

.ind-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.ind-chart-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
}

.ind-chart-svg-wrap {
  flex: 1;
  min-height: 170px;
}

/* MODAL COMPANIES SECTION */
.modal-companies-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-subtabs-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.modal-subtabs {
  display: flex;
  gap: 8px;
}

.subtab-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.subtab-btn.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.modal-controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.checkbox-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* SELECTED COMPANY HISTORY CHARTS */
.company-history-panel {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.comp-chart-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.comp-chart-badge {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--primary);
  letter-spacing: 0.04em;
}

#selectedCompanyTitle {
  margin: 2px 0 0;
  font-size: 14px;
  font-weight: 800;
}

.comp-snis-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.comp-sni-tag {
  font-size: 11px;
  background: #fff;
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
}

.comp-sni-tag:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

.mini-chart-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.mini-chart-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

.modal-company-locate-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.locate-results-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
}

.locate-status-label {
  font-weight: 700;
  color: #1e3a8a;
}

.locate-match-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #93c5fd;
  background: #ffffff;
  color: #1e40af;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.12s;
}

.locate-match-chip:hover {
  border-color: var(--primary);
  background: #dbeafe;
}

.locate-match-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.28);
}

.modal-table-wrap {
  position: relative;
  overflow-x: auto;
  height: calc(100vh - 140px);
  min-height: 620px;
  max-height: none;
  flex: 1 1 auto;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.loading-banner {
  padding: 22px;
  text-align: center;
  font-weight: 700;
  color: var(--primary);
  background: rgba(255, 255, 255, 0.9);
}

.comp-row {
  cursor: pointer;
}

.comp-row.selected-row {
  background: #eff6ff !important;
}

.comp-row.located-target-row {
  background: #fef9c3 !important;
  outline: 2px solid #eab308;
  outline-offset: -2px;
}

.located-rank-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eab308;
  color: #0f172a;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 6px;
}

.rank-gap-row td {
  background: #f1f5f9 !important;
  color: #475569 !important;
  text-align: center !important;
  font-family: var(--font-sans) !important;
  font-size: 11.5px !important;
  font-weight: 700 !important;
  padding: 7px 12px !important;
  border-top: 1px dashed #94a3b8 !important;
  border-bottom: 1px dashed #94a3b8 !important;
}

.empty-cell {
  text-align: center !important;
  padding: 32px !important;
  color: var(--text-muted);
  font-family: var(--font-sans) !important;
}

@media (max-width: 1100px) {
  .macro-kpi-bar {
    grid-template-columns: repeat(2, 1fr);
  }
  .industry-overview-grid {
    grid-template-columns: 1fr;
  }
  .comp-charts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* MOBILE PHONE ADAPTATION */
@media (max-width: 768px) {
  .app-shell {
    padding: 10px 10px 36px;
  }

  .top-header {
    padding: 12px 12px;
    gap: 10px;
    border-radius: 12px;
  }

  .header-left {
    align-items: flex-start;
    gap: 10px;
  }

  .brand-badge {
    padding: 6px 8px;
    font-size: 11px;
  }

  .app-title {
    font-size: 15px;
    line-height: 1.25;
  }

  .app-subtitle {
    font-size: 11px;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .unit-switch-group {
    flex: 1;
    justify-content: space-between;
  }

  .segmented {
    flex-wrap: wrap;
  }

  .seg-btn {
    padding: 5px 8px;
    font-size: 10.5px;
  }

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

  .kpi-card {
    padding: 10px 12px;
  }

  .kpi-value {
    font-size: 15px;
  }

  .kpi-sub {
    font-size: 10.5px;
  }

  .main-tabs {
    flex-direction: column;
    gap: 6px;
  }

  .tab-btn {
    width: 100%;
    justify-content: center;
    padding: 10px 12px;
    font-size: 12px;
  }

  .toolbar-panel {
    padding: 10px 12px;
    border-radius: 12px;
  }

  .toolbar-controls,
  .modal-controls-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .ctrl-item {
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
  }

  .select-ctrl {
    width: 100%;
    font-size: 12px;
    padding: 7px 8px;
  }

  .ctrl-actions {
    grid-column: 1 / -1;
    margin-left: 0;
    justify-content: stretch;
  }

  .ctrl-actions .btn-mini {
    flex: 1;
    text-align: center;
    padding: 8px;
  }

  .table-info-strip {
    flex-direction: column;
    align-items: flex-start;
    font-size: 11px;
  }

  .table-scroll-container {
    max-height: none;
    border-radius: 12px;
    -webkit-overflow-scrolling: touch;
  }

  .tree-cell {
    min-width: 230px;
    max-width: 300px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .btn-drill-group {
    width: 100%;
    margin-left: 26px;
    margin-top: 2px;
  }

  .chart-card {
    padding: 12px;
  }

  .chart-canvas-wrap {
    height: 220px;
  }

  /* Modal full-screen on mobile */
  .modal-drawer {
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh;
    padding-left: 0;
  }

  .modal-resize-handle {
    display: none !important;
  }

  .modal-header {
    padding: 10px 12px;
  }

  #modalIndustryName {
    font-size: 14px;
  }

  .modal-body {
    padding: 10px 10px 28px;
    gap: 12px;
  }

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

  .ind-chart-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal-companies-section {
    padding: 10px;
  }

  .modal-subtabs {
    flex-direction: column;
    width: 100%;
  }

  .subtab-btn {
    width: 100%;
    text-align: center;
    font-size: 12px;
  }

  .comp-charts-grid {
    grid-template-columns: 1fr;
  }

  .modal-table-wrap {
    height: 72vh;
    min-height: 420px;
    -webkit-overflow-scrolling: touch;
  }

  .fin-tooltip-popover {
    left: 12px !important;
    right: 12px !important;
    width: calc(100vw - 24px) !important;
  }
}

@media (max-width: 420px) {
  .macro-kpi-bar {
    grid-template-columns: 1fr;
  }
  .toolbar-controls,
  .modal-controls-row {
    grid-template-columns: 1fr;
  }
}
