:root {
  --bg: #e8f1f4;
  --bg-deep: #0b3d4a;
  --surface: #f7fbfc;
  --ink: #12323a;
  --muted: #5a727a;
  --line: #c5d8de;
  --accent: #0e8a9a;
  --accent-2: #f0a202;
  --danger: #c23b22;
  --ok: #1f7a4c;
  --pin-public: #0e8a9a;
  --pin-private: #c45c26;
  --pin-deleted: #8a8a8a;
  --shadow: 0 10px 30px rgba(11, 61, 74, 0.12);
  --radius: 14px;
  --font: "Sora", "Noto Sans TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #b9e4ec 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #ffe4b0 0%, transparent 45%),
    var(--bg);
}

/* Side menu floats over content so map/main size never changes on toggle */
.app {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
  position: relative;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(240px, 85vw);
  height: 100vh;
  z-index: 1500;
  background: linear-gradient(180deg, #0b3d4a 0%, #145868 100%);
  color: #eef8fa;
  padding: 1.4rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: transform 0.22s ease, opacity 0.22s ease, box-shadow 0.22s ease;
  overflow: auto;
  min-width: 0;
  box-shadow: none;
  transform: translateX(-100%);
  pointer-events: none;
  opacity: 0;
}
.app.sidebar-hover .sidebar,
.app.sidebar-open .sidebar,
.app.sidebar-pinned .sidebar {
  transform: none;
  pointer-events: auto;
  opacity: 1;
  box-shadow: 8px 0 28px rgba(11, 61, 74, 0.28);
}

#menu-toggle[aria-expanded="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sidebar-foot {
  margin-top: auto;
  padding: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.7;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  padding-bottom: 0.35rem;
}
.sidebar-top .brand {
  flex: 1;
  min-width: 0;
  border-bottom: 0;
  padding-bottom: 0.65rem;
}
.sidebar-pin {
  flex-shrink: 0;
  margin-top: 0.35rem;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: #eef8fa;
}
.sidebar-pin[aria-pressed="true"] {
  background: var(--accent-2);
  border-color: #c98400;
  color: #1a1200;
}
.brand {
  padding: 0.4rem 0.6rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}
.brand p {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  opacity: 0.75;
}

.nav { display: flex; flex-direction: column; gap: 0.35rem; }
.nav button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
}
.nav button:hover { background: rgba(255,255,255,0.08); }
.nav button.active { background: rgba(240, 162, 2, 0.22); outline: 1px solid rgba(240,162,2,0.45); }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem 0.5rem;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  position: relative;
  z-index: 1600; /* above floating sidebar */
}
.topbar h2 { margin: 0; font-size: 1.25rem; }
.pin-btn[aria-pressed="true"] {
  background: var(--accent-2);
  border-color: #c98400;
  color: #1a1200;
}
.topbar .badge {
  font-size: 0.75rem;
  background: #fff7e6;
  color: #8a5a00;
  border: 1px solid #f0d08a;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

.content {
  flex: 1;
  padding: 0.75rem 1.25rem 1.25rem;
  min-height: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.filters-wrap {
  border-bottom: 1px solid var(--line);
  background: #f0f7f9;
  position: sticky;
  top: 0;
  z-index: 500;
}
.filters-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.85rem;
  flex-wrap: wrap;
}
.filters-wrap.auto-hide:not(.open) .filters {
  display: none;
}
.filters-wrap.pinned .filters,
.filters-wrap.open .filters {
  display: flex;
}
.filters-wrap #filters-pin[aria-pressed="true"] {
  background: var(--accent-2);
  border-color: #c98400;
}
.hours-edit-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  margin-bottom: 0.35rem;
}
.hours-edit-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-right: auto;
}
.hours-edit-group {
  margin: 0.55rem 0;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafcfd;
}
.hours-group-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem 0.55rem;
  margin-top: 0.45rem;
}
.hours-slots-label {
  margin: 0.55rem 0 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}
