/* 對話框（底部彈出／全螢幕）、表單欄位、相片格、詳情頁 */

.sheet {
  padding: 0;
  border: none;
  background: transparent;
  max-width: 100vw;
  max-height: 100dvh;
  width: 100%;
  color: var(--text);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
}

.sheet__inner {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  max-height: 100dvh;
}

/* 手機：由下方滑出 */
.sheet {
  margin: 0;
  margin-top: auto;
  animation: sheet-up 0.28s var(--ease);
}

.sheet--bottom .sheet__inner {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 88dvh;
}

.sheet--full .sheet__inner {
  height: 100dvh;
  border-radius: 0;
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet__header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: var(--tap) 1fr auto;
  align-items: center;
  gap: var(--space-2);
  padding: calc(var(--safe-top) + var(--space-2)) var(--space-3) var(--space-2);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.sheet__title {
  font-size: 1.02rem;
  text-align: center;
}

.sheet__close {
  width: var(--tap);
  height: var(--tap);
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
}

.sheet__body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-4) var(--space-4) calc(var(--safe-bottom) + var(--space-6));
  display: grid;
  gap: var(--space-5);
  align-content: start;
}

.sheet__footer {
  padding: var(--space-3) var(--space-4) calc(var(--safe-bottom) + var(--space-3));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

/* ---------- 表單 ---------- */
.field {
  display: grid;
  gap: var(--space-2);
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.field--row {
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.field__col { display: grid; gap: var(--space-2); min-width: 0; }

.field__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field__sublabel {
  font-size: 0.8rem;
  color: var(--text-subtle);
  margin-top: var(--space-1);
}

.field__hint {
  font-size: 0.8rem;
  color: var(--text-subtle);
  line-height: 1.5;
}

.required {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: var(--radius-full);
}

.input {
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 1rem; /* 16px 以上避免 iOS 自動放大 */
  transition: border-color 0.16s var(--ease);
}

.input::placeholder { color: var(--text-subtle); }
.input:focus { outline: none; border-color: var(--accent); }

.textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.6;
  padding-top: var(--space-3);
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: var(--space-6);
}

.form-errors {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  font-size: 0.85rem;
}

.form-errors ul { margin: 0; padding-left: 1.2em; }

/* 評分滑桿 */
.rating-slider {
  width: 100%;
  height: 36px;
  appearance: none;
  background: transparent;
}

.rating-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--poor), var(--ok), var(--great));
}

.rating-slider::-moz-range-track {
  height: 8px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--poor), var(--ok), var(--great));
}

.rating-slider::-webkit-slider-thumb {
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 3px solid var(--accent);
  box-shadow: var(--shadow-md);
}

.rating-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 3px solid var(--accent);
}

.rating-output {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent);
}

.rating-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-subtle);
  margin-top: -6px;
}

/* 標籤輸入 */
.tag-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
}

.tag-suggest summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--accent);
  padding: var(--space-1) 0;
}

.tag-suggest[open] summary { margin-bottom: var(--space-2); }

/* 相片 */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--space-2);
}

.photo-grid:empty { display: none; }

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-input);
}

.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }

.photo-thumb__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.72rem;
  display: grid;
  place-items: center;
}

.photo-thumb__cover {
  position: absolute;
  bottom: 4px;
  left: 4px;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.62rem;
  font-weight: 700;
}

.photo-add {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 96px;
  padding: var(--space-3);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-input);
  cursor: pointer;
  text-align: center;
}

.photo-add__icon { font-size: 1.5rem; }
.photo-add__text { font-size: 0.9rem; font-weight: 600; }
.photo-add__hint { font-size: 0.74rem; color: var(--text-subtle); }

.location-status {
  font-size: 0.82rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

.location-status[data-state='error'] { color: var(--danger); }
.location-status[data-state='ok'] { color: var(--great); }

/* ---------- 詳情 ---------- */
.detail-gallery {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  margin: calc(var(--space-4) * -1) calc(var(--space-4) * -1) 0;
  padding: 0 var(--space-4);
}

.detail-gallery::-webkit-scrollbar { display: none; }

.detail-gallery img {
  flex: none;
  width: min(78vw, 420px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  scroll-snap-align: center;
  cursor: zoom-in;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.detail-title { font-size: 1.3rem; }

.detail-sub { color: var(--text-muted); font-size: 0.9rem; }

.detail-score {
  display: grid;
  place-items: center;
  min-width: 72px;
  padding: var(--space-2);
  border-radius: var(--radius);
}

.detail-score .score__value { font-size: 1.7rem; }

.detail-rows { display: grid; gap: var(--space-3); }

.detail-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: var(--space-3);
  font-size: 0.92rem;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.detail-row__key { color: var(--text-subtle); font-size: 0.85rem; }
.detail-row__value { min-width: 0; overflow-wrap: anywhere; }

.detail-comment {
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--bg-input);
  font-size: 0.95rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.map-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.map-links .coords {
  width: 100%;
  font-variant-numeric: tabular-nums;
}

.map-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 32px;
  padding: 0 var(--space-3);
  border: 1px solid var(--accent);
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.map-link:hover { background: var(--accent); color: var(--accent-contrast); }

/* ---------- 全螢幕相片 ---------- */
.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.95);
}

.lightbox::backdrop { background: rgba(0, 0, 0, 0.9); }

.lightbox img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.lightbox__close {
  position: absolute;
  top: calc(var(--safe-top) + var(--space-3));
  right: var(--space-3);
  z-index: 2;
  width: var(--tap);
  height: var(--tap);
  border: none;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* ---------- 雲端同步 ---------- */
.sync-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 0.9rem;
}

.sync-status__dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--text-subtle);
}

.sync-status__dot[data-state='ready'] { background: var(--great); }
.sync-status__dot[data-state='syncing'] { background: var(--ok); animation: pulse-dot 1s ease-in-out infinite; }
.sync-status__dot[data-state='error'] { background: var(--danger); }
.sync-status__dot[data-state='disabled'] { background: var(--text-subtle); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---------- 設定 ---------- */
.settings-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  text-align: center;
}

/* 平板以上：對話框置中 */
@media (min-width: 720px) {
  .sheet {
    margin: auto;
    max-width: 640px;
    padding: var(--space-5) var(--space-4);
  }

  .sheet__inner {
    border-radius: var(--radius-lg);
    max-height: 86dvh;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
  }

  .sheet--full .sheet__inner {
    height: auto;
    border-radius: var(--radius-lg);
  }

  .sheet--bottom .sheet__inner {
    border-radius: var(--radius-lg);
  }

  .sheet__header { padding-top: var(--space-3); }
}

/* ---------- 密碼登入 ---------- */
.login-error {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  font-size: 0.85rem;
}

#login-dialog::backdrop {
  background: var(--bg);
  opacity: 0.96;
}
