/* CrimeGrade Portal - Common Styles */
:root {
  --cg-gold: #e1cc62;
  --cg-blue: #2c5aa0;
  --cg-dark-blue: #1a3a6b;
  --cg-green: #207440;
  --cg-red: #dd4545;
  --cg-gray: #666666;
  --cg-light-gray: #f5f5f5;
  --cg-border: #d0d0d0;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: #333;
  line-height: 1.6;
  background: #fff;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------------------
   LAYOUT-SHIFT PREVENTION
   Reserve space for the header and sidebar before their async HTML loads.
   sidebar.js sets html.sidebar-collapsed synchronously from the cookie so the
   correct sidebar width is available on first paint.
   --------------------------------------------------------------------------- */

/* Header placeholder — matches the rendered header dimensions so the page
   doesn't reflow when header.html injects.  :empty ensures the styles only
   apply while the div is still waiting for content. */
[data-include*="header"] {
  flex-shrink: 0;
}

[data-include*="header"]:empty {
  min-height: 83px;
  background: white;
  border-bottom: 3px solid var(--cg-blue);
}

.dashboard-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar Wrapper - reserves the correct width before sidebar.html loads */
.sidebar-wrapper {
  width: 250px;
  background: var(--cg-dark-blue);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

html.sidebar-collapsed .sidebar-wrapper {
  width: 70px;
}

/* Only animate the sidebar wrapper after init has set the correct state */
body.layout-ready .sidebar-wrapper {
  transition: width 0.3s ease;
}

/* ---------------------------------------------------------------------------
   VIEW TRANSITIONS (same-origin MPA)
   Elements with a view-transition-name persist visually across navigations in
   browsers that support the View Transitions API.  Unsupported browsers simply
   ignore these rules and get normal page loads.
   --------------------------------------------------------------------------- */
[data-include*="header"] {
  view-transition-name: site-header;
}

.sidebar-wrapper {
  view-transition-name: sidebar;
}

.main-content {
  view-transition-name: main-content;
}

::view-transition-old(main-content) {
  animation: vt-fade-out 0.15s ease-out;
}

::view-transition-new(main-content) {
  animation: vt-fade-in 0.2s ease-in;
}

::view-transition-old(site-header),
::view-transition-old(sidebar) {
  animation: none;
}

::view-transition-new(site-header),
::view-transition-new(sidebar) {
  animation: none;
}

@keyframes vt-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes vt-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Main Content */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 30px;
  background: var(--cg-light-gray);
  overflow-y: auto;
  overflow-x: auto;
}

/* Custom scrollbar styling for main content area */
.main-content::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}

.main-content::-webkit-scrollbar-track {
  background: #f0f0f0;
}

.main-content::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 7px;
  border: 2px solid #f0f0f0;
}

.main-content::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Firefox scrollbar styling for main content */
.main-content {
  scrollbar-width: auto;
  scrollbar-color: #888 #f0f0f0;
}

.page-header {
  margin-bottom: 30px;
}

.page-header h1 {
  font-size: 28px;
  color: var(--cg-dark-blue);
  margin-bottom: 10px;
}

.page-header .subtitle {
  color: var(--cg-gray);
  font-size: 14px;
}

/* Cards */
.card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  overflow: visible;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 2px solid var(--cg-border);
}

.card-header h2 {
  font-size: 20px;
  color: var(--cg-dark-blue);
}

.card-actions {
  display: flex;
  gap: 10px;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
}

.btn-primary {
  background: var(--cg-blue);
  color: white;
}

.btn-primary:hover {
  background: var(--cg-dark-blue);
}

.btn-secondary {
  background: white;
  color: var(--cg-blue);
  border: 1px solid var(--cg-blue);
}

.btn-secondary:hover {
  background: var(--cg-light-gray);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* Grade Badges */
.grade-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 14px;
}

