:root {
  --bg: #f6f7f4;
  --ink: #17211b;
  --muted: #5d6a61;
  --line: #d8ded7;
  --surface: #ffffff;
  --accent: #1d6b4f;
  --accent-strong: #124331;
  --accent-soft: #dfeee8;
  --warning: #9a4d16;
  --error: #a52d2d;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 4vw, 56px);
  background: rgba(246, 247, 244, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

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

h1 {
  font-size: clamp(1.25rem, 2vw, 1.7rem);
}

h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
}

h3 {
  font-size: 1.12rem;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 100%;
}

.tabs a {
  min-height: 44px;
  color: var(--ink);
  padding: 8px 12px;
  text-decoration: none;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

.tabs a:hover {
  background: var(--accent-soft);
}

.tabs .internal-tool-link {
  width: 38px;
  min-height: 38px;
  justify-content: center;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 1rem;
}

.tabs .internal-tool-link:hover,
.tabs .internal-tool-link:focus-visible {
  border-color: var(--line);
  background: #fff;
  outline: 2px solid rgba(29, 107, 79, 0.18);
  outline-offset: 2px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  background: #f3ead8;
}

.hero-banner {
  margin: 0;
  padding: clamp(12px, 2vw, 24px) clamp(12px, 4vw, 56px) 0;
}

.hero-banner img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #f3ead8;
  object-fit: contain;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: clamp(24px, 4vw, 48px) clamp(18px, 4vw, 56px) clamp(30px, 5vw, 56px);
}

.hero-copy p {
  max-width: 34rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.8;
}

.content-section {
  padding: 56px clamp(18px, 4vw, 56px);
}

.login-section:not(:target),
.protected-section:not(:target) {
  display: none;
}

.login-section:target {
  display: block;
}

.band {
  background: #edf2ee;
}

.section-heading {
  display: grid;
  gap: 4px;
  margin-bottom: 22px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.route-card,
.plan-row,
.booking-form,
.result-panel,
.lookup-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.route-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  min-width: 0;
}

.card-topline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.92rem;
}

.meta {
  color: var(--muted);
}

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

.tags span {
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.88rem;
}

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

.protected-entry-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}

.protected-entry-icon {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-size: 1.15rem;
}

.protected-entry-icon:hover,
.protected-entry-icon:focus-visible {
  border-color: var(--accent);
  outline: 2px solid rgba(37, 99, 235, 0.18);
  outline-offset: 2px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding-inline: 14px;
  touch-action: manipulation;
}

.book-route,
.primary-action {
  background: var(--accent);
  color: #fff;
}

.primary-action:disabled,
.primary-action.is-complete {
  cursor: default;
  opacity: 0.78;
}

.route-detail {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent-strong);
  background: #fff;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  overflow-wrap: anywhere;
}

.secondary-action {
  padding-inline: 18px;
  background: var(--ink);
  color: #fff;
}

.unavailable {
  color: var(--warning);
  font-weight: 700;
}

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

.plan-row {
  padding: 18px;
}

dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 18px;
  margin: 14px 0 0;
}

dt {
  color: var(--muted);
  font-size: 0.86rem;
}

dd {
  margin: 3px 0 0;
  line-height: 1.6;
}

.booking-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 20px;
}

.booking-layout .section-heading {
  grid-column: 1 / -1;
}

.booking-form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.radio-field {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.radio-field legend {
  padding: 0;
}

.radio-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #c7d0c8;
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-size: 16px;
}

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

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

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
}

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

.consent {
  align-items: flex-start;
  line-height: 1.6;
}

.notice,
.errors {
  color: var(--error);
  font-weight: 700;
}

.errors ul {
  margin: 0;
  padding-left: 20px;
}

.result-panel {
  align-self: start;
  display: grid;
  gap: 10px;
  padding: 20px;
}

.result-panel strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 1.2rem;
}

.result-note {
  color: var(--muted);
  line-height: 1.7;
}

.lookup-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.lookup-form button {
  align-self: stretch;
}

.lookup-result {
  margin-top: 16px;
}

.lookup-card {
  padding: 18px;
}

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

