/* styles.css */
/* ================== Reset & Base ================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: sans-serif;
  background-color: #f4f4f4;
  padding: 2rem;
  color: #222;
}

/* ================== Nav ================== */
nav {
  background-color: #334D74;
  padding: .25rem;
}

nav a {
  color: #EFEFEF;
  margin-right: 1rem;
  text-decoration: none;
  font-weight: bold;
}

nav a:hover {
  color: #C12F2F;
}

nav a.active {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ================== Dashboard Grid ================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 2rem;
}

/* ================== Cards ================== */
/* Legacy .card (kept) */
.card {
  background-color: #ffffff;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card h3 {
  margin-bottom: 1rem;
  color: #334D74;
}

/* Header band look */
.card h3 {
  background-color: #334D74;
  color: white;
  padding: 0.5rem 1rem;
  margin: -1.5rem -1.5rem 1rem -1.5rem;
  border-bottom: 1px solid #ccc;
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;
}

/* NLA variant */
.card.card-nla h3 {
  background-color: #C12F2F;
  color: #fff;
}

.card.card-nla {
  border-color: #C12F2F;
}

/* New .dash-card styles (same visual as .card) */
.dash-card {
  background-color: #ffffff;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.dash-card-title {
  background-color: #334D74;
  color: white;
  padding: 0.5rem 1rem;
  margin: -1.5rem -1.5rem 1rem -1.5rem;
  border-bottom: 1px solid #ccc;
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;
  font-size: 1.15rem;
}

/* ================== Tables / Load List ================== */

/* wrapper in template */
.table-sticky {
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  /* <- prevent sideways scroll */
}

/* base table */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  table-layout: auto;
}

.table th,
.table td {
  padding: 0.75rem;
  border: 1px solid #ddd;
  text-align: left;
  vertical-align: middle;
  /* let long text wrap instead of forcing the table wider */
  white-space: normal;
  word-break: break-word;
  font-size: 0.9rem;
  line-height: 1.3;
}

.table tr:hover {
  background-color: #f8f9fa;
}

/* sticky header row (works inside .table-sticky scroll container) */
.table-sticky thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8f9fa;
}

/* sortable headers */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  /* headers stay tidy */
  background-color: #f8f9fa;
}

th.sortable .arrow {
  margin-left: .25rem;
  opacity: .6;
  font-size: .8em;
}

th.sortable.active {
  font-weight: 600;
}

/* expanded-row styling for detail rows */
tr.expand-row>td {
  background: #f7fbff;
  border-top: 0;
}

/* mini-map container in expansion */
.mini-map {
  width: 360px;
  height: 360px;
  border-radius: 8px;
  overflow: hidden;
  background: #e9ecef;
}

/* grid of kv pairs in expansion */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .5rem .75rem;
}

.detail-grid.two-col {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  align-items: start;
}

.kv {
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: .5rem;
  padding: .5rem .6rem;
  background: #fff;
}

.kv .k {
  font-size: .8rem;
  color: #6c757d;
  margin-bottom: .15rem;
}

.kv .v {
  font-weight: 600;
  word-break: break-word;
}

.exp-actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-bottom: .5rem;
}

/* Leaflet polyline styling hook */
.route-line {
  pointer-events: none;
}

.leaflet-overlay-pane svg path.route-line {
  opacity: 1 !important;
  stroke-width: 5 !important;
}

/* ================== Inline Forms (Saved Search Criteria card) ================== */
.inline-form {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 12px;
  margin-top: .75rem;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: .5rem;
  padding: .75rem;
  background: #f8f9fa;
  overflow-x: auto;
  white-space: nowrap;
}

.inline-form .field {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}

.inline-form .field.w-100 {
  width: 100px;
}

.inline-form .field.w-140 {
  width: 140px;
}

.inline-form .field.w-150 {
  width: 150px;
}

.inline-form .field.w-160 {
  width: 160px;
}

.inline-form .field.w-170 {
  width: 170px;
}

.inline-form .field.w-180 {
  width: 180px;
}

.inline-form .actions {
  display: inline-flex;
  gap: 8px;
}

/* ================== Forms ================== */
.form-select,
.form-control {
  padding: 0.5rem;
  border-radius: 0.375rem;
  border: 1px solid #ccc;
  width: 100%;
  margin-bottom: 1rem;
}