.grade-a-plus { background: rgba(32, 116, 64, 0.9); color: white; }
.grade-a { background: rgba(67, 147, 88, 0.9); color: white; }
.grade-a-minus { background: rgba(102, 178, 112, 0.85); color: white; }
.grade-b-plus { background: rgba(137, 209, 136, 0.8); color: #333; }
.grade-b { background: rgba(172, 225, 160, 0.75); color: #333; }
.grade-b-minus { background: rgba(199, 233, 192, 0.7); color: #333; }
.grade-c-plus { background: rgba(225, 204, 98, 0.8); color: #333; }
.grade-c { background: rgba(237, 218, 138, 0.75); color: #333; }
.grade-c-minus { background: rgba(243, 229, 171, 0.7); color: #333; }
.grade-d-plus { background: rgba(243, 177, 131, 0.75); color: #333; }
.grade-d { background: rgba(237, 140, 100, 0.8); color: white; }
.grade-d-minus { background: rgba(230, 103, 82, 0.85); color: white; }
.grade-f { background: rgba(221, 69, 69, 0.9); color: white; }

/* Risk Badges */
.risk-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 120px;
  text-align: center;
}

.risk-low { background: rgba(32, 116, 64, 0.9); color: white; }
.risk-moderate { background: rgba(107, 159, 92, 0.9); color: white; }
.risk-elevated { background: rgba(225, 204, 98, 0.9); color: #333; }
.risk-high { background: rgba(232, 150, 81, 0.9); color: white; }
.risk-severe { background: rgba(221, 69, 69, 0.9); color: white; }

/* Risk Distribution */
.risk-distribution {
  margin-top: 10px;
}

.risk-bar-container {
  margin-bottom: 20px;
}

.risk-bar {
  display: flex;
  height: 40px;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.risk-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.risk-segment.risk-low {
  background-color: #207440;
}

.risk-segment.risk-moderate {
  background-color: #6b9f5c;
}

.risk-segment.risk-elevated {
  background-color: #e1cc62;
}

.risk-segment.risk-high {
  background-color: #e89651;
}

.risk-segment.risk-severe {
  background-color: #dd4545;
}

.risk-label {
  color: white;
  font-weight: 600;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.risk-segment.risk-elevated .risk-label {
  color: #333;
}

.risk-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin-top: 15px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.legend-color {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-text {
  color: var(--cg-gray);
}

/* Crime Category Cards */
.crime-categories {
  margin-top: 10px;
}

.crime-category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.crime-category-card {
  background: var(--cg-light-gray);
  padding: 20px;
  border-radius: 6px;
  border-left: 4px solid var(--cg-blue);
}

.crime-category-icon {
  font-size: 32px;
  margin-bottom: 10px;
}

.crime-category-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--cg-dark-blue);
  margin-bottom: 15px;
}

.crime-category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.crime-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 6px 0;
}

.crime-item span:first-child {
  color: #333;
}

.crime-note {
  margin-top: 15px;
  padding: 12px;
  background: #f9f9f9;
  border-radius: 4px;
  font-size: 12px;
  color: var(--cg-gray);
}

/* Trend Insights */
.trend-insights {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--cg-border);
}

.insight-box {
  background: #f9f9f9;
  padding: 15px;
  border-radius: 4px;
  border-left: 4px solid var(--cg-gold);
}

.insight-box strong {
  color: var(--cg-dark-blue);
}

.insight-box ul {
  color: #333;
  line-height: 1.8;
}

.insight-box li {
  margin-bottom: 8px;
}

/* Tables */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: none; /* IE/Edge legacy */
  scrollbar-width: none; /* Firefox: hide native scrollbar */
}

/* Hide native horizontal scrollbar; custom rail is used instead */
.table-wrapper::-webkit-scrollbar {
  height: 0;
  display: none;
}

/* Overflow rail (common.js shows it only when the table overflows). Sticky: while the table runs below the window it
   holds to the window's bottom edge; once the table's end scrolls into view it rests under the last row. The white
   ring hides the rows it floats over. */
.table-scrollbar-rail {
  position: sticky;
  bottom: 8px;
  z-index: 4;
  height: 14px;
  margin-top: 8px;
  background: #e8e8e8;
  border-radius: 7px;
  box-shadow: 0 0 0 8px #fff;
  display: none;
}

.table-scrollbar-thumb {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  min-width: 44px;
  background: #888;
  border-radius: 7px;
  cursor: grab;
}

.table-scrollbar-thumb:hover {
  background: #555;
}

.table-scrollbar-thumb.dragging {
  cursor: grabbing;
}

/* Fixed header clone rendered while table rows are in view */
.cg-sticky-table-head {
  position: fixed;
  z-index: 950;
  display: none;
  overflow: hidden;
  background: white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.cg-sticky-table-head .data-table {
  margin: 0;
}

.cg-sticky-table-head .data-table th {
  box-shadow: none;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  position: relative;
}

.data-table th,
.data-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--cg-border);
  white-space: nowrap;
}

/* Allow location column to wrap */
.data-table td:first-child {
  white-space: normal;
  min-width: 180px;
}

.data-table thead {
  background: var(--cg-light-gray);
}

.data-table th {
  background: var(--cg-light-gray);
  font-weight: 600;
  color: var(--cg-dark-blue);
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  border-bottom: 2px solid var(--cg-border);
}

.data-table th:hover {
  background: #e8e8e8;
}

.data-table th.sortable::after {
  content: ' ⇅';
  opacity: 0.4;
}

.data-table th.sorted-asc::after {
  content: ' ↑';
  opacity: 1;
}

.data-table th.sorted-desc::after {
  content: ' ↓';
  opacity: 1;
}

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

.data-table td a {
  color: var(--cg-blue);
  text-decoration: none;
}

.data-table td a:hover {
  text-decoration: underline;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  border-left: 4px solid var(--cg-blue);
}

.stat-card.gold {
  border-left-color: var(--cg-gold);
}

.stat-card.green {
  border-left-color: var(--cg-green);
}

.stat-card.red {
  border-left-color: var(--cg-red);
}

.stat-label {
  font-size: 14px;
  color: var(--cg-gray);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--cg-dark-blue);
}

.stat-change {
  font-size: 12px;
  margin-top: 8px;
}

.stat-change.positive {
  color: var(--cg-green);
}

.stat-change.negative {
  color: var(--cg-red);
}

/* Column Selector - legacy styles removed; columns now managed via modal in locations.html */

/* Slider Controls */
.slider-controls {
  background: white;
  padding: 20px;
  border-radius: 4px;
  margin-bottom: 20px;
}

.slider-controls h3 {
  font-size: 16px;
  margin-bottom: 15px;
  color: var(--cg-dark-blue);
}

.slider-row {
  margin-bottom: 20px;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--cg-gray);
}

.slider-row input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--cg-light-gray);
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--cg-blue);
  cursor: pointer;
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--cg-blue);
  cursor: pointer;
  border: none;
}

