/* ==========================================================================
   Waypoint - styles
   White paper background, wayfinding-signage ink, route-blue accent.
   Signature element: a dashed "route line" connecting saved places,
   like stops on a journey.
   ========================================================================== */

:root {
  --paper: #ffffff;
  --ink: #14181f;
  --muted: #6b7280;
  --line: #e7e9ee;
  --route: #2a4cff;        /* accent - saturated cobalt, wayfinding blue */
  --route-soft: #edf0ff;   /* accent tint for fills */
  --danger: #d92d20;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 31, 0.05), 0 8px 24px rgba(20, 24, 31, 0.06);
  --shadow-lift: 0 2px 4px rgba(20, 24, 31, 0.06), 0 14px 34px rgba(20, 24, 31, 0.1);

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

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* ==========================================================================
   Header
   ========================================================================== */

.app-header {
  max-width: 560px;
  margin: 0 auto;
  padding: 28px 20px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Pulsing origin dot - the "you are here" of the app */
.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--route);
  position: relative;
  flex: none;
}

.brand-dot::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid var(--route);
  opacity: 0;
  animation: ping 2.6s ease-out infinite;
}

@keyframes ping {
  0%   { transform: scale(0.5); opacity: 0.7; }
  70%  { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}

.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.tagline {
  margin: 2px 0 0 22px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ==========================================================================
   Layout / panels
   ========================================================================== */

.app-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 9px;
}

.hint {
  margin: 8px 2px 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ==========================================================================
   Inputs & buttons (shared)
   ========================================================================== */

input[type="text"],
select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  -webkit-appearance: none;
  appearance: none;
}

input::placeholder { color: #a4aab4; }

input:focus-visible,
select:focus-visible {
  border-color: var(--route);
  box-shadow: 0 0 0 3px var(--route-soft);
}

.btn-primary {
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--route);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  cursor: pointer;
  flex: none;
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.btn-primary:hover { background: #1f3de0; box-shadow: var(--shadow); }
.btn-primary:active { transform: scale(0.96); }

.btn-ghost {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.btn-ghost:hover { background: #f6f7f9; }
.btn-ghost:active { transform: scale(0.96); }

.btn-danger {
  font: inherit;
  font-weight: 600;
  color: var(--danger);
  background: transparent;
  border: 1.5px solid #f3c1bc;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.btn-danger:hover { background: #fdf1f0; }
.btn-danger:active { transform: scale(0.96); }

.inline-form {
  display: flex;
  gap: 10px;
}

/* ==========================================================================
   Origin selector
   ========================================================================== */

.select-wrap {
  position: relative;
}

.select-wrap select {
  padding-right: 40px;
  font-weight: 600;
  cursor: pointer;
}

.select-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.custom-origin {
  margin-top: 10px;
  animation: slide-down 0.25s ease both;
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Transport mode selector
   ========================================================================== */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.mode-btn {
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    color 0.18s ease,
    border-color 0.18s ease,
    background 0.18s ease,
    transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.mode-btn svg {
  width: 30px;
  height: 30px;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mode-btn:active { transform: scale(0.93); }

/* Selected state: inked-in stop on the route */
.mode-btn[aria-checked="true"] {
  color: var(--route);
  border-color: var(--route);
  background: var(--route-soft);
  box-shadow: 0 0 0 3px var(--route-soft);
}

.mode-btn[aria-checked="true"] svg {
  transform: scale(1.12);
}

/* Pop animation applied via JS on selection */
.mode-btn.pop {
  animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop {
  0%   { transform: scale(0.9); }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ==========================================================================
   Saved places - the route list (signature element)
   A dashed vertical line runs down the left side, each place is a "stop".
   ========================================================================== */

.places-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.places-header .panel-label { margin-bottom: 0; }

.btn-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--route);
  background: var(--route-soft);
  border: none;
  border-radius: 999px;
  padding: 8px 15px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.btn-add svg { width: 13px; height: 13px; }
.btn-add:hover { background: #dfe5ff; }
.btn-add:active { transform: scale(0.94); }

.route-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0 0 0 26px;
  position: relative;
}

/* The dashed route line itself */
.route-list::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 14px;
  bottom: 14px;
  width: 0;
  border-left: 2px dashed #c9d2f5;
}

.route-item {
  position: relative;
  margin-bottom: 12px;
  animation: item-in 0.3s ease both;
}

@keyframes item-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Stop dot on the route line */
.route-item::before {
  content: "";
  position: absolute;
  left: -25px;
  top: 26px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--paper);
  border: 2.5px solid var(--route);
  transition: background 0.15s ease;
}

.route-item:hover::before { background: var(--route); }

.place-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 13px;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.place-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  border-color: #d5daf9;
}

.place-card:active { transform: scale(0.985); }

.place-emoji {
  font-size: 1.5rem;
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: #f6f7f9;
  border-radius: 11px;
}

.place-text {
  flex: 1;
  min-width: 0;
}

.place-title {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place-address {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place-edit {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.place-edit:hover { background: #f0f1f4; color: var(--ink); }
.place-edit svg { width: 16px; height: 16px; }

.empty-state {
  margin-top: 14px;
  padding: 26px 18px;
  text-align: center;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.88rem;
}

.empty-state p { margin: 3px 0; }

/* ==========================================================================
   Bottom sheet (add / edit place)
   ========================================================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 31, 0.4);
  z-index: 40;
  animation: fade-in 0.2s ease both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-width: 560px;
  margin: 0 auto;
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(20, 24, 31, 0.18);
  animation: sheet-up 0.28s cubic-bezier(0.32, 0.72, 0, 1) both;
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 4px auto 14px;
}

.sheet h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sheet-field { margin-bottom: 13px; }

.sheet-field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.sheet-actions {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sheet-actions-right {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

/* ==========================================================================
   Toast
   ========================================================================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  background: var(--ink);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ==========================================================================
   Larger screens
   ========================================================================== */

@media (min-width: 640px) {
  .app-header { padding-top: 44px; }
  .mode-grid { gap: 14px; }
  .sheet {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 20px;
    animation: fade-in 0.2s ease both;
  }
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
