/* ════════════════════════════════════════════════════════════
   UI Components
   ════════════════════════════════════════════════════════════ */

/* ── Panel (base) ─────────────────────────────────────────── */
.panel {
  background: var(--bg-primary);
}

.panel-title {
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  padding: 8px 12px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Description icon (ⓘ) — shown next to a title/label;
   hover/focus reveals a custom dark tooltip via [data-tooltip] (below) */
.panel-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-left: 6px;
  border-radius: 50%;
  border: 1px solid var(--text-disabled);
  color: var(--text-disabled);
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 0;
  vertical-align: middle;
  cursor: help;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.panel-info:hover,
.panel-info:focus-visible {
  color: var(--text-primary);
  border-color: var(--text-primary);
}

[data-tooltip] { outline: none; }

/* ── Custom dark tooltip popup (matches the dashboard's dark theme) ──
   Built and positioned in JS (see tooltip.js) so it renders in a fixed,
   viewport-anchored layer — escaping any panel's `overflow: hidden` and
   staying clear of the dashboard edges. Trigger with data-tooltip="...";
   use &#10; for line breaks (rendered via white-space: pre-line). */
.tooltip-popup {
  position: fixed;
  z-index: 2000;
  max-width: 520px;
  width: max-content;
  padding: 8px 10px;
  background: var(--bg-tooltip);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  font-family: inherit;
  font-size: 12px;
  font-weight: 400;
  font-style: normal;
  letter-spacing: normal;
  line-height: 1.5;
  text-align: left;
  white-space: pre-line;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
.tooltip-popup.is-visible {
  opacity: 1;
  visibility: visible;
}

.panel-body {
  padding: 12px;
}

/* ── Header: Logo ────────────────────────────────────────── */
.area-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--header-logo-bg);
  flex-shrink: 0;
  width: 200px;
  height: 100%;
}
.area-logo img {
  width: 70%;
  height: 70%;
  object-fit: contain;
}

/* ── Header: Title + description ─────────────────────────── */
.area-title {
  position: relative;
  background: var(--header-title-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  font-size: clamp(13px, 3vw, 24px);
  font-weight: 600;
  color: var(--text-primary);
  height: 100%;
  padding-right: 200px;
  text-align: center;
  white-space: nowrap;
}

/* Header help/info button — opens the "About this viewer" modal */
.header-help-btn {
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid var(--header-help-btn-border);
  background: var(--header-help-btn-bg);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  cursor: help;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.header-help-btn:hover,
.header-help-btn:focus-visible {
  background: var(--header-help-btn-bg-hover);
  border-color: var(--text-primary);
  outline: none;
}

/* ── About / help modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 3000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease;
}
.modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}
.modal {
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-medium);
}
.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-disabled);
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  transition: color 0.15s ease;
}
.modal-close:hover,
.modal-close:focus-visible {
  color: var(--text-primary);
  outline: none;
}
.modal-body {
  padding: 16px 18px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.modal-body h3 {
  font-size: 13px;
  color: var(--text-primary);
  margin: 14px 0 6px;
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body p { margin-bottom: 8px; }
.modal-body ul { padding-left: 20px; margin-bottom: 8px; }
.modal-body li { margin-bottom: 4px; }

/* ── Input form panel ───────────────────────────────────────────── */

/* 2 Column grid:
   Left column : Lat, Lon, Start Epoch, End Epoch
   Right column:   Elev. Mask, Constellations + Buttons */
.form-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(4, 32px);
  gap: 8px;
}

.form-fields .form-row-lat   { grid-column: 1; grid-row: 1; }
.form-fields .form-row-lon   { grid-column: 1; grid-row: 2; }
.form-fields .form-row-start { grid-column: 1; grid-row: 3; }
.form-fields .form-row-end   { grid-column: 1; grid-row: 4; }
.form-fields .form-row-elev  { grid-column: 2; grid-row: 1; }

.form-controls {
  grid-column: 2;
  grid-row: 2 / -1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  justify-content: flex-start;
  padding-top: 0;
}

@media (max-width: 760px) {
  .form-fields {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .form-fields .form-row-lat,
  .form-fields .form-row-lon,
  .form-fields .form-row-elev,
  .form-fields .form-row-start,
  .form-fields .form-row-end  { grid-column: 1; grid-row: auto; }
  .form-controls { grid-column: 1; grid-row: auto; flex-direction: row; flex-wrap: wrap; }
}

.form-row {
  display: flex;
  align-items: stretch;
  overflow: hidden;
  height: 32px;
}

.form-row .f-label {
  background: var(--label-bg);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: bold;
  border-radius: var(--r-lg);
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  white-space: nowrap;
  width: 115px;
  flex-shrink: 0;
}

.form-row input[type="number"],
.form-row input[type="datetime-local"] {
  flex: 1;
  background: transparent;
  border-radius: var(--r-lg);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 13px;
  padding: 0 10px;
  outline: none;
  min-width: 0;
  margin-left: 8px;
}
.form-row input[type="datetime-local"] {
  font-size: 12px;
  padding: 0 4px;
}
.form-row input:focus { border-color: var(--border-selected); }

/* Highlight unapplied change — value differs from the last applied Update */
.form-row-pending input[type="number"],
.form-row-pending input[type="datetime-local"] {
  color: var(--c-yellow);
}
/* Remove native datetime spinner arrows */
.form-row input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.form-row input[type="number"]::-webkit-outer-spin-button,
.form-row input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }
.form-row input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(85%) sepia(15%) saturate(300%) hue-rotate(180deg);
  cursor: pointer;
}

