/* ==========================================================================
   馬太鞍溪土砂採樣展示平台 Demo — global styles
   Design: restrained, engineering-report look. All colors via CSS variables.
   ========================================================================== */

:root {
  /* Primary palette: terracotta red for markers, buttons, headings —
     desaturated enough to stay calm on the UI, warm enough to remain
     legible against the (green-dominant) orthophoto basemap */
  --color-primary: #b0413e;
  --color-primary-dark: #872f2d;

  /* Three-state test status colors (the only accent colors) */
  --color-status-done: #2e7d32;      /* completed  = calm green  */
  --color-status-progress: #b26a00;  /* in progress = amber      */
  --color-status-planned: #757c85;   /* planned    = medium gray */

  /* Neutrals */
  --color-bg: #ffffff;
  --color-bg-muted: #f4f5f7;
  --color-text: #1f2937;
  --color-text-muted: #5b6470;
  --color-border: #d4d9de;

  --shadow-panel: 0 1px 6px rgba(0, 0, 0, 0.25);
  --font-sans: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei',
               system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
}

/* Full-screen map */
#map {
  height: 100%;
  width: 100%;
}

/* Keyboard focus visibility for all interactive elements */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Leaflet overrides
   -------------------------------------------------------------------------- */

.leaflet-container {
  font-family: var(--font-sans);
  font-size: 14px;
}

.leaflet-tooltip.marker-tooltip {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary-dark);
}

/* --------------------------------------------------------------------------
   Legend (bottom-left map control)
   -------------------------------------------------------------------------- */

.legend {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: var(--shadow-panel);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.6;
  max-width: 280px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Marker symbols drawn with CSS to match the map markers */
.legend-symbol {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: none;
}

.legend-symbol--sampled {
  background: var(--color-primary);
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px var(--color-border);
}

.legend-symbol--planned {
  background: #ffffff;
  border: 3px solid var(--color-primary);
}

.legend-hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--color-text-muted);
}

/* Collapsible pending-location list (points without coordinates) */
.legend-pending {
  margin-top: 8px;
  border-top: 1px solid var(--color-border);
  padding-top: 6px;
}

.legend-pending summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--color-primary);
}

.legend-pending ul {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}

.legend-pending-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 3px 2px;
  font-family: inherit;
  font-size: 14px;
  color: var(--color-text);
  cursor: pointer;
  border-radius: 3px;
}

.legend-pending-item:hover {
  background: var(--color-bg-muted);
}

.legend-pending-item strong {
  color: var(--color-primary);
  margin-right: 6px;
}

/* --------------------------------------------------------------------------
   Marker popup (first-layer summary)
   -------------------------------------------------------------------------- */

.point-popup .leaflet-popup-content {
  margin: 14px 18px;
  font-size: 14px;
  line-height: 1.6;
}

.popup-id {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary-dark);
}

.popup-sub {
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.popup-date {
  margin-bottom: 6px;
}

.popup-detail-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 7px 12px;
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.popup-detail-btn:hover {
  background: var(--color-primary-dark);
}

/* --------------------------------------------------------------------------
   Three-state test status list (popup + 試驗資料 tab)
   -------------------------------------------------------------------------- */

.status-list {
  list-style: none;
  margin: 4px 0;
  padding: 0;
}

.status-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 1px 0;
}

.status-symbol {
  width: 1.2em;
  text-align: center;
  font-weight: 700;
  flex: none;
}

.status--done .status-symbol,
.status--done .status-label {
  color: var(--color-status-done);
}

.status--progress .status-symbol,
.status--progress .status-label {
  color: var(--color-status-progress);
}

.status--planned .status-symbol,
.status--planned .status-label {
  color: var(--color-status-planned);
}

.status-name {
  flex: 1;
}

.status-label {
  font-size: 0.92em;
}

/* --------------------------------------------------------------------------
   Detail side panel
   -------------------------------------------------------------------------- */

.panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 450px;
  max-width: 100%;
  background: var(--color-bg);
  box-shadow: -2px 0 12px rgba(0, 0, 0, 0.25);
  z-index: 1100; /* above Leaflet map panes and controls */
  display: flex;
  flex-direction: column;
  font-size: 15px;
  visibility: hidden;
  transform: translateX(100%);
  transition: transform 0.25s ease, visibility 0s linear 0.25s;
}

.panel.open {
  visibility: visible;
  transform: none;
  transition: transform 0.25s ease;
}

