/* =========================================================
   🌗 THEME VARIABLES
   Light defaults overridden by [data-theme="dark"]
   ========================================================= */
:root {
  --bg: #f7f7fb;
  --fg: #1a1a1a;

  --top-bar-bg: #e8e8e8;
  --top-bar-text: #94a3b8;
  
  --card-bg: #ffffff;
  --card-border: #e6e6ee;
  --input-bg: #ffffff;
  --input-border: #d9d9e6;

  --accent: #2a7de1;
  --accent-contrast: #ffffff;

  --btn-bg: #ffffff;
  --btn-border: #d9d9e6;
  --btn-hover: #f2f3f9;

  --map-bg: #ffffff;
  --map-border: #e6e6ee;

  --table-bg: #ffffff;
  --table-border: #e6e6ee;
  --table-head-bg: #f3f4f8;
  --table-row-odd: #ffffff;
  --table-row-even: #f9f9fc;
  --table-row-hover: #eef3ff;

  --muted: #667085;
  --shadow: rgba(0, 0, 0, 0.08);

  --tooltip-bg: #111;
  --tooltip-fg: #fff;
  --tooltip-border: rgba(0,0,0,0.2);

  /* Dropzone tokens (light) */
  --drop-border: #2a7de1;
  --drop-bg: #ffffff;
  --drop-text: #334155;
  --drop-muted: #94a3b8;
  --drop-hover-bg: #f8fafc;
  --dragover-bg: #eef6ff;
  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --err: #dc2626;
  --err-bg: #fef2f2;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121418;
  --fg: #e6e8ed;

  --top-bar-bg: #2b2f38;
  --top-bar-text: #94a3b8;

  --card-bg: #1b1e24;
  --card-border: #2b2f38;
  --input-bg: #242832;
  --input-border: #3a3f4b;

  --accent: #4e92ff;
  --accent-contrast: #0b1220;

  --btn-bg: #2d3440;
  --btn-border: #3a3f4b;
  --btn-hover: #3a4150;

  --map-bg: #1b1e24;
  --map-border: #2b2f38;

  --table-bg: #1b1e24;
  --table-border: #2b2f38;
  --table-head-bg: #2a2f38;
  --table-row-odd: #1a1d24;
  --table-row-even: #1c1f26;
  --table-row-hover: #2b303b;

  --muted: #9aa3b2;
  --shadow: rgba(0, 0, 0, 0.4);

  --tooltip-bg: #000;
  --tooltip-fg: #fff;
  --tooltip-border: rgba(255,255,255,0.1);

  /* Dropzone tokens (dark) */
  --drop-border: #5393f2;
  --drop-bg: #0b1220;         /* or use var(--card-bg) */
  --drop-text: var(--fg);
  --drop-muted: #94a3b8;
  --drop-hover-bg: #151a26;
  --dragover-bg: rgba(83,147,242,.14);
  --ok: #22c55e;
  --ok-bg: rgba(34,197,94,.10);
  --err: #ef4444;
  --err-bg: rgba(239,68,68,.10);

}

/* =========================================================
   BASE + LAYOUT
   ========================================================= */
* { box-sizing: border-box; }
html, body { height: 100%; }
main {
  padding-bottom: 5rem !important;
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
  transition: background 0.3s ease, color 0.3s ease;
}

.is-hidden { display: none !important; }

.wrap {
  max-width: 1100px;
  width: 92vw;
  margin: 0 auto;
  padding: 16px;
}

/* =========================================================
   TOP BAR
   ========================================================= */
.top-bar {
  padding: 0.5rem;
  background-color: var(--top-bar-bg);
  position: fixed;
  bottom: 0;
  left: auto;
  right: auto;
  top: auto;
  width: 100%;
  z-index: 9999;
}
.top-bar-content {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
  max-width: 1100px;
  width: 92vw;
  margin: 0 auto;
  color: var(--top-bar-text);
}
.top-bar-content a {
  color: var(--top-bar-text);
}
.author {
  font-size: 0.8rem;
}
.socials {
  display: flex;
  gap: 0.5rem;
}
.social-icon {
  width: 1.5rem;
  height: 1.5rem;
}
/* =========================================================
   HEADER
   ========================================================= */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.language-switcher {
  display: flex;
  align-items: center;
}
.language-select {
  appearance: none;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}
.language-select:hover {
  background: var(--btn-hover);
}
.language-select:focus-visible {
  background: var(--btn-hover);
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
h1 { margin: 0; font-size: 20px; }
#themeToggle {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--fg);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background .2s ease;
}
#themeToggle:hover { background: var(--btn-hover); }

