/* Web Fonts */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400;1,700&display=swap');

/* ========================================================================== */
/* Color System & Theme Tokens                                                */
/* ========================================================================== */
:root {
  --color-white: #ffffff;
  --color-bg-page: #f9fafb;
  --color-text-dark: #1f2937;
  --color-text-mid: #374151;
  --color-text-muted: #4b5563;
  --color-text-light: #6b7280;
  --color-border: #d1d5db;
  --color-border-light: #e5e7eb;
  --color-border-strong: #9ca3af;
  --color-card-bg: #f3f4f6;
  --color-primary: #2563eb;
  --color-primary-light: #3b82f6;
  --color-primary-dark: #1e3a8a;
  --color-accent: #f97316;
  --color-accent-dark: #ea580c;
  --color-success: #10b981;
  --color-success-dark: #059669;
  --color-danger: #b91c1c;
}

/* ========================================================================== */
/* Base & Typography                                                          */
/* ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Atkinson Hyperlegible', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--color-bg-page);
}

/* ========================================================================== */
/* Custom additions to Tailwind                                               */
/* ========================================================================== */


.p-2 {
  padding: 0.5rem;
}

.font-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}


/* ========================================================================== */
/* Authentication Views                                                       */
/* ========================================================================== */

.login-page {
  min-height: 100vh;
  background-image: linear-gradient(rgba(15, 23, 42, 0.65), rgba(15, 23, 42, 0.65)), url('assets/background.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  width: min(100%, 420px);
  background-color: rgba(255, 255, 255, 1);
  border-radius: 1.25rem;
  padding: 2.5rem;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(8px);
}

@media (max-width: 480px) {
  .login-page {
    padding: 1.5rem 1rem;
  }

  .login-card {
    padding: 2rem;
  }
}

/* ========================================================================== */
/* Navigation & Header                                                        */
/* ========================================================================== */
.nav-container {
  position: relative;
}

.nav-bar {
  min-height: 3.25rem;
}

.nav-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.nav-menu {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-links {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-mobile-overlay {
  display: none;
}

.nav-reload-btn {
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

@media (max-width: 767px) {
  .nav-container {
    border-bottom: none;
    height: 0;
    overflow: hidden;
  }

  .nav-container.nav-open {
    height: auto;
  }

  .nav-toggle-btn {
    display: inline-flex;
  }

  .nav-menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(80%, 14rem);
    max-width: 16rem;
    background-color: var(--color-white);
    flex-direction: column;
    align-items: stretch;
    gap: 1.5rem;
    padding: 4.5rem 1.5rem 2rem;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 60;
    box-shadow: 2px 0 16px rgba(15, 23, 42, 0.18);
    overflow-y: auto;
    pointer-events: none;
    will-change: transform;
  }

  .nav-container.nav-open .nav-menu {
    transform: translateX(0);
    pointer-events: auto;
  }

  .nav-links {
    flex-direction: column;
    gap: 0.75rem;
  }

  .nav-links button {
    width: 100%;
    justify-content: flex-start;
  }

  .nav-mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 50;
  }

  .nav-container.nav-open .nav-mobile-overlay {
    display: block;
  }

  .nav-bar {
    min-height: 0;
  }

  .nav-menu {
    display: flex;
  }

  .header-bar {
    gap: 0.5rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .header-left,
  .header-user-menu {
    flex: 0 0 auto;
  }

  .header-center {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
  }

  .header-left .nav-toggle-btn {
    padding: 0.35rem;
    width: 2.5rem;
    height: 2.5rem;
  }

  .header-user-menu button {
    padding: 0.35rem 0.6rem;
  }

  .header-user-menu .user-button-label {
    display: none;
  }
}

/* ========================================================================== */
/* App Shell & Header                                                         */
/* ========================================================================== */

body.nav-mobile-open {
  overflow: hidden;
}

body.nav-mobile-open .page-content-wrapper {
  overflow: hidden;
}

.header-bar {
  position: relative;
  z-index: 1;
  min-height: 3.25rem;
}

.header-left,
.header-user-menu {
  flex: 1 1 0;
}

.header-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.header-center {
  flex: 0 0 auto;
  text-align: center;
  display: flex;
  justify-content: center;
}

.header-title {
  margin: 0;
  color: #1f2328;
  font-size: 1.6rem;
}

.header-user-menu {
  display: flex;
  justify-content: flex-end;
  position: relative;
}

.header-user-menu .user-menu-button {
  background-color: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(15, 23, 42, 0.12);
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.04);
  --backdrop-filter: blur(4px);
}

.header-user-menu .user-menu-button:hover,
.header-user-menu .user-menu-button:focus-visible {
  background-color: #fff;
  border-color: rgba(15, 23, 42, 0.2);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
}

.header-hero {
  position: relative;
  background-image: url('assets/header.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  overflow: visible;
}

.header-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.35));
  z-index: 0;
}

