:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f8fafc;
  --text: #1e293b;
  --text-muted: #64748b;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --green: #22c55e;
  --green-dark: #16a34a;
  --red: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  margin: 0;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

h1, h2, h3 { font-weight: 600; margin: 0 0 0.5rem; }

/* ---- Layout ---- */
.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  padding: 0.9rem 1.2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  font-size: 1.05rem;
}

.topbar .who {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar .who a { color: var(--text-muted); text-decoration: underline; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1.1rem;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: var(--green-dark); }
.btn-secondary { background: #eef2f7; color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: #fee2e2; color: var(--red); }
.btn-danger:hover { background: #fecaca; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.82rem; }

/* ---- Login ---- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  padding: 2rem 1.75rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.login-card h1 { color: var(--primary); font-size: 1.4rem; }
.login-sub { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.login-form { display: flex; flex-direction: column; gap: 0.9rem; }
.pin-input {
  font-size: 1.6rem;
  letter-spacing: 0.4rem;
  text-align: center;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.pin-input:focus { border-color: var(--primary); }

.alert {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 1rem;
  text-align: left;
}
.alert-error { background: #fee2e2; color: #b91c1c; }
.alert-success { background: #dcfce7; color: #15803d; }

/* ---- Search / filter ---- */
.filter-bar {
  margin: 1rem 0 0;
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.filter-input {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 320px;
  padding: 0.65rem 0.9rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--card-bg);
}
.filter-input:focus { border-color: var(--primary); }
.filter-bar .btn { flex-shrink: 0; }
.filter-count { font-size: 0.8rem; color: var(--text-muted); }
.filter-count-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* ---- Property cards ---- */
.property-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.property-list-header { display: none; }
.property-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, transform 0.05s;
}
.property-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.1); }
.property-card:active { transform: scale(0.99); }
.property-card.has-gateway {
  background: #e9faf0;
  border-left: 3px solid var(--green);
}
.property-card .pc-main { min-width: 0; }
.property-card .pc-title { font-weight: 600; font-size: 1rem; }
.property-card .pc-sub { font-size: 0.83rem; color: var(--text-muted); margin-top: 0.15rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.property-card .pc-rid {
  font-size: 0.75rem; color: var(--text-muted); background: #eef2f7;
  border-radius: 6px; padding: 0.15rem 0.5rem; flex-shrink: 0;
}
.property-card .pc-arrow { color: var(--text-muted); flex-shrink: 0; }
.pc-col { display: none; }
.pc-site-id { display: none; }
.pc-changed { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.15rem; }
.pc-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  white-space: nowrap;
}
.pc-badge-ems { background: #e0e7ff; color: #4338ca; }
.pc-badge-network { background: #d1fae5; color: #047857; }
.pc-badge-issues { background: #fee2e2; color: #b91c1c; }

.no-results {
  background: #fff8c5;
  padding: 1rem;
  text-align: center;
  border-radius: 8px;
  margin-top: 1rem;
}

/* ---- Detail page ---- */
.detail-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; }
.detail-header .back { color: var(--text-muted); text-decoration: none; font-size: 1.3rem; }
.detail-header h1 { font-size: 1.2rem; margin: 0; }

.section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.section h2 {
  font-size: 1rem;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 0.9rem;
}
.subsection-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 1rem 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.subsection-title:first-of-type { margin-top: 0; }

/* Photo gallery */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #eef2f7;
  cursor: pointer;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .photo-del {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.55); color: #fff;
  border: none; border-radius: 50%;
  width: 24px; height: 24px;
  font-size: 0.85rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
}

/* ---- Foto-Vollbildansicht (Lightbox) ---- */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  touch-action: pan-y;
}
.lightbox-img {
  max-width: 92vw;
  max-height: 88vh;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
}
.lightbox-btn {
  position: absolute;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, 0.22); }
