/* DuckTracks · a stuxduck tool. Mobile-first. */
:root {
  --primary: #14b8a6;      /* DuckTracks teal (brand primary) */
  --primary-dark: #0d9488;
  --primary-soft: #ccfbf1;
  --secondary: #ffd23f;    /* bill & cap yellow (brand secondary) */
  --tile: #0f0f10;         /* stuxduck tile background */
  --ink: #17191c;
  --muted: #69727d;
  --line: #e4e7eb;
  --bg: #f5f6f7;
  --card: #fff;
  --go: #16a34a;
  --stop: #dc2626;
  --route: #2563eb;
  --pending: #f08c00;
  --radius: 14px;
  --tabbar-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overscroll-behavior: none;
}
a { color: var(--primary-dark); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pad { padding: 2rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.stack > * + * { margin-top: .75rem; }

/* ---------- top bar / brand ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: calc(.45rem + var(--safe-t)) max(1rem, env(safe-area-inset-right)) .45rem max(1rem, env(safe-area-inset-left));
  background: var(--tile); color: #fff; flex-shrink: 0; z-index: 1001;
}
.topbar a { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: .5rem; }
.wordmark { display: flex; flex-direction: column; line-height: 1; }
.wm { font-family: "Bricolage Grotesque", system-ui, sans-serif; font-weight: 800; font-size: 1.25rem; letter-spacing: -.3px; }
.wm b { color: var(--primary); font-weight: 800; }
.sub { font-size: .62rem; letter-spacing: .28em; color: #a9b0b8; font-weight: 700; margin-top: 2px; }
#userbox { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
#userbox a.btn, #userbox button { background: transparent; color: #fff; border-color: #ffffff40; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: var(--tile); font-weight: 800; font-size: .9rem;
}

main { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: .5rem .85rem; display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 40px; text-decoration: none; touch-action: manipulation;
}
button:hover { border-color: #c5ccd4; }
button:active { transform: scale(.98); }
button.primary { background: var(--primary); border-color: var(--primary-dark); color: #04201d; font-weight: 700; }
button.primary:hover { background: #2dd4bf; }
button.dark { background: var(--tile); border-color: var(--tile); color: #fff; font-weight: 600; }
button.danger { color: var(--stop); }
button.small, .chip { font-size: .82rem; padding: .25rem .6rem; min-height: 34px; }
button.block { width: 100%; }
button:disabled { opacity: .5; cursor: default; transform: none; }
button.yes.on { background: #dcfce7; border-color: var(--go); }
button.no.on { background: #fee2e2; border-color: var(--stop); }

input, textarea, select {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px; width: 100%; background: #fff; color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 2.75rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .6rem 0 .25rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.error { color: var(--stop); font-size: .9rem; min-height: 1.2em; margin-top: .5rem; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .8rem; margin: 1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.badge { background: var(--pending); color: #fff; border-radius: 99px; padding: .05rem .5rem; font-size: .75rem; font-weight: 700; }
.warn { background: #fff7e6; border: 1px solid #ffd591; color: #8a5a00; border-radius: 10px; padding: .5rem .7rem; font-size: .85rem; margin: .5rem 0 0; }
.note { background: var(--primary-soft); border: 1px solid #99f6e4; color: #134e4a; border-radius: 10px; padding: .6rem .75rem; font-size: .9rem; }

/* ---------- auth ---------- */
.narrow { max-width: 440px; margin: 0 auto; width: 100%; padding: 1rem; }
.wide { max-width: 760px; margin: 0 auto; width: 100%; padding: 1rem 1rem calc(2rem + var(--safe-b)); }
.hero { text-align: center; padding: 1.25rem 0 .5rem; }
.hero img { width: 96px; height: 96px; }
.hero .wm { font-size: 2rem; display: block; margin-top: .4rem; }
.hero .sub { color: var(--muted); font-size: .7rem; display: block; margin-top: .3rem; }
.motd {
  display: flex; gap: .6rem; align-items: center; background: var(--tile); color: #fff; border-radius: var(--radius);
  padding: .7rem .9rem; margin: .75rem 0 1rem; font-size: .92rem;
}
.motd .tag { background: var(--secondary); color: var(--tile); font-weight: 800; font-size: .65rem; letter-spacing: .12em; padding: .2rem .45rem; border-radius: 6px; white-space: nowrap; }
.motd b { color: var(--secondary); }
.tabs { display: flex; gap: .25rem; margin-bottom: .75rem; background: var(--bg); padding: .25rem; border-radius: 12px; }
.tabs button { flex: 1; border: none; background: transparent; }
.tabs button.active { background: #fff; box-shadow: 0 1px 3px #0002; font-weight: 600; }

/* ---------- trip list ---------- */
.trip-list { display: grid; gap: .6rem; margin: 1rem 0 1.5rem; }
.trip-item { display: flex; justify-content: space-between; align-items: center; gap: .5rem; text-decoration: none; color: inherit; }
.trip-item:hover { border-color: var(--primary); }
.trip-item .chev { color: var(--muted); font-size: 1.3rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ---------- invite box ---------- */
.invite-out { margin-top: .6rem; }
.invite-out input { font-size: 14px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }

/* ---------- trip view ---------- */
.trip-view { flex: 1; min-height: 0; display: flex; }
.map-wrap { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; }
.map-btns { position: absolute; right: 10px; top: 10px; z-index: 900; display: flex; flex-direction: column; gap: 6px; }
.map-btns button { width: 40px; height: 40px; padding: 0; background: #fff; box-shadow: 0 1px 4px #0003; border: none; font-size: 1.05rem; }
.sidebar {
  width: 420px; max-width: 100%; overflow-y: auto; border-left: 1px solid var(--line); background: var(--bg);
  padding: .75rem; display: flex; flex-direction: column; gap: .75rem;
}
.tabbar { display: none; }
.stats { display: flex; gap: 1rem; margin-top: .4rem; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 1.1rem; }
.stats span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

.itin { list-style: none; padding: 0; margin: 0; }
.itin-stop { display: flex; gap: .6rem; align-items: flex-start; padding: .45rem 0; cursor: pointer; }
.itin-stop .meta { flex: 1; min-width: 0; }
.itin-stop .name { font-weight: 600; overflow-wrap: anywhere; }
.itin-leg { margin-left: 13px; padding: .15rem 0 .15rem 1.1rem; border-left: 3px dotted #b6c2d1; font-size: .82rem; color: var(--muted); }
.itin-day { font-size: .72rem; font-weight: 800; text-transform: uppercase; color: var(--primary-dark); letter-spacing: .6px; margin-top: .5rem; }
.pin {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  background: var(--route); color: #fff; font-weight: 700; font-size: .8rem; border: 2px solid #fff; box-shadow: 0 1px 3px #0005;
}
.pin.start { background: var(--go); }
.pin.end { background: var(--stop); }
.pin.pending { background: var(--pending); }
.pin.temp { background: var(--tile); }
.pin.me { background: var(--primary); }
.stop-details { margin: .2rem 0 .5rem 2.3rem; }

.suggestion { border-left: 4px solid var(--pending); }
.suggestion + .suggestion { margin-top: .6rem; }
.suggestion.blocked { border-left-color: var(--stop); }
.suggestion.selected { box-shadow: 0 0 0 2px var(--pending); }
.votes { display: flex; flex-wrap: wrap; gap: .3rem; margin: .5rem 0; }
.chip { border-radius: 99px; background: #eef1f4; border: 1px solid transparent; display: inline-flex; align-items: center; gap: .25rem; min-height: 28px; }
.chip.y { background: #dcfce7; }
.chip.n { background: #fee2e2; }
.vote-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .6rem; }
.vote-row button { min-height: 44px; font-weight: 600; }

.results { list-style: none; padding: 0; margin: .5rem 0 0; max-height: 280px; overflow-y: auto; }
.results li { padding: .6rem .5rem; border-radius: 8px; cursor: pointer; }
.results li:hover, .results li:active { background: #eef1f4; }
.results .label { font-size: .78rem; color: var(--muted); }
.selected-place { margin-top: .6rem; border-top: 1px solid var(--line); padding-top: .6rem; }

.members { list-style: none; padding: 0; margin: 0; }
.members li { display: flex; justify-content: space-between; align-items: center; padding: .3rem 0; gap: .5rem; }
code.joincode { font-size: 1.05rem; letter-spacing: 2px; background: #fff3c4; padding: .1rem .4rem; border-radius: 5px; }

.map-pin { background: none; border: none; }
.leaflet-popup-content button { margin-top: .4rem; }
.leaflet-container { font: inherit; }

#toast {
  position: fixed; bottom: calc(1rem + var(--tabbar-h) + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--tile); color: #fff; padding: .6rem 1rem; border-radius: 12px; opacity: 0; transition: opacity .2s;
  pointer-events: none; z-index: 2000; max-width: calc(100vw - 2rem); text-align: center;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--stop); }

/* ---------- phones: app layout with map on top and a bottom tab bar ---------- */
@media (max-width: 800px) {
  :root { --tabbar-h: 60px; }
  body { font-size: 16px; }
  #userbox .uname { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .wm { font-size: 1.1rem; }

  .trip-view { flex-direction: column; }
  .map-wrap { flex: none; height: 38dvh; transition: height .25s ease; }
  .trip-view.map-big .map-wrap { height: 68dvh; }
  .leaflet-control-zoom { display: none; }
  .sidebar {
    width: 100%; border-left: none; flex: 1; min-height: 0;
    padding: .75rem .75rem calc(.75rem + var(--tabbar-h) + var(--safe-b));
    -webkit-overflow-scrolling: touch;
  }
  .sidebar > section[data-tab]:not(.tab-on) { display: none; }
  .sidebar > section { border-radius: var(--radius); }

  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    background: rgba(255, 255, 255, .96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); padding-bottom: var(--safe-b); height: calc(var(--tabbar-h) + var(--safe-b));
  }
  .tabbar button {
    border: none; background: none; border-radius: 0; flex-direction: column; gap: 2px; font-size: .7rem; color: var(--muted);
    min-height: var(--tabbar-h); position: relative; font-weight: 600;
  }
  .tabbar button .ico { font-size: 1.3rem; line-height: 1; }
  .tabbar button.on { color: var(--primary-dark); }
  .tabbar button.on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
  .tabbar .badge { position: absolute; top: 6px; left: calc(50% + 6px); font-size: .65rem; padding: 0 .35rem; }
}
