* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

#app { display: flex; height: 100vh; }
#sidebar {
  width: 400px; min-width: 340px; overflow-y: auto;
  padding: 16px; background: #fafaf8; border-right: 1px solid #ddd;
  display: flex; flex-direction: column; gap: 16px;
}
#map { flex: 1; }

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

/* Account block, pinned to the bottom of the sidebar */
#account {
  margin-top: auto; padding-top: 12px; border-top: 1px solid #e2e2de;
  display: flex; flex-direction: column; gap: 10px;
}
#account #trips-section { display: flex; flex-direction: column; gap: 6px; }
#auth-area { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; }
#auth-area img { width: 22px; height: 22px; border-radius: 50%; }
#auth-area a { color: #1a7f4e; }
button.small { padding: 6px 10px; font-size: 0.8rem; }
button.danger { background: none; border: 1px solid #ccc; border-radius: 6px; color: #b33; cursor: pointer; }
h1 { font-size: 1.15rem; margin: 0; }
#settings-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; }
button.link { background: none; border: none; color: #1a7f4e; cursor: pointer; font-size: 0.75rem; padding: 0; }

section { display: flex; flex-direction: column; gap: 6px; }
/* Scoped to our own panels — unscoped form rules leak into Leaflet's
   controls (the layer switcher renders radio inputs and labels). */
#sidebar label, #feedback-card label { font-weight: 600; font-size: 0.85rem; }
.hint { font-size: 0.72rem; color: #5f6b64; margin: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }

#sidebar textarea, #sidebar input, #sidebar select,
#feedback-card textarea, #feedback-card input, #feedback-card select {
  width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 6px;
  font: inherit; font-size: 0.9rem;
}
textarea { resize: vertical; }

.row { display: flex; gap: 8px; }
.row select { flex: 1; }

button.primary {
  padding: 9px 14px; border: none; border-radius: 6px; cursor: pointer;
  background: #1a7f4e; color: #fff; font-weight: 600; font-size: 0.9rem;
}
button.primary:hover:not(:disabled) { background: #156a41; }
button.primary:disabled { background: #aaa; cursor: not-allowed; }

#chat-log {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 260px; overflow-y: auto; padding: 4px 0;
}
#chat-log:empty { display: none; }
.msg { padding: 8px 10px; border-radius: 10px; font-size: 0.85rem; white-space: pre-wrap; max-width: 92%; }
.msg.user { align-self: flex-end; background: #d9ecdf; }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid #e2e2de; }

#status { font-size: 0.82rem; padding: 8px; border-radius: 6px; background: #eef3ff; color: #234; }
#status.error { background: #fdecea; color: #a12622; }

#waypoint-list { margin: 0; padding-left: 0; font-size: 0.86rem; list-style: none; }
#waypoint-list li { padding: 3px 4px; display: flex; align-items: center; gap: 8px; border-radius: 6px; }
#waypoint-list li.hl { background: #d9ecdf; }
#waypoint-list .wp-label { flex: 1; }
#waypoint-list .remove { cursor: pointer; color: #b33; border: none; background: none; font-size: 0.8rem; }
.wp-num {
  flex: none; width: 20px; height: 20px; line-height: 20px;
  border-radius: 50%; background: #1a7f4e; color: #fff;
  font-size: 11px; font-weight: 700; text-align: center;
}
.wp-num.start { background: #2266cc; }
.wp-num.end { background: #cc3322; }

#stats { flex-direction: row; gap: 10px; }
.stat {
  flex: 1; background: #fff; border: 1px solid #e2e2de; border-radius: 8px;
  padding: 8px; text-align: center; display: flex; flex-direction: column;
}
.stat span { font-weight: 700; font-size: 1.05rem; }
.stat small { color: #5f6b64; font-size: 0.7rem; }

#elevation { width: 100%; background: #fff; border: 1px solid #e2e2de; border-radius: 8px; }

details { font-size: 0.8rem; color: #444; }
details summary { cursor: pointer; font-weight: 600; }
details ul { padding-left: 18px; }
#feedback-tab {
  position: fixed; right: 0; top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  padding: 12px 8px;
  background: #1a7f4e; color: #fff;
  border: none; border-radius: 8px 0 0 8px;
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  z-index: 1200; box-shadow: -1px 1px 6px rgba(0,0,0,.25);
}
#feedback-tab:hover { background: #156a41; }
#feedback-modal {
  position: fixed; inset: 0; z-index: 1300;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
}
#feedback-card {
  background: #fff; border-radius: 12px; padding: 16px;
  width: min(420px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
}

.hidden { display: none !important; }

/* Mobile: map on top, scrollable panel below */
@media (max-width: 768px) {
  #app { flex-direction: column-reverse; }
  #map { flex: none; height: 44vh; }
  #sidebar {
    width: 100%; min-width: 0; flex: 1;
    border-right: none; border-top: 1px solid #ddd;
    padding: 12px;
  }
  #chat-log { max-height: 170px; }
  /* 16px inputs prevent iOS auto-zoom on focus */
  #sidebar textarea, #sidebar input, #sidebar select,
  #feedback-card textarea, #feedback-card input, #feedback-card select { font-size: 16px; }
  button.primary { padding: 11px 14px; }
}

.wp-marker {
  background: #1a7f4e; color: #fff; border-radius: 50%;
  width: 24px; height: 24px; line-height: 24px; text-align: center;
  font-size: 12px; font-weight: 700; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.wp-marker.start { background: #2266cc; }
.wp-marker.end { background: #cc3322; }
.wp-marker.hl {
  transform: scale(1.4);
  box-shadow: 0 0 0 4px rgba(26, 127, 78, 0.4), 0 1px 4px rgba(0,0,0,.4);
}

#examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip {
  border: 1px solid #cfd8d2; background: #fff; border-radius: 999px;
  padding: 4px 10px; font-size: 0.75rem; cursor: pointer; color: #234;
}
.chip:hover { background: #eef5f0; border-color: #1a7f4e; }
.chip.location { border-color: #1a7f4e; color: #1a7f4e; font-weight: 600; }

#share-result { display: flex; flex-direction: column; gap: 4px; }
#share-url { font-size: 0.8rem; background: #f4f4f2; }

#retrace-warning {
  margin: 0; padding: 8px 10px; border-radius: 6px;
  background: #fff6e5; border: 1px solid #f0d9a8; color: #7a5b12;
  font-size: 0.78rem;
}

/* Live "working" bubble: animated dots + elapsed time + current step */
.msg.pending { display: flex; align-items: center; gap: 8px; color: #44504a; }
.msg.pending .plabel { font-size: 0.8rem; }
.msg.pending .elapsed { font-size: 0.75rem; color: #5f6b64; font-variant-numeric: tabular-nums; }
.dots { display: inline-flex; gap: 3px; flex: none; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%; background: #1a7f4e;
  animation: dot 1.2s infinite ease-in-out both;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot {
  0%, 80%, 100% { opacity: .25; transform: scale(.8); }
  40%           { opacity: 1;   transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .7; } }

/* Roomy enough to paste a multi-day plan without scrolling */
#chat-input { min-height: 8.5rem; }
@media (max-width: 768px) { #chat-input { min-height: 6rem; } }
