:root {
  color-scheme: light;
  --ink: #142522;
  --muted: #65706b;
  --paper: #f7f1e6;
  --paper-strong: #fffaf0;
  --line: #d9d0bf;
  --pine: #1f3d3b;
  --pine-2: #28534e;
  --clay: #b94f3b;
  --sun: #f0bd4b;
  --lake: #3b7f92;
  --leaf: #5d7a43;
  --white: #ffffff;
  --shadow: 0 14px 34px rgba(20, 37, 34, 0.14);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(240, 189, 75, 0.22), transparent 22rem),
    radial-gradient(circle at 88% 8%, rgba(59, 127, 146, 0.18), transparent 20rem),
    linear-gradient(135deg, #f7f1e6 0%, #edf5ef 46%, #f8eee4 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
}

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 16px;
  text-align: center;
  color: var(--muted);
}

.layout {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px 18px calc(88px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0 14px;
  background: linear-gradient(180deg, rgba(247, 241, 230, 0.96), rgba(247, 241, 230, 0.82));
  backdrop-filter: blur(14px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--pine);
  box-shadow: 0 10px 18px rgba(31, 61, 59, 0.2);
  color: var(--paper-strong);
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.1rem, 3vw, 1.7rem);
  line-height: 1.05;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.shell-grid {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.rail {
  position: sticky;
  top: 82px;
  display: grid;
  gap: 12px;
}

.panel,
.stat-card,
.trip-card,
.memory-card,
.expense-row,
.stop-row,
.share-card,
.map-detail,
.empty-state {
  border: 1px solid rgba(20, 37, 34, 0.1);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 0 8px 24px rgba(20, 37, 34, 0.07);
}

.panel {
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 1rem;
}

.small,
.meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn,
.icon-btn,
.tab-btn,
.chip,
.category-chip {
  min-height: 40px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: var(--white);
  border: 1px solid rgba(20, 37, 34, 0.14);
  cursor: pointer;
  text-decoration: none;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.btn {
  padding: 0 12px;
  font-weight: 800;
}

.btn:hover,
.icon-btn:hover,
.tab-btn:hover,
.chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(20, 37, 34, 0.12);
}

.btn.primary {
  background: var(--pine);
  color: var(--paper-strong);
  border-color: var(--pine);
}

.btn.warn {
  background: var(--clay);
  color: var(--paper-strong);
  border-color: var(--clay);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.62);
}

.icon-btn {
  width: 40px;
  padding: 0;
  font-weight: 900;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tab-btn {
  padding: 10px 8px;
  flex-direction: column;
  font-size: 0.78rem;
  color: var(--muted);
}

.tab-btn .tab-icon {
  font-size: 1.08rem;
  color: var(--ink);
}

.tab-btn.active {
  background: var(--pine);
  color: var(--paper-strong);
  border-color: var(--pine);
}

.tab-btn.active .tab-icon {
  color: var(--paper-strong);
}

.mobile-tabs {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 30;
  display: none;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(20, 37, 34, 0.14);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.96);
  box-shadow: var(--shadow);
}

.mobile-tabs .tab-btn {
  min-height: 48px;
  padding: 6px 4px;
}

.trip-list {
  display: grid;
  gap: 8px;
}

.trip-button {
  width: 100%;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  text-align: left;
  border: 1px solid rgba(20, 37, 34, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
}

.trip-button.active {
  border-color: var(--pine);
  background: rgba(31, 61, 59, 0.08);
}

.thumb {
  min-width: 0;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--lake);
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--paper-strong);
  font-weight: 900;
}

.thumb img,
.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-failed {
  background:
    linear-gradient(135deg, rgba(31, 61, 59, 0.9), rgba(59, 127, 146, 0.76)),
    var(--lake);
}

.image-failed::before {
  content: "Photo";
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--paper-strong);
  font-size: 0.78rem;
  font-weight: 900;
}

.trip-button strong,
.trip-button span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.trip-button .small {
  display: block;
}

.content {
  display: grid;
  gap: 16px;
}

.hero-board {
  position: relative;
  overflow: hidden;
  min-height: 320px;
  padding: 22px;
  color: var(--paper-strong);
  border-radius: 8px;
  background:
    linear-gradient(110deg, rgba(20, 37, 34, 0.9), rgba(31, 61, 59, 0.65)),
    var(--hero-image, linear-gradient(135deg, var(--pine), var(--lake)));
  background-size: cover;
  background-position: center;
  box-shadow: var(--shadow);
}

.hero-board::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 44%;
  background: linear-gradient(0deg, rgba(20, 37, 34, 0.78), transparent);
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 278px;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.hero-title {
  max-width: 720px;
}

.hero-title h2 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 4.4rem);
  line-height: 0.96;
}