.slider-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* Chart Container */
.chart-container {
  position: relative;
  height: 300px;
  margin-top: 20px;
}

/* Benchmark Comparison */
.benchmark-comparison {
  margin-top: 10px;
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  margin-bottom: 10px;
}

.comparison-table th,
.comparison-table td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--cg-border);
}

.comparison-table thead th {
  background: var(--cg-light-gray);
  font-weight: 600;
  color: var(--cg-dark-blue);
  font-size: 14px;
}

.comparison-table tbody tr:hover {
  background: #fafafa;
}

.comparison-table tbody td:first-child {
  font-weight: 500;
  color: var(--cg-dark-blue);
  width: 25%;
}

.score-cell {
  text-align: center;
  font-size: 15px;
}

.score-high {
  color: #207440;
  font-weight: 600;
}

.score-medium {
  color: #e1cc62;
  font-weight: 600;
}

.score-low {
  color: #dd4545;
  font-weight: 600;
}

.variance-cell {
  text-align: center;
  font-weight: 600;
}

.variance-value {
  color: var(--cg-blue);
  font-size: 14px;
}

.benchmark-note {
  background: #f9f9f9;
  padding: 12px 15px;
  border-radius: 4px;
  border-left: 3px solid var(--cg-blue);
}

/* Map Container */
.map-container {
  width: 100%;
  height: 500px;
  border-radius: 8px;
  overflow: hidden;
}

