:root {
  --bg: #f5f6f8;
  --panel: #fff;
  --border: #e2e5ea;
  --text: #1c2024;
  --muted: #6b7280;
  --accent: #2563eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 1.15rem; margin: 0; }

.status { font-size: 0.8rem; color: var(--muted); }

.userbox { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.user-pic { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
#logout {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 0.3rem 0.6rem; font-size: 0.8rem; cursor: pointer;
}
#logout:hover { color: var(--accent); border-color: var(--accent); }

/* Écran de connexion */
.login {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login[hidden] { display: none; }
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 2.5rem 2rem; text-align: center; max-width: 360px; width: 90%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
}
.login-logo { font-size: 2.5rem; }
.login-box h2 { margin: 0.3rem 0 0; }
.login-box p { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 1.5rem; }
.login-box #g_id_signin { display: flex; justify-content: center; }
.login-msg { min-height: 1em; color: var(--muted); font-size: 0.8rem; margin-top: 1rem !important; }

main {
  display: grid;
  grid-template-columns: 420px 1fr;
  height: calc(100vh - 53px);
}

.panel {
  padding: 1rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

form { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.25rem; }

label { font-size: 0.85rem; color: var(--muted); }

textarea {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
}

button {
  align-self: flex-start;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

.ghostbtn {
  align-self: flex-start;
  background: none;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.ghostbtn:hover { border-color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }

th, td {
  text-align: left;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; }

#map { height: 100%; }

.empty { color: var(--muted); font-style: italic; padding: 1rem 0.4rem; }

.form-msg { font-size: 0.8rem; color: var(--muted); min-height: 1em; }

/* Bloc capture iOS */
.capture { margin: 0 0 1.25rem; border: 1px solid var(--border); border-radius: 10px; }
.capture > summary {
  cursor: pointer; padding: 0.6rem 0.8rem; font-size: 0.85rem; font-weight: 600;
  list-style: none;
}
.capture > summary::-webkit-details-marker { display: none; }
.capture-body { padding: 0 0.8rem 0.8rem; font-size: 0.82rem; }
.capture-body p { color: var(--muted); margin: 0.2rem 0 0.7rem; }
.capture-body label { display: block; font-size: 0.75rem; color: var(--muted); margin: 0.5rem 0 0.2rem; }
.copyrow { display: flex; align-items: center; gap: 0.4rem; }
.copyrow code {
  flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.35rem 0.5rem; font-size: 0.78rem;
}
.copybtn {
  flex: 0 0 auto; background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 0.35rem 0.55rem; font-size: 0.75rem; cursor: pointer; color: var(--muted);
}
.copybtn:hover { color: var(--accent); border-color: var(--accent); }
.capture-steps { margin: 0.8rem 0 0.5rem; padding-left: 1.1rem; color: var(--text); line-height: 1.5; }
.capture-steps li { margin-bottom: 0.3rem; }
.capture-steps code { background: var(--bg); padding: 0 3px; border-radius: 4px; }
.linkbtn { background: none; border: none; color: var(--accent); font-size: 0.8rem; cursor: pointer; padding: 0.3rem 0; }

.preview {
  max-width: 100%;
  max-height: 160px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
}

input[type="file"] { font-size: 0.85rem; }

.filters { margin-bottom: 0.75rem; }
.filters #f-q {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  margin-bottom: 0.4rem;
}
.filters-row { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.filters-row select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.35rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  background: #fff;
}
.filters-row #f-reset {
  flex: 0 0 auto;
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}
.filters-row #f-reset:hover { color: var(--accent); border-color: var(--accent); }

.tag-chip {
  display: inline-block;
  font-size: 0.72rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  margin: 1px 1px;
  cursor: pointer;
}
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.muted { color: var(--muted); font-size: 0.8rem; }
.csv-link { font-size: 0.8rem; color: var(--accent); text-decoration: none; }
.csv-link:hover { text-decoration: underline; }

.item { display: flex; gap: 0.6rem; }
.thumb {
  width: 56px; height: 56px; flex: 0 0 56px;
  object-fit: cover; border-radius: 8px; border: 1px solid var(--border);
}
.thumb-empty {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); font-size: 1.3rem;
}
.item-body { min-width: 0; }
td .name { font-weight: 600; }
td .addr { color: var(--muted); font-size: 0.8rem; }
td .rating { font-size: 0.78rem; margin-top: 2px; }
td .desc { font-size: 0.78rem; margin-top: 3px; color: #374151; }
td .meta { font-size: 0.72rem; color: var(--muted); margin-top: 3px; display: flex; gap: 0.6rem; flex-wrap: wrap; }
td .note { color: var(--text); font-size: 0.78rem; margin-top: 2px; }
.tags { color: var(--muted); font-size: 0.8rem; vertical-align: top; }

/* Marqueurs thématiques (emoji + couleur) */
.mk-wrap { background: transparent; border: none; }
.mk-pin {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1; color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.4);
}

/* Popup carte enrichie */
.pp { font: 13px/1.4 system-ui, sans-serif; max-width: 300px; }
.pp-photo {
  width: 100%; height: 140px; object-fit: cover;
  border-radius: 8px; margin-bottom: 6px; display: block;
}
.pp-name { font-weight: 700; font-size: 14px; }
.pp-meta { color: #b45309; margin: 2px 0; }
.pp-addr { color: #6b7280; }
.pp-summary { margin: 6px 0; font-style: italic; }
.pp-hours { margin: 6px 0; }
.pp-hours summary { cursor: pointer; color: #2563eb; }
.pp-hours div { color: #6b7280; font-size: 12px; margin-top: 4px; }
.pp-reviews { margin-top: 8px; border-top: 1px solid #eee; padding-top: 6px; }
.pp-reviews-title { font-weight: 600; font-size: 12px; margin-bottom: 4px; }
.pp-review { margin-bottom: 6px; }
.pp-review-head { color: #f59e0b; font-size: 12px; }
.pp-author { color: #374151; margin-left: 6px; }
.pp-review-text { color: #374151; font-size: 12px; }
.pp-links { margin-top: 8px; display: flex; gap: 12px; }
.pp-links a { color: #2563eb; text-decoration: none; font-weight: 600; }

.badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  border-radius: 6px;
  padding: 1px 6px;
  vertical-align: middle;
}
.badge.amb { color: #5b21b6; background: #ede9fe; cursor: help; }

/* Fenêtre de choix du lieu */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 8vh;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff; width: min(460px, 92vw);
  border-radius: 12px; padding: 1rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.modal-head button {
  background: none; border: none; font-size: 1rem; cursor: pointer; color: var(--muted);
}
.chooser-hint {
  margin: 0 0 0.6rem;
  padding: 0.5rem 0.7rem;
  background: #fef3c7;
  color: #92400e;
  border-radius: 8px;
  font-size: 0.82rem;
}
.chooser-hint[hidden] { display: none; }
#chooser-q {
  width: 100%; padding: 0.5rem 0.6rem;
  border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
.chooser-results { margin-top: 0.6rem; max-height: 50vh; overflow-y: auto; }
.cand {
  display: block; width: 100%; text-align: left;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 0.6rem; margin-bottom: 0.4rem; cursor: pointer;
}
.cand:hover { border-color: var(--accent); background: #f8faff; }
.cand-name { font-weight: 600; font-size: 0.9rem; }
.cand-addr { color: var(--muted); font-size: 0.78rem; }

.actions { white-space: nowrap; text-align: right; }
.actions button {
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  margin-left: 3px;
  font-size: 0.9rem;
  cursor: pointer;
}
.actions button:hover { color: var(--accent); border-color: var(--accent); }

/* Bouton flottant bascule liste/carte (mobile uniquement) */
#view-toggle {
  display: none;
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 1500;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.1rem;
  font: inherit;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  cursor: pointer;
}

/* ====== Responsive mobile ====== */
@media (max-width: 760px) {
  header {
    flex-wrap: wrap;
    gap: 0.4rem 0.75rem;
    padding: 0.6rem 1rem;
  }
  header h1 { font-size: 1.05rem; }
  .status { font-size: 0.72rem; }
  .userbox { font-size: 0.8rem; gap: 0.4rem; }
  #logout { padding: 0.25rem 0.5rem; }

  /* Une seule colonne : liste par défaut, carte via le bouton */
  main { grid-template-columns: 1fr; height: auto; }
  .panel {
    border-right: none;
    overflow: visible;
    height: auto;
    padding: 1rem 1.1rem 5rem; /* marge basse pour ne pas masquer sous le bouton */
  }
  #map { display: none; height: calc(100dvh - 110px); }
  body.show-map .panel { display: none; }
  body.show-map #map { display: block; }
  #view-toggle { display: inline-flex; }

  /* Liste en cartes : plus de respiration, actions en colonne à droite */
  #bookmarks thead { display: none; }
  #bookmarks tbody { display: block; }
  #bookmarks tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "lieu actions" "tags actions";
    column-gap: 10px;
    row-gap: 4px;
    padding: 0.8rem 0;
    border-bottom: 1px solid var(--border);
  }
  #bookmarks td { display: block; border: none; padding: 0; }
  #bookmarks td:first-child { grid-area: lieu; }
  #bookmarks td.tags { grid-area: tags; }
  #bookmarks td.actions { grid-area: actions; align-self: start; }

  .actions { display: flex; flex-direction: column; gap: 6px; text-align: center; }
  .actions button { margin: 0; width: 40px; height: 36px; font-size: 1rem; }
}
