:root {
  --bg: #f4f5f4;
  --card: #ffffff;
  --ink: #13241d;
  --muted: #5b6b65;
  --line: #dde3e0;
  --primary: #0b3d2e;
  --primary-ink: #ffffff;
  --accent: #1f8a5a;
  --danger: #b22d2d;
  --warn: #c9871a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--primary);
  color: var(--primary-ink);
  padding-top: calc(12px + env(safe-area-inset-top));
}

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

.brand .logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand h1 {
  font-size: 1.05rem;
  margin: 0;
  line-height: 1.1;
}

.brand .subtitle {
  margin: 2px 0 0;
  font-size: 0.78rem;
  opacity: 0.85;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

label > span {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="date"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

input[type="text"]:focus,
input[type="date"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.btn {
  --btn-bg: #eef1ef;
  --btn-ink: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--btn-ink);
  border: 1px solid var(--line);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.1s ease, transform 0.05s ease;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  --btn-bg: var(--accent);
  --btn-ink: #fff;
  border-color: transparent;
}

.btn-ghost {
  --btn-bg: transparent;
  --btn-ink: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

.app-header .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-ghost-dark {
  --btn-bg: transparent;
  --btn-ink: var(--muted);
  border-color: var(--line);
}

.btn-primary-soft {
  --btn-bg: #e6f3ec;
  --btn-ink: var(--primary);
  border-color: #c7e3d3;
}

.btn-upload {
  --btn-bg: #eef1ef;
  --btn-ink: var(--ink);
}

.btn-danger-ghost {
  --btn-bg: transparent;
  --btn-ink: var(--danger);
  border-color: #e4c6c6;
  font-size: 0.85rem;
  padding: 7px 10px;
}

.property-switcher {
  display: flex;
  gap: 6px;
  align-items: center;
}

.property-switcher select {
  max-width: 220px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
}

.property-switcher select option {
  color: #111;
  background: #fff;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.meta-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.meta-header h2 {
  margin: 0;
}

.meta-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.save-status {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef3f0;
  min-width: 60px;
  text-align: center;
}

.save-status.saving {
  color: #7a5200;
  background: #fff2d6;
}

.save-status.error {
  color: #fff;
  background: var(--danger);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #d0d0d0;
  display: inline-block;
}

.dot.ok {
  background: #39d27a;
  box-shadow: 0 0 0 3px rgba(57, 210, 122, 0.2);
}

.dot.err {
  background: #ff6b6b;
}

.groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tag-clusters {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tag-cluster-title {
  margin: 0 0 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 4px;
  border-bottom: 1px solid #d6e3dc;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.tag-cluster-count {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: normal;
  text-transform: none;
}

.group.collapsed .tag-clusters {
  display: none;
}

.group-title-locked {
  color: var(--ink);
  background: transparent;
  cursor: default;
}

.group-title-locked:focus {
  outline: none;
  background: transparent;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  cursor: pointer;
  user-select: none;
  border-radius: 8px;
  padding: 2px 0;
}

.group-header:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.group.collapsed .group-header {
  margin-bottom: 0;
}

.group.collapsed .thumbs {
  display: none;
}

.group-chevron {
  display: inline-block;
  width: 14px;
  color: var(--muted);
  font-size: 0.95rem;
  transition: transform 0.18s ease;
  line-height: 1;
  flex: 0 0 auto;
}

.group.collapsed .group-chevron {
  transform: rotate(-90deg);
}

.group-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.group-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 6px;
  min-width: 120px;
}

.group-title:focus {
  outline: 2px solid var(--accent);
  background: #f6faf7;
}

.group-count {
  color: var(--muted);
  font-size: 0.85rem;
}

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

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.thumb {
  margin: 0;
  background: #0d0d0d;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.thumb.dragging {
  opacity: 0.5;
}

.thumb.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

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

.thumb figcaption {
  padding: 6px;
  background: #fff;
}

.thumb-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.thumb-tagbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
  background: #eef5ef;
  border-bottom: 1px solid #d3e0d7;
}

.thumb-building {
  flex: 0 0 auto;
  padding: 4px 8px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid #c7dccf;
  border-radius: 6px;
  background: #fff;
  color: var(--primary);
  letter-spacing: 0.3px;
}

.thumb-group-hint {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb img {
  cursor: zoom-in;
}

.thumb-label {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.85rem;
  background: #fff;
}

.thumb-remove {
  width: 30px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  font-size: 1rem;
  color: var(--danger);
  cursor: pointer;
}

.thumb-add {
  margin: 0;
  background: #f6faf7;
  border: 2px dashed #b6d3c1;
  border-radius: 10px;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s ease, border-color 0.1s ease;
  color: var(--primary);
}

.thumb-add:hover,
.thumb-add:focus-within {
  background: #ecf5f0;
  border-color: var(--accent);
}

.thumb-add-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.thumb-add-plus {
  font-size: 2rem;
  line-height: 1;
  font-weight: 300;
}

.thumb-add-label {
  font-size: 0.85rem;
  font-weight: 600;
}

/* ---------- View toggle ---------- */
.view-toggle {
  display: inline-flex;
  align-self: flex-start;
  background: #eef1ef;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--line);
  gap: 2px;
}

.view-toggle-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}

.view-toggle-btn.is-active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(0, 0, 0, 0.92);
  display: grid;
  place-items: center;
  padding: 16px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-stage {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #000;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
}

.lightbox-btn {
  position: absolute;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 1.6rem;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.lightbox-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-close {
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
}

.lightbox-prev {
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-next {
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-caption {
  position: absolute;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 90vw;
  text-align: center;
  white-space: pre-line;
}

/* ---------- Export photos dialog ---------- */
.dialog {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.dialog[hidden] {
  display: none;
}

.dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 30, 20, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.dialog-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-card h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ink);
}

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

.dialog-card .dialog-help {
  font-size: 0.78rem;
  color: var(--muted);
  background: #f4f7f5;
  padding: 10px 12px;
  border-radius: 8px;
}

.dialog-card .dialog-help strong {
  color: var(--ink);
}

.dialog-card .dialog-help em {
  font-style: normal;
  font-weight: 600;
  color: var(--ink);
}

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dialog-actions .btn {
  width: 100%;
  justify-content: center;
  padding: 11px 14px;
  font-weight: 600;
}

/* ---------- In-app camera overlay ---------- */
.camera-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  color: #fff;
  overflow: hidden;
}

.camera-overlay[hidden] {
  display: none;
}

.camera-overlay video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.camera-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 90ms ease-out;
  z-index: 1;
}

.camera-flash.show {
  opacity: 0.9;
  transition: opacity 20ms ease-out;
}

.camera-hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  z-index: 2;
}

.camera-hud > * {
  pointer-events: auto;
}

.camera-hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
}