/* Colorblind Mode Styles - Yellow to Red Two-Tone Palette */

/* Grade Badges in Colorblind Mode — blue (safe) → gold → orange (danger) */
body.colorblind-mode .grade-a-plus { background: rgba(74, 144, 217, 0.9); color: white; }
body.colorblind-mode .grade-a { background: rgba(88, 153, 216, 0.85); color: white; }
body.colorblind-mode .grade-a-minus { background: rgba(110, 166, 215, 0.8); color: #333; }
body.colorblind-mode .grade-b-plus { background: rgba(140, 180, 210, 0.8); color: #333; }
body.colorblind-mode .grade-b { background: rgba(165, 190, 185, 0.8); color: #333; }
body.colorblind-mode .grade-b-minus { background: rgba(190, 195, 145, 0.8); color: #333; }
body.colorblind-mode .grade-c-plus { background: rgba(205, 190, 120, 0.85); color: #333; }
body.colorblind-mode .grade-c { background: rgba(212, 184, 106, 0.85); color: #333; }
body.colorblind-mode .grade-c-minus { background: rgba(215, 175, 90, 0.85); color: #333; }
body.colorblind-mode .grade-d-plus { background: rgba(218, 160, 78, 0.9); color: #333; }
body.colorblind-mode .grade-d { background: rgba(216, 142, 62, 0.9); color: white; }
body.colorblind-mode .grade-d-minus { background: rgba(214, 130, 48, 0.9); color: white; }
body.colorblind-mode .grade-f { background: rgba(212, 120, 43, 0.9); color: white; }

/* Risk Badges in Colorblind Mode */
body.colorblind-mode .risk-low { background: rgba(74, 144, 217, 0.9); color: white; }
body.colorblind-mode .risk-moderate { background: rgba(145, 178, 190, 0.85); color: #333; }
body.colorblind-mode .risk-elevated { background: rgba(212, 184, 106, 0.9); color: #333; }
body.colorblind-mode .risk-high { background: rgba(216, 148, 68, 0.9); color: white; }
body.colorblind-mode .risk-severe { background: rgba(212, 120, 43, 0.9); color: white; }

/* Risk Distribution Segments in Colorblind Mode */
body.colorblind-mode .risk-segment.risk-low {
  background-color: #4A90D9;
}

body.colorblind-mode .risk-segment.risk-moderate {
  background-color: #8FB4A2;
}

body.colorblind-mode .risk-segment.risk-elevated {
  background-color: #D4B86A;
}

body.colorblind-mode .risk-segment.risk-high {
  background-color: #D49848;
}

body.colorblind-mode .risk-segment.risk-severe {
  background-color: #D4782B;
}

/* Risk Legend Colors in Colorblind Mode */
body.colorblind-mode .legend-item:nth-child(1) .legend-color {
  background-color: #4A90D9 !important;
}

body.colorblind-mode .legend-item:nth-child(2) .legend-color {
  background-color: #8FB4A2 !important;
}

body.colorblind-mode .legend-item:nth-child(3) .legend-color {
  background-color: #D4B86A !important;
}

body.colorblind-mode .legend-item:nth-child(4) .legend-color {
  background-color: #D49848 !important;
}

body.colorblind-mode .legend-item:nth-child(5) .legend-color {
  background-color: #D4782B !important;
}

/* Score Highlighting in Colorblind Mode */
body.colorblind-mode .score-high {
  color: #4A90D9;
}

body.colorblind-mode .score-medium {
  color: #D4B86A;
}

body.colorblind-mode .score-low {
  color: #D4782B;
}

/* Stat Cards in Colorblind Mode */
body.colorblind-mode .stat-card.green {
  border-left-color: #4A90D9;
}

body.colorblind-mode .stat-card.red {
  border-left-color: #D4782B;
}

/* Risk Labels in Colorblind Mode */
body.colorblind-mode .risk-segment.risk-low .risk-label {
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
body.colorblind-mode .risk-segment.risk-moderate .risk-label {
  color: #333;
  text-shadow: none;
}
body.colorblind-mode .risk-segment.risk-elevated .risk-label {
  color: #333;
  text-shadow: none;
}

/* Pagination Controls */
.pagination-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 20px 16px;
  gap: 32px;
  border-top: 1px solid #e0e0e0;
  margin-top: 0;
}

.pagination-info {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.87);
  font-weight: 400;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.pagination-per-page {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-per-page label {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.87);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  margin: 0;
  white-space: nowrap;
}

.pagination-per-page select {
  padding: 4px 24px 4px 8px;
  border: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.42);
  border-radius: 0;
  font-size: 14px;
  background: transparent;
  cursor: pointer;
  color: rgba(0, 0, 0, 0.87);
  font-weight: 400;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='rgba(0,0,0,0.54)' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  transition: border-color 0.2s;
  min-width: 60px;
}

.pagination-per-page select:hover {
  border-bottom-color: rgba(0, 0, 0, 0.87);
}

.pagination-per-page select:focus {
  outline: none;
  border-bottom-color: var(--cg-blue);
  border-bottom-width: 2px;
}

.pagination-buttons {
  display: flex;
  gap: 24px;
  align-items: center;
}

.pagination-btn {
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: rgba(0, 0, 0, 0.54);
  transition: all 0.2s;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 400;
  border-radius: 50%;
}

.pagination-btn:hover:not(:disabled) {
  color: rgba(0, 0, 0, 0.87);
}

.pagination-btn:disabled {
  opacity: 0.38;
  cursor: default;
  color: rgba(0, 0, 0, 0.38);
}

.pagination-btn:disabled:hover {
  background: transparent;
}

/* Print Styles */
@media print {
  .sidebar,
  .btn,
  .card-actions,
  .colorblind-toggle,
  .pagination-controls {
    display: none;
  }
  
  .main-content {
    padding: 0;
  }
  
  .card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid var(--cg-border);
  }
}

/* Responsive */
@media (max-width: 1024px) {
  [data-include*="header"]:empty {
    min-height: 67px;
  }

  /* Hide sidebar completely on mobile - use header hamburger menu instead */
  .sidebar-wrapper,
  .dashboard-container .sidebar {
    display: none !important;
  }
  
  .main-content {
    padding: 15px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .crime-category-grid {
    grid-template-columns: 1fr;
  }
  
  .risk-legend {
    flex-direction: column;
    gap: 10px;
  }
  
  .comparison-table {
    font-size: 12px;
  }
  
  .comparison-table th,
  .comparison-table td {
    padding: 10px 8px;
  }
  
  .comparison-table thead th {
    font-size: 12px;
  }
  
  .score-cell,
  .variance-cell {
    font-size: 13px;
  }
  
  .chart-container {
    height: 250px;
  }
  
  .pagination-controls {
    justify-content: flex-end;
    gap: 16px;
    padding: 16px 8px;
  }
  
  .pagination-info {
    font-size: 12px;
  }
  
  .pagination-per-page label {
    font-size: 12px;
  }
  
  .pagination-per-page select {
    font-size: 12px;
    min-width: 50px;
  }
  
  .pagination-buttons {
    gap: 16px;
  }
  
  .pagination-btn {
    width: 28px;
    height: 28px;
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  [data-include*="header"]:empty {
    min-height: 63px;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .card-actions {
    width: 100%;
  }
  
  .card-actions .btn {
    width: 100%;
  }
  
  .comparison-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .risk-label {
    font-size: 11px;
  }
  
  /* Wrap pagination into two lines on very small screens */
  .pagination-controls {
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 12px;
  }
  
  .pagination-per-page {
    order: 1;
    flex: 0 0 100%;
  }
  
  .pagination-info {
    order: 2;
    flex: 0 1 auto;
  }
  
  .pagination-buttons {
    order: 3;
    flex: 0 1 auto;
  }
}

/* ============================================================================
   USER CUSTOMIZATIONS - EDITABLE FIELDS
   ============================================================================ */

/* Location name editing */
.editable-location {
  position: relative;
}

.location-name {
  position: relative;
  display: inline-block;
}

.location-name.custom-name {
  color: #2196F3;
}

.edit-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 2px;
  margin-left: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
  color: var(--cg-gray);
  vertical-align: middle;
}

.editable-location:hover .edit-icon {
  opacity: 1;
}

.edit-icon:hover {
  color: var(--cg-primary);
}

.edit-icon svg {
  display: block;
}

/* Tags display */
.tag-badge {
  display: inline-block;
  background: #E3F2FD;
  color: #1976D2;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  margin-right: 4px;
  margin-bottom: 2px;
  white-space: nowrap;
}

.editable-tags,
.editable-notes {
  cursor: pointer;
  transition: background-color 0.2s;
  position: relative;
}

.editable-tags:hover,
.editable-notes:hover {
  background-color: #f8f9fa !important;
}

.editable-tags:hover::after,
.editable-notes:hover::after {
  content: '✎';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--cg-gray);
  font-size: 14px;
  opacity: 0.6;
}

.no-data {
  color: var(--cg-gray);
  font-style: italic;
}

/* Editable notes preview */
.editable-notes {
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Print styles - hide edit icons */
@media print {
  .edit-icon {
    display: none !important;
  }
  
  .editable-tags:hover::after,
  .editable-notes:hover::after {
    display: none !important;
  }
}

/* ============================================================================
   PERMISSION UI
   ============================================================================ */

/* Permission-disabled state for buttons/links */
.cg-permission-disabled {
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  position: relative;
}

.cg-permission-disabled::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  cursor: not-allowed;
}

/* Toast notifications */
.cg-toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 14px 28px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 100000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  max-width: 90vw;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.cg-toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.cg-toast-error {
  background: #333;
  color: white;
  border-left: 4px solid var(--cg-red);
}

.cg-toast-success {
  background: #333;
  color: white;
  border-left: 4px solid var(--cg-green);
}

/* ============================================================================
   ADMIN PANEL
   ============================================================================ */

.cg-admin-panel {
  border-left: 4px solid var(--cg-blue);
}

.cg-admin-invite-bar {
  padding: 16px 24px;
  background: #f8f9fa;
  border-bottom: 1px solid var(--cg-border);
}

.cg-admin-invite-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.cg-admin-invite-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--cg-dark-blue);
  white-space: nowrap;
}

.cg-admin-invite-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--cg-border);
  border-radius: 6px;
  font-size: 14px;
}

.cg-admin-invite-input:focus {
  outline: none;
  border-color: var(--cg-blue);
  box-shadow: 0 0 0 2px rgba(44, 90, 160, 0.12);
}

.cg-admin-status {
  margin-top: 8px;
  font-size: 13px;
}

.cg-admin-table-wrap {
  padding: 16px 24px;
}

.cg-admin-table th {
  font-size: 13px;
  white-space: nowrap;
}

.cg-admin-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--cg-blue);
  cursor: pointer;
}

.cg-admin-checkbox:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cg-admin-user-email {
  font-weight: 600;
  color: #333;
}

.cg-admin-user-name {
  font-size: 12px;
  color: var(--cg-gray);
}

.cg-admin-user-self {
  font-size: 11px;
  color: var(--cg-blue);
  font-weight: 600;
}

.cg-admin-status-active {
  color: var(--cg-green);
  font-weight: 600;
  font-size: 13px;
}

.cg-admin-status-pending {
  color: #e1a100;
  font-weight: 600;
  font-size: 13px;
}

.cg-admin-status-other {
  color: var(--cg-gray);
  font-size: 13px;
}

.cg-admin-loading {
  text-align: center;
  padding: 30px 20px;
  color: var(--cg-gray);
  font-size: 14px;
}

.cg-admin-error {
  text-align: center;
  padding: 30px 20px;
}

.cg-admin-error-title {
  color: var(--cg-red);
  margin: 0 0 8px 0;
  font-weight: 600;
  font-size: 15px;
}

.cg-admin-error-detail {
  color: var(--cg-gray);
  font-size: 13px;
  margin: 0;
  line-height: 1.5;
}

/* Highlight row on successful update */
@keyframes adminRowFlash {
  0% { background: #e8f5e9; }
  100% { background: transparent; }
}

.cg-admin-row-success {
  animation: adminRowFlash 0.8s ease-out;
}

@media (max-width: 768px) {
  .cg-admin-invite-bar {
    padding: 12px 16px;
  }
  .cg-admin-invite-row {
    flex-direction: column;
    align-items: stretch;
  }
  .cg-admin-table-wrap {
    padding: 12px 16px;
  }
}

@media print {
  .cg-admin-panel,
  .cg-toast {
    display: none !important;
  }
}

/* ============================================================================
   SHARED MODAL FRAMEWORK
   Used by locations filters, column selector, and map-view filters.
   ============================================================================ */
.cg-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 10000;
  padding: 40px 20px;
  overflow-y: auto;
  animation: cgFadeIn 0.2s ease-out;
}

@keyframes cgFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.cg-modal-dialog {
  background: white;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 680px;
  animation: cgSlideIn 0.25s ease-out;
  margin: auto;
}

@keyframes cgSlideIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.cg-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 2px solid var(--cg-border);
  background: linear-gradient(135deg, #f8f9fa 0%, #eef1f5 100%);
  border-radius: 10px 10px 0 0;
}

.cg-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--cg-dark-blue);
}

.cg-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--cg-gray);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s;
  line-height: 1;
}

