:root {
  color-scheme: light;
  --bg: #f6f4ee;
  --panel: #ffffff;
  --ink: #1d2935;
  --muted: #64748b;
  --line: #d9ded8;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --amber: #b7791f;
  --red: #b42318;
  --green-soft: #ddf3ed;
  --amber-soft: #fff4d6;
  --red-soft: #ffe4df;
  --shadow: 0 18px 45px rgba(29, 41, 53, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 0.88rem;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 1.22rem;
}

.today-pill {
  min-width: 112px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border: 1px solid #c6d8d3;
  border-radius: 8px;
  background: linear-gradient(120deg, #0f766e, #174e62 62%, #7a4f16);
  box-shadow: var(--shadow);
}

.summary-item {
  min-height: 98px;
  padding: 18px;
  border-right: 1px solid rgba(255, 255, 255, 0.24);
  color: white;
}

.summary-item:last-child {
  border-right: 0;
}

.summary-value {
  display: block;
  font-size: clamp(1.9rem, 5vw, 3rem);
  font-weight: 800;
  line-height: 1;
}

.summary-label {
  display: block;
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.92rem;
}

.planner-switch {
  display: none;
}

.pane-tab {
  min-width: 0;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.pane-tab.active {
  background: #ffffff;
  color: var(--teal-dark);
  box-shadow: 0 3px 10px rgba(29, 41, 53, 0.08);
}

.planner-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.planner-pane {
  min-width: 0;
}

.trip-form,
.calendar-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(29, 41, 53, 0.08);
}

.trip-form {
  order: 2;
  position: sticky;
  top: 16px;
  display: grid;
  gap: 14px;
  padding: 18px;
}

.calendar-panel {
  order: 1;
  padding: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 0.9rem;
  font-weight: 700;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.compact-action {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.distance-status {
  min-height: 20px;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5d1;
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  padding: 10px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.time-selects,
.select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.select-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.time-colon {
  color: var(--muted);
  font-weight: 900;
}

.quick-panel {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.quick-panel + .quick-panel {
  margin-top: -14px;
  border-top: 0;
}

.compact-title h2 {
  font-size: 1rem;
}

.form-actions,
.toolbar,
.trip-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.secondary-button,
.ghost-button,
.mini-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  flex: 1;
  background: var(--teal);
  color: white;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--teal-dark);
}

.secondary-button,
.mini-button {
  background: #f8faf9;
  border-color: #cbd5d1;
  color: #243442;
}

.secondary-button:hover,
.mini-button:hover,
.secondary-button:focus-visible,
.mini-button:focus-visible {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.ghost-button {
  min-height: 36px;
  background: transparent;
  border-color: #cbd5d1;
  color: var(--teal-dark);
}

.danger-soft {
  color: var(--red);
}

.view-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 16px 0 12px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2ef;
}

.tab-button {
  min-width: 0;
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab-button.active {
  background: #ffffff;
  color: var(--teal-dark);
  box-shadow: 0 3px 10px rgba(29, 41, 53, 0.08);
}

.toolbar {
  justify-content: flex-end;
  margin-bottom: 14px;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 28px 18px;
  border: 1px dashed #b7c5c0;
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.empty-state.hidden {
  display: none;
}

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

.trip-card {
  border: 1px solid var(--line);
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.trip-card.done {
  border-left-color: #70816d;
  opacity: 0.82;
}

.trip-card.cancelled {
  border-left-color: var(--red);
  background: #fffafa;
}

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

.time-block {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
}

.trip-time {
  color: var(--teal-dark);
  font-size: 1.42rem;
  font-weight: 900;
  line-height: 1;
}

.trip-date {
  color: var(--muted);
  font-size: 0.82rem;
}

.trip-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.trip-route {
  margin-bottom: 8px;
  font-size: 1rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.status-badge {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.status-badge.done {
  background: #edf2ea;
  color: #52634f;
}

.status-badge.cancelled {
  background: var(--red-soft);
  color: var(--red);
}

.trip-meta,
.trip-notes {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.trip-notes {
  margin-top: 8px;
  color: #425466;
}

.trip-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.mini-button {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.86rem;
}

.delete-button {
  color: var(--red);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  width: min(360px, calc(100vw - 36px));
  border: 1px solid #bee1d8;
  border-radius: 8px;
  background: #ecfff9;
  color: #123832;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-weight: 800;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .today-pill {
    width: 100%;
    text-align: left;
  }

  .summary-band,
  .planner-layout {
    grid-template-columns: 1fr;
  }

  .planner-switch {
    position: sticky;
    top: 0;
    z-index: 6;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-top: 14px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef2ef;
    box-shadow: 0 8px 22px rgba(29, 41, 53, 0.08);
  }

  .planner-layout {
    margin-top: 12px;
  }

  .trip-form {
    position: static;
  }

  .trip-form,
  .calendar-panel {
    order: initial;
  }

  .planner-layout[data-active-panel="trips"] .trip-form,
  .planner-layout[data-active-panel="form"] .calendar-panel {
    display: none;
  }
}

@media (max-width: 520px) {
  .field-grid {
    grid-template-columns: 1fr;
  }

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

  .summary-item {
    min-height: 82px;
    padding: 14px 10px;
  }

  .summary-label {
    font-size: 0.8rem;
  }

  .view-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .time-selects {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .select-row {
    grid-template-columns: 1fr;
  }

  .trip-main {
    grid-template-columns: 1fr;
  }

  .trip-title-row {
    flex-direction: column;
  }

  .trip-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mini-button {
    width: 100%;
  }
}
