:root {
  --teal: #0f3d3e;
  --ink: #14221f;
  --muted: #5c6f6a;
  --line: #e4ece8;
  --bg: #f3f6f5;
  --card: #ffffff;
  --live: #1f8a68;
  --amber: #9a6708;
  --amber-bg: #fff6e4;
  --radius: 12px;
  --control: 40px;
  --font: "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

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

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(220px, 42dvh);
}

.stage { order: 1; }
.rail { order: 2; }

.stage {
  position: relative;
  min-height: 0;
  background: #d7e2dc;
}

.map { position: absolute; inset: 0; }

.map-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #e7efeb;
}

.map-fallback[hidden] { display: none; }

.fallback-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}

.fallback-card h2 { margin: 0 0 8px; font-size: 1.1rem; }
.fallback-card p { margin: 0; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.fallback-card code { font-size: 0.85em; }

.rail {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}

.rail-head,
.dialog-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 12px 16px;
}

.rail-head {
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.brand p,
.muted,
.fine,
.empty {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.brand p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-actions,
.btn-row,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rail-actions { flex-shrink: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-weight: 650;
  font-size: 0.9rem;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.btn-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #f7fbfa;
}

.btn-icon {
  width: var(--control);
  padding: 0;
}

.btn-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.btn.is-on {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.btn:disabled { opacity: 0.55; cursor: default; }

.detail {
  display: grid;
  flex: 0 0 auto;
  gap: 10px;
  padding: 12px 16px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfefd;
}

.detail[hidden] { display: none; }

.detail-copy h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}

.detail-copy p { margin: 4px 0 0; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.stat {
  min-height: 64px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eef6f2;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
}

.btn-row .btn { flex: 1; }

.field input,
.field select,
.stop-option {
  height: var(--control);
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1;
}

.field select {
  padding-right: 32px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.2L6 6.2L11 1.2' fill='none' stroke='%235c6f6a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px 6px;
}

.field[hidden],
#add-remind-field[hidden],
#add-remind-panel[hidden],
#add-remind-lock[hidden] { display: none; }

.fine { margin: 0; }

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

.time-range span { color: var(--muted); font-weight: 650; }

.card-list {
  min-height: 0;
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.card-list:empty { display: none; flex: 0; }

.empty { margin: 0; padding: 20px 16px; }

.card-wrap {
  display: grid;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.card-wrap.is-selected {
  border-color: var(--teal);
  box-shadow: inset 3px 0 0 var(--teal);
}

.card,
.card-tools { grid-row: 1; grid-column: 1; }

.card-alerts { grid-row: 2; grid-column: 1; }

.card {
  display: block;
  width: 100%;
  padding: 12px 86px 12px 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.card-top,
.card-metrics {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card h3 {
  margin: 8px 0 2px;
  font-size: 0.98rem;
  line-height: 1.3;
}

.card p { margin: 0; color: var(--muted); font-size: 0.8rem; line-height: 1.35; }

.card-tools {
  display: flex;
  align-items: center;
  justify-self: end;
  align-self: start;
  gap: 2px;
  height: 32px;
  margin: 7px 8px 0 0;
  z-index: 1;
}

.card-top .muted {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn svg {
  display: block;
  width: 16px;
  height: 16px;
}

.icon-btn:hover { background: #f3f6f5; color: var(--ink); }

.card-alerts {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  border-top: 1px solid var(--line);
}

.card-alert {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  margin: 0;
  padding: 6px 8px;
  border: 0;
  border-left: 1px solid var(--line);
  background: #f7fbfa;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.25;
  text-align: center;
}

.card-alert:first-child { border-left: 0; }

button.card-alert {
  cursor: pointer;
  color: var(--teal);
}

button.card-alert.is-on { background: #e7f6f0; }

.card-metrics { margin-top: 10px; }
.card-metrics strong { font-size: 1.05rem; color: var(--teal); }

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--amber-bg);
  color: var(--amber);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.03em;
}

.card.is-live .pill {
  background: #e7f6f0;
  color: var(--live);
}

.dialog {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(20, 34, 31, 0.18);
}

.dialog::backdrop { background: rgba(20, 34, 31, 0.45); }

.dialog form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 24px);
}

.dialog-bar { border-bottom: 1px solid var(--line); }
.dialog-bar h2 { margin: 0; font-size: 1.05rem; }
.dialog-actions {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.dialog-body {
  display: grid;
  gap: 12px;
  padding: 16px;
  overflow: auto;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--muted);
}

.stop-list {
  min-height: 80px;
  max-height: 160px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.stop-option {
  display: flex;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
  cursor: pointer;
}

.stop-option:last-child { border-bottom: 0; }
.stop-option.is-selected { background: #eef6f2; color: var(--teal); font-weight: 650; }

.map-stop-label {
  background: rgba(255, 255, 255, 0.94);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid #d5e0db;
  white-space: nowrap;
  transform: translateY(-2px);
}

@media (max-width: 959px) {
  .rail { overflow: auto; }
  .rail-head { position: sticky; top: 0; z-index: 2; }
  .card-list { flex: none; overflow: visible; }
}

@media (min-width: 960px) {
  .app {
    grid-template-columns: 400px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .rail {
    order: 1;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .stage { order: 2; min-height: 100dvh; }
}

@media (min-width: 960px) and (max-height: 640px) {
  .rail {
    overflow: auto;
  }

  .rail-head {
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .card-list {
    flex: none;
    overflow: visible;
  }

  .stat {
    min-height: 0;
    padding: 8px 10px;
  }

  .stat strong {
    font-size: 1rem;
  }
}

@media (max-width: 420px) {
  .rail-head { padding-inline: 12px; }
  .btn { padding-inline: 10px; }
}