/* Constellation filter checkboxes */
.constellation-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 0;
}
.constellation-row label.c-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 4px;
}
.constellation-row label.c-option {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-disabled);
  cursor: pointer;
  transition: color 0.15s ease;
}
.constellation-row label.c-option:has(input:checked) {
  color: var(--text-secondary);
}
.constellation-row input[type="checkbox"] {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  position: relative;

  transition: all 0.15s ease;
}
.constellation-row input[type="checkbox"]:checked {
  background: var(--border-selected);
  border-color: var(--text-secondary);
}

/* ── LED status indicator (e.g. GALMON Network Status) ───── */
.led-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.led {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-disabled);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.led-up {
  background: var(--c-green);
  box-shadow: 0 0 6px 1px var(--c-green);
}
.led-down {
  background: var(--c-red);
  box-shadow: 0 0 6px 1px var(--c-red);
}

/* Action buttons */
.form-actions {
  display: flex;
  flex-direction: row;
  gap: 8px;
  width: 100%;
  position: relative;
}

.form-actions .btn {
  justify-content: center;
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
}

.btn-auto-refresh {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
}
.btn-auto-refresh.is-active {
  background: var(--border-selected);
  color: var(--bg-canvas);
  border-color: var(--border-selected);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-update  { background: var(--btn-update-bg); color: var(--bg-canvas); border: none; }
.btn-update.btn-cancel { background: var(--btn-cancel-bg); color: var(--text-primary); }
.btn-geo     { background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border-medium); }

/* ── Toast notifications ─────────────────── */
#toast-container {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.toast {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--r);
  background: var(--bg-secondary);
  border-left: 3px solid var(--border-strong);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  font-family: inherit;
  line-height: 1.45;
  pointer-events: all;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  transition: max-height 0.25s ease, opacity 0.2s ease, transform 0.2s ease, margin-bottom 0.25s ease;
  margin-bottom: 0;
}
/* Horizontal row holding spinner/icon, message and close button. */
.toast-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.toast.toast-visible {
  max-height: 140px;
  opacity: 1;
  transform: translateY(0);
  margin-bottom: 0;
}
.toast.toast-leaving {
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: 0;
}

.toast-success { border-left-color: var(--c-green); }
.toast-error   { border-left-color: var(--c-red); }
.toast-warning { border-left-color: var(--c-orange); }
.toast-loading { border-left-color: var(--c-blue); }
.toast-initial { border-left-color: var(--c-light-blue); }

.toast-icon {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: bold;
  line-height: 1.3;
}
.toast-success .toast-icon { color: var(--c-green); }
.toast-error   .toast-icon { color: var(--c-red); }
.toast-warning .toast-icon { color: var(--c-orange); }
.toast-initial .toast-icon { color: var(--c-light-blue); }
.toast-loading .spinner    { color: var(--c-blue); }

.toast-msg {
  flex: 1;
  color: var(--text-primary);
  word-break: break-word;
}

/* ── Toast progress bar ───────────────────────────────────────*/
.toast-progress {
  height: 3px;
  border-radius: 2px;
  background: var(--border-medium);
  overflow: hidden;
}

.toast-progress-bar {
  height: 100%;
  background: var(--c-blue);
  transform: scaleX(0);
  transform-origin: left center;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-disabled);
  font-size: 15px;
  line-height: 1;
  padding: 0 0 0 4px;
  cursor: pointer;
  transition: color 0.15s;
  align-self: flex-start;
}
.toast-close:hover { color: var(--text-primary); }

