/* styles.css -- minimal project CSS, mobile-first, responsive. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #3b82f6;
  --primary-ink: #ffffff;
  --danger: #ef4444;
  --candidate: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #1a212b;
    --text: #e6eaee;
    --muted: #8b94a1;
    --border: #28303b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --candidate: #fbbf24;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans",
    "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: clamp(1.4rem, 4vw, 2rem); }
h2 { font-size: clamp(1.1rem, 3vw, 1.5rem); }
a { color: var(--primary); }

.muted { color: var(--muted); }
.badge {
  display: inline-block; padding: 0.1rem 0.5rem; margin: 0.15rem 0;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em;
  color: var(--primary-ink); background: var(--primary); border-radius: 999px;
}
.row { display: flex; align-items: center; gap: 0.5rem; }
.row--end { justify-content: flex-end; }
.row--between { justify-content: space-between; align-items: center; }
.row--gap { gap: 0.5rem; flex-wrap: wrap; }

/* app shell */
.app { display: flex; flex-direction: column; min-height: 100dvh; }
.app__header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: calc(0.75rem + var(--safe-top));
}
.brand { line-height: 1.1; }
.brand__name { font-weight: 700; font-size: 1.15rem; }
.brand__tagline { color: var(--muted); font-size: 0.8rem; }
.nav { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.nav__link { text-decoration: none; color: var(--text); padding: 0.4rem 0.6rem; border-radius: 8px; }
.nav__link.is-active { background: var(--primary); color: var(--primary-ink); }
.app__main { flex: 1; padding: 1rem; max-width: 1080px; width: 100%; margin: 0 auto; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: 1px solid transparent; border-radius: 8px;
  padding: 0.55rem 1rem; font-size: 0.95rem; cursor: pointer;
  background: var(--surface); color: var(--text); border-color: var(--border);
  transition: background 0.15s, opacity 0.15s;
}
.btn--primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn--ghost { background: transparent; }
.btn--danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn--danger-ghost { color: var(--danger); border-color: var(--danger); }
.btn--sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  font-size: 1.1rem; cursor: pointer; padding: 0.2rem 0.4rem; border-radius: 6px;
}
.icon-btn:disabled { opacity: 0.3; }
.icon-btn--danger { color: var(--danger); }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; font-size: 0.95rem; }

/* candidate toggle switch (see screens/tripDetail.js) */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  display: inline-block; width: 34px; height: 20px; border-radius: 999px;
  background: var(--border); position: relative; flex: 0 0 auto;
  transition: background 0.15s;
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}
.switch input:checked + .switch__track { background: var(--candidate); }
.switch input:checked + .switch__track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.card--auth { max-width: 22rem; width: 100%; }
.card--form { max-width: 34rem; margin: 1rem 0; }
.center-screen { min-height: 70dvh; display: grid; place-items: center; padding: 1rem; }
.field { display: block; margin-bottom: 0.85rem; }
.field span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: 0.55rem 0.65rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text); font-size: 0.95rem;
}
.field textarea { min-height: 5rem; resize: vertical; }
.form-error { color: var(--danger); font-size: 0.85rem; margin: 0.5rem 0; }