.hero-title p {
  max-width: 580px;
  margin: 12px 0 0;
  color: rgba(255, 250, 240, 0.82);
  font-size: 1rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-actions .btn {
  background: rgba(255, 250, 240, 0.94);
}

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

.stat-card {
  padding: 14px;
}

.stat-card b {
  display: block;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  line-height: 1;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.84rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid rgba(20, 37, 34, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  padding: 9px 10px;
}

textarea {
  min-height: 98px;
  resize: vertical;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
  text-transform: none;
}

.checkline input {
  width: 18px;
  min-height: 18px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.trip-card,
.memory-card,
.share-card,
.empty-state {
  padding: 14px;
}

.trip-card h3,
.memory-card h3,
.share-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
}

.trip-card {
  display: grid;
  gap: 12px;
}

.trip-cover {
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: var(--lake);
}

.trip-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip,
.category-chip {
  min-height: 30px;
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--pine);
  background: rgba(31, 61, 59, 0.08);
}

.category-chip[data-category="Campground"] { color: #3f5f2f; background: rgba(93, 122, 67, 0.16); }
.category-chip[data-category="Waterfall"] { color: #296b7c; background: rgba(59, 127, 146, 0.16); }
.category-chip[data-category="Mountain"] { color: #584a2f; background: rgba(170, 130, 57, 0.18); }
.category-chip[data-category="Scenic Drive"] { color: #8b412f; background: rgba(185, 79, 59, 0.15); }
.category-chip[data-category="Beach"] { color: #246c62; background: rgba(57, 141, 124, 0.15); }
.category-chip[data-category="Garden"] { color: #4f6c35; background: rgba(93, 122, 67, 0.17); }
.category-chip[data-category="Lake"] { color: #296b7c; background: rgba(59, 127, 146, 0.14); }
.category-chip[data-category="Attraction"] { color: #7d4f22; background: rgba(240, 189, 75, 0.18); }
.category-chip[data-category="Food"] { color: #8b412f; background: rgba(185, 79, 59, 0.13); }
.category-chip[data-category="Fuel"] { color: #384c48; background: rgba(31, 61, 59, 0.12); }

.stop-list,
.expense-list,
.memory-grid {
  display: grid;
  gap: 10px;
}

.stop-row,
.expense-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.78);
}

.stop-row-top,
.expense-row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.rating {
  color: #9d7424;
  white-space: nowrap;
}

.photo-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 8px;
}

.photo {
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: #d9d0bf;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(54px, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: rgba(20, 37, 34, 0.08);
}

.segmented-btn {
  min-height: 32px;
  border-radius: 6px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.segmented-btn.active {
  color: var(--paper-strong);
  background: var(--pine);
}

.real-map {
  position: relative;
  min-height: 540px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(20, 37, 34, 0.12);
  background: #dce9dd;
  z-index: 0;
}

.map-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.leaflet-container {
  font: inherit;
  background: #dce9dd;
}

.leaflet-control-attribution {
  font-size: 0.68rem;
}

.gb-map-marker {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 9px 9px 9px 0;
  background: var(--clay);
  box-shadow: 0 10px 20px rgba(20, 37, 34, 0.2);
  border: 2px solid var(--paper-strong);
  transform: rotate(-45deg);
}

.gb-map-marker span {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--paper-strong);
}

.gb-map-marker.favorite {
  background: var(--sun);
}

.gb-map-marker.active {
  background: var(--pine);
  transform: rotate(-45deg) scale(1.18);
}

.map-popup {
  display: grid;
  gap: 5px;
  min-width: 190px;
}

.map-popup img {
  width: 100%;
  height: 92px;
  object-fit: cover;
  border-radius: 6px;
}

.map-popup strong,
.map-popup span {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.map-popup span {
  color: var(--muted);
  font-size: 0.82rem;
}

.map-detail {
  padding: 14px;
  min-height: 180px;
}

.expense-bars {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 74px;
  gap: 8px;
  align-items: center;
  font-size: 0.86rem;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(20, 37, 34, 0.08);
}

.bar-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--lake), var(--sun));
}

.caption-output {
  min-height: 210px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid rgba(20, 37, 34, 0.14);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.7fr);
  gap: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-bottom));
  z-index: 60;
  transform: translateX(-50%) translateY(20px);
  max-width: min(520px, calc(100vw - 28px));
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--paper-strong);
  background: var(--pine);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.screen-reader-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@media (max-width: 1120px) {
  .shell-grid {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .kpi-grid,
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-2,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .layout {
    padding: 10px 10px calc(86px + var(--safe-bottom));
  }

  .topbar {
    grid-template-columns: 1fr;
    position: relative;
    padding-top: 10px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
  }

  .top-actions .btn {
    width: 100%;
    min-width: 0;
    padding: 0 8px;
    white-space: nowrap;
  }

  .top-actions [data-view="trips"] {
    grid-column: 1 / -1;
  }

  .shell-grid {
    display: block;
  }

  .rail {
    position: static;
    margin-bottom: 12px;
  }

  .rail .tab-panel {
    display: none;
  }

  .mobile-tabs {
    display: grid;
  }

  .trip-list {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    overflow: visible;
  }

  .hero-board {
    min-height: 0;
    padding: 18px;
  }

  .hero-inner {
    display: block;
    min-height: 0;
  }

  .hero-title h2 {
    max-width: 100%;
    font-size: clamp(1.85rem, 9vw, 2.25rem);
    line-height: 1.04;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .hero-actions {
    margin-top: 18px;
  }

  .form-grid,
  .kpi-grid,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .real-map {
    min-height: 430px;
  }

  .bar-row {
    grid-template-columns: 88px minmax(0, 1fr) 64px;
  }
}

@media (max-width: 500px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .top-actions .btn {
    font-size: 0.92rem;
  }

  .mobile-tabs .tab-btn span:not(.tab-icon) {
    font-size: 0.68rem;
  }

  .hero-title h2 {
    font-size: 2.25rem;
  }

  .panel,
  .trip-card,
  .memory-card,
  .share-card {
    padding: 12px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .rail,
  .mobile-tabs,
  .btn,
  .icon-btn,
  .toast,
  form,
  .no-print {
    display: none !important;
  }

  .layout {
    width: 100%;
    padding: 0;
  }

  .shell-grid,
  .grid-2,
  .settings-grid {
    display: block;
  }

  .panel,
  .memory-card,
  .trip-card {
    box-shadow: none;
    break-inside: avoid;
    border-color: #aaa;
  }
}