.header-user-menu .dropdown-panel {
  background-color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(15, 23, 42, 0.15);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18), 0 4px 8px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(6px);
}

/* ========================================================================== */
/* Map & Visualization Components                                              */
/* ========================================================================== */

/* Leaflet Map Container */
.map-container {
  width: 100%;
  height: 400px;
  border-radius: 0.5rem;
  overflow: hidden;
}

.map-pin {
  width: 56px;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-pin-svg {
  width: 100%;
  height: 100%;
}

.light-gray {
  color: var(--color-border-strong);
}

/* Loading Spinner */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* ========================================================================== */
/* Data Grid & Card Layout                                                     */
/* ========================================================================== */

/* Grid Scrolling with Sticky Header */
.grid-wrapper {
  overflow: hidden;
  max-height: calc(100vh - 220px);
  position: relative;
  border: 1px solid var(--color-border-light);
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
}

.page-content-wrapper {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}



/* ========================================================================== */
/* Status, Category & Permission Chips                                        */
/* ========================================================================== */
.data-grid {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  border-radius: 0.5rem;
  overflow: hidden;
  background: white;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.data-grid thead {
  flex-shrink: 0;
  background-color: var(--color-card-bg);
  display: block;
  width: 100%;
  /* Reserve space for scrollbar (sucks, kludge, different for every browser) */
  padding-right: 10px;
}

.data-grid thead tr {
  display: flex;
  width: 100%;
}

.data-grid thead th {
  background-color: var(--color-card-bg);
  padding: 0.75rem;
  text-align: left;
  font-size: 0.875rem;
  font-weight: 600;
  border-bottom: 1px solid var(--color-border-light);
  border-right: 1px solid var(--color-border-light);
  vertical-align: top;
  flex: 1;
  min-width: 50px;
}

.data-grid tbody {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  display: block;
  width: 100%;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  height: 100%;
}

.data-grid tbody tr {
  display: flex;
  width: 100%;
}

.data-grid tbody td {
  flex: 1;
  min-width: 50px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.data-grid tbody td:hover{
    overflow: visible; 
    white-space: normal;
    height:auto;
}

/* Allow wrapping when virtualization is disabled */
.grid-wrapper.grid-nonvirtual .data-grid tbody td {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

@media (min-width: 768px) {
  .data-grid thead th[data-column-min] {
    min-width: var(--grid-column-min, 50px);
  }

  .data-grid tbody td[data-column-min] {
    min-width: var(--grid-column-min, 50px);
  }
}

.data-grid th.sortable {
  cursor: pointer;
  user-select: none;
}

.data-grid th.sortable:hover {
  background-color: var(--color-border-light);
}

.grid-header-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.grid-sort-icon {
  color: var(--color-border-strong);
  transition: color 0.2s ease;
}

.grid-sort-icon-active {
  color: var(--color-text-dark);
}

.data-grid th.sortable:hover .grid-sort-icon {
  color: var(--color-text-dark);
}

.data-grid td {
  padding: 0.75rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
  overflow-wrap: break-word;
}

.data-grid tbody tr:hover {
  background-color: var(--color-bg-page);
}

.data-grid th.column-select,
.data-grid td.column-select {
  flex: 0 0 80px;
  min-width: 80px;
  max-width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 0.25rem;
}

.data-grid tbody tr.selected-row {
  background-color: #eff6ff;
}

.data-grid tbody tr.selected-row:hover {
  background-color: #dbeafe;
}

.data-grid tbody tr.retired-row {
  --background-color: var(--color-card-bg);
  background: repeating-linear-gradient(45deg, #fff, #fff 10px, #ffe7e7 10px, #ffe7e7 12px);
}

.data-grid tbody tr.retired-row:hover {
  background-color: var(--color-border-light);
}

.grid-card {
  background-color: var(--color-white);
  border: 1px solid var(--color-border-light);
  border-radius: 0.75rem;
  padding: 1rem 1.125rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.grid-card.section-card-retired {
  --background-color: #f8fafc;
  background: repeating-linear-gradient(45deg, #fff, #fff 10px, #ffe7e7 10px, #ffe7e7 12px);
  border-color: var(--color-border);
}

.data-grid td.grid-card-cell {
  padding: 0 0 1rem 0;
  border: none;
}

.data-grid tbody tr:last-of-type td.grid-card-cell {
  padding-bottom: 0;
}

.grid-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.grid-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-dark);
}

.grid-card-status {
  flex-shrink: 0;
}

.grid-card-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--color-text-mid);
}

.grid-card-line-uuid {
  font-size: 0.8rem;
  font-family: monospace;
  font-weight: 600;
  color: var(--color-text-dark);
  user-select: all;
}

.grid-card-line .grid-card-label {
  font-weight: 600;
  color: var(--color-text-muted);
}

.grid-card-line .grid-card-value {
  flex: 1;
  text-overflow: ellipsis;
  overflow-x: hidden;  
}

.section-name-value {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.section-name-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.retired-label {
  color: var(--color-danger);
  font-weight: 600;
  white-space: nowrap;
}

.grid-card-row-split {
  display: flex;
  --flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.grid-card-row-split > .grid-card-line {
  flex: 1 1 220px;
  justify-content: space-between;
}

.grid-card-align-end {
  justify-content: flex-end;
  text-align: right;
}

.grid-card-align-end .grid-card-label {
  margin-right: 0.25rem;
}

.grid-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  width: 100%;
}

.card-action-btn {
  display: inline-flex;
  background: #fff !important;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 600;
  min-width: 0;
  outline: 1px solid lightgray;
}

.action-btn-label {
  display: none;
}

.grid-card-empty {
  padding: 1.25rem;
  border: 1px dashed var(--color-border);
  border-radius: 0.75rem;
  background-color: var(--color-bg-page);
}

.grid-card-interactive {
  cursor: pointer;
}

.grid-card-interactive:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.retired-publish-checkbox {
  cursor: not-allowed;
}

.retired-publish-checkbox input {
  cursor: not-allowed;
}

.grid-card.selected-card {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  --background-color: #eff6ff;
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary) 1.5%, #eff6ff 1%);
}

@media (max-width: 767px) {
  .grid-wrapper {
    border: none;
    padding: 0;
    border-radius: 0;
  }

  .grid-wrapper .data-grid {
    display: block;
    border: none;
  }

  .grid-wrapper .data-grid thead {
    display: none;
  }

  .grid-wrapper .data-grid tbody {
    display: block;
    --padding: 0 0.5rem 1rem;
  }

  .grid-wrapper .data-grid tbody tr {
    display: block;
    background: transparent;
  }

  .grid-wrapper .data-grid tbody tr:hover {
    background: transparent;
  }

  .grid-wrapper .data-grid tbody td.grid-card-cell {
    padding: 0;
    border: none;
  }

  .grid-wrapper .data-grid tbody td {
    display: block;
    padding: 0;
    border: none;
  }

  .grid-card-actions {
    flex-wrap: nowrap;
  }

  .grid-card-actions .card-action-btn {
    flex: 1 1 0;
  }

  .grid-card-actions .action-btn-label {
    display: inline;
  }
}

/* Status Chips */
.status-chip {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-chip.new {
  background-color: #d1fae5;
  color: #065f46;
}

.status-chip.changed {
  background-color: #fef3c7;
  color: #92400e;
}

.status-chip.same {
  background-color: var(--color-card-bg);
  color: var(--color-text-mid);
}

.status-chip.active {
  background-color: #d1fae5;
  color: #065f46;
}

.status-chip.inactive {
  background-color: #db2e2e;
  color: var(--color-white);
}

.station-type-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.3rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  background-color: var(--color-border-light);
  color: var(--color-text-mid);
}

.station-type-chip svg {
  width: 0.9rem;
  height: 0.9rem;
  stroke: currentColor;
  stroke-width: 1.75;
}

.station-type-chip.station-type-online {
  background-color: #dbeafe;
  color: var(--color-primary-dark);
}

.station-type-chip.station-type-synthetic {
  background-color: #ede9fe;
  color: #5b21b6;
}

.station-type-chip.station-type-manual {
  background-color: #fef3c7;
  color: #92400e;
}

.station-type-chip.station-type-unknown {
  background-color: var(--color-border-light);
  color: var(--color-text-muted);
}

.station-type-cell {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.station-type-cell .station-type-chip {
  margin-left: 0;
}

.station-type-value {
  display: flex;
  align-items: center;
}

.section-category-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.3rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  background-color: var(--color-border-light);
  color: var(--color-text-mid);
}

.section-category-chip svg {
  width: 0.9rem;
  height: 0.9rem;
  stroke: currentColor;
  stroke-width: 1.75;
}

.section-category-chip.section-category-whitewater {
  background-color: #e0f2fe;
  color: #075985;
}

.section-category-chip.section-category-flatwater {
  background-color: var(--color-border-light);
  color: var(--color-text-muted);
}

.section-category-chip.section-category-freestyle {
  background-color: #ede9fe;
  color: #5b21b6;
}

.section-category-chip.section-category-drop {
  background-color: #f9e0d1;
  color: #b9571c;
}

.section-category-chip.section-category-slalom {
  background-color: #f3f1b4;
  color: #4f4d0d;
}

.section-category-chip.section-category-unknown {
  background-color: var(--color-border-light);
  color: var(--color-text-muted);
}

.section-category-chip.section-category-generic {
  background-color: var(--color-card-bg);
  color: var(--color-text-mid);
}

.section-category-cell {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.section-category-cell .section-category-chip {
  margin-left: 0;
}

.grid-card-value .section-category-chip {
  margin-left: 0;
}

.permission-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
}

.permission-chip svg {
  width: 0.8rem;
  height: 0.8rem;
  stroke: currentColor;
  stroke-width: 1.75;
}

.permission-chip.permission-admin {
  background-color: #fee2e2;
  color: #991b1b;
}

.permission-chip.permission-publish {
  background-color: #dbeafe;
  color: #1d4ed8;
}

.permission-chip.permission-add {
  background-color: #ede9fe;
  color: #5b21b6;
}

.permission-chip.permission-edit,
.permission-chip.permission-edit-section,
.permission-chip.permission-edit-station {
  background-color: #fef3c7;
  color: #92400e;
}

.permission-chip.permission-generic {
  background-color: var(--color-border-light);
  color: var(--color-text-mid);
}

.user-active-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.user-active-chip.user-active {
  background-color: #d1fae5;
  color: #065f46;
}

.user-active-chip.user-inactive {
  background-color: #fee2e2;
  color: #991b1b;
}

.user-permissions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.user-card-permissions .grid-card-value {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.user-card-notes {
  flex-direction: column;
  align-items: flex-start;
}

.user-card-notes .grid-card-label {
  margin-bottom: 0.15rem;
}

.link-like {
  color: var(--color-primary);
  text-decoration: underline;
}

.link-like:hover,
.link-like:focus-visible {
  color: var(--color-primary-dark);
}

/* ========================================================================== */
/* Field State Indicators & Validation                                         */
/* ========================================================================== */

/* Changed Field Highlighting */
.field-changed {
  border-color: #fb923c !important;
  background-color: #ffedd5 !important;
}

.field-invalid {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 2px rgb(255 0 0 / 48%);
}

.toggle-changed {
  outline: 2px solid #fb923c;
  outline-offset: 0;
  border-radius: 9999px;
}

.field-previous-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background-color: var(--color-card-bg);
  border: 1px solid var(--color-border-light);
  border-radius: 9999px;
  padding: 0.15rem 0.6rem;
  margin-top: 0.35rem;
  line-height: 1.2;
}

.field-previous-pill-label {
  font-weight: 600;
  color: var(--color-text-dark);
}

.field-previous-pill.hidden {
  display: none;
}

/* Filter Input Active */
.filter-active {
  border-color: #fb923c !important;
  background-color: #ffedd5 !important;
}

.calibration-last-reviewed-value {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  background-color: #fff;
}

.calibration-last-reviewed-editable {
  cursor: pointer;
}

.calibration-last-reviewed-editable:focus-visible {
  outline: 2px solid var(--color-primary-light);
  outline-offset: 2px;
}

.calibration-last-reviewed-value.calibration-last-reviewed-changed {
  color: #000;
  border-color: #fb923c;
  background-color: #ffedd5;
}

/* ========================================================================== */
/* Toggles, Calibration Rows & Helpers                                        */
/* ========================================================================== */

/* Binary Toggle */
.binary-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border-strong);
  border-radius: 0.3rem;
  overflow: hidden;
}

.binary-toggle.toggle-disabled {
  opacity: 0.5;
  pointer-events: none;
}

.binary-toggle .toggle-segment {
  border: none;
  background: var(--color-bg-page);
  color: var(--color-bg-page);
  padding: 0.4rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 0;
  transition: background-color 0.2s, color 0.2s;
}

.binary-toggle .toggle-segment:first-child {
  border-right: 1px solid var(--color-border-strong);
}

.binary-toggle .toggle-segment:focus-visible {
  outline: 2px solid var(--color-primary-light);
  outline-offset: -4px;
}

.binary-toggle .toggle-segment.toggle-yes.active {
  background-color: var(--color-primary-light);
  color: var(--color-white);
}

.binary-toggle .toggle-segment.toggle-no.active {
  background-color: var(--color-border);
  color: var(--color-text-mid);
}

.binary-toggle.binary-toggle-danger .toggle-segment.toggle-no.active {
  background-color: #dc2626;
  color: var(--color-white);
}

.calibration-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.calibration-row-primary {
  display: grid;
  grid-template-columns: minmax(260px, 1fr);
  gap: 1rem;
  align-items: flex-start;
}

.calibration-row-secondary {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.75rem;
  align-items: flex-start;
}

.calibration-row-secondary .calibration-toggle,
.calibration-row-secondary .calibration-unit,
.calibration-row-secondary .calibration-last-reviewed-field {
  flex: 1 1 0;
  min-width: 0;
}

.calibration-unit-select {
  width: auto;
  min-width: 110px;
  display: inline-block;
}

@media (max-width: 767px) {
  .calibration-row-primary {
    grid-template-columns: 1fr;
  }
}

.calibration-last-reviewed-value {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.calibration-last-reviewed-date {
  font-weight: 500;
  line-height: 1.1;
}

.calibration-last-reviewed-relative {
  font-size: 0.75rem;
  line-height: 0.8;
  color: inherit;
}

.selectable-text {
  user-select: all;
  -webkit-user-select: all;
  -moz-user-select: all;
}

.status-chip-link {
  text-decoration: none;
  display: inline-flex;
}

/* ========================================================================== */
/* Dialogs, Overlays & Notifications                                          */
/* ========================================================================== */

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  overflow-y: auto;
  padding: 2rem 0;
}

.modal-content {
  background: white;
  border-radius: 0.5rem;
  padding: 1.5rem;
  max-width: 64rem;
  width: 100%;
  margin: 0 1rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content.dialog-with-scroll {
  display: flex;
  flex-direction: column;
  max-height: min(94vh, 62rem);
  overflow: hidden;
}

.modal-content.dialog-with-scroll > h2 {
  position: sticky;
  top: 0;
  background: var(--color-white);
  z-index: 2;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border-light);
}

.dialog-scroll-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.5rem;
  padding-right: 0.25rem;
  padding-bottom: 1rem;
}

