/* ── Design System: OpenGHGRP Brand Colors ─────────────────────── */
/* To rebrand the entire app, only edit the color variables below.    */
/* All component styles reference these variables.                    */
:root {
  /* ── OpenGHGRP Brand Color Palette ───────────────────────────── */
  --deep-maroon:     #500000;  /* Primary branding, headers, buttons */
  --deep-maroon-dark: #3a0000; /* Darker shade for hover states */
  --deep-maroon-light: #f2e6e6; /* Light background tint */
  --deep-maroon-border: #d9b3b3; /* Border color */

  --navy:            #1F4E79;  /* Secondary branding, navigation, links */
  --navy-dark:       #1c4468;  /* Darker shade for hover states */
  --navy-light:      #e6eef4;  /* Light background tint */
  --navy-border:     #b3c9dc;  /* Border color */

  --sage-green:      #9BBF8A;  /* Supporting graphics and backgrounds */
  --sky-blue:        #74BCEB;  /* Charts, highlights, data visualization */
  --warm-gold:       #C69C2D;  /* Calls to action and emphasis */
  --terracotta:      #B5653C;  /* Data accents, alerts, key metrics */
  --terracotta-light: #f9ede7; /* Light background for alerts */

  --slate-gray:      #4E5D66;  /* Primary body text */
  --soft-ivory:      #F8F7F2;  /* Main page/document background */
  --white:           #FFFFFF;  /* Primary web background, cards */

  /* ── Semantic Color Aliases (For Easy Rebranding) ────────────── */
  /* When rebranding, update the primary/secondary colors above,    */
  /* then update these aliases to match your new brand colors.      */
  --primary:         var(--deep-maroon);
  --primary-hover:   var(--deep-maroon-dark);
  --primary-light:   var(--deep-maroon-light);

  --secondary:       var(--deep-maroon);
  --secondary-hover: var(--deep-maroon-dark);
  --secondary-light: var(--deep-maroon-light);

  --accent:          var(--warm-gold);
  --danger:          var(--terracotta);
  --danger-light:    var(--terracotta-light);

  /* ── UI Variables ────────────────────────────────────────────── */
  --text:            var(--slate-gray);
  --text-muted:      #6b7780;
  --border:          #d8dde6;
  --bg:              var(--white);
  --surface:         var(--white);
  --surface-alt:     #f1f2f4;  /* Light grey — wizard bar, SQL query box */
  --radius:          8px;
  --shadow-sm:       0 1px 4px rgba(0,0,0,.08);
  --shadow-md:       0 4px 16px rgba(0,0,0,.12);
  --transition:      0.2s ease;

  /* ── Typography ───────────────────────────────────────────────── */
  /* Primary: Avenir Next (Bold/SemiBold/Medium) for headings, nav, buttons. */
  /* Not a web font; falls back to Avenir, then the free Nunito Sans. */
  --font-heading:    "Avenir Next", "Avenir", "Nunito Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  /* Secondary: Source Sans Pro for body copy, reports, forms, tables. */
  --font-body:        "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* Monospace: Roboto Mono for data, technical values, and code. */
  --font-mono:        "Roboto Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ── Reset / Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

/* ── Site Header ───────────────────────────────────────────────── */
.site-header {
  background: var(--primary);
  padding: 20px 0;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 32px;
}

.site-title {
  font-family: var(--font-heading);
  font-size: 40px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -0.5px;
  margin: 0;
}

/* ── Main Layout ───────────────────────────────────────────────── */
.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 32px 64px;
}

/* ── Wizard Bar ────────────────────────────────────────────────── */
.wizard-bar {
  display: flex;
  align-items: center;
  gap: 32px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 32px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
}

.wizard-label {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: 0.3px;
}

.stepper {
  display: flex;
  align-items: center;
  flex: 1;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 100px;
}

