:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #eef4ee;
  --ink: #16211d;
  --muted: #5e6b66;
  --line: #d9e0dc;
  --accent: #167a64;
  --accent-dark: #0c5f4d;
  --accent-soft: #dff2eb;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #117a37;
  --shadow: 0 18px 45px rgba(19, 35, 29, 0.08);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 0;
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 68px;
  padding: 12px 28px;
  background: rgba(246, 247, 244, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand-name {
  font-weight: 800;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  background: #e8eeea;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.tab.active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 4px 14px rgba(20, 31, 28, 0.08);
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.sidebar,
.map-zone,
.panel,
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  min-height: calc(100vh - 104px);
  overflow: hidden;
}

.pane {
  display: none;
  padding: 18px;
}

.pane.active {
  display: block;
}

.pane-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

.hint,
.muted {
  color: var(--muted);
}

.hint {
  margin: 4px 0 0;
  font-size: 13px;
}

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

.field {
  display: grid;
  gap: 6px;
}

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

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  padding: 9px 10px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 7px;
  background: #eef2ef;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-dark);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.btn.danger {
  background: #fee4df;
  color: var(--danger);
}

.btn.icon {
  width: 40px;
  padding: 0;
}

.stack {
  display: grid;
  gap: 12px;
}

.divider {
  height: 1px;
  margin: 18px -18px;
  background: var(--line);
}

.list {
  display: grid;
  gap: 10px;
}

.item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.item-title {
  font-weight: 800;
}

.item-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pill.ok {
  background: #dcfce7;
  color: var(--ok);
}

.pill.warn {
  background: #fef3c7;
  color: var(--warn);
}

.pill.danger {
  background: #fee4df;
  color: var(--danger);
}

.route-builder {
  display: grid;
  gap: 14px;
}

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

.visit-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.num {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.row-buttons {
  display: flex;
  gap: 5px;
}

.map-zone {
  position: sticky;
  top: 86px;
  min-height: calc(100vh - 104px);
  overflow: hidden;
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.map {
  position: relative;
  height: min(62vh, 650px);
  min-height: 390px;
  overflow: hidden;
  background: #dfe8e2;
}

#googleMap {
  display: none;
  width: 100%;
  height: 100%;
}

.fallback-map {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(22, 122, 100, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(22, 122, 100, 0.08) 1px, transparent 1px),
    #edf3ef;
  background-size: 42px 42px;
}

.fallback-line {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.fallback-pin {
  position: absolute;
  transform: translate(-50%, -100%);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50% 50% 50% 5px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  rotate: -45deg;
  box-shadow: 0 8px 20px rgba(10, 47, 39, 0.24);
}

.fallback-pin span {
  rotate: 45deg;
}

.fallback-pin.origin {
  background: #1f2937;
}

.map-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}

.summary-cell {
  padding: 14px;
  border-right: 1px solid var(--line);
}

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

.summary-value {
  font-size: 22px;
  font-weight: 900;
}

.legs {
  max-height: 230px;
  overflow: auto;
  padding: 14px;
}

.leg {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.leg:last-child {
  border-bottom: 0;
}

.share-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

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

.metric {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric strong {
  display: block;
  font-size: 28px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(13, 22, 19, 0.48);
}

.modal.active {
  display: flex;
}

.modal-panel {
  width: min(900px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 18px;
}

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

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

.photo-preview img {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: none;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #10211c;
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.show {
  display: block;
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .tabs {
    overflow-x: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .map-zone {
    position: static;
    min-height: 0;
  }
}

@media (max-width: 620px) {
  .form-grid,
  .review-grid,
  .admin-grid,
  .map-summary {
    grid-template-columns: 1fr;
  }

  .summary-cell {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-cell:last-child {
    border-bottom: 0;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