.dialog-footer {
  position: sticky;
  bottom: 0;
  background: var(--color-white);
  padding-top: 1rem;
  border-top: 1px solid var(--color-border-light);
  margin-top: 0.5rem;
  z-index: 2;
}

.modal-content[data-width="sm"] {
  max-width: 24rem;
}

.modal-content[data-width="md"] {
  max-width: 32rem;
}

.modal-content[data-width="lg"] {
  max-width: 48rem;
}

.modal-content[data-width="xl"] {
  max-width: 64rem;
}

.modal-card {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.modal-card-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background-color: var(--color-primary);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 50;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Responsive Design */
@media (max-width: 767px) {
  .modal-overlay {
    padding: 0;
    align-items: stretch;
    justify-content: flex-start;
  }

  .modal-overlay.modal-overlay-compact,
  .modal-overlay.alert-overlay {
    padding: 2rem 0;
    align-items: center;
    justify-content: center;
  }

  .modal-overlay:not(.modal-overlay-compact):not(.alert-overlay) .modal-content {
    max-width: 100%;
    width: 100%;
    margin: 0;
    border-radius: 0;
    padding: 1rem;
    min-height: 100vh;
    max-height: none;
  }

  .modal-overlay:not(.modal-overlay-compact):not(.alert-overlay) .modal-content.dialog-with-scroll {
    min-height: 100vh;
  }

  .modal-overlay.modal-overlay-compact .modal-content,
  .modal-overlay.alert-overlay .modal-content {
    --width: auto;
    margin: 0 1.5rem;
    border-radius: 0.5rem;
    max-height: 90vh;
    padding: 1.25rem;
  }

  .data-grid {
    font-size: 0.75rem;
  }

  .data-grid th,
  .data-grid td {
    padding: 0.5rem;
  }

}

/* ========================================================================== */
/* Form Controls & Ownership Picker                                           */
/* ========================================================================== */

/* Form Elements */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
}

