/* ===========================================================================
   Mittendrin — Material 3 styling
   Light + dark via [data-theme]; responsive: side panel (desktop) / sheet (mobile)
   =========================================================================== */

:root {
  /* Material 3 tonal palette — calm teal primary */
  --primary:        #0b6c62;
  --on-primary:     #ffffff;
  --primary-container: #a7f2e4;
  --on-primary-container: #00201c;

  --secondary:      #4a635e;
  --secondary-container: #cce8e1;
  --on-secondary-container: #06201b;

  --tertiary:       #b8562f; /* warm accent for midpoint */
  --tertiary-container: #ffdbcd;

  --surface:        #f6faf8;
  --surface-1:      #eef5f2;
  --surface-2:      #e7f0ed;
  --surface-3:      #dfeae6;
  --surface-container: #ffffff;
  --on-surface:     #171d1b;
  --on-surface-var: #3f4946;
  --outline:        #6f7976;
  --outline-var:    #c3ccc8;

  --error:          #ba1a1a;
  --scrim:          rgba(0,0,0,.32);

  --shadow-1: 0 1px 2px rgba(0,0,0,.16), 0 1px 3px rgba(0,0,0,.10);
  --shadow-2: 0 2px 6px rgba(0,0,0,.14), 0 1px 2px rgba(0,0,0,.10);
  --shadow-3: 0 6px 20px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.10);

  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --panel-w: 420px;
  --bar-h: 64px;

  --ease: cubic-bezier(.2,0,0,1);
  --ease-emph: cubic-bezier(.2,0,0,1);
}

[data-theme="dark"] {
  --primary:        #8bd6c8;
  --on-primary:     #00382f;
  --primary-container: #005046;
  --on-primary-container: #a7f2e4;

  --secondary:      #b1ccc5;
  --secondary-container: #324b46;
  --on-secondary-container: #cce8e1;

  --tertiary:       #ffb59a;
  --tertiary-container: #6e3a1f;

  --surface:        #0e1513;
  --surface-1:      #161d1b;
  --surface-2:      #1b2320;
  --surface-3:      #202825;
  --surface-container: #1a211f;
  --on-surface:     #dee4e1;
  --on-surface-var: #bec9c4;
  --outline:        #899390;
  --outline-var:    #3f4946;

  --error:          #ffb4ab;
  --scrim:          rgba(0,0,0,.5);

  --shadow-1: 0 1px 2px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
  --shadow-2: 0 2px 6px rgba(0,0,0,.5);
  --shadow-3: 0 8px 24px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* beat element display:flex etc. */
html, body { height: 100%; margin: 0; }
body {
  font-family: "Roboto", system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--on-surface);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
h1, h2 { font-family: "Roboto Flex", "Roboto", sans-serif; }
button { font-family: inherit; }

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  grid-template-rows: var(--bar-h) 1fr;
  grid-template-areas:
    "bar bar"
    "panel map";
}

/* ----------------------------- App bar --------------------------------- */
.app-bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 20px;
  background: var(--surface-container);
  border-bottom: 1px solid var(--outline-var);
  z-index: 30;
}
.app-bar__brand { display: flex; align-items: center; gap: 12px; }
.app-bar__logo {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--primary-container);
  color: var(--on-primary-container);
}
.app-bar__titles { line-height: 1.1; }
.app-bar__title { font-size: 22px; font-weight: 800; margin: 0; letter-spacing: -.2px; }
.app-bar__subtitle { font-size: 12.5px; margin: 2px 0 0; color: var(--on-surface-var); }
.app-bar__actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: none; border-radius: 50%;
  background: transparent; color: var(--on-surface-var);
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--on-surface); }
.icon-btn:active { background: var(--surface-3); }
.icon-btn--text { font-weight: 700; font-size: 14px; letter-spacing: .5px; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ----------------------------- Map ------------------------------------- */
.map-wrap { grid-area: map; position: relative; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.maplibregl-ctrl-bottom-right { margin-bottom: 6px; }
.maplibregl-ctrl-attrib { font-size: 10px; border-radius: 8px 0 0 0; }

/* Map tools (style switcher) */
.map-tools { position: absolute; top: 12px; right: 12px; z-index: 15; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.map-fab {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  border: 1px solid var(--outline-var); border-radius: 50%;
  background: var(--surface-container); color: var(--on-surface-var);
  box-shadow: var(--shadow-2); cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), transform .12s var(--ease);
}
.map-fab:hover { color: var(--primary); }
.map-fab:active { transform: scale(.94); }
.style-menu {
  background: var(--surface-container);
  border: 1px solid var(--outline-var);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-3);
  padding: 8px;
  min-width: 168px;
  display: flex; flex-direction: column; gap: 2px;
  animation: pop .16s var(--ease);
}
.style-menu__title {
  margin: 2px 4px 6px; font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .7px; color: var(--on-surface-var);
}
.style-opt {
  display: flex; align-items: center; gap: 10px;
  border: none; background: transparent; cursor: pointer;
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; color: var(--on-surface);
  text-align: left;
  transition: background .14s var(--ease);
}
.style-opt:hover { background: var(--surface-2); }
.style-opt.is-active { background: var(--primary-container); color: var(--on-primary-container); }
.style-dot { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--outline-var); }

