:root {
  --map-bg: #1b1f24;
  --bar: rgba(20, 24, 29, 0.92);
  --bar-fg: #f2f4f6;
  --sheet: #ffffff;
  --sheet-fg: #111418;
  --muted: #5b6672;
  --line: #dde2e7;
  --accent: #1e88e5;
  --accent-fg: #ffffff;
  --warn: #b26a00;
  --danger: #c62828;
  --chip: #eef3f8;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--map-bg); overflow: hidden; }
body {
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--sheet-fg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; }

#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* Πάνω μπάρα */
.topbar {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-t) + 8px) 10px 8px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bar); color: var(--bar-fg);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.brand { font-weight: 700; letter-spacing: 0.2px; white-space: nowrap; }
.brand .logo { color: #64b5f6; }
.ver { font-weight: 400; opacity: 0.6; font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 6px; }

.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 9px 14px; min-height: 42px;
  background: #2b323a; color: #fff; cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.icon { padding: 0; width: 42px; display: grid; place-items: center; }
.btn.big { min-height: 52px; padding: 12px 22px; font-size: 17px; margin: 6px 0 4px; }
.btn:active { filter: brightness(0.9); }

.busy {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.25); border-top-color: #64b5f6;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Πλωτά κουμπιά */
.fabs {
  position: absolute; right: 12px; bottom: calc(var(--sheet-h, 150px) + 14px);
  display: flex; flex-direction: column; gap: 10px;
}
.fab {
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: #fff; color: #263238; display: grid; place-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.fab.gps.on { color: var(--accent); }
.fab.gps.follow { background: var(--accent); color: #fff; }

/* Κάτω φύλλο συντεταγμένων — υψηλή αντίθεση για χρήση στον ήλιο */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--sheet); color: var(--sheet-fg);
  border-radius: 16px 16px 0 0; box-shadow: 0 -2px 14px rgba(0, 0, 0, 0.3);
  padding: 10px 12px calc(var(--safe-b) + 10px);
}
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--chip); color: var(--sheet-fg);
  border-radius: 999px; padding: 6px 12px; font-weight: 700; cursor: pointer;
}
.row { display: flex; align-items: flex-start; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.row-label { width: 62px; flex: none; font-size: 11px; font-weight: 800; color: var(--muted); padding-top: 4px; letter-spacing: 0.3px; }
.row-body { flex: 1; min-width: 0; }
.coord { font: 600 17px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace; word-break: break-word; }
.meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.meta .warn { color: var(--warn); font-weight: 600; }
.copy {
  flex: none; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--sheet-fg); font-size: 18px; cursor: pointer;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Κενή κατάσταση */
.empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: calc(var(--safe-t) + 70px) 16px calc(var(--sheet-h, 150px) + 20px);
  pointer-events: none;
}
.empty-card {
  pointer-events: auto; max-width: 440px; width: 100%;
  background: #fff; border-radius: 16px; padding: 18px 18px 14px; box-shadow: 0 6px 30px rgba(0, 0, 0, 0.4);
}
.empty-card h1 { font-size: 20px; margin: 0 0 8px; }
.empty-card ul { padding-left: 18px; margin: 6px 0 10px; }
.empty-card li { margin: 3px 0; }
.hint { color: var(--muted); font-size: 13px; }