.owner-picker {
  position: relative;
}

.owner-picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  text-align: left;
  color: #111827;
  min-height: 2.5rem;
}

.owner-picker-trigger:hover,
.owner-picker-trigger:focus-visible {
  border-color: var(--color-primary-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  outline: none;
}

.owner-chip-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex: 1 1 auto;
  min-width: 0;
}

.owner-placeholder {
  flex: 1 1 auto;
  color: var(--color-text-light);
}

.owner-caret {
  margin-left: auto;
  flex: 0 0 auto;
  color: var(--color-text-light);
}

.owner-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  background-color: #eff6ff;
  color: #1d4ed8;
  max-width: 100%;
}

.owner-dropdown {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  background-color: var(--color-white);
  border: 1px solid var(--color-border-light);
  border-radius: 0.5rem;
  box-shadow: 0 10px 25px -12px rgba(15, 23, 42, 0.45);
  max-height: 240px;
  overflow-y: auto;
  padding: 0.25rem 0;
  z-index: 30;
}

.owner-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

.owner-option:hover {
  background-color: var(--color-card-bg);
}

.owner-option + .owner-option {
  border-top: 1px solid var(--color-card-bg);
}

.owner-option-checkbox {
  margin-top: 0.15rem;
  flex: 0 0 auto;
}