/* Markers */
.marker {
  width: 30px; height: 30px;
  transform: translateY(-4px);
  cursor: pointer;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.35));
}
.marker--midpoint { width: 40px; height: 40px; }
.marker__pin { width: 100%; height: 100%; color: var(--primary); }
.marker--midpoint .marker__pin { color: var(--tertiary); }
.marker__num {
  position: absolute; top: 5px; left: 0; right: 0;
  text-align: center; font-size: 12px; font-weight: 700;
  color: var(--on-primary);
}

/* --------------------------- Control panel ----------------------------- */
.panel {
  grid-area: panel;
  background: var(--surface-container);
  border-right: 1px solid var(--outline-var);
  display: flex; flex-direction: column;
  min-height: 0;
  z-index: 20;
}
.panel__grabber { display: none; }
.panel__scroll {
  overflow-y: auto;
  padding: 18px 18px 28px;
  display: flex; flex-direction: column;
  gap: 14px;
}
.panel__heading {
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--on-surface-var);
  margin: 2px 0;
}

/* First-run hint */
.hint {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--primary-container);
  color: var(--on-primary-container);
  padding: 14px 16px;
  border-radius: var(--radius-md);
}
.hint__icon { flex: none; opacity: .9; }
.hint p { margin: 0; font-size: 14px; line-height: 1.4; }

/* Participants list */
.participants { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.participant {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-1);
  border: 1px solid var(--outline-var);
  border-radius: var(--radius-md);
  padding: 10px 8px 10px 12px;
  animation: pop .22s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.participant__badge {
  flex: none;
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  font-weight: 700; font-size: 14px;
}
.participant__body { min-width: 0; flex: 1; }
.participant__name { font-size: 14.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.participant__sub { font-size: 12px; color: var(--on-surface-var); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.participant__sub.is-error { color: var(--error); }
.participant__refine, .participant__remove {
  flex: none; border: none; background: transparent; cursor: pointer;
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--on-surface-var);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.participant__refine:hover { background: var(--surface-3); color: var(--primary); }
.participant__remove:hover { background: var(--surface-3); color: var(--error); }
.participant__refine.is-active { background: var(--primary-container); color: var(--on-primary-container); }

/* Search field */
.search { position: relative; }
.search__field {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-1);
  border: 1.5px solid var(--outline-var);
  border-radius: var(--radius-md);
  padding: 0 12px;
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
.search__field:focus-within { border-color: var(--primary); background: var(--surface-container); }
.search__icon { color: var(--on-surface-var); flex: none; }
.search__field:focus-within .search__icon { color: var(--primary); }
#place-input {
  flex: 1; border: none; background: transparent; outline: none;
  font-size: 15px; color: var(--on-surface);
  padding: 14px 0;
}
#place-input::placeholder { color: var(--on-surface-var); }
.search__spinner {
  width: 18px; height: 18px; flex: none;
  border: 2.5px solid var(--outline-var); border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* In-flow (not absolute) so the panel's overflow:auto never clips it. */
.suggestions {
  list-style: none; margin: 8px 0 0; padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--outline-var);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  max-height: 340px; overflow-y: auto;
  animation: pop .16s var(--ease);
}
.suggestion {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 12px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14.5px; line-height: 1.3;
}
.suggestion:hover, .suggestion.is-active { background: var(--surface-3); }
.suggestion__icon { color: var(--on-surface-var); flex: none; }
.suggestion__main { font-weight: 500; }
.suggestion__sub { color: var(--on-surface-var); font-size: 12.5px; }
.suggestion--empty { color: var(--on-surface-var); cursor: default; }
.suggestion--empty:hover { background: transparent; }

.search__pinhint { margin: -6px 2px 0; font-size: 12.5px; color: var(--primary); font-weight: 500; }

/* Radius */
.radius { display: flex; flex-direction: column; gap: 12px; }
.radius__head { display: flex; align-items: center; justify-content: space-between; }
.radius__value { display: flex; align-items: baseline; gap: 4px; color: var(--on-surface); font-weight: 600; }
#radius-input {
  width: 56px; text-align: right;
  border: 1.5px solid var(--outline-var); border-radius: var(--radius-sm);
  background: var(--surface-1); color: var(--on-surface);
  font-size: 15px; font-weight: 700; padding: 6px 8px; outline: none;
}
#radius-input:focus { border-color: var(--primary); }

.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px; background: var(--outline-var); outline: none; margin: 8px 0; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--primary); border: 3px solid var(--surface-container); box-shadow: var(--shadow-1); cursor: pointer; transition: transform .12s var(--ease); }
.slider::-webkit-slider-thumb:active { transform: scale(1.25); }
.slider::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); border: 3px solid var(--surface-container); cursor: pointer; }