.cg-modal-close:hover {
  background: rgba(0,0,0,0.08);
  color: #333;
}

.cg-modal-body {
  padding: 20px 24px;
  max-height: calc(80vh - 140px);
  overflow-y: auto;
}

.cg-modal-body::-webkit-scrollbar { width: 8px; }
.cg-modal-body::-webkit-scrollbar-track { background: #f0f0f0; border-radius: 4px; }
.cg-modal-body::-webkit-scrollbar-thumb { background: #bbb; border-radius: 4px; }
.cg-modal-body::-webkit-scrollbar-thumb:hover { background: #888; }

.cg-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--cg-border);
  background: #fafafa;
  border-radius: 0 0 10px 10px;
}

.cg-modal-footer .btn { min-width: 110px; }

@media (max-width: 600px) {
  .cg-modal-overlay { padding: 20px 10px; }
  .cg-modal-dialog { max-width: 100%; }
  .cg-modal-header { padding: 14px 16px; }
  .cg-modal-header h3 { font-size: 16px; }
  .cg-modal-body { padding: 16px; max-height: calc(85vh - 130px); }
  .cg-modal-footer { padding: 12px 16px; }
}

/* ============================================================================
   COLLAPSIBLE SECTIONS (inside modals)
   ============================================================================ */
.cg-collapse {
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin-bottom: 10px;
}

.cg-collapse-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--cg-dark-blue) 0%, #234d8a 100%);
  color: white;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s;
}