/* ================== Buttons ================== */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  font-weight: 600;
  text-align: center;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  background-color: #334D74;
  color: #fff;
  line-height: 1.25rem;
  font-size: 0.9rem;
}

.btn-primary {
  background-color: #334D74;
  color: #fff;
}

.btn-success {
  background-color: #198754;
  color: #fff;
}

.btn-warning {
  background-color: #FFC107;
  color: #000;
}

.btn-danger {
  background-color: #DC3545;
  color: #fff;
}

.btn-outline-secondary {
  background: transparent;
  border: 1px solid #6c757d;
  color: #6c757d;
}

.btn-link {
  background: transparent;
  border: none;
  padding: 0;
  color: #0d6efd;
  font-weight: 400;
  cursor: pointer;
}

/* ================== Flash Messages ================== */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin: 1rem auto;
  font-weight: bold;
  text-align: center;
  width: 80%;
}

.flash-success {
  background-color: #d1e7dd;
  color: #0f5132;
  border: 1px solid #badbcc;
}

.flash-danger,
.flash-error {
  background-color: #f8d7da;
  color: #842029;
  border: 1px solid #f5c2c7;
}

.flash-warning {
  background-color: #fff3cd;
  color: #664d03;
  border: 1px solid #ffecb5;
}

/* ================== Tiny Utilities ================== */
.text-center {
  text-align: center;
}

.text-muted {
  color: #6c757d;
}

.text-end {
  text-align: right;
}

.mb-0 {
  margin-bottom: 0;
}

.mb-1 {
  margin-bottom: .25rem;
}

.mb-2 {
  margin-bottom: .5rem;
}

.mb-3 {
  margin-bottom: .75rem;
}

.mb-4 {
  margin-bottom: 1rem;
}

.mt-2 {
  margin-top: .5rem;
}

.ms-auto {
  margin-left: auto;
}

.ms-2 {
  margin-left: .5rem;
}

.gap-2 {
  gap: .5rem;
}

.small {
  font-size: .8rem;
}

.leading-5 {
  line-height: 1.25rem;
}

.flex {
  display: flex;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.py-1 {
  padding-top: .25rem;
  padding-bottom: .25rem;
}

/* d-inline helper for delete forms in table */
.d-inline {
  display: inline;
}

/* gap utility for flex rows in header bars */
.d-flex {
  display: flex;
}

.align-items-center {
  align-items: center;
}

.justify-content-between {
  justify-content: space-between;
}

/* ========== Responsive tweaks ========== */

/* collapse dashboard grid to 1 column on narrow screens */
@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* Make the big load tables go "card-style" on very narrow screens.
   This removes the need for horizontal scrolling on phones. */
@media (max-width: 768px) {
  .table-sticky {
    max-height: none;
    overflow: visible;
  }

  .table {
    border: 0;
  }

  .table thead {
    display: none;
  }

  .table tbody tr {
    display: block;
    border: 1px solid #ddd;
    border-radius: .5rem;
    background: #fff;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .05);
  }

  /* hide the expand-row spacer border so detail rows look attached */
  .table tbody tr.expand-row>td {
    border-top: 0;
  }

  .table tbody tr td {
    display: flex;
    justify-content: space-between;
    border: 0;
    border-bottom: 1px solid #eee;
    padding: .5rem .75rem;
    white-space: normal;
  }

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

  /* we'll rely on data-label="" from template for per-cell label */
  .table tbody tr td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6c757d;
    padding-right: .5rem;
  }

  /* expansion row styling (map/details) should span full width cleanly */
  tr.expand-row {
    padding: 0;
  }

  tr.expand-row td {
    display: block;
    border: 0;
    padding: .75rem;
  }

  .detail-grid.two-col {
    grid-template-columns: 1fr;
  }

  .mini-map {
    width: 100%;
    max-width: 360px;
    height: 240px;
    margin-bottom: 1rem;
  }
}

/* When criteria-card <summary> shows chevron */
details.card summary::-webkit-details-marker {
  display: none;
}

.chev {
  transition: transform .15s ease;
}

details[open] .chev {
  transform: rotate(90deg);
}