.protected-section {
  padding: 0;
  background: transparent;
}

.protected-section:target {
  padding: 28px clamp(16px, 5vw, 56px);
}

.admin-section {
  background: transparent;
}

.admin-section:target {
  background: #f9faf7;
}

.leader-section:target {
  background: #f2f7f5;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
}

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

.admin-section-heading h3 {
  margin: 0;
}

.hint {
  color: var(--muted);
  line-height: 1.6;
}

.field-hint {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.55;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stats-group {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.stat .num {
  font-size: 1.45rem;
  font-weight: 800;
}

.stat .lbl {
  color: var(--muted);
  font-size: 0.88rem;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.admin-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.admin-table th {
  color: var(--muted);
  background: #f3f6f1;
  font-size: 0.82rem;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 220px;
}

.small-action {
  min-height: 36px;
  padding: 0 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.84rem;
}

.small-action.danger {
  background: var(--error);
}

.manual-assignment-fields {
  display: grid;
  gap: 8px;
  flex: 1 1 260px;
  min-width: 260px;
}

.manual-assignment-fields .hint {
  margin: 0;
  font-size: 0.82rem;
}

.manual-assignment-fields label {
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}

.manual-assignment-fields input,
.manual-assignment-fields textarea,
.leader-select,
.insurance-select {
  min-height: 36px;
  padding: 5px 8px;
  font-size: 16px;
}

.manual-assignment-fields textarea {
  resize: vertical;
}

.admin-detail {
  margin-top: 16px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
}

.admin-detail-layer {
  display: none;
}

.admin-detail-layer.is-open {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 48px);
}

.admin-detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 33, 27, 0.48);
}

.admin-detail-modal {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  max-height: min(84vh, 760px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(23, 33, 27, 0.22);
  outline: 3px solid rgba(29, 107, 79, 0.18);
}

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

.admin-detail-modal dl {
  margin: 0;
}

.system-settings-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 18px;
}

.settings-grid dt {
  color: var(--muted);
  font-size: 0.86rem;
}

.settings-grid dd {
  margin: 3px 0 0;
  font-weight: 700;
}

.settings-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  align-items: end;
}

.hidden {
  display: none !important;
}

@media (max-width: 1024px) {
  .content-section {
    padding: 44px clamp(16px, 3vw, 32px);
  }

  .booking-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .result-panel {
    width: 100%;
  }

  .admin-stats {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

@media (max-width: 760px) {
  .hero,
  .booking-layout,
  .lookup-form {
    grid-template-columns: 1fr;
  }

  .app-header {
    position: static;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
  }

  .tabs {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }

  .tabs a {
    flex: 0 0 auto;
  }

  .hero-banner {
    padding: 10px 10px 0;
  }

  .hero-banner img {
    border-radius: 6px;
  }

  .hero-copy {
    padding: 26px 18px 32px;
  }

  .content-section {
    padding: 36px 16px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .route-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .route-detail,
  .book-route,
  .primary-action,
  .secondary-action {
    width: 100%;
  }

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

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

  .booking-form,
  .result-panel,
  .lookup-card,
  .admin-detail,
  .admin-detail-modal,
  .system-settings-panel {
    padding: 16px;
  }

  .admin-detail-layer.is-open {
    align-items: start;
    padding: 12px;
  }

  .admin-detail-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .stat {
    padding: 12px;
  }

  .stat .num {
    font-size: 1.25rem;
  }

  .admin-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .admin-table {
    min-width: 920px;
    font-size: 0.86rem;
  }

  .admin-actions {
    min-width: 180px;
  }

  .small-action {
    min-height: 44px;
    flex: 1 1 100%;
  }

  .manual-assignment-fields {
    min-width: 100%;
  }

  .leader-select,
  .insurance-select {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 430px) {
  h2 {
    font-size: 1.42rem;
  }

  .app-header h1 {
    font-size: 1.22rem;
  }

  .hero-banner {
    padding-inline: 8px;
  }

  .admin-stats {
    grid-template-columns: 1fr;
  }

  .card-topline {
    display: grid;
  }

  .tags span {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
}