.owner-option-text {
  flex: 1 1 auto;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-dark);
}

.owner-option-email {
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: var(--color-text-light);
}

.owner-clear-btn {
  background: none;
  border: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.owner-clear-btn:hover {
  text-decoration: underline;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input:disabled,
select:disabled,
textarea:disabled {
  background-color: var(--color-card-bg);
  cursor: not-allowed;
}

/* ========================================================================== */
/* Button System                                                              */
/* ========================================================================== */

/* Button Styles */
button {
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--color-primary-light);
  color: white;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary);
}

.btn-secondary {
  background-color: white;
  color: var(--color-text-mid);
  border: 1px solid var(--color-border);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--color-card-bg);
}

.btn-warning {
  background-color: var(--color-accent);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-accent-dark);
}

.btn-warning:hover:not(:disabled) {
  background-color: var(--color-accent-dark);
}

.btn-danger {
  background-color: var(--color-primary);
  color: white;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
}

.btn-danger:hover:not(:disabled) {
  background-color: var(--color-danger);
}

.btn-success {
  background-color: var(--color-success);
  color: white;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
}

.btn-success:hover:not(:disabled):not(.btn-disabled) {
  background-color: var(--color-success-dark);
}

.btn-success.btn-disabled {
  background-color: var(--color-success);
}