.hours-slot-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.45rem 0.55rem;
  align-items: end;
  margin-bottom: 0.4rem;
}
.hours-slot-del {
  padding: 0.35rem 0.55rem;
  min-width: 2.2rem;
}
.hours-group-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}
.hours-group-view {
  margin: 0.25rem 0 0.55rem;
}
.hours-group-head {
  font-weight: 600;
}
.hours-slot {
  padding-left: 0.65rem;
  font-size: 0.9rem;
  color: var(--ink, #1a2a2e);
}
.hours-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.hours-heading {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.hours-edit-group input,
.hours-edit-group select {
  width: 100%;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 0.82rem;
}
.weekday-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
}
.wd-check {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--ink, #1a2a2e);
  cursor: pointer;
  user-select: none;
}
@media (max-width: 640px) {
  .hours-group-meta {
    grid-template-columns: 1fr 1fr;
  }
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.8rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #f0f7f9;
  align-items: center;
}
.filters label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.filters input[type="number"],
.filters input[type="text"],
.filters select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.filters .sep { width: 1px; height: 1.4rem; background: var(--line); }

#map {
  height: calc(100vh - 190px);
  min-height: 420px;
  width: 100%;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn.danger:hover { filter: brightness(0.95); }
.etl-section {
  padding: 0.4rem 1rem 0.6rem;
  border-top: 1px solid var(--line);
}
.etl-heading {
  margin: 0.4rem 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.etl-hint {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.etl-conn label {
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.etl-conn input {
  min-width: 7rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
.btn.ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.25);
  color: #fff;
}
.btn.icon {
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.grid-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}
.table-wrap { overflow: auto; max-height: calc(100vh - 220px); }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
table.data th, table.data td {
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0.65rem;
  text-align: left;
  white-space: nowrap;
}
table.data th {
  position: sticky;
  top: 0;
  background: #eef6f8;
  cursor: pointer;
  user-select: none;
}
table.data th .sort { color: var(--accent); margin-left: 0.25rem; }
table.data tr:hover td { background: #f3fafb; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
  padding: 1rem;
}
.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem;
  background: #fff;
}
.card h3 { margin: 0 0 0.35rem; font-size: 1rem; }
.card .meta { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.55rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag {
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #e7f4f6;
  color: #0b5a66;
  border: 1px solid #b7d9df;
}
.tag.off { background: #f3f3f3; color: #777; border-color: #ddd; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 1rem;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.form-grid input, .form-grid select, .form-grid textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
.form-grid .full { grid-column: 1 / -1; }
.contact-pool-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  line-height: 1.35;
  margin-top: 0.25rem;
}
.contact-pool-list {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}
a.pool-map-link {
  display: inline-block;
  max-width: 100%;
  padding: 0.28rem 0.7rem;
  border: 1px solid var(--line, #c9d5d9);
  border-radius: 10px;
  background: #f3f7f8;
  color: var(--accent, #0e8a9a);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  box-sizing: border-box;
}
a.pool-map-link:hover {
  border-color: var(--accent, #0e8a9a);
  background: #e7f4f6;
  color: var(--ink, #0b3d4a);
}
.form-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0 1rem 1rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 36, 0.45);
  display: grid;
  place-items: center;
  z-index: 2000;
  padding: 1rem;
}
.modal {
  width: min(520px, 100%);
  max-height: 85vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
}
.modal header h3 { margin: 0; font-size: 1.05rem; }
.list {
  max-height: 320px;
  overflow: auto;
}
.list button {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font: inherit;
}
.list button:hover { background: #f3fafb; }
.list .list-check {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  width: 100%;
  margin: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font: inherit;
  box-sizing: border-box;
}
.list .list-check:hover { background: #f3fafb; }
.list .list-check.selected { background: #e8f6f8; }
.list .list-check input { margin-top: 0.2rem; flex-shrink: 0; }
.list .list-check span { flex: 1; min-width: 0; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--line);
}

.popup-body { min-width: 220px; font-family: var(--font); font-size: 0.85rem; }
.popup-body h4 { margin: 0 0 0.35rem; }
.popup-body .row { margin: 0.2rem 0; color: #444; }
.popup-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.55rem; }

.pin-move-bar {
  position: absolute;
  left: 50%;
  bottom: 1.1rem;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  max-width: calc(100% - 1.5rem);
  padding: 0.7rem 1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
}
.pin-move-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.pin-move-text span { color: var(--muted); font-size: 0.78rem; }
.pin-move-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.map-panel { position: relative; }

.mode-tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.mode-tabs button {
  border: 0;
  background: #fff;
  padding: 0.45rem 0.8rem;
  font: inherit;
  cursor: pointer;
}
.mode-tabs button.active {
  background: var(--accent);
  color: #fff;
}

.import-log {
  margin: 1rem;
  padding: 0.85rem;
  background: #0b3d4a;
  color: #d7f2f6;
  border-radius: 10px;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
}

.pin-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0 1rem 0.7rem;
}
.pin-legend .legend-note {
  margin-left: auto;
  opacity: 0.85;
}
.dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.25rem;
}
.dot.public { background: var(--pin-public); }
.dot.private { background: var(--pin-private); }
.dot.deleted { background: var(--pin-deleted); }

/* Map pin + cluster focus (PRD 01 §2.3) — kill Leaflet divIcon chrome */
.leaflet-container .pool-pin,
.leaflet-container .pool-cluster {
  background: transparent !important;
  border: none !important;
}

@media (max-width: 900px) {
  .brand { border: 0; padding: 0.2rem 0.4rem; }
  #map { height: 55vh; }
  .form-grid { grid-template-columns: 1fr; }
}
