/* ==========================================================================
   Paddle Adventures — Isle of Man coastline tracker
   A deep-water palette so the map reads as sea and the covered coast glows.
   ========================================================================== */

:root {
  --sea-900: #04101c;
  --sea-800: #071726;
  --sea-700: #0c2033;
  --sea-600: #133048;
  --sea-500: #1d4160;
  --line:    #1e3c56;

  --ink:      #eaf4fb;
  --ink-soft: #9fb9cd;
  --ink-dim:  #6d8ba4;

  --glow:      #3ce0c5;   /* coastline you have paddled */
  --glow-deep: #12a893;
  --track:     #ffb35c;   /* the line of an individual trip */
  --coral:     #ff6b6b;

  --radius:     14px;
  --radius-sm:  10px;
  --panel-w:    390px;

  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .35);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  background: var(--sea-900);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--glow); }

/* --------------------------------------------------------------- layout */

.app {
  display: flex;
  height: 100%;
  height: 100dvh;
}

.panel {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  display: flex;
  flex-direction: column;
  background: linear-gradient(175deg, var(--sea-700) 0%, var(--sea-800) 55%, var(--sea-900) 100%);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 18px calc(18px + env(safe-area-inset-bottom));
}

/* The panel is a height-capped flex column, so without this its children get
   shrunk below their content height and pile on top of one another instead of
   making the panel scroll. */
.panel > * { flex-shrink: 0; }

.map-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--sea-900);
}

/* ------------------------------------------------------------ panel head */

.panel-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(18px + env(safe-area-inset-top)) 0 14px;
  /* Solid, not a fade — the panel scrolls underneath this and a transparent
     tail lets the trip list show through the header. */
  background: var(--sea-700);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 36px;
  height: 36px;
  flex: none;
  color: var(--glow);
  filter: drop-shadow(0 0 10px rgba(60, 224, 197, .35));
}

.brand h1 { font-size: 1.06rem; line-height: 1.2; }

.brand-sub {
  margin: 2px 0 0;
  font-size: .72rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, .03);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { color: var(--ink); border-color: var(--sea-500); background: rgba(255, 255, 255, .07); }

/* -------------------------------------------------------- progress card */

.progress-card {
  position: relative;
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(60, 224, 197, .14), transparent 62%),
    var(--sea-600);
  overflow: hidden;
}

.progress-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; }

.pct {
  display: block;
  font-size: 2.9rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  color: var(--glow);
  text-shadow: 0 0 26px rgba(60, 224, 197, .4);
}
.pct small { font-size: 1.35rem; font-weight: 600; opacity: .75; margin-left: 1px; }

.pct-label {
  display: block;
  margin-top: 6px;
  font-size: .78rem;
  color: var(--ink-soft);
}

.progress-ring-wrap { flex: none; }

.ring { width: 62px; height: 62px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; stroke-linecap: round; }
.ring-track { stroke: rgba(255, 255, 255, .09); }
.ring-fill {
  stroke: var(--glow);
  stroke-dasharray: 213.6;         /* 2 * PI * r, r = 34 */
  stroke-dashoffset: 213.6;
  filter: drop-shadow(0 0 6px rgba(60, 224, 197, .6));
  transition: stroke-dashoffset .8s cubic-bezier(.22, 1, .36, 1);
}

.progress-bar {
  position: relative;
  height: 7px;
  margin: 15px 0 11px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .3);
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--glow-deep), var(--glow));
  box-shadow: 0 0 14px rgba(60, 224, 197, .55);
  transition: width .8s cubic-bezier(.22, 1, .36, 1);
}

.progress-legend { margin: 0; font-size: .8rem; color: var(--ink-soft); }
.progress-legend strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- stat row */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 14px; }

.stat {
  padding: 11px 8px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .025);
}
.stat-n {
  display: block;
  font-size: 1.28rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat-l {
  display: block;
  margin-top: 3px;
  font-size: .66rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

/* -------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: .87rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .15s, background .15s, border-color .15s, color .15s;
}
.btn svg { width: 17px; height: 17px; flex: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--glow), var(--glow-deep));
  color: #04231f;
  box-shadow: 0 6px 18px rgba(60, 224, 197, .22);
}
.btn-primary:hover { filter: brightness(1.09); }

.btn-ghost {
  background: rgba(255, 255, 255, .04);
  border-color: var(--line);
  color: var(--ink-soft);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--sea-500); background: rgba(255, 255, 255, .08); }

.btn-danger { color: var(--coral); }
.btn-danger:hover { color: #fff; background: rgba(255, 107, 107, .16); border-color: var(--coral); }

.panel-actions { display: flex; gap: 8px; }
.panel-actions .btn-primary { flex: 1; }

/* ------------------------------------------------------------ trip list */

.trip-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 10px;
}
.trip-list-head h2 {
  font-size: .72rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.sync-dot {
  border: 0;
  padding: 0 2px;
  background: none;
  font-size: .8rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-dim);
  transition: color .2s;
}
.sync-dot.is-synced  { color: var(--glow); }
.sync-dot.is-pending { color: var(--track); }
.sync-dot.is-error   { color: var(--coral); }
.sync-dot.is-busy    { color: var(--glow); animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .25; } }

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