/* ========================================================================== */
/* Card Layouts & Supporting Tokens                                           */
/* ========================================================================== */

/* Card Styles */
.card {
  --border: 1px solid var(--color-border-light);
  --border-radius: 0.5rem;
  --padding: 1rem;
  margin-bottom: 1rem;
}

.card-title {
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.section-grade-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  align-items: flex-start;
}

.dialog-field-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.section-coord-grid,
.section-notes-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.section-notes-grid {
  margin-bottom: 1rem;
}

@media (max-width: 767px) {
  .section-coord-grid,
  .section-notes-grid {
    grid-template-columns: 1fr;
  }
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  background-color: var(--color-primary-light);
  color: white;
}

/* Icon Button */
.icon-btn {
  padding: 0.25rem;
  background: transparent;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.icon-btn.icon-btn-disabled {
  --opacity: 0.4;
  color: #bbb;
  cursor: not-allowed;
  background: #fff !important;
}

.icon-btn:hover {
  background-color: var(--color-card-bg);
}

/* ========================================================================== */
/* Action Menus & Overlays                                                    */
/* ========================================================================== */

/* Overflow Action Menu */
.action-overflow-menu {
  position: absolute;
  min-width: 12rem;
  padding: 0.25rem;
  background-color: var(--color-white);
  border: 1px solid var(--color-border-light);
  border-radius: 0.5rem;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.18);
  z-index: 70;
}

