:root {
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --border: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --surface-0: #f8fafc;
  --surface-1: #ffffff;
  --surface-2: #ffffff;
  --radius: 6px;
  --danger: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* Layout                                                              */
/* ------------------------------------------------------------------ */
.layout {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* Sidebar                                                             */
/* ------------------------------------------------------------------ */
.sidebar-wrapper {
  position: relative;
  display: flex;
  flex-shrink: 0;
  height: 100vh;
  z-index: 2;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: width 0.25s ease, opacity 0.2s ease;
}

.sidebar-inner {
  width: 300px;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.sidebar-wrapper.collapsed .sidebar {
  width: 0;
  opacity: 0;
  border-right: none;
}

.collapse-handle {
  position: absolute;
  top: 70px;
  right: -22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-1);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
}

.collapse-handle svg {
  width: 22px;
  height: 22px;
  stroke: var(--text-primary);
  stroke-width: 3;
  transition: transform 0.25s ease;
}

.sidebar-wrapper.collapsed .collapse-handle svg {
  transform: rotate(180deg);
  margin-right: -14px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.25rem 1.25rem 10px;
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header-text{
  width: 100%;
}

.sidebar-header-text h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  background-color: rgb(208, 222, 251);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  width: 100;
  padding: 4px 0 4px 10px;
}

.sidebar-header-text p {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 2px 0 0 0;
  padding-left: 10px;
}

.sidebar-content {
  padding: 1.25rem;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.filter-field {
  margin-bottom: 1.1rem;
}

.filter-field:last-child {
  margin-bottom: 0;
}

.filter-field label {
  display: block;
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.filter-field input[type="text"] {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text-primary);
}

.filter-field input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-field select,
.filter-field input[type="date"] {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

.filter-field select:focus,
.filter-field input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-field input[type="date"]:disabled {
  background: #f1f5f9;
  color: var(--text-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}

.filter-field-dates {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.date-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.date-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  min-width: 30px;
}

.sidebar-actions {
  display: flex;
  flex-direction: row;
  gap: 0.55rem;
  padding: 1rem 1.25rem;
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
  justify-content: end;
}

.sidebar-actions .btn {
  /* flex: 1; */
  justify-content: center;
}

/* ------------------------------------------------------------------ */
/* Page (main content)                                                 */
/* ------------------------------------------------------------------ */
.page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100vh;
  padding: 1.25rem 1.5rem;
  overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* Top Bar                                                             */
/* ------------------------------------------------------------------ */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.top-bar h1 {
  font-weight: bold;
  font-size: 26px;
  margin: 0;
  color: var(--text-primary);
  flex-shrink: 0;
}

.date-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.date-controls label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.date-controls select,
.date-controls input[type="date"] {
  padding: 0.35rem 0.5rem;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

.date-controls select:focus,
.date-controls input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.date-controls input[type="date"]:disabled {
  background: #f1f5f9;
  color: var(--text-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}

.date-controls span.sep {
  font-size: 13px;
  color: var(--text-secondary);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

/* ------------------------------------------------------------------ */
/* Stats grid                                                          */
/* ------------------------------------------------------------------ */
.stats-grid {
  display: flex;
  flex-wrap: nowrap;
  background: linear-gradient(135deg, #3b6fe0 0%, #2f5bd6 40%, #4a7ae8 70%, #2f5bd6 100%);
  border-radius: 16px;
  margin-bottom: 1rem;
  overflow: hidden;
  flex-shrink: 0;
}

.stat-card {
  flex: 1 1 0;
  min-width: 0;
  padding: 1rem 1.25rem;
  border-right: 2px solid rgba(255, 255, 255);
}

.stat-card:last-child {
  border-right: none;
}

.stat-card .label {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 0.5rem;
  text-align: center;
}

.stat-card .value {
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
  text-align: center;
}

/* ------------------------------------------------------------------ */
/* Results section                                                     */
/* ------------------------------------------------------------------ */
.results-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.hidden { display: none !important; }

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
  background-color: rgb(208, 222, 251);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

.results-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
  padding: 4px 0 4px 8px;
}

.results-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: end;
  margin-bottom: 0.5rem;
  padding-right: 12px;
}

.results-actions .btn {
  min-width: 140px;
  justify-content: center;
}

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */
.btn {
  padding: 5px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: none;
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
}

.btn-accent:hover { background: #1d4ed8; }
.btn-accent:disabled { background: #93c5fd; cursor: not-allowed; }

.btn-secondary {
  border: 0.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
}

.btn-secondary:hover { background: #f1f5f9; }

/* Aliases for legacy class names used in script.js */
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }

/* ------------------------------------------------------------------ */
/* Column picker dropdown                                              */
/* ------------------------------------------------------------------ */
.column-picker { position: relative; }

.column-picker-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  padding: 1rem;
  z-index: 30;
}

.column-picker-dropdown .cp-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.column-picker-dropdown label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.2rem 0;
}

.column-picker-dropdown input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* Data grid                                                           */
/* ------------------------------------------------------------------ */
.grid-wrapper {
  flex: 1;
  overflow: auto;
  border: 0.5px solid var(--border);
  /* border-radius: 12px; */
  background: var(--surface-2);
  min-height: 0;
}

table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.grid thead th {
  position: sticky;
  top: 0;
  background: var(--accent);
  padding: 0.215rem 1rem;
  text-align: center;
  color: var(--surface-1);
  font-weight: 600;
  border: 1px solid var(--accent);
  white-space: nowrap;
  border-color: rgb(252, 234, 222);
  border-style: solid;
  border-width: 1px;
}

table.grid tbody td {
  padding: 0.6rem 1rem;
  color: var(--text-primary);
  white-space: nowrap;
  border-color: rgb(252, 234, 222);
  border-style: solid;
  border-width: 1px;
}

table.grid tbody tr:nth-child(even) { background: #f9f9f9; }
table.grid tbody tr:hover { background: #f8fafc; }

/* ------------------------------------------------------------------ */
/* Multiselect component                                               */
/* ------------------------------------------------------------------ */
.multiselect {
  position: relative;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  min-height: 36px;
  width: 100%;
  padding: 0.25rem 0.4rem;
  cursor: text;
}

.multiselect:focus-within {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.multiselect .ms-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: flex-start;
  min-width: 0;
  width: 100%;
  max-height: 70px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.multiselect .ms-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 12px;
  max-width: 100%;
  min-width: 0;
}

.multiselect .ms-tag span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.multiselect .ms-tag button {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
}

.multiselect .ms-input {
  border: none;
  outline: none;
  flex: 1;
  min-width: 60px;
  font-size: 13px;
  padding: 0.15rem;
  background: transparent;
}

.ms-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: min(360px, 90vw);
  background: #fff;
  border: 0.5px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
}

.ms-option {
  padding: 0.4rem 0.75rem;
  font-size: 13px;
  cursor: pointer;
}

.ms-option:hover,
.ms-option.active { background: var(--accent-light); }

.ms-empty {
  padding: 0.4rem 0.75rem;
  font-size: 12px;
  color: var(--text-secondary);
}

.multiselect.loading { opacity: 0.6; }

/* ------------------------------------------------------------------ */
/* Info / error / banner boxes                                         */
/* ------------------------------------------------------------------ */
.info-box {
  background: #eff6ff;
  border: 0.5px solid var(--accent-light);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 13px;
}

.error-box {
  background: #fdf2f2;
  border: 0.5px solid #fca5a5;
  color: #7b1d1d;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 13px;
  margin-bottom: 0.5rem;
}

.filters-loading {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
}

.banner {
  background: #fffbeb;
  border: 0.5px solid #fcd34d;
  color: #78350f;
  border-radius: 6px;
  padding: 0.5rem 0.85rem;
  font-size: 13px;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.error-text {
  color: var(--danger);
  font-size: 12px;
}

/* ------------------------------------------------------------------ */
/* Loading spinner                                                     */
/* ------------------------------------------------------------------ */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin-right: 0.5rem;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ */
/* Lazy-loading sentinel row                                           */
/* ------------------------------------------------------------------ */
.lazy-sentinel-cell {
  text-align: center;
  padding: 0.65rem 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.lazy-sentinel-cell .spinner { margin-right: 0.4rem; }