.lightbox-close {
  top: 1rem;
  right: 1rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.1rem;
}
.lightbox-prev, .lightbox-next {
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 64px;
  border-radius: 8px;
  font-size: 1.8rem;
  line-height: 1;
}
.lightbox-prev { left: 0.6rem; }
.lightbox-next { right: 0.6rem; }
.lightbox-counter {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  font-size: 0.82rem;
}
@media (max-width: 640px) {
  .lightbox-prev, .lightbox-next { width: 42px; height: 56px; font-size: 1.5rem; }
}
.upload-zone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
}
.upload-zone.dragover { border-color: var(--primary); background: #f0f5ff; color: var(--primary); }
.upload-zone input { display: none; }

/* Field blocks (alle Spalten in DB-Reihenfolge, gemischt scalar/JSON) */
.field-block { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.field-block:last-child { border-bottom: none; }
.field-block > label {
  display: block;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}
.field-block input[type="text"],
.field-block textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}
.field-block input[type="text"]:focus,
.field-block textarea:focus { border-color: var(--primary); }
.field-block.readonly input { background: #f4f6f9; color: var(--text-muted); }

.save-bar {
  position: sticky;
  bottom: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 0.8rem 1rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin: 1rem -1.2rem -1.1rem;
  border-radius: 0 0 var(--radius) var(--radius);
}

.save-status {
  font-size: 0.85rem;
  color: var(--text-muted);
  align-self: center;
  margin-right: auto;
}

/* ---- JSON editor ---- */
.json-editor { display: flex; flex-direction: column; gap: 0.5rem; }
.json-node { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem; }
.json-node + .json-node { margin-top: 0.5rem; }
.json-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.json-row:last-child { margin-bottom: 0; }
.json-key {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 90px;
  flex-shrink: 0;
}
.json-key-input {
  min-width: 90px;
  flex: 0 1 140px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}
.json-val-input {
  flex: 1 1 140px;
  min-width: 80px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}
.json-children { margin-left: 1rem; margin-top: 0.4rem; padding-left: 0.7rem; border-left: 2px solid var(--border); }
.json-btn {
  border: none;
  background: #eef2f7;
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
  flex-shrink: 0;
}
.json-btn:hover { background: #e2e8f0; }
.json-add-btn { margin-top: 0.3rem; }
.json-array-item {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.json-array-index {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 18px;
  padding-top: 0.4rem;
  flex-shrink: 0;
}
.json-array-item .json-node { flex: 1; }

/* ---- JSON-Editor: Popup fuer neues Feld/Element ---- */
.je-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}
.je-modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.je-modal-title { font-size: 1rem; color: var(--primary); margin: 0 0 0.9rem; }
.je-modal-message { font-size: 0.92rem; color: var(--text); margin: 0; }
.je-modal-row { margin-bottom: 0.8rem; }
.je-modal-row:last-of-type { margin-bottom: 0; }
.je-modal-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
.je-modal-input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
}
.je-modal-input:focus { border-color: var(--primary); }
.je-modal-btns {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

/* ---- Gateway-Editor ---- */
.gw-editor { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.8rem; }
.gw-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  background: #fafbfd;
}
.gw-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
}
.gw-row:last-child { margin-bottom: 0; }
.gw-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 55px;
  flex-shrink: 0;
}
.gw-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}
.gw-input:focus { border-color: var(--primary); outline: none; }
.gw-add-btn { width: 100%; }
.gw-scan-btn { width: 100%; margin: -0.3rem 0 0.9rem; }