.action-overflow-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  color: #111827;
  font-size: 0.9rem;
  text-align: left;
  transition: background-color 0.15s ease;
}

.action-overflow-item:hover {
  background-color: var(--color-card-bg);
}

.action-overflow-item-danger {
  color: var(--color-danger);
}

.action-overflow-item-primary {
  color: #1d4ed8;
}

.action-overflow-item-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.action-overflow-label {
  flex: 1;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.loading-spinner {
  background: white;
  padding: 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ========================================================================== */
/* Page Filters, Counters & Search                                            */
/* ========================================================================== */

/* Page Filters */
.filters-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: auto;
}

.filters-toggle-btn.filters-toggle-btn-active {
  background-color: #ffedd5;
  border-color: #fb923c;
  color: #000;
}

.filters-toggle-btn.filters-toggle-btn-active:hover {
  background-color: #c2410c;
  color: #000;
}

.page-controls-leading {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: stretch;
  flex: 1 1;
  min-width: 0;
}

.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.page-title-row .page-mobile-title {
  margin: 0;
}

.page-row-count {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.page-row-count-mobile {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.page-row-count-desktop {
  display: none;
  align-items: center;
  gap: 0.25rem;
}

.page-search-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
}

.ownership-dialog-content {
  width: min(90vw, 30rem);
  max-width: 32rem;
  min-height: 380px;
  max-height: 90vh;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ownership-dialog-content .owner-picker-trigger {
  min-height: 2.75rem;
}

.ownership-dialog-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ownership-picker-container {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ownership-dialog-footer {
  flex: 0 0 auto;
  margin-top: auto;
}

@media (max-width: 767px) {
  .ownership-dialog-content {
    width: calc(100vw - 1.5rem);
    min-height: 420px;
  }
}

.ownership-editable {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.ownership-editable:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
  border-radius: 0.25rem;
}

.ownership-editable:hover {
  color: #1d4ed8;
}

.page-search-container {
  flex: 1 1 240px;
  min-width: 0;
}

.page-controls-leading .filters-toggle-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.page-filters {
  width: 100%;
}

.page-mobile-title {
  display: none;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  color: var(--color-text-dark);
}

.page-filters-backdrop {
  display: none;
}

.page-filters-panel {
  background-color: var(--color-white);
  border: 1px solid var(--color-border-light);
  border-radius: 0.75rem;
  padding: 1.25rem;
  box-shadow: 0 10px 15px -12px rgba(15, 23, 42, 0.4);
}

.page-filters-header {
  margin-bottom: 1rem;
}

.filters-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 9999px;
  background: transparent;
  border: none;
  color: var(--color-text-dark);
  cursor: pointer;
}

.page-filters-content {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.grid-filter-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.grid-filter-input-row .grid-filter-input {
  flex: 1 1 auto;
  min-width: 0;
}

.grid-filter-sort-buttons {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 0.15rem;
  padding: 0.15rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background-color: var(--color-bg-page);
}

.grid-filter-sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.grid-filter-sort-button .icon {
  width: 14px;
  height: 14px;
}

.grid-filter-sort-button:is(:hover, :focus-visible) {
  background-color: #e0e7ff;
  color: #1d4ed8;
}

.grid-filter-sort-button.is-active {
  background-color: var(--color-primary);
  color: var(--color-white);
}

.page-filter-fields {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}

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

.grid-filter-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-mid);
}

.grid-filter-input {
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  background-color: var(--color-white);
}

.grid-filter-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.grid-filter-placeholder {
  height: 32px;
  margin-top: 0.25rem;
}

body.filters-panel-open {
  overflow: hidden;
}

body.filters-panel-open .page-content-wrapper {
  overflow: hidden;
}

@media (min-width: 640px) {
  .page-row-count-desktop {
    display: inline-flex;
  }

  .page-row-count-mobile {
    display: none !important;
  }

  .page-search-row {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
  }

  .page-search-row .search-field {
    flex: 1 1 auto;
  }
}

@media (max-width: 767px) {
  .page-mobile-title {
    display: block;
    margin-bottom: 0.25rem;
  }

  .page-controls-leading {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
  }

  .page-search-container {
    flex: 1 1 auto;
    min-width: 0;
  }

  .page-controls-leading .filters-toggle-btn {
    width: auto;
    margin-left: auto;
    flex-shrink: 0;
  }

  .page-search-container .search-field {
    max-width: none;
    width: 100%;
  }

  .page-filter-fields {
    grid-template-columns: 1fr;
  }

  .page-filters {
    position: fixed;
    inset: 0;
    display: none;
    align-items: flex-start;
    justify-content: center;
    z-index: 60;
  }

  .page-filters-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
  }

  .page-filters-panel {
    position: relative;
    width: min(100%, 24rem);
    max-height: calc(100% - 2rem);
    margin: 1rem auto;
    transform: translateY(10%);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
    overflow-y: auto;
  }

  .page-filters.is-open {
    display: flex;
  }

  .page-filters.is-open .page-filters-panel {
    transform: translateY(0);
    opacity: 1;
  }

  .filters-close-btn {
    border: none;
    background: var(--color-card-bg);
  }
}

@media (min-width: 768px) {
  .filters-toggle-btn {
    display: none;
  }

  .page-filters-panel {
    box-shadow: none;
  }
}

/* Search Control */
.search-field {
  position: relative;
  max-width: 24rem;
}

.search-input {
  padding: 0.5rem 2.25rem 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  background-color: var(--color-white);
}

.search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.1);
}