.step-bubble {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.step-name {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  font-weight: 500;
  transition: color var(--transition);
  white-space: nowrap;
}

/* Active step */
.step.active .step-bubble {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
  box-shadow: 0 0 0 4px rgba(80,0,0,.15);
}

.step.active .step-name {
  color: var(--primary);
  font-weight: 700;
}

/* Completed step */
.step.completed {
  cursor: pointer;
}

.step.completed:hover .step-bubble {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.step.completed .step-bubble {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

.step.completed .step-name {
  color: var(--primary);
}

.step-connector {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin-bottom: 20px; /* aligns with center of circles */
  transition: background var(--transition);
}

.step-connector.done {
  background: var(--primary);
}

/* ── Step Sections ─────────────────────────────────────────────── */
.step-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 32px;
  box-shadow: var(--shadow-sm);
}

.step-section.hidden { display: none; }

/* ── Section Header ────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.section-titles h2 {
  font-family: var(--font-heading);
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.section-hint {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  margin-top: 4px;
  text-transform: uppercase;
}

/* ── Search Input ──────────────────────────────────────────────── */
.search-input {
  font-family: var(--font-body);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  width: 280px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  color: var(--text);
}

.search-input:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(80,0,0,.12);
}

/* ── Toolbar ───────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

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

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  font-family: var(--font-heading);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), opacity var(--transition),
              transform var(--transition);
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-primary:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
}

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

.btn-secondary:hover {
  background: var(--secondary-light);
  border-color: var(--secondary);
}

.btn-back {
  background: transparent;
  color: var(--secondary);
  border: 1px solid var(--border);
  padding: 9px 18px;
}

.btn-back:hover {
  background: var(--secondary-light);
  border-color: var(--secondary);
}

/* ── Card Grid ─────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

/* ── Subpart / Table Cards ─────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: box-shadow var(--transition), border-color var(--transition),
              transform var(--transition);
  user-select: none;
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
  transform: translateY(-2px);
}

.card-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 14px;
  color: var(--primary);
  margin-bottom: 8px;
  line-height: 1.4;
}

.card-desc {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Column Cards (toggleable) ─────────────────────────────────── */
.column-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.col-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: box-shadow var(--transition), border-color var(--transition),
              background var(--transition);
  user-select: none;
  position: relative;
}

.col-card:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }

.col-card.selected {
  border-color: var(--primary);
  border-left-width: 4px;
  background: var(--primary-light);
}

.col-card.selected .col-title { color: var(--primary-hover); }

.col-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.col-card.selected .col-check {
  background: var(--primary);
  border-color: var(--primary);
}

.col-check-icon {
  display: none;
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.col-card.selected .col-check-icon { display: block; }

.col-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
  margin-right: 28px;
  line-height: 1.4;
}

.col-name {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 6px;
}

.col-desc {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

.col-type-badge {
  font-family: var(--font-body);
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--secondary-light);
  color: var(--secondary);
  margin-bottom: 6px;
}