/* ── KPI stat cards ───────────────────────────────────────── */
.kpi-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 90px;
  border: none;
}
.kpi-card .panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px 14px;
  gap: 4px;
}
/* Bottom row: big number on the left, sparkline on the right */
.kpi-body-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 0;
}
.kpi-sparkline-wrap {
  flex: 1;
  min-width: 0;
  height: 50px;
  position: relative;
}
.kpi-sparkline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.55;
  display: block;
}
.kpi-title {
  font-size: 11px;
  font-weight: bold;
  color: var(--text-secondary);
}
.kpi-value {
  font-size: 38px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.5px;
  color: var(--c-green-light);
  flex-shrink: 0;
}

/* Bargauge (PDOP %) */
.kpi-body-row > div {
  flex-shrink: 0;
  min-width: 2ch;
}
.bargauge-value {
  font-size: 28px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
  flex-shrink: 0;
  min-width: 6ch;
}
.bargauge-track {
  height: 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 2px;
}
.bargauge-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.5s ease, background-color 0.5s ease;
}

/* ── Mini stat (visible satellite counters) ───────────────── */
.mini-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  text-align: left;
  min-height: 70px;
}
.mini-stat-value {
  font-size: 40px;
  font-weight: 500;
  color: var(--c-blue-light);
  line-height: 1;
  margin-top: 8px;  
}
.mini-stat-label {
  font-size: 14px;
  color: var(--text-secondary);

}

/* ── PDOP table ───────────────────────────────────────────── */
.pdop-table { width: 100%; border-collapse: separate; border-spacing: 0 4px;}
.pdop-table tr { transition: background 0.3s ease; }
.pdop-table td {
  padding: 3px 2px;
  font-size: 12px;
  font-weight: 400;
}
.pdop-table td:first-child { border-radius: var(--r-lg) 0 0 var(--r-lg); padding-left: 8px;}
.pdop-table td:last-child  { text-align: right; font-size: 18px; font-weight: 500; border-radius: 0 var(--r-lg) var(--r-lg) 0; padding-right: 8px; }

/* ── PDOP row background tints (gradient, matches threshold colour) ── */
.pdop-row-na      { color: var(--text-secondary); background: var(--c-pdop-row-na); }
.pdop-row-vlow    { color: var(--bg-canvas); background: var(--c-pdop-row-vlow); }
.pdop-row-low     { color: var(--bg-canvas); background: var(--c-pdop-row-low); }
.pdop-row-mid     { color: var(--bg-canvas); background: var(--c-pdop-row-mid); }
.pdop-row-high    { color: var(--bg-canvas); background: var(--c-pdop-row-high); }
.pdop-row-vhigh   { color: var(--text-secondary); background: var(--c-pdop-row-vhigh); }
.pdop-row-crit    { color: var(--text-secondary); background: var(--c-pdop-row-crit); }

/* ── Satellite status cells ───────────────────────────────── */
.sat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

/* textMode: "name", colorMode: "background" */
.sat-cell {
  flex: 1 1 40px;
  padding: 4px 8px;
  border-radius: var(--r-lg);
  font-size: 13px;
  text-align: center;
  font-weight: 400;
  cursor: default;
  color: var(--text-primary);
}

/* OSNMA: 0=gray(unavail), 1=blue(no auth), 2=green(auth) */
.sc-gray  { background: var(--cell-gray-bg); }
.sc-blue  { background: var(--cell-blue-bg); }
.sc-green { background: var(--cell-green-bg); }

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 11px; height: 11px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Epoch slider ─────────────────────────────────────────── */
.epoch-slider-body {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
}
.epoch-slider-body .f-label {
  background: var(--label-bg);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: bold;
  border-radius: var(--r-lg);
  padding: 4px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
#inp-epoch-slider {
  flex: 1;
  cursor: pointer;
  height: 14px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
#inp-epoch-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--slider-track);
}
#inp-epoch-slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--slider-track);
}
#inp-epoch-slider::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--slider-track);
}

#inp-epoch-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: none;
  border-radius: 50%;
  background: var(--border-selected);
}
#inp-epoch-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--border-selected);
}
#epoch-slider-label {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  min-width: 170px;
  text-align: center;
  background: var(--epoch-label-bg);
  border: 1px solid var(--border-selected);
  border-radius: var(--r-lg);
  padding: 2px 10px;
  flex-shrink: 0;
}


@media (max-width: 800px) {
  .area-logo { display: none; }
  .area-title { padding-right: 0; }
}