.search-input-icon {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  pointer-events: none;
}

.search-input-icon.has-value {
  pointer-events: auto;
  cursor: pointer;
}

.search-input-icon:disabled {
  cursor: default;
}

.search-input-icon svg {
  width: 1rem;
  height: 1rem;
}

.page-filters-panel .search-field {
  max-width: none;
  width: 100%;
}

/* ========================================================================== */
/* Guidelines Page Controls                                                   */
/* ========================================================================== */

/* Guidelines language dropdown */
.lang-dropdown-toggle {
  min-width: 4rem;
}

.lang-dropdown-toggle .fi {
  flex-shrink: 0;
}

.lang-dropdown-toggle .lang-dropdown-caret {
  margin-left: auto;
  transition: transform 0.2s ease;
}

.lang-dropdown-toggle.open .lang-dropdown-caret {
  transform: rotate(180deg);
}

.lang-dropdown-menu {
  min-width: 6rem;
}

.lang-dropdown-item {
  background: transparent;
  border: none;
}

.lang-dropdown-item.is-active {
  background-color: var(--color-card-bg);
  font-weight: 600;
}

.lang-dropdown-item:focus {
  outline: none;
  background-color: var(--color-border-light);
}

.lang-dropdown-item .fi {
  flex-shrink: 0;
}