.brand { 
  display:flex;
  align-items:center; 
  text-decoration:none; 
}
.brand-logo { 
  display:block; 
  height:50px; 
  width:auto; 
  transition: filter 0.3s ease, opacity 0.3s ease;
}
[data-theme="dark"] .brand-logo {
  content: url("assets/timewisegpx_logo_dark.svg");
}
@media (max-width: 560px) { 
  .brand-logo { 
    height:26px; 
  } 
}

/* =========================================================
    FILE UPLOAD
   ========================================================= */
.gpx-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.gpx-card .field.file {
  flex: 1;
  display: flex;
}
.dropzone{
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:10px; text-align:center;
  padding:28px; border:2px dashed var(--drop-border); border-radius:14px;
  background: var(--drop-bg); color: var(--drop-text);
  min-height:180px;
  width: 100%;
  transition: background .15s ease, box-shadow .15s ease, border-color .15s;
}
.dropzone svg{ color: var(--drop-muted); }
.dropzone h3{ margin:6px 0 0; font-size:18px; color: var(--text, var(--fg)); }
.dropzone p{ margin:0; font-size:14px; color: var(--drop-muted); }
.dropzone .btn{
  appearance:none; border:1px solid var(--btn-border); background: var(--card-bg); color: var(--fg);
  padding:8px 14px; border-radius:10px; cursor:pointer;
  display:inline-flex; align-items:center; gap:8px;
}
.dropzone:hover{ background: var(--drop-hover-bg); }

.dropzone.dragover{
  border-color: var(--drop-border);
  background: var(--dragover-bg);
  box-shadow: 0 0 0 4px rgba(42,125,225,.12) inset; /* light fallback */
}

/* status line */
.dz-status { margin-top: 6px; font-size: 13px; color: var(--drop-text); opacity:.85; }
.dz-status .ok { color: var(--ok); font-weight: 600; }
.dz-status .err { color: var(--err); font-weight: 600; }

/* visual states for the drop box */
.dropzone.uploaded{
  border-color: var(--ok);
  background: var(--ok-bg);
  box-shadow: 0 0 0 4px rgba(22,163,74,.10) inset;
}
.dropzone.error{
  border-color: var(--err);
  background: var(--err-bg);
  box-shadow: 0 0 0 4px rgba(220,38,38,.08) inset;
}
.dropzone.uploaded .btn{ border-color: var(--ok); }


/* =========================================================
   CARDS
   ========================================================= */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px var(--shadow);
}
.card h2 {
  margin: 0 0 10px;
  font-size: 16px;
}
.card-header {
  display:flex;
  flex-direction: row;
  justify-content: space-between;
  margin-bottom: 10px;
}

#summaryCard .summary-formula {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

#summaryCard .summary-formula-heading {
  margin: 0 0 0.25rem;
  font-weight: 600;
  color: var(--text);
}

#summaryCard .summary-formula-text {
  margin: 0;
}

/* =========================================================
   CONTROLS
   ========================================================= */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.field {
  display: grid;
  gap: 6px;
  min-width: 200px;
  flex: 1 1 240px;
}
.field.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 240px;
  min-width: 220px;
}
.field.break { flex-basis: 100%; }

.field input[type="number"],
.field input[type="file"],
.controls select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--fg);
}
.checkboxes {
  display: flex;
  flex-direction: column;
}

/* =========================================================
   TOOLTIP HELP ICON
   ========================================================= */
.label-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.help-tip {
  appearance: none;
  border: 0;
  padding: 0;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--table-head-bg);
  color: var(--fg);
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
  cursor: help;
  position: relative;
}
.help-tip::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 10;
  left: 0; top: 130%;
  min-width: 180px;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--tooltip-bg);
  color: var(--tooltip-fg);
  border: 1px solid var(--tooltip-border);
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  font-size: 12px;
  line-height: 1.25;
  white-space: normal;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
}
.help-tip::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 120%;
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  background: var(--tooltip-bg);
  border-left: 1px solid var(--tooltip-border);
  border-top: 1px solid var(--tooltip-border);
  opacity: 0;
  transition: opacity .12s ease;
}
.help-tip:hover::after,
.help-tip:focus-visible::after,
.help-tip:hover::before,
.help-tip:focus-visible::before {
  opacity: 1;
  transform: translateY(0);
}

/* =========================================================
   ACTION BUTTONS
   ========================================================= */
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.settings-actions {
  justify-content: flex-end;
}
.actions .spacer { flex: 1; }
.button {
  appearance: none;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
  font-size: 0.875rem;
  text-decoration: none;
}
button {
  appearance: none;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}
