/* Thème clair (par défaut) */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #111114;
  --muted: #6b6b73;
  --line: #e3e3e8;
  --accent: #0a6fd6;
  --chip: #e6e6eb;
  --danger: #e5484d;
  color-scheme: light;
}

/* Thème sombre : automatique selon l'iPhone, ou forcé dans les paramètres */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #9a9aa2;
    --line: #2e2e32;
    --accent: #3d9bff;
    --chip: #2c2c2e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --text: #f2f2f7;
  --muted: #9a9aa2;
  --line: #2e2e32;
  --accent: #3d9bff;
  --chip: #2c2c2e;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
}

body { padding-bottom: env(safe-area-inset-bottom); }

a { color: var(--accent); }

/* Barre du haut, façon iOS */
#bar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
}

#title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 56vw;
}

.hbtn {
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  font-size: 17px;
  padding: 6px 0;
  cursor: pointer;
}
.hbtn[hidden] { display: none; }
.hbtn:disabled { opacity: 0.35; cursor: default; }
.hbtn.big { font-size: 28px; line-height: 1; padding: 0 2px; }
#left { justify-self: start; }
.hright { justify-self: end; display: flex; align-items: center; gap: 16px; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}

/* Listes et cartes */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 0.5px solid var(--line);
}
.row:last-child { border-bottom: 0; }

.row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  color: inherit;
  text-decoration: none;
}

.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub, .muted { color: var(--muted); font-size: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.badge > span { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.badge small { font-size: 11px; }

.arrow { width: 14px; height: 14px; flex: none; }

.del, .mv {
  flex: none;
  border: 0;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font: 700 18px/1 inherit;
  cursor: pointer;
}
.del { background: var(--danger); color: #fff; }
.mv { background: var(--chip); color: var(--text); }
.mv:disabled { opacity: 0.3; }

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.card-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty .boat { font-size: 52px; }
.empty h2 { color: var(--text); margin: 8px 0 4px; }

.btn {
  display: inline-block;
  margin-top: 12px;
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  font: 600 16px/1.2 inherit;
  text-decoration: none;
  cursor: pointer;
}

.foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 18px; }

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading, .error { text-align: center; padding: 48px 12px; color: var(--muted); }

/* Ajout d'un spot */
input[type="search"], .field input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* évite le zoom automatique d'iOS */
  padding: 10px 12px;
  border-radius: 10px;
  border: 0;
  background: var(--chip);
  color: var(--text);
}
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.results { margin-top: 8px; }
.results button {
  all: unset;
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  cursor: pointer;
}
.results li + li button { border-top: 0.5px solid var(--line); }

.map {
  height: 300px;
  border-radius: 12px;
  margin: 12px 0;
  overflow: hidden;
  position: relative;
  background: #0b2540;
}
.map-hint {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
  pointer-events: none;
  white-space: nowrap;
}
.pin { font-size: 28px; line-height: 32px; text-align: center; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7)); }