/* Calculation method (segmented control) */
.method { display: flex; flex-direction: column; gap: 10px; }
.segmented {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-1);
  border: 1px solid var(--outline-var);
  border-radius: 999px;
}
.seg {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: none; cursor: pointer;
  padding: 9px 10px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600;
  color: var(--on-surface-var); background: transparent;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.seg:hover { color: var(--on-surface); }
.seg.is-active { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-1); }
.seg svg { opacity: .9; }
.method__desc { margin: 0 2px; font-size: 12.5px; line-height: 1.4; color: var(--on-surface-var); }

/* Result card */
.result-card {
  background: var(--secondary-container); color: var(--on-secondary-container);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  animation: pop .26s var(--ease);
}
.result-card__top { display: flex; align-items: flex-start; gap: 12px; }
.result-card__dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--tertiary); margin-top: 4px; box-shadow: 0 0 0 4px color-mix(in srgb, var(--tertiary) 25%, transparent); }
.result-card__label { margin: 0; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; opacity: .8; }
.result-card__place { margin: 2px 0 0; font-size: 17px; font-weight: 600; }
.result-card__coords { margin: 0; font-size: 13px; font-family: "Roboto Mono", ui-monospace, monospace; opacity: .85; }
.result-card__note { margin: 0; font-size: 12.5px; line-height: 1.4; background: color-mix(in srgb, var(--tertiary) 18%, transparent); padding: 8px 10px; border-radius: var(--radius-sm); }
.result-card__actions { display: flex; gap: 8px; }

.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer;
  padding: 11px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  transition: filter .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
.btn--filled { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-1); }
.btn--filled:hover { filter: brightness(1.05); box-shadow: var(--shadow-2); }
.btn--tonal { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.btn--tonal:hover { background: color-mix(in srgb, var(--primary) 24%, transparent); }
.btn:active { transform: translateY(1px); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(8px);
  background: #2e3331; color: #f2f4f3;
  padding: 13px 20px; border-radius: var(--radius-sm);
  font-size: 14px; box-shadow: var(--shadow-3);
  z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity .22s var(--ease), transform .22s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ----------------------------- Mobile ---------------------------------- */
@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--bar-h) 1fr;
    grid-template-areas: "bar" "map";
  }
  .app-bar__subtitle { display: none; }

  .panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    top: auto;
    height: auto;
    max-height: 58vh;
    border-right: none;
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    box-shadow: var(--shadow-3);
    transform: translateY(calc(100% - var(--sheet-peek, 132px)));
    transition: transform .34s var(--ease-emph);
  }
  .panel.is-open { transform: translateY(0); }
  /* Full-width drag strip: the whole 44px band accepts the pull gesture,
     not just the visible handle. touch-action:none lives HERE (not on the
     panel) so the content below stays touch-scrollable. */
  .panel__grabber {
    display: block; position: relative;
    height: 44px; cursor: grab;
    touch-action: none;
  }
  .panel__grabber:active { cursor: grabbing; }
  /* Round tab, centered, poking out above the sheet edge */
  .grab-tab {
    position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
    display: grid; place-items: center;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--surface-container);
    border: 1px solid var(--outline-var);
    box-shadow: var(--shadow-2);
    color: var(--on-surface-var);
  }
  .grab-tab svg { transition: transform .25s var(--ease); }
  .panel.is-open .grab-tab svg { transform: rotate(180deg); }
  /* invisible enlarged hit area around the tab */
  .grab-tab::before { content: ""; position: absolute; inset: -16px; border-radius: 50%; }
  .panel__scroll { padding-top: 0; }
  .suggestions { max-height: 240px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