.cg-collapse-header:hover {
  background: linear-gradient(135deg, #1e4a7a 0%, #2c5aa0 100%);
}

.cg-collapse-arrow {
  font-size: 11px;
  transition: transform 0.2s;
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}

.cg-collapse-arrow.open { transform: rotate(90deg); }

.cg-collapse-content {
  padding: 12px 16px;
  background: white;
}

.cg-subheading {
  font-size: 12px;
  font-weight: 700;
  color: var(--cg-blue);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 14px 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1px solid #e8e8e8;
}

.cg-collapse-content .cg-subheading:first-child { margin-top: 4px; }

/* ============================================================================
   FILTER FORM ELEMENTS
   ============================================================================ */
.cg-filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  min-height: 36px;
}

.cg-filter-row:last-child { margin-bottom: 4px; }

.cg-filter-label {
  flex: 0 0 140px;
  font-size: 13px;
  font-weight: 600;
  color: #444;
  text-align: right;
  padding-right: 4px;
}

.cg-filter-input {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cg-filter-input input[type="text"],
.cg-filter-input input[type="number"],
.cg-filter-input input[type="date"] {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--cg-border);
  border-radius: 4px;
  font-size: 13px;
  color: #333;
  background: white;
  transition: border-color 0.15s;
}

.cg-filter-input input:focus {
  outline: none;
  border-color: var(--cg-blue);
  box-shadow: 0 0 0 2px rgba(44, 90, 160, 0.12);
}

.cg-filter-input input[type="number"] { width: 70px; text-align: center; }

.cg-range-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cg-range-sep {
  font-size: 12px;
  color: var(--cg-gray);
  white-space: nowrap;
}

.cg-range-hint {
  font-size: 11px;
  color: #888;
  white-space: nowrap;
  font-style: italic;
}

.cg-date-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cg-date-group input[type="date"] { width: auto; min-width: 130px; }
.cg-date-group .cg-range-sep { flex-shrink: 0; }

.cg-grade-select {
  padding: 7px 10px;
  border: 1px solid var(--cg-border);
  border-radius: 4px;
  font-size: 13px;
  color: #333;
  background: white;
  cursor: pointer;
  min-width: 70px;
  transition: border-color 0.15s;
}

.cg-grade-select:focus {
  outline: none;
  border-color: var(--cg-blue);
  box-shadow: 0 0 0 2px rgba(44, 90, 160, 0.12);
}

@media (max-width: 600px) {
  .cg-filter-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .cg-filter-label { flex: none; text-align: left; padding-right: 0; }
  .cg-filter-input { width: 100%; }
}

/* ============================================================================
   MULTI-SELECT COMPONENT
   ============================================================================ */
.cg-ms {
  position: relative;
  flex: 1;
  max-width: 100%;
}

.cg-ms-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border: 1px solid var(--cg-border);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 13px;
  color: #333;
  min-height: 34px;
  transition: border-color 0.15s;
  user-select: none;
}

.cg-ms-trigger:hover { border-color: #999; }

.cg-ms-trigger.open {
  border-color: var(--cg-blue);
  box-shadow: 0 0 0 2px rgba(44, 90, 160, 0.12);
}

.cg-ms-display {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cg-ms-arrow {
  font-size: 10px;
  color: var(--cg-gray);
  margin-left: 6px;
  transition: transform 0.15s;
}

.cg-ms-trigger.open .cg-ms-arrow { transform: rotate(180deg); }

.cg-ms-dropdown {
  position: fixed;
  background: white;
  border: 1px solid var(--cg-blue);
  border-radius: 0 0 6px 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.15);
  z-index: 10001;
  max-height: 220px;
  display: flex;
  flex-direction: column;
}

.cg-ms-search {
  padding: 8px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

.cg-ms-search input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  outline: none;
}

.cg-ms-search input:focus { border-color: var(--cg-blue); }

.cg-ms-options {
  overflow-y: auto;
  padding: 4px 0;
  flex: 1;
}

.cg-ms-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
}

.cg-ms-option:hover { background: #f0f4fa; }

.cg-ms-option input[type="checkbox"] {
  accent-color: var(--cg-blue);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* ============================================================================
   ACTIVE FILTERS BAR & CHIPS
   ============================================================================ */
.cg-active-filters {
  background: white;
  border: 1px solid var(--cg-border);
  border-left: 4px solid var(--cg-blue);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.cg-active-filters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.cg-active-filters-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--cg-dark-blue);
}

.cg-active-filters-count {
  font-size: 12px;
  color: var(--cg-gray);
  font-weight: 400;
  margin-left: 6px;
}

.cg-clear-all-btn {
  background: none;
  border: none;
  color: var(--cg-red);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.15s;
}

.cg-clear-all-btn:hover { background: rgba(221, 69, 69, 0.08); }

.cg-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cg-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e8eef6;
  color: var(--cg-dark-blue);
  padding: 4px 8px 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.cg-chip-label { font-weight: 600; }

.cg-chip-remove {
  background: none;
  border: none;
  color: var(--cg-gray);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  border-radius: 50%;
  transition: all 0.15s;
}

.cg-chip-remove:hover {
  color: var(--cg-red);
  background: rgba(221, 69, 69, 0.1);
}