/* Détail d'un spot */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 0;
  border-radius: 99px;
  padding: 7px 13px;
  font: 600 14px/1 inherit;
  background: var(--chip);
  color: var(--text);
  cursor: pointer;
}
.chip.on { color: #fff; }
.chip.off { opacity: 0.4; }
.model-info { color: var(--muted); font-size: 13px; margin: 6px 2px 12px; }

.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-box { height: 220px; position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11px; margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.legend i.dash { width: 14px; height: 0; border-radius: 0; border-top: 2px dashed; }

.day h3 { font-size: 15px; margin: 18px 2px 6px; }
.table { background: var(--card); border-radius: 12px; padding: 2px 10px; }
.thead, .trow {
  display: grid;
  grid-template-columns: 36px 56px 40px 40px 26px 1fr 32px 14px;
  gap: 5px;
  align-items: center;
}
.thead {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 0;
  border-bottom: 0.5px solid var(--line);
}
.trow { padding: 5px 0; border-bottom: 0.5px solid var(--line); font-variant-numeric: tabular-nums; }
.trow:last-child { border-bottom: 0; }
.c { text-align: center; }
.r { text-align: right; }
.kn, .gust { text-align: center; border-radius: 6px; padding: 3px 0; }
.kn { font-weight: 700; }
.dir { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.wave, .temp { text-align: right; font-size: 13px; }
.wave { color: var(--muted); }
.rain { font-size: 11px; text-align: center; }

/* Lien vers les alertes */
.alerts-link { margin-bottom: 12px; }
.chevron { color: var(--muted); font-size: 22px; }
.card p { margin: 0 0 10px; }
.card .btn { margin: 10px 0 8px; }

/* Renommer un spot en mode Modifier */
.rename {
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.pencil { font-size: 13px; }

/* Choix de l'affichage */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--chip);
  border-radius: 10px;
  padding: 2px;
  margin-bottom: 12px;
}
.seg button {
  border: 0;
  background: none;
  color: var(--text);
  font: 600 13px/1.2 inherit;
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
}
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }

/* Tableau de comparaison des modèles */
.ctable { background: var(--card); border-radius: 12px; padding: 6px; }
.chead, .crow { display: grid; gap: 3px; align-items: center; }
.chead { font-size: 10px; font-weight: 800; text-align: center; padding: 2px 0 6px; white-space: nowrap; }
.crow { padding: 1.5px 0; }
.crow .h { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border-radius: 6px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.cell .top { display: flex; align-items: center; gap: 2px; font-weight: 800; font-size: 14px; }
.cell .arrow { width: 10px; height: 10px; }
.cell small { font-size: 10px; opacity: 0.75; }
.cell.none { background: var(--chip); color: var(--muted); }
.agree { text-align: center; font-weight: 900; font-size: 14px; }
.agree.ok { color: #2fa84f; }
.agree.mid { color: #e8930c; }
.agree.bad { color: var(--danger); }

.howto summary { font-weight: 600; cursor: pointer; }
.howto p { font-size: 14px; margin: 8px 0 0; }
.agree[data-label] { cursor: pointer; }

.agree.fiab { font-size: 13px; }

/* Paramètres */
.gear { font-size: 24px; line-height: 1; padding: 0 2px; }
.settings-list { list-style: none; margin: 0; padding: 0; }
.settings-list li + li { border-top: 0.5px solid var(--line); }
.option {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 2px;
  cursor: pointer;
}
.option .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.option .txt { flex: 1; min-width: 0; }
.option .check { color: var(--accent); font-weight: 700; font-size: 18px; }
.option .sub { display: block; }

/* Poignée pour réorganiser les spots */
.grip {
  flex: none;
  width: 36px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 24px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.row.dragging {
  position: relative;
  z-index: 2;
  background: var(--card);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  border-radius: 10px;
}
.row.dragging .grip { cursor: grabbing; }
.row.shifting { transition: transform 0.18s ease; }

/* Interrupteurs façon Réglages iPhone */
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px;
  cursor: pointer;
}
.switch-row .txt { flex: 1; min-width: 0; }
.switch-row .sub { display: block; }
.switch-row.disabled { opacity: 0.45; cursor: default; }
.switch {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  position: relative;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 31px;
  background: var(--chip);
  transition: background 0.2s ease;
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { cursor: default; }

/* Tutoriel d'installation (site web uniquement) */
.install { position: relative; border: 1.5px solid var(--accent); }
.install-head { display: flex; gap: 12px; align-items: center; padding-right: 64px; }
.install-head img { border-radius: 10px; flex: none; }
.install-steps { margin: 12px 0 4px; padding-left: 22px; }
.install-steps li { margin: 6px 0; font-size: 15px; }
.ios-share { width: 18px; height: 18px; vertical-align: -3px; color: var(--accent); }
.install-hide {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  background: none;
  color: var(--muted);
  font: 13px/1 inherit;
  cursor: pointer;
}
.install-reopen {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  border: 0;
  border-radius: 12px;
  padding: 12px;
  background: var(--card);
  color: var(--accent);
  font: 600 15px/1.2 inherit;
  cursor: pointer;
}

/* Garde le titre centré même quand le bouton de gauche est absent */
#left[hidden] { display: block; visibility: hidden; }

/* Raccourcis vers chaque jour (restent visibles en faisant défiler) */
.daybar {
  position: sticky;
  top: var(--bar-h, 52px);
  z-index: 900;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 8px -16px 4px;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.daybar::-webkit-scrollbar { display: none; }
.daybar button {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 6px 11px;
  background: var(--card);
  color: var(--text);
  font: 600 13px/1 inherit;
  cursor: pointer;
}
.day { scroll-margin-top: calc(var(--bar-h, 52px) + 56px); }
.relay {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--chip);
  border-radius: 99px;
  padding: 2px 8px;
  margin-left: 6px;
  vertical-align: 2px;
}

/* Cases à cocher des spots surveillés */
.check-row { display: flex; align-items: center; gap: 12px; padding: 11px 2px; cursor: pointer; }
.tick {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid var(--muted);
  border-radius: 50%;
  display: grid;
  place-content: center;
  cursor: pointer;
}
.tick:checked { background: var(--accent); border-color: var(--accent); }
.tick:checked::after { content: "✓"; color: #fff; font-size: 14px; font-weight: 800; line-height: 1; }