/* ---- QR/Barcode-Scanner-Modal ---- */
.qr-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1100;
}
.qr-panel { width: 100%; max-width: 560px; }
.qr-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.6rem;
}
.qr-row-label { color: #cfd6df; font-size: 0.85rem; }
.qr-cam-select {
  flex: 1;
  background: #1a222b;
  color: #eef;
  border: 1px solid #334;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}
.qr-view {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  border: 1px solid #222;
}
.qr-view video { width: 100%; height: 100%; object-fit: cover; }
.qr-status { color: #cfd6df; margin-top: 0.6rem; font-size: 0.85rem; }

@media (max-width: 640px) {
  .page { padding: 0.7rem; }
  .topbar {
    padding: 0.6rem 0.9rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
  .topbar .brand { font-size: 0.95rem; }
  .topbar .who { font-size: 0.78rem; }
  .section { padding: 0.9rem; }
  .field-table th { width: 45%; font-size: 0.8rem; }
  .save-bar { margin: 1rem -0.9rem -0.9rem; }
}

/* ---- Desktop-Layout: volle Bildschirmbreite statt schmaler, zentrierter Spalte ----
   Per "html.force-mobile" (siehe view-toggle.js) laesst sich die mobile Ansicht
   auch auf breiten Bildschirmen erzwingen - alle Regeln hier sind daher an
   "html:not(.force-mobile)" gebunden. */
@media (min-width: 900px) {
  html:not(.force-mobile) .page {
    max-width: none;
    padding: 1.75rem 3rem;
  }

  /* Spaltenueberschriften oberhalb der Liste, exakt auf das Raster
     der .property-card-Zeilen abgestimmt. */
  html:not(.force-mobile) .property-list-header {
    display: grid;
    grid-template-columns: 4.4rem 1.8fr 1.3fr 1.5fr 1fr 0.8fr 8.8rem 1.4fr 1rem;
    gap: 1.1rem;
    padding: 0 1.1rem 0.4rem;
    margin-top: 1rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
  }
  html:not(.force-mobile) .plh-btn {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
  }
  html:not(.force-mobile) .plh-btn:hover,
  html:not(.force-mobile) .plh-btn.active { color: var(--primary); }
  html:not(.force-mobile) .plh-btn .sort-indicator { font-size: 0.65rem; }

  /* Liegenschaftsliste: weiterhin eine Zeile pro Liegenschaft, aber
     breiter mit zusaetzlichen, gut lesbaren Detailspalten. Die RID steht
     im DOM zwischen den Detailspalten und dem Pfeil, wird hier aber per
     "order" optisch an den Anfang der Zeile gezogen. */
  html:not(.force-mobile) .property-card {
    display: grid;
    grid-template-columns: 4.4rem 1.8fr 1.3fr 1.5fr 1fr 0.8fr 8.8rem 1.4fr 1rem;
    align-items: center;
    gap: 1.1rem;
  }
  html:not(.force-mobile) .pc-rid { order: -2; }
  html:not(.force-mobile) .pc-arrow { order: 10; }
  html:not(.force-mobile) .pc-sub { display: none; }
  html:not(.force-mobile) .property-card .pc-main { min-width: 0; overflow-wrap: anywhere; }
  html:not(.force-mobile) .property-card .pc-rid { justify-self: start; }
  html:not(.force-mobile) .pc-changed { display: none; }
  html:not(.force-mobile) .pc-site-id {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 1px;
  }
  html:not(.force-mobile) .pc-col {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  html:not(.force-mobile) .pc-col-main { color: var(--text); }
  html:not(.force-mobile) .pc-col-sub { font-size: 0.72rem; opacity: 0.8; margin-top: 1px; }
  html:not(.force-mobile) .pc-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    white-space: normal;
  }

  /* "Weitere Daten": einfache Felder zweispaltig, JSON-Bereiche ueber die volle Breite */
  html:not(.force-mobile) .section-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 2.5rem;
  }
  html:not(.force-mobile) .section-grid > h2,
  html:not(.force-mobile) .section-grid > .field-block-wide {
    grid-column: 1 / -1;
  }

  /* Gateway-/Switch-Karten (EMS, Netzwerk) als Raster statt Liste */
  html:not(.force-mobile) .gw-editor {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
  }
}

/* ---- Umschalter "mobile/Desktop-Ansicht" im Header ---- */
.view-toggle-wrap { display: none; }
.view-toggle {
  font-size: inherit;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
}
.view-toggle:hover { color: var(--primary); }

/* ---- Zaehlerkamera: Kamera-Block in der Gateway-Karte ---- */
.gw-camera { margin-top: 0.7rem; padding-top: 0.6rem; border-top: 1px dashed var(--border); }
.gw-camera-summary { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.4rem; }
.gw-camera-dirty {
  margin-top: 0.4rem; padding: 0.3rem 0.5rem; border-radius: 6px;
  background: #fff7ed; color: #c2410c; font-size: 0.78rem;
}
.gw-camera-thumbs { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.gw-camera-thumb {
  display: block; text-decoration: none; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #f4f6f9;
}
.gw-camera-thumb img { display: block; height: 64px; width: auto; max-width: 160px; object-fit: contain; }
.gw-camera-thumb-cap { display: block; font-size: 0.68rem; padding: 0.1rem 0.35rem; text-align: center; }

/* ---- Zaehlerkamera: Popup ---- */
.cam-overlay {
  position: fixed; inset: 0; z-index: 1150; background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.cam-modal {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0,0,0,0.3);
  width: 100%; max-width: 1180px; max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
}
.cam-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.8rem 1.1rem; border-bottom: 1px solid var(--border); }
.cam-title { margin: 0; font-size: 1rem; color: var(--primary); }
.cam-close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--text-muted); padding: 0.2rem 0.4rem; }
.cam-body { display: flex; gap: 1.2rem; padding: 1rem 1.1rem; overflow: auto; flex: 1; min-height: 0; }
.cam-left { flex: 1 1 60%; min-width: 0; }
.cam-right { flex: 0 0 300px; }
.cam-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.8rem 1.1rem; border-top: 1px solid var(--border); }