.panel-header {
  position: relative;
  padding: 16px 48px 10px 20px;
  border-bottom: 1px solid var(--color-border);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-id {
  margin: 0;
  font-size: 24px;
  color: var(--color-primary-dark);
}

.panel-id:focus {
  outline: none;
}

.uscs-badge {
  background: var(--color-primary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

.panel-name {
  margin: 4px 0 0;
  color: var(--color-text-muted);
}

.panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 4px;
}

.panel-close:hover {
  background: var(--color-bg-muted);
  color: var(--color-text);
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
}

.panel-tab {
  flex: 1;
  padding: 10px 4px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-family: inherit;
  font-size: 15px;
  color: var(--color-text-muted);
  cursor: pointer;
}

.panel-tab:hover {
  background: var(--color-bg-muted);
}

.panel-tab.active {
  color: var(--color-primary-dark);
  font-weight: 700;
  border-bottom-color: var(--color-primary);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.panel-section-title {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--color-primary-dark);
}

.panel-placeholder {
  color: var(--color-text-muted);
}

/* Label/value table on the 基本資料 tab */
.info-table {
  width: 100%;
  border-collapse: collapse;
}

.info-table th,
.info-table td {
  text-align: left;
  vertical-align: top;
  padding: 8px 4px;
  border-bottom: 1px solid var(--color-border);
  font-size: 15px;
  line-height: 1.6;
}

.info-table th {
  width: 96px;
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.coord-note {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 13px;
  color: var(--color-text-muted);
  background: var(--color-bg-muted);
}

/* --------------------------------------------------------------------------
   試驗資料 tab: status notes, USCS line, PSD chart, index-value table
   -------------------------------------------------------------------------- */

.status-note {
  display: block;
  font-size: 13px;
  color: var(--color-text-muted);
}

.uscs-line {
  margin: 12px 0 4px;
  font-size: 15px;
}

.uscs-line strong {
  color: var(--color-primary-dark);
}

.panel-body .panel-section-title {
  margin-top: 18px;
}

.panel-body .panel-section-title:first-child {
  margin-top: 0;
}

.psd-chart-box {
  position: relative;
  height: 320px;
  margin-bottom: 4px;
}

.metrics-table {
  width: 100%;
  border-collapse: collapse;
}

.metrics-table th,
.metrics-table td {
  text-align: left;
  vertical-align: baseline;
  padding: 7px 4px;
  border-bottom: 1px solid var(--color-border);
  font-size: 15px;
  line-height: 1.5;
}

.metrics-table th {
  width: 88px;
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.metrics-table td {
  width: 34%;
}

/* --------------------------------------------------------------------------
   Photo grid (現地照片 tab)
   -------------------------------------------------------------------------- */

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

.photo-cell {
  margin: 0;
}

.photo-thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--color-bg-muted);
  cursor: zoom-in;
}

.photo-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.photo-caption {
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.5;
}

.photo-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 12px;
  color: var(--color-text-muted);
}

/* --------------------------------------------------------------------------
   Lightbox
   -------------------------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.lightbox.open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease;
}

.lightbox-figure {
  margin: 0;
  max-width: 90vw;
  text-align: center;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 82vh;
  display: block;
  margin: 0 auto;
  background: #333333;
}

.lightbox-caption {
  margin-top: 10px;
  color: #f0f0f0;
  font-size: 15px;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  cursor: pointer;
  border-radius: 4px;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  background: rgba(255, 255, 255, 0.28);
}

.lightbox-close {
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  font-size: 28px;
}

.lightbox-prev,
.lightbox-next {
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 72px;
  font-size: 40px;
}

.lightbox-prev {
  left: 16px;
}

.lightbox-next {
  right: 16px;
}

/* --------------------------------------------------------------------------
   Tablet: panel becomes full-width overlay
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .panel {
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
   Map tool buttons (top-left, below zoom control)
   -------------------------------------------------------------------------- */

.map-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-tool-btn {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: var(--shadow-panel);
  padding: 7px 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-primary-dark);
  cursor: pointer;
}

.map-tool-btn:hover {
  background: var(--color-bg-muted);
}

/* --------------------------------------------------------------------------
   Filter card (below the map tool buttons)
   -------------------------------------------------------------------------- */

.filter-toggle.active {
  background: var(--color-primary);
  color: #ffffff;
}

.filter-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: var(--shadow-panel);
  padding: 10px 14px;
  width: 230px;
  font-size: 14px;
}

.filter-group {
  border: none;
  margin: 0 0 8px;
  padding: 0;
}

.filter-group legend {
  font-weight: 700;
  color: var(--color-primary-dark);
  padding: 0 0 2px;
}

.filter-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  cursor: pointer;
}

.filter-option input {
  accent-color: var(--color-primary);
  width: 15px;
  height: 15px;
  flex: none;
}

.filter-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--color-border);
  padding-top: 8px;
}

.filter-count {
  color: var(--color-text-muted);
  font-size: 13px;
}

.filter-reset {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--color-primary-dark);
  cursor: pointer;
}

.filter-reset:hover {
  background: var(--color-bg-muted);
}

/* --------------------------------------------------------------------------
   Modal (summary table / plasticity chart)
   -------------------------------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1150; /* above panel (1100), below lightbox (1200) */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(24, 30, 38, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease;
}

.modal-box {
  background: var(--color-bg);
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  width: min(760px, calc(100vw - 32px));
  max-height: 84vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  position: relative;
  padding: 16px 52px 10px 20px;
  border-bottom: 1px solid var(--color-border);
}

.modal-title {
  margin: 0;
  font-size: 19px;
  color: var(--color-primary-dark);
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--color-text-muted);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--color-bg-muted);
  color: var(--color-text);
}

.modal-body {
  overflow: auto;
  padding: 0 20px 16px;
}