/* Μηνύματα */
.toast {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-t) + 70px); max-width: calc(100% - 24px);
  background: #263238; color: #fff; padding: 10px 14px; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4); font-size: 14px; z-index: 5;
}
.toast.error { background: var(--danger); }
.progress { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.45); z-index: 6; }
.progress-card { background: #fff; padding: 16px 18px; border-radius: 12px; width: min(340px, 88vw); }
#progressText { white-space: pre-line; word-break: break-word; }
.progress-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; min-height: 8px; }
.progress-foot .btn { background: #e9edf1; color: var(--sheet-fg); min-height: 36px; padding: 6px 14px; }
#progressPct { font-weight: 700; color: var(--muted); }
.bar { height: 6px; background: #e3e8ed; border-radius: 3px; margin-top: 10px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }

/* Παράθυρα */
dialog.panel {
  border: none; border-radius: 16px; padding: 14px 16px 16px; width: min(520px, 94vw);
  max-height: 86vh; overflow: auto; color: var(--sheet-fg); background: #fff;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel h2 { font-size: 19px; margin: 4px 0 8px; }
.panel h3 { font-size: 15px; margin: 16px 0 4px; }
.close { border: none; background: none; font-size: 20px; width: 40px; height: 40px; cursor: pointer; }
.field { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.field select, .field input {
  display: block; width: 100%; margin-top: 4px; font-size: 16px; padding: 10px; color: var(--sheet-fg);
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
textarea { width: 100%; font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.actions .btn:not(.primary) { background: #e9edf1; color: var(--sheet-fg); }

.layer { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin: 8px 0; }
.layer-top { display: flex; align-items: center; gap: 8px; }
.layer-top input[type=checkbox] { width: 22px; height: 22px; }
.layer-name { flex: 1; font-weight: 700; word-break: break-all; }
.layer-kind { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: var(--chip); }
.layer-meta { font-size: 12px; color: var(--muted); margin: 6px 0; }
.layer-meta .warn { color: var(--warn); font-weight: 600; }
.layer-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.layer-actions input[type=range] { flex: 1 1 100%; margin: 4px 0; }
.layer-actions .spacer { flex: 1; }
.layer-actions .btn { min-height: 36px; padding: 6px 10px; background: #e9edf1; color: var(--sheet-fg); }
.layer-actions .btn.danger { color: var(--danger); }

/* Μόνιμη ειδοποίηση με ενέργεια */
.banner {
  position: absolute; left: 10px; right: 10px; top: calc(var(--safe-t) + 66px); z-index: 4;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff; color: var(--sheet-fg); padding: 10px 12px; border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4); font-size: 14px;
}
.banner #bannerText { flex: 1 1 180px; }
.banner .btn { min-height: 38px; padding: 6px 14px; }
.banner .close { width: 32px; height: 32px; font-size: 16px; }

/* Επιλογή προέλευσης */
.source-btn {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--sheet-fg); border-radius: 12px;
  padding: 14px; margin: 8px 0; font: inherit;
}
.source-btn:active { background: var(--chip); }
.source-btn small { color: var(--muted); }
.source-ico { width: 36px; display: grid; place-items: center; font-size: 26px; flex: none; }

/* Επιλογή συστήματος αναφοράς */
dialog.panel.tall { height: min(86vh, 760px); flex-direction: column; }
dialog.panel.tall[open] { display: flex; }
.search { width: 100%; font-size: 16px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; margin: 6px 0 8px; }
.crs-list { flex: 1; overflow: auto; min-height: 120px; border-top: 1px solid var(--line); }
.crs-list h4 { margin: 12px 2px 4px; font-size: 11px; letter-spacing: 0.4px; text-transform: uppercase; color: var(--muted); }
.crs-row { display: flex; align-items: center; gap: 8px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.crs-row:active { background: var(--chip); }
.crs-main { flex: 1; min-width: 0; }
.crs-name { font-weight: 600; word-break: break-word; }
.crs-code { font-size: 12px; color: var(--muted); }
.crs-warn { font-size: 12px; color: var(--warn); font-weight: 600; }
.crs-acc { font-size: 12px; color: var(--muted); }
.star { border: none; background: none; font-size: 22px; width: 40px; height: 40px; cursor: pointer; color: #b0b8c1; flex: none; }
.star.on { color: #f5a623; }
.custom-crs { margin-top: 8px; font-size: 14px; }
.custom-crs summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 6px 0; }
.custom-crs textarea { font-size: 13px; }
.btn.select-like { display: block; width: 100%; margin-top: 4px; text-align: left; background: #fff; color: var(--sheet-fg); border: 1px solid var(--line); font-weight: 600; }

/* Χάρτες cloud */
.layer.cloud { border-color: #9cc3f0; background: #f6faff; }
.cloud-tag { color: #1565c0; font-weight: 700; }