/* ── Step 3 : Year Panel ───────────────────────────────────────── */
.year-panel {
  background: var(--primary-light);
  border: 2px solid var(--deep-maroon-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
}

.year-panel-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.year-panel-title {
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.year-panel-hint {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-muted);
}

.year-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.year-chip {
  font-family: var(--font-body);
  padding: 6px 14px;
  border-radius: 16px;
  border: 2px solid var(--deep-maroon-border);
  background: var(--surface);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.year-chip:hover { background: var(--primary-light); border-color: var(--primary); }

.year-chip.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

/* ── Step 4 : Data View ────────────────────────────────────────── */

/* Stats bar */
.data-stats {
  font-family: var(--font-body);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.data-stats strong { color: var(--text); font-weight: 600; }
.stats-sep { color: var(--border); }

/* Applied filters notice */
.filter-notice {
  font-family: var(--font-body);
  background: var(--primary-light);
  border: 2px solid var(--deep-maroon-border);
  color: var(--primary);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 16px;
  font-weight: 600;
}

/* Error banner */
.error-banner {
  font-family: var(--font-body);
  background: var(--danger-light);
  border: 2px solid var(--danger);
  color: #8b2e0f;
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 14px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
}

.error-banner:focus {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}

.error-banner strong {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

.error-banner small {
  display: block;
  margin-top: 8px;
  opacity: 0.85;
  font-size: 13px;
  line-height: 1.4;
}

/* Loading spinner */
.data-loading {
  font-family: var(--font-body);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 0;
  font-size: 14px;
  color: var(--text-muted);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* Data table */
.table-wrap {
  overflow-x: auto;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.data-table {
  font-family: var(--font-body);
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  white-space: nowrap;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th {
  font-family: var(--font-heading);
  background: var(--primary);
  color: var(--white);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  border-right: 1px solid rgba(255,255,255,0.2);
  cursor: pointer;
  user-select: none;
  white-space: normal;
  min-width: 130px;
  max-width: 280px;
  line-height: 1.5;
}

.data-table th:last-child { border-right: none; }

.data-table th:hover { background: var(--primary-hover); }

/* ── Column aggregation row ────────────────────────────────────── */
.agg-row td.agg-cell {
  background: var(--primary-light);
  border-right: 1px solid var(--deep-maroon-border);
  border-bottom: 1px solid var(--deep-maroon-border);
  padding: 8px 10px;
  vertical-align: middle;
  min-width: 130px;
  max-width: 280px;
  cursor: default;
}

.agg-row td.agg-cell:last-child { border-right: none; }

.agg-op {
  font-family: var(--font-body);
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--deep-maroon-border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.agg-op:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(80,0,0,.15);
}

.data-table td.agg-value {
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
}

/* ── Column filter row ─────────────────────────────────────────── */
.filter-row td.filter-cell {
  background: var(--primary-light);
  border-right: 1px solid var(--deep-maroon-border);
  border-bottom: 2px solid var(--deep-maroon-border);
  padding: 8px 10px;
  vertical-align: top;
  min-width: 130px;
  max-width: 280px;
  cursor: default;
}

.filter-row td.filter-cell:last-child { border-right: none; }

.filter-mode {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 8px;
}

.filter-mode-chip {
  font-family: var(--font-body);
  padding: 3px 10px;
  border-radius: 12px;
  border: 1px solid var(--deep-maroon-border);
  background: var(--surface);
  color: var(--secondary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.filter-mode-chip.active {
  background: var(--secondary);
  color: var(--white);
  border-color: var(--secondary);
}

.filter-condition {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.filter-op {
  flex: 0 0 auto;
  max-width: 42%;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.filter-op:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 2px rgba(80,0,0,.15);
}

.filter-val {
  font-family: var(--font-body);
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.filter-val:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 2px rgba(80,0,0,.15);
}

.filter-remove {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.filter-remove:hover:not(:disabled) {
  background: #fdecec;
  color: #b02a2a;
  border-color: #f0b6b6;
}

.filter-remove:disabled { opacity: 0.35; cursor: not-allowed; }

.filter-add {
  font-family: var(--font-body);
  display: block;
  margin-top: 4px;
  padding: 3px 6px;
  border: none;
  background: none;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.filter-add:hover { text-decoration: underline; }

.sort-icon {
  margin-left: 6px;
  opacity: 0.8;
  font-style: normal;
}

.data-table td {
  font-family: var(--font-body);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table td:last-child { border-right: none; }

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:nth-child(even) { background: #fafbfc; }

.data-table tbody tr:hover { background: var(--primary-light); }

.td-null { color: var(--text-muted); font-style: italic; font-size: 13px; }

/* Pagination */
.pagination-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 0 8px;
  flex-wrap: wrap;
}

.page-btn {
  font-family: var(--font-body);
  min-width: 38px;
  height: 36px;
  padding: 0 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
}

.page-btn:hover:not(:disabled):not(.active) {
  background: var(--secondary-light);
  border-color: var(--secondary);
}

.page-btn.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
  cursor: default;
}

.page-btn:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.page-ellipsis {
  font-family: var(--font-body);
  padding: 0 6px;
  color: var(--text-muted);
  line-height: 36px;
  font-size: 14px;
}

/* ── Utility ───────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Loading / Empty States ────────────────────────────────────── */
.loading-msg, .empty-msg {
  font-family: var(--font-body);
  grid-column: 1 / -1;
  text-align: center;
  padding: 56px 32px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ── SQL query box ─────────────────────────────────────────────── */
.sql-box {
  margin-top: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  overflow: hidden;
}

.sql-box-summary {
  cursor: pointer;
  padding: 12px 16px;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border-bottom: 1px solid transparent;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sql-box-summary::-webkit-details-marker { display: none; }

.sql-box-summary::before {
  content: "▶";
  color: var(--text-muted);
  font-size: 10px;
  transition: transform var(--transition);
}

.sql-box[open] > .sql-box-summary::before { transform: rotate(90deg); }

.sql-box[open] > .sql-box-summary { border-bottom-color: var(--border); }

.sql-box-summary:hover { background: var(--primary-light); }

.sql-box-body {
  margin: 0;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .wizard-bar { flex-direction: column; align-items: flex-start; }
  .stepper { width: 100%; }
  .section-header { flex-direction: column; }
  .search-input { width: 100%; }
  .toolbar { flex-direction: column; align-items: flex-start; }
}