.trip {
  position: relative;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--track);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .028);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
}
.trip:hover { background: rgba(255, 255, 255, .07); transform: translateX(2px); }
.trip.is-active { border-color: var(--glow); background: rgba(60, 224, 197, .1); }

.trip-title {
  font-size: .92rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 3px;
  overflow-wrap: anywhere;
}

.trip-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: .74rem;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.trip-meta .cond { color: var(--track); }

.trip-notes {
  margin: 7px 0 0;
  font-size: .79rem;
  line-height: 1.45;
  color: var(--ink-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty {
  margin: 6px 0;
  padding: 26px 16px;
  text-align: center;
  font-size: .85rem;
  line-height: 1.6;
  color: var(--ink-dim);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}

.panel-foot {
  margin-top: auto;
  padding-top: 20px;
  font-size: .68rem;
  line-height: 1.5;
  color: var(--ink-dim);
}

/* ------------------------------------------------------------ map chrome */

.map-badge {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  max-width: min(88%, 460px);
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(7, 23, 38, .9);
  backdrop-filter: blur(10px);
  font-size: .78rem;
  color: var(--ink-soft);
  text-align: center;
  box-shadow: var(--shadow-md);
  transition: opacity .3s;
}
.map-badge.is-hidden { opacity: 0; pointer-events: none; }

.draw-bar {
  position: absolute;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 600;
  width: min(94%, 660px);
  padding: 13px 15px;
  border: 1px solid var(--sea-500);
  border-radius: var(--radius);
  background: rgba(7, 23, 38, .95);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-lg);
}

.draw-hint {
  margin-bottom: 11px;
  font-size: .84rem;
  font-weight: 500;
  color: var(--ink);
  text-align: center;
}
.draw-hint em { color: var(--glow); font-style: normal; font-weight: 650; }

.draw-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.chip {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(255, 255, 255, .05);
  color: var(--ink-soft);
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover:not(:disabled) { color: var(--ink); border-color: var(--sea-500); background: rgba(255, 255, 255, .1); }
.chip:disabled { opacity: .38; cursor: default; }
.chip-danger:hover:not(:disabled) { color: #fff; background: rgba(255, 107, 107, .2); border-color: var(--coral); }
.chip-go {
  margin-left: auto;
  background: linear-gradient(135deg, var(--glow), var(--glow-deep));
  border-color: transparent;
  color: #04231f;
}
.chip-go:hover:not(:disabled) { filter: brightness(1.09); color: #04231f; }

/* toggle switch */
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .14);
  transition: background .18s;
}
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink-soft);
  transition: transform .18s, background .18s;
}
.toggle input:checked + .toggle-track { background: rgba(60, 224, 197, .32); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(18px); background: var(--glow); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--glow); outline-offset: 2px; }
.toggle-label { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }

.fab { display: none; }

/* ------------------------------------------------------- leaflet restyle */

.leaflet-container { background: #04101c; font-family: var(--font); }

.leaflet-control-zoom a,
.leaflet-control-layers-toggle {
  background-color: rgba(7, 23, 38, .92) !important;
  color: var(--ink-soft) !important;
  border-color: var(--line) !important;
}
.leaflet-control-zoom a:hover { background-color: var(--sea-600) !important; color: var(--ink) !important; }

.leaflet-control-layers {
  background: rgba(7, 23, 38, .95) !important;
  color: var(--ink-soft);
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-md) !important;
}
.leaflet-control-layers label { font-size: .82rem; }

.leaflet-control-attribution {
  background: rgba(4, 16, 28, .82) !important;
  color: var(--ink-dim) !important;
  font-size: .64rem !important;
}
.leaflet-control-attribution a { color: var(--ink-soft) !important; }

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--sea-700);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}
.leaflet-popup-content-wrapper { border-radius: var(--radius-sm); }
.leaflet-popup-content { margin: 12px 14px; font-size: .84rem; line-height: 1.5; }
.leaflet-popup-content h3 { font-size: .93rem; margin-bottom: 4px; }
.leaflet-popup-content .pop-meta { color: var(--ink-dim); font-size: .75rem; }
.leaflet-popup-content .pop-notes { margin: 8px 0 0; color: var(--ink-soft); white-space: pre-wrap; }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink-dim); }