/* location typeahead (see components/locationAutocomplete.js) */
.nomi { position: relative; }
.nomi-list {
  display: none;
  position: absolute; top: calc(100% + 0.25rem); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); overflow: auto; max-height: 15rem;
}
.nomi-list.is-open { display: block; }
.nomi-status { padding: 0.5rem 0.65rem; color: var(--muted); font-size: 0.85rem; }
.nomi-item { padding: 0.45rem 0.65rem; cursor: pointer; }
.nomi-item.is-active { background: var(--primary); }
.nomi-item.is-active .nomi-item__name { color: var(--primary-ink); }
.nomi-item.is-active .nomi-item__sub { color: rgba(255, 255, 255, 0.8); }
.nomi-item__name { font-size: 0.95rem; }
.nomi-item__sub { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* location mode switch (name vs lat/lng) */
.nomi-seg { display: flex; gap: 0.25rem; margin-bottom: 0.45rem; }
.seg {
  flex: 1; border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: 0.3rem 0.5rem; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
}
.seg.is-active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.nomi-latlng input { flex: 1; }
.nomi-latlng input.is-invalid { border-color: var(--danger); }
.nomi-err { margin: 0.4rem 0 0; }

/* locale-aware date/datetime display (see components/datefield.js) */
.datefield { position: relative; }
.datefield__text {
  display: none;
  position: absolute; top: 50%; left: 0.65rem; right: 2.6rem;
  transform: translateY(-50%);
  pointer-events: none; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.datefield--zh input { color: transparent; caret-color: transparent; }
.datefield--zh input::-webkit-datetime-edit { color: transparent; }
.datefield--zh input::-webkit-calendar-picker-indicator { color: var(--text); opacity: 1; }
.datefield--zh .datefield__text { display: block; color: var(--text); }

/* states (loading/empty/error) */
.state { text-align: center; color: var(--muted); padding: 3rem 1rem; display: grid; gap: 1rem; place-items: center; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* grids */
.grid { display: grid; gap: 1rem; }
.grid--cards { grid-template-columns: 1fr; }
.trip-card { cursor: pointer; }
.trip-card h2 { margin-bottom: 0.25rem; }

/* timeline */
.timeline { display: grid; gap: 0.75rem; margin-top: 1rem; }
.item { display: flex; align-items: center; gap: 0.75rem; }
.item__badge {
  flex: 0 0 auto; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--primary); border: 1px solid var(--primary); border-radius: 999px; padding: 0.15rem 0.5rem;
}
.item--leg .item__badge { color: #10b981; border-color: #10b981; }
.item--event .item__badge { color: #f59e0b; border-color: #f59e0b; }
.item__body { flex: 1; min-width: 0; }
.item__body h3 { margin: 0; font-size: 1rem; }
.item__actions { flex: 0 0 auto; }
.item--candidate { border-style: dashed; opacity: 0.85; }
.item--candidate .item__badge { color: var(--candidate); border-color: var(--candidate); }
.item--candidate h3 { color: var(--muted); }

/* tabs */
.tabs { display: flex; gap: 0.4rem; margin: 1rem 0; overflow-x: auto; }
.tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 0.4rem 0.8rem; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tab.is-active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* media */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.6rem; margin-top: 1rem; }
.media-tile { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--border); margin: 0; }
.media-tile img, .media-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile__del {
  position: absolute; top: 0.25rem; right: 0.25rem; z-index: 2;
  background: rgba(0,0,0,0.6); color: #fff; border: none; border-radius: 50%;
  width: 1.4rem; height: 1.4rem; cursor: pointer; line-height: 1.4rem;
}
.media-tile__caption {
  position: absolute; bottom: 0; left: 0; right: 0; font-size: 0.7rem;
  padding: 0.2rem 0.4rem; background: rgba(0,0,0,0.55); color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 1rem; }
.chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.25rem 0.7rem; font-size: 0.85rem;
}

/* map */
.map-searchbar { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.map-search { flex: 1; padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.map-container { height: 45vh; min-height: 20rem; border-radius: var(--radius); overflow: hidden; }
.map-marker-num {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink);
  border: 2px solid var(--surface);
  font-size: 0.8rem; font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.map-marker-num.is-candidate { background: var(--candidate); border-style: dashed; opacity: 0.85; }
.map-arrow {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
  font-size: 1.1rem; line-height: 1;
  color: var(--primary);
  text-shadow: 0 0 2px var(--surface), 0 0 3px var(--surface);
  pointer-events: none;
}
@media (orientation: landscape) and (max-height: 500px) {
  .map-container { height: 40vh; }
}

/* toasts */
.toasts { position: fixed; bottom: calc(1rem + var(--safe-bottom)); left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 0.5rem; width: min(92vw, 26rem); }
.toast { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 1rem; box-shadow: var(--shadow); text-align: center; }
.toast--danger { border-color: var(--danger); color: var(--danger); }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 60; display: grid; place-items: center; padding: 1rem; }
.modal.box { width: min(94vw, 26rem); }

/* item media miniatures + fullscreen lightbox */
.item__media { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.item__media .media-tile { width: 3.5rem; height: 3.5rem; cursor: zoom-in; }
.item__media .media-tile img, .item__media .media-tile video { cursor: zoom-in; }
.lightbox { background: rgba(0,0,0,0.94); padding: 0; }
.lightbox img, .lightbox video { width: 100%; height: 100%; max-width: 100vw; max-height: 100dvh; object-fit: contain; }

/* split trip layout: timeline left, persistent map right */
.trip-content--split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
}
.trip-pane { min-width: 0; min-height: 0; }
.trip-pane--right {
  display: flex;
  flex-direction: column;
}
.trip-pane--right .map-searchbar { margin-top: 0; }
.trip-pane--right .map-container { height: 60vh; flex: 1; }
@media (orientation: landscape) and (max-height: 500px) {
  .trip-pane--right .map-container { height: 40vh; }
}

/* responsive */
@media (min-width: 480px) {
  .grid--cards { grid-template-columns: repeat(2, 1fr); }
  .trip-content--split { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
}
@media (min-width: 768px) {
  .app__main { padding: 1.5rem; }
  .grid--cards { grid-template-columns: repeat(3, 1fr); }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .map-container { height: 60vh; }
}
@media (min-width: 1024px) {
  .grid--cards { grid-template-columns: repeat(4, 1fr); }
}