/* --------------------------------------------------------------------------
   Plasticity chart modal
   -------------------------------------------------------------------------- */

.plasticity-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding-top: 12px;
}

.plasticity-chart-box {
  position: relative;
  flex: 1 1 460px;
  height: 430px;
  min-width: 0;
}

.plasticity-aside {
  flex: 0 1 180px;
  font-size: 14px;
  line-height: 1.7;
}

.plasticity-aside h3 {
  margin: 0 0 4px;
  font-size: 15px;
  color: var(--color-primary-dark);
}

.plasticity-aside p {
  margin: 0 0 10px;
}

.plasticity-note {
  font-size: 13px;
  color: var(--color-text-muted);
}

.overlay-chart-box {
  position: relative;
  height: 470px;
  margin-top: 12px;
}

/* --------------------------------------------------------------------------
   Summary table
   -------------------------------------------------------------------------- */

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.summary-table th {
  position: sticky;
  top: 0;
  background: var(--color-bg);
  border-bottom: 2px solid var(--color-primary);
  padding: 0;
  text-align: left;
}

.summary-sort {
  display: block;
  width: 100%;
  padding: 10px 8px 6px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary-dark);
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.summary-sort:hover {
  background: var(--color-bg-muted);
}

.sort-arrow {
  display: inline-block;
  width: 1.1em;
  margin-left: 2px;
  font-size: 11px;
  color: var(--color-primary);
}

.summary-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--color-border);
  line-height: 1.5;
}

.summary-table tbody tr {
  cursor: pointer;
}

.summary-table tbody tr:hover,
.summary-table tbody tr:focus-visible {
  background: var(--color-bg-muted);
}

/* --------------------------------------------------------------------------
   Photo upload + admin import
   -------------------------------------------------------------------------- */

.photo-upload {
  margin-top: 18px;
  border-top: 1px solid var(--color-border);
  padding-top: 10px;
}

.photo-upload-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.photo-upload select,
.photo-upload input[type="text"] {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

.photo-upload input[type="text"] {
  flex: 1;
}

.photo-upload input[type="file"] {
  flex: 1;
  font-size: 13px;
}

.photo-upload-btn {
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 6px 16px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.photo-upload-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.photo-upload-msg {
  font-size: 13px;
  color: #b3261e;
}

.photo-cell {
  position: relative;
}

.photo-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 5;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 3px;
  background: rgba(24, 30, 38, 0.6);
  color: #ffffff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.photo-delete:hover {
  background: #b3261e;
}

.import-box {
  padding: 14px 0;
}

.import-actions {
  display: flex;
  gap: 10px;
  margin: 12px 0;
}

.import-report ul {
  margin: 4px 0 12px;
  padding-left: 20px;
  font-size: 14px;
}

.import-report h3 {
  font-size: 15px;
  margin: 10px 0 2px;
}

.import-bad { color: #b3261e; }
.import-warn { color: var(--color-status-progress); }
.import-ok { color: var(--color-status-done); font-weight: 700; }

/* --------------------------------------------------------------------------
   Login overlay + user chip
   -------------------------------------------------------------------------- */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(24, 30, 38, 0.55);
}

.login-overlay.open {
  display: flex;
}

.login-card,
.register-card {
  background: var(--color-bg);
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  padding: 28px 32px;
  width: min(360px, calc(100vw - 32px));
}

.login-card h1,
.register-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  color: var(--color-primary-dark);
}

.login-hint {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--color-text-muted);
}

.login-card label,
.register-card label {
  display: block;
  font-size: 14px;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

.login-card input,
.register-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 15px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

.login-card input:focus,
.register-card input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 0;
  border-color: var(--color-primary);
}

.login-error {
  margin: 0 0 10px;
  font-size: 14px;
  color: #b3261e;
}

.login-submit {
  width: 100%;
  padding: 9px 12px;
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.login-submit:hover {
  background: var(--color-primary-dark);
}

.user-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  box-shadow: var(--shadow-panel);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.user-logout {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 2px 8px;
  font-family: inherit;
  font-size: 12px;
  color: var(--color-primary-dark);
  cursor: pointer;
}

.user-logout:hover {
  background: var(--color-bg-muted);
}

.login-alt {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--color-text-muted);
  text-align: center;
}

.login-link {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 13px;
  color: var(--color-primary);
  text-decoration: underline;
  cursor: pointer;
}

.users-table td {
  font-size: 14px;
  vertical-align: middle;
}

.users-table .map-tool-btn {
  padding: 3px 10px;
  font-size: 13px;
  box-shadow: none;
}

.user-role-select {
  font-family: inherit;
  font-size: 13px;
  padding: 3px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

.user-row-pending td {
  background: #fff8ec;
}

/* --------------------------------------------------------------------------
   Data-loading error banner
   -------------------------------------------------------------------------- */

.data-error {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  background: #fff3f3;
  border: 1px solid #d9534f;
  color: #a94442;
  padding: 10px 16px;
  border-radius: 4px;
  font-size: 14px;
  box-shadow: var(--shadow-panel);
}

/* --------------------------------------------------------------------------
   Motion preferences
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