button:hover {
  background: var(--btn-hover);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
button.process {
  width: 100%;
}

/* Advanced fields start hidden unless .show-adv */
#settingsCard .advanced { display: none; }
#settingsCard.show-adv .advanced { display: grid; }

/* =========================================================
   MAP + GRID LAYOUT
   ========================================================= */
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1.2fr 0.8fr;
  margin-bottom: 16px;
}
@media (max-width: 960px) {
  .grid { grid-template-columns: 1fr; }
}

/* Avoid extra height on side-by-side cards; the grid gap handles spacing */
.grid > .card {
  margin-bottom: 0;
}
.map {
  height: 420px;
  width: 100%;
  border: 1px solid var(--map-border);
  border-radius: 8px;
  background: var(--map-bg);
}

/* === Waypoint name as a permanent popup label === */
.leaflet-popup.wb-labelpop { pointer-events: none; }
.wb-labelpop .leaflet-popup-content-wrapper,
.wb-labelpop .leaflet-popup-tip { pointer-events: none; }
.wb-labelpop .wb-label-btn { pointer-events: auto; }
.leaflet-marker-icon.leaflet-interactive, .leaflet-image-layer.leaflet-interactive, .leaflet-pane > svg path.leaflet-interactive, svg.leaflet-image-layer.leaflet-interactive path { pointer-events: none !important; }


.wb-label-btn { cursor: pointer; }


.wb-labelpop .leaflet-popup-content-wrapper {
  background: #fff;
  color: #111;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  display: inline-block;
}
.wb-labelpop .leaflet-popup-content { 
  margin: 0;
  width: auto !important; 
}
.wb-labelpop .leaflet-popup-tip { /* keep the little caret */ }


.wb-label-btn {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  color: inherit;
}

.wb-label-btn:hover { filter: brightness(0.96); }

.wb-label-btn:focus-visible { outline: 2px solid var(--accent); border-radius: 6px; }



/* Map mini-toolbar shown when a waypoint is selected */
.wb-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}
.wb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--fg);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.wb-btn:hover { opacity: .92; }
.wb-btn .ico { font-size: 14px; line-height: 1; }


/* Inline buttons inside the label */
.wb-inline-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--fg);
  cursor: pointer;
}
.wb-inline-btn:hover { opacity: .9; }



/* =========================================================
   ITINERARY
   ========================================================= */
.table-outer {
  position: relative;
}
.table-outer::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 1px;
  background: var(--table-border);
  z-index: 10; /* above everything so the gap is always covered */
}
.table-wrap {
  overflow-x: auto;
  height: auto;
  -webkit-overflow-scrolling: touch;
}
.table-fade {
  position: absolute;
  top: 0;
  height: 100%;
  width: 18px;
  pointer-events: none;
  opacity: 1;
  transition: opacity .15s ease;
  z-index: 8; /* above table cells; below sticky col shadow if any */
}
.table-fade-right {
  right: 0;
  background: linear-gradient(to left, rgba(0,0,0,0.10), transparent);
}
[data-theme="dark"] .table-fade-right {
  background: linear-gradient(to left, rgba(255,255,255,0.12), transparent);
}
#roadbooks table {
  min-width: 1041px; 
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--table-bg);
  border: 1px solid var(--table-border);
  border-radius: 8px;
}
thead th {
  background: var(--table-head-bg);
  border-bottom: 1px solid var(--table-border);
  text-align: center;
  color: var(--fg);
}
th, td {
  padding: 8px 10px;
  border-right: 1px solid var(--table-border);
  white-space: nowrap;
  text-align: right;
  color: var(--fg);
}
th:first-child, td:first-child { text-align: center; }
th:nth-child(2), td:nth-child(2) { text-align: left; }

tbody tr:nth-child(odd) { background: var(--table-row-odd); }
tbody tr:nth-child(even) { background: var(--table-row-even); }
tbody tr:hover { background: var(--table-row-hover); }

@media (max-width: 600px) {
  #roadbooks table { font-size: 12px; }
  #roadbooks th, #roadbooks td { padding: 6px 8px; }
}

/* --- Observations column wrapping --- */
#roadbooks td.obs-cell,
#roadbooks td.obs-cell .wb-obs {
  max-width: 140px;        
  white-space: normal;    
  word-break: break-word;  
  overflow-wrap: anywhere;  
  vertical-align: top;     
  text-align: left;       
  line-height: 1.3;
}

/* Smaller, cleaner table text */
#roadbooks table { font-size: 11px; }
#roadbooks th,
#roadbooks td { padding: 6px 8px; }

#roadbooks th,
#roadbooks td {
  max-width: 150px;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  position: relative;
  left: auto;
  z-index: auto;
}