.cam-toolbar { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.cam-zoom.active { background: var(--primary); color: #fff; }
.cam-legend { margin-left: auto; font-size: 0.75rem; color: var(--text-muted); }
.cam-key { display: inline-block; width: 14px; height: 10px; vertical-align: middle; border-radius: 2px; }
.cam-key-ref { border: 2px dashed #f59e0b; }
.cam-key-new { border: 2px solid var(--primary); }

.cam-scroll { max-height: 60vh; overflow: auto; border-radius: 8px; border: 1px solid var(--border); background: #111827; }
.cam-stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; user-select: none; -webkit-user-select: none;
  background:
    repeating-linear-gradient(45deg, #1f2937 0 10px, #182030 10px 20px);
}
.cam-ref { position: absolute; display: block; object-fit: fill; pointer-events: none; }
.cam-ref-outline { position: absolute; border: 2px dashed #f59e0b; pointer-events: none; box-sizing: border-box; }
.cam-crop {
  position: absolute; border: 2px solid var(--primary); box-sizing: border-box; cursor: move;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55); touch-action: none; outline: none;
}
.cam-crop:focus-visible { border-color: #93c5fd; }
.cam-crop-label {
  position: absolute; left: 0; bottom: 100%; margin-bottom: 3px; background: var(--primary); color: #fff;
  font-size: 0.68rem; padding: 0.05rem 0.4rem; border-radius: 4px; white-space: nowrap; pointer-events: none;
}
.cam-handle {
  position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--primary);
  border-radius: 3px; box-sizing: border-box; touch-action: none;
}
.cam-handle::after { content: ''; position: absolute; inset: -12px; }
.cam-handle-nw { left: -8px; top: -8px; cursor: nwse-resize; }
.cam-handle-n  { left: calc(50% - 7px); top: -8px; cursor: ns-resize; }
.cam-handle-ne { right: -8px; top: -8px; cursor: nesw-resize; }
.cam-handle-e  { right: -8px; top: calc(50% - 7px); cursor: ew-resize; }
.cam-handle-se { right: -8px; bottom: -8px; cursor: nwse-resize; }
.cam-handle-s  { left: calc(50% - 7px); bottom: -8px; cursor: ns-resize; }
.cam-handle-sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.cam-handle-w  { left: -8px; top: calc(50% - 7px); cursor: ew-resize; }

.cam-status { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }
.cam-thumbs { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.cam-thumb {
  background: #f4f6f9; border: 2px solid transparent; border-radius: 8px; padding: 0.2rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
}
.cam-thumb.active { border-color: var(--primary); }
.cam-thumb img { height: 56px; width: auto; max-width: 150px; object-fit: contain; display: block; }
.cam-thumb-cap { font-size: 0.66rem; color: var(--text-muted); }

.cam-sec { margin: 0.9rem 0 0.4rem; font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.cam-sec:first-child { margin-top: 0; }
.cam-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.cam-field { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.78rem; color: var(--text-muted); }
.cam-input {
  width: 100%; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem;
}
.cam-input:focus { border-color: var(--primary); outline: none; }
.cam-input-small { width: 5rem; }
.cam-info { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.5rem; }
.cam-btnrow { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }
.cam-qrow { display: flex; align-items: center; gap: 0.6rem; }
.cam-range { flex: 1; }
.cam-radio { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; margin-bottom: 0.3rem; }
.cam-hint { font-size: 0.74rem; color: var(--text-muted); margin-top: 0.2rem; }
.cam-note { margin-top: 1rem; padding: 0.5rem 0.6rem; background: #eff6ff; color: #1e40af; border-radius: 6px; font-size: 0.76rem; }

@media (max-width: 800px) {
  .cam-overlay { padding: 0; }
  .cam-modal { max-width: none; height: 100%; border-radius: 0; }
  .cam-body { flex-direction: column; gap: 0.9rem; }
  .cam-right { flex: 0 0 auto; }
  .cam-scroll { max-height: 42vh; }
}