.camera-hud-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.95rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.camera-count {
  font-size: 0.78rem;
  opacity: 0.8;
  font-weight: 500;
}

.camera-hud-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 8px 14px;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-width: 80px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.camera-hud-btn.primary {
  background: var(--accent);
  border-color: transparent;
}

.camera-hud-btn.ghost {
  background: rgba(0, 0, 0, 0.35);
  min-width: 44px;
  padding: 10px;
}

.camera-hud-btn.placeholder {
  background: transparent;
  border: none;
  cursor: default;
}

.camera-thumbs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
}

.camera-thumbs:empty {
  display: none;
}

.cam-thumb {
  position: relative;
  width: 68px;
  height: 68px;
  flex: 0 0 auto;
  border-radius: 8px;
  overflow: hidden;
  background: #222;
  border: 2px solid rgba(255, 255, 255, 0.85);
}

.cam-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cam-thumb button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.camera-hud-bottom {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
}

.camera-hud-bottom > :first-child {
  justify-self: start;
}

.camera-hud-bottom > :last-child {
  justify-self: end;
}

.camera-shutter {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  justify-self: center;
}

.camera-shutter-inner {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.08s ease;
}

.camera-shutter:active .camera-shutter-inner {
  transform: scale(0.9);
  background: #eee;
}

.add-group-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.add-group-row input {
  flex: 1;
}

.tips ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.tips li {
  margin-bottom: 4px;
}

.tips strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #111;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  max-width: 90vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.err {
  background: var(--danger);
}

@media (max-width: 520px) {
  .brand h1 {
    font-size: 0.95rem;
  }
  .brand .subtitle {
    display: none;
  }
  .app-header {
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
    flex-wrap: wrap;
  }
  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .property-switcher select {
    max-width: 140px;
  }
  .container {
    padding: 12px;
  }
  .btn {
    padding: 8px 11px;
  }
}