.map-drawing { cursor: crosshair !important; }

/* trip start/end pin */
.pin {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--track);
  border: 2.5px solid var(--sea-900);
  box-shadow: 0 0 0 1.5px var(--track), 0 0 14px rgba(255, 179, 92, .75);
}
.pin-draft { background: var(--glow); box-shadow: 0 0 0 1.5px var(--glow), 0 0 14px rgba(60, 224, 197, .75); }

/* ------------------------------------------------------------- dialogs */

.sheet {
  width: min(520px, calc(100% - 28px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(170deg, var(--sea-700), var(--sea-800));
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.sheet::backdrop { background: rgba(2, 8, 14, .72); backdrop-filter: blur(3px); }
.sheet h2 { font-size: 1.2rem; margin-bottom: 6px; }
.sheet h3 { font-size: .95rem; margin-bottom: 5px; }

.muted { margin: 0 0 14px; font-size: .83rem; line-height: 1.55; color: var(--ink-soft); }

.setting-block { padding: 16px 0; border-bottom: 1px solid var(--line); }
.setting-block:first-of-type { padding-top: 12px; }

.field { display: block; margin: 0 0 14px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.field > span .muted { display: inline; margin: 0; text-transform: none; letter-spacing: 0; }

.field input[type="text"],
.field input[type="date"],
.field input[type="number"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, .28);
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
}
.field textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--glow);
  box-shadow: 0 0 0 3px rgba(60, 224, 197, .16);
}
.field input[type="range"] { width: 100%; accent-color: var(--glow); }

.field-hint { display: block; margin-top: 6px; font-size: .74rem; line-height: 1.45; color: var(--ink-dim); }
.field-hint strong { color: var(--ink-soft); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.chip-inline { margin-top: 8px; padding: 6px 11px; font-size: .74rem; }

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.sheet-actions-left { margin-top: 8px; }
.spacer { flex: 1; }

.token-state {
  display: none;
  margin-bottom: 14px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: .82rem;
  line-height: 1.5;
}
.token-state.show { display: block; }
.token-state.ok   { background: rgba(60, 224, 197, .12); border: 1px solid rgba(60, 224, 197, .3); color: var(--glow); }
.token-state.warn { background: rgba(255, 179, 92, .12); border: 1px solid rgba(255, 179, 92, .3); color: var(--track); }
.token-state.bad  { background: rgba(255, 107, 107, .12); border: 1px solid rgba(255, 107, 107, .3); color: var(--coral); }

/* welcome */
.sheet-welcome { text-align: left; }
.welcome-art { color: var(--glow); margin-bottom: 14px; }
.welcome-art svg { display: block; width: 100%; max-height: 92px; }

.welcome-points { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; }
.welcome-points li { font-size: .85rem; line-height: 1.55; color: var(--ink-soft); }
.welcome-points strong { color: var(--ink); }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  z-index: 4000;
  max-width: min(90%, 440px);
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(7, 23, 38, .96);
  backdrop-filter: blur(10px);
  font-size: .84rem;
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .22s, transform .22s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { border-color: var(--coral); color: #ffd9d9; }

/* --------------------------------------------------------------- mobile */

@media (max-width: 860px) {
  .app { flex-direction: column-reverse; }

  .map-wrap { flex: 1 1 auto; min-height: 0; }

  .panel {
    width: 100%;
    flex: 0 0 auto;
    max-height: 46dvh;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -14px 40px rgba(0, 0, 0, .5);
  }

  .panel-head { padding-top: 14px; }

  /* the sidebar button is redundant next to the FAB on small screens */
  .panel-actions .btn-primary { display: none; }
  .panel-actions { justify-content: flex-end; }
  .panel-actions .btn-ghost { flex: 1; }

  .fab {
    display: grid;
    place-items: center;
    position: absolute;
    right: 14px;
    bottom: 14px;
    z-index: 550;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--glow), var(--glow-deep));
    color: #04231f;
    cursor: pointer;
    box-shadow: 0 8px 26px rgba(60, 224, 197, .38);
  }
  .fab svg { width: 25px; height: 25px; }
  .fab.is-hidden { display: none; }

  .field-row { grid-template-columns: 1fr; }

  .chip-go { margin-left: 0; flex: 1; }
  .draw-controls { gap: 7px; }
  .toggle { width: 100%; }
}

@media (max-width: 420px) {
  .pct { font-size: 2.4rem; }
  .sheet { padding: 20px 18px; }
}

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