/* ===== Design system ===== */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --header-h: 56px;
  --sheet-h: 74vh;
  --sheet-peek: 96px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1f232b;
  --text: #e7e9ee;
  --muted: #9aa1ac;
  --border: #2a2f38;
  --accent: #818cf8;
  --accent-hover: #a5b0ff;
  --accent-contrast: #11131a;
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

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

/* ===== Header ===== */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1100;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -.02em;
}

.brand .accent {
  color: var(--accent);
}

.theme-toggle {
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* ===== Layout ===== */
.layout {
  display: flex;
  flex-direction: column;
}

.panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-handle,
.sheet-summary {
  display: none;
}

.map-wrap {
  width: 100%;
}

#map {
  width: 100%;
  height: 56vh;
}

.intro {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

/* ===== Points ===== */
.point-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.point-address {
  position: relative;
  flex: 1;
  min-width: 0;
}

.point-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .6rem;
  min-height: 44px;
}

.point-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.point-status {
  width: 1.1rem;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
}

.point-row.is-valid .point-status {
  color: var(--success);
}

.point-row.is-valid .point-input {
  border-color: var(--success);
}

.point-spinner {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
}

.point-row.is-loading .point-spinner {
  display: inline-block;
}

.point-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 1000;
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.point-suggestion {
  padding: .6rem .55rem;
  cursor: pointer;
  border-radius: 6px;
  font-size: .92rem;
}

.point-suggestion:hover,
.point-suggestion.active {
  background: var(--surface-2);
}

/* Stepper de poids */
.weight-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.w-btn {
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 38px;
  height: 44px;
}

.w-btn:hover {
  color: var(--accent);
}

.w-value {
  min-width: 30px;
  text-align: center;
  font-weight: 600;
  padding: 0 2px;
}

.point-remove {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: var(--radius-sm);
  width: 40px;
  height: 44px;
}

.point-remove:hover:not(:disabled) {
  color: var(--danger);
  border-color: var(--danger);
}

.point-remove:disabled {
  opacity: .35;
  cursor: not-allowed;
}

/* ===== Buttons ===== */
.btn {
  font: inherit;
  cursor: pointer;
  padding: .6rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.btn-add {
  width: 100%;
  margin-top: 4px;
  color: var(--accent);
  border-style: dashed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
  font-weight: 600;
  width: 100%;
  padding: .75rem;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

/* ===== Action bar ===== */
.action-bar {
  position: sticky;
  bottom: 0;
  padding: 12px 0 4px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.legend {
  margin: 0;
  color: var(--muted);
  font-size: .8rem;
}

/* ===== Résultat ===== */
.result {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: .95rem;
}

.result .result-label {
  font-weight: 600;
}

.result .result-coords {
  color: var(--muted);
  font-size: .85rem;
}

.result.is-warning {
  border-left-color: var(--danger);
}

/* ===== Spinner ===== */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--muted) 40%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.btn .spinner {
  width: 16px;
  height: 16px;
  border-top-color: var(--accent-contrast);
  border-color: color-mix(in srgb, var(--accent-contrast) 40%, transparent);
  border-top-color: var(--accent-contrast);
  display: inline-block;
  vertical-align: -3px;
  margin-right: 8px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== Toasts ===== */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: 90vw;
}

.toast {
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: .9rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s, transform .25s;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-info {
  background: #334155;
}

.toast-success {
  background: var(--success);
}

.toast-error {
  background: var(--danger);
}

/* ===== Leaflet ===== */
.map-candidate button {
  font: inherit;
  cursor: pointer;
  margin-top: 2px;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 8px;
  padding: .55rem .85rem;
  font-weight: 600;
  min-height: 40px;
}

.bar-pin {
  background: transparent;
  border: none;
}

/* ===== Desktop (≥900px) ===== */
@media (min-width: 900px) {
  .layout {
    flex-direction: row;
    height: calc(100vh - var(--header-h));
  }

  .panel {
    width: 380px;
    min-width: 380px;
    overflow-y: auto;
    border-right: 1px solid var(--border);
  }

  .map-wrap {
    flex: 1;
  }

  #map {
    height: 100%;
  }
}

/* ===== Mobile (<900px) : carte plein écran + bottom sheet ===== */
@media (max-width: 899px) {

  html,
  body {
    overflow: hidden;
  }

  .layout {
    display: block;
  }

  .map-wrap {
    position: fixed;
    inset: var(--header-h) 0 0 0;
  }

  #map {
    height: 100%;
  }

  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1200;
    height: var(--sheet-h);
    padding: 0 16px 16px;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
    overflow: hidden;
    gap: 10px;
    transform: translateY(0);
    transition: transform .28s ease;
  }

  .panel.is-collapsed {
    transform: translateY(calc(var(--sheet-h) - var(--sheet-peek)));
  }

  .sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0 6px;
    cursor: pointer;
    flex: none;
  }

  .sheet-handle .grip {
    width: 42px;
    height: 5px;
    border-radius: 3px;
    background: var(--border);
  }

  .sheet-summary {
    display: none;
    align-items: center;
    gap: 10px;
    flex: none;
    padding-bottom: 6px;
  }

  .panel.is-collapsed .sheet-summary {
    display: flex;
  }

  .sheet-summary-text {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    font-size: .95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sheet-modify {
    flex: none;
    padding: .4rem .7rem;
  }

  .panel.is-collapsed .sheet-content {
    visibility: hidden;
  }

  .sheet-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 2px;
  }

  .action-bar {
    background: linear-gradient(to top, var(--surface) 75%, transparent);
  }
}