/* Only cells explicitly marked .col-index are sticky */
#roadbooks th.col-index,
#roadbooks td.col-index {
  position: sticky;
  left: 0;
  z-index: 9; /* above fades */
  /* background per section so sticky doesn't show row alt colors through */
}

/* Header cell appearance for the sticky index */
#roadbooks thead th.col-index {
  background: var(--table-head-bg);
  box-shadow: 4px 0 6px -4px rgba(0,0,0,.15);
  min-width: 36px;
  max-width: 44px;
  text-align: center;
}

/* Body cells for the sticky index */
#roadbooks tbody td.col-index {
  background: var(--table-bg);
  box-shadow: 4px 0 6px -4px rgba(0,0,0,.15);
  min-width: 36px;
  max-width: 44px;
  text-align: center;
}

/* --- Editable text (spans) --- */
.leg-cell .leg-name,
.wb-stops,
.wb-cond,
.wb-obs {
  border-bottom: 1px dashed var(--table-border);
}
.leg-cell .leg-name:focus,
.wb-stops:focus,
.wb-cond:focus,
.wb-obs:focus {
  outline: 2px solid var(--accent);
  border-bottom-color: transparent;
}

/* Pencil icon on editable table cells */
#roadbooks td.editable-cell {
  position: relative;
  padding-right: 22px; /* room for icon */
  overflow: visible;
  cursor: pointer;
}
#roadbooks td.editable-cell::after {
  content: "";
  width: 14px;
  height: 14px;
  background: no-repeat center / contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="%2399a" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 013 3L7 19l-4 1 1-4 12.5-12.5z"/></svg>');
  font-size: 0.8em;
  opacity: 0;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  transition: opacity 0.2s ease;
  pointer-events: none; /* don’t block clicks */
}
#roadbooks td.editable-cell:hover::after,
#roadbooks td.editable-cell:focus-within::after {
  opacity: 0.6;
}

/* Optional: subtle hover feedback */
#roadbooks td.editable-cell:hover {
  background-color: var(--hover-bg, rgba(0,0,0,0.05));
}

/* Critical column styling */
td.critical-cell {
  text-align: center;
  vertical-align: middle;
}
td.critical-cell.critical-on {
  background: var(--critical-bg, #ffe9e9);
}
td.critical-cell .crit-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
}
[data-theme="dark"] td.critical-cell.critical-on {
  background: rgba(255, 120, 120, 0.18);
}


/* =========================================================
   PRINT
   ========================================================= */
/* ---- Print: only show Itinerary ---- */
@media print {
  body {
    background: #fff;
    color: #000 !important;
    font-size: 11px;
    line-height: 1.4;
  }

  /* Hide everything except summary + table + print title */
  header,
  #settingsCard,
  #mapCard,
  .controls,
  .actions,
  .map,
  .socials,
  #fileUploadCard,
  #uploadCard,
  #separator, 
  button {
    display: none !important;
  }

  /* Show the print-only heading */
  .print-only {
    display: block !important;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
    margin-top: 6px;
  }

  /* Container */
  .wrap {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0 12px;
  }

  /* Remove borders/shadows for a clean sheet */
  .card {
    box-shadow: none !important;
    margin: 0 0 10px 0;
    padding: 8px;
    page-break-inside: avoid;
    border: none !important;

  }

  /* Table styling */

  #roadbooks table {
    width: 100%;
    font-size: 9px;
    border: none;
  }
  #roadbooks th, #roadbooks td {
    padding: 6px 6px !important;
    max-width: 100px;
    text-align: center;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    color:#000;
  }
  #roadbooks td, #roadbooks tbody td.col-index {
    background: none;
    border-right: none;
    border-bottom: 1px solid #efeff6;
  }

  #roadbooks th:first-child,
  #roadbooks td:first-child {
    text-align: center;
  }

  #roadbooks th:nth-child(2),
  #roadbooks td:nth-child(2) {
    text-align: left;
  }

  #roadbooks thead th {
    border-right: none;
    border-bottom: 2px solid #cdcdcd;
    font-weight: 600;
  }
  .leg-cell .leg-name, .wb-stops, .wb-cond, .wb-obs {
      border-bottom: none;
  }
  .critical-cell {
    position: relative;
  }
  .critical-cell.critical-on {
    background: #ffdddd !important;
    border-color: #fbb;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .critical-cell input[type="checkbox"] {
    display: none !important;
  }
  .critical-cell.critical-on::after {
    content: attr(data-critical-label);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #a00;
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
  }
  #roadbooks td.obs-cell,
  #roadbooks td.obs-cell .wb-obs {
    max-width: 100px;        
  }
  /* Hide cards that aren't summary or table */
  .card:not(#summaryCard):not(#roadbooksCard) {
    display: none !important;
  }
}