/* ===== Bars list ===== */
#bars-section h2 {
  font-size: 1rem;
  margin: 4px 0 8px;
}

#bars-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.bar-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.bar-item-name {
  font-weight: 600;
}

.bar-item-dist {
  color: var(--muted);
  font-size: .85rem;
  white-space: nowrap;
}

.bar-item-meta {
  color: var(--muted);
  font-size: .85rem;
  margin: 2px 0 8px;
}

.bar-item-links {
  display: flex;
  gap: 8px;
}

.bars-empty {
  color: var(--muted);
  font-size: .9rem;
}

.bar-link {
  text-decoration: none;
  font-size: .85rem;
  font-weight: 600;
  padding: .35rem .7rem;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-contrast);
}

.bar-item-links .bar-link:nth-child(2) {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.beer-pin {
  font-size: 20px;
  line-height: 26px;
  text-align: center;
  background: transparent;
  border: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .4));
}

.bar-popup strong {
  display: block;
  margin-bottom: 2px;
}

.bar-popup-info {
  color: #555;
  font-size: .85rem;
  margin-bottom: 6px;
}

.bar-popup-links {
  display: flex;
  gap: 8px;
}

.bar-popup-links .bar-link {
  text-decoration: none;
  font-weight: 600;
  font-size: .8rem;
  padding: .3rem .6rem;
  border-radius: 6px;
  background: #4f46e5;
  color: #fff;
}


/* ===== Bars filters ===== */
.bars-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  padding: 12px;
}

.bars-filters label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--muted);
}

.bars-filters input[type=range] {
  flex: 1;
}

.bars-filters select,
.bars-filters input[type=number],
.bars-filters input[type=time] {
  font: inherit;
  padding: .3rem .4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.bars-filters #f-dist-out {
  font-weight: 600;
  color: var(--text);
  min-width: 56px;
  text-align: right;
}

/* ===== S3 : accordéon adresses + bouton en flux normal ===== */
.points-card {
  padding: 0;
}

.points-card>summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 12px 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.points-card>summary::-webkit-details-marker {
  display: none;
}

.points-card>summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--muted);
  transition: transform .2s ease;
}

.points-card[open]>summary::after {
  transform: rotate(180deg);
}

.points-card>summary:hover {
  color: var(--accent);
}

.points-card .points-body {
  padding: 0 14px 14px;
}

/* Bouton dans le flux (plus de sticky/float, plus de contenu qui passe dessous) */
.action-bar {
  position: static;
  padding: 8px 0 0;
  background: transparent;
}