*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1923;
  --surface: #1a2733;
  --surface-alt: #223344;
  --accent: #2a4a6b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --text: #e8ecf0;
  --text-muted: #8899aa;
  --border: #2a3a4a;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --panel-w: 420px;
  --floor-sel-w: 56px;
  --header-h: 52px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ===== HEADER ===== */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
  position: relative;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#floor-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}
.header-btn:hover { background: var(--surface-alt); }

/* ===== MAIN LAYOUT ===== */
#viewer-main {
  display: flex;
  height: calc(100vh - var(--header-h));
  position: relative;
  overflow: hidden;
}

/* ===== PLAN VIEWPORT ===== */
#plan-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}
#plan-viewport:active { cursor: grabbing; }

#plan-container {
  position: relative;
  transform-origin: center center;
  transition: none;
  will-change: transform;
  display: inline-block;
}

#plan-image {
  display: block;
  max-width: 90vw;
  max-height: 85vh;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

#units-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ===== EMPTY STATE ===== */
#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.empty-content {
  text-align: center;
  color: var(--text-muted);
}
.empty-content p { margin-top: 12px; font-size: 16px; }
.empty-content .sub { font-size: 13px; margin-top: 4px; opacity: 0.6; }

/* ===== UNIT ZONES ===== */
.unit-zone {
  position: absolute;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s, border-color 0.15s;
}
.unit-zone:hover {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.6);
}
.unit-zone.selected {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--primary);
}

/* Status colors on hover */
.unit-zone.status-disponible:hover { background: rgba(34, 197, 94, 0.15); border-color: rgba(34, 197, 94, 0.6); }
.unit-zone.status-reservado:hover  { background: rgba(234, 179, 8, 0.15); border-color: rgba(234, 179, 8, 0.6); }
.unit-zone.status-vendido:hover    { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.6); }

.unit-zone.status-disponible.selected { background: rgba(34, 197, 94, 0.2); border-color: var(--success); }
.unit-zone.status-reservado.selected  { background: rgba(234, 179, 8, 0.2); border-color: var(--warning); }
.unit-zone.status-vendido.selected    { background: rgba(239, 68, 68, 0.2); border-color: var(--danger); }

/* Admin mode: always show zones */
.unit-zone.admin {
  border: 2px dashed rgba(59, 130, 246, 0.5);
  background: rgba(59, 130, 246, 0.08);
}
.unit-zone.admin.status-disponible { border-color: rgba(34, 197, 94, 0.5); background: rgba(34, 197, 94, 0.08); }
.unit-zone.admin.status-reservado  { border-color: rgba(234, 179, 8, 0.5); background: rgba(234, 179, 8, 0.08); }
.unit-zone.admin.status-vendido    { border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.08); }

.unit-zone.dragging { opacity: 0.7; }

.unit-zone-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  white-space: nowrap;
  pointer-events: none;
}

/* Resize handle */
.resize-handle {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 12px;
  height: 12px;
  background: var(--primary);
  border: 2px solid #fff;
  border-radius: 2px;
  cursor: se-resize;
  pointer-events: auto;
}

/* ===== ZOOM CONTROLS ===== */
#zoom-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}
.zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(26, 39, 51, 0.9);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
  backdrop-filter: blur(8px);
}
.zoom-btn:hover { background: var(--surface-alt); }

/* ===== FLOOR SELECTOR ===== */
#floor-selector {
  width: var(--floor-sel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  overflow-y: auto;
  z-index: 10;
  flex-shrink: 0;
}
#floor-selector:empty,
#floor-selector.hidden {
  display: none;
}

.floor-btn {
  width: 44px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.floor-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}
.floor-btn.active {
  background: #fff;
  color: #111;
  font-weight: 700;
  border-color: #fff;
}

/* ===== UNIT PANEL ===== */
#unit-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--panel-w);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 15;
  overflow-y: auto;
  transition: transform 0.3s ease;
}
#unit-panel.panel-closed {
  transform: translateX(100%);
  pointer-events: none;
}
#unit-panel.panel-open {
  transform: translateX(0);
  pointer-events: auto;
}

.panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.panel-close:hover { background: var(--surface-alt); }

#unit-panel-content {
  padding: 0;
}

#unit-gallery {
  width: 100%;
  background: #fff;
  padding: 12px;
}
.gallery-img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 6px;
}
.gallery-img + .gallery-img {
  margin-top: 8px;
}

#unit-info {
  padding: 20px;
}
#unit-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-badge.status-disponible { background: rgba(34,197,94,0.15); color: var(--success); }
.status-badge.status-reservado  { background: rgba(234,179,8,0.15); color: var(--warning); }
.status-badge.status-vendido    { background: rgba(239,68,68,0.15); color: var(--danger); }

.unit-specs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.spec-item { display: flex; flex-direction: column; gap: 2px; }
.spec-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.spec-value { font-size: 15px; font-weight: 600; }

.unit-desc {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}
.unit-desc:empty { display: none; }

/* ===== EMBED MODE (iframe) ===== */
/* Collapse header to a floating layer, hide back button + title, keep fullscreen */
body.embed-mode #app-header {
  height: 0;
  padding: 0;
  background: transparent;
  border-bottom: none;
  position: absolute;
  top: 0; left: 0; right: 0;
  pointer-events: none;
  z-index: 30;
}
body.embed-mode .header-left { display: none; }
body.embed-mode .header-right {
  position: absolute;
  top: 12px;
  right: 12px;
  pointer-events: auto;
}
body.embed-mode #btn-fullscreen {
  background: rgba(255,255,255,0.92);
  color: #111;
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
body.embed-mode #btn-fullscreen:hover { background: #fff; }
body.embed-mode #viewer-main { height: 100vh; }

/* ===== UNIT ACTIONS ===== */
.unit-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.unit-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.unit-action-btn:active { transform: scale(0.98); }
.unit-action-btn.primary {
  background: var(--primary, #2563eb);
  color: #fff;
}
.unit-action-btn.primary:hover { filter: brightness(1.08); }
.unit-action-btn.whatsapp {
  background: #25D366;
  color: #fff;
}
.unit-action-btn.whatsapp:hover { filter: brightness(1.08); }

/* ===== LIGHTBOX ===== */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  animation: lb-fade 0.2s ease;
}
.lightbox.hidden { display: none; }
@keyframes lb-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: background 0.15s ease;
}
.lightbox-close:hover { background: rgba(255,255,255,0.28); }
.lightbox-header {
  position: absolute;
  top: 20px;
  left: 20px;
  color: #fff;
  z-index: 2;
}
.lightbox-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}
.lightbox-header span {
  display: block;
  font-size: 13px;
  opacity: 0.75;
  margin-top: 2px;
}
.lightbox-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 20px 20px;
  overflow: auto;
}
.lightbox-content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
}

/* ===== ADMIN TOOLBAR ===== */
#admin-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(26, 39, 51, 0.95);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.admin-toolbar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
}

.admin-badge {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

.admin-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.admin-btn:hover { background: var(--accent); }

.admin-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  max-width: 560px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-sm { max-width: 380px; }
.modal h2 { margin-bottom: 20px; font-size: 18px; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full-width { grid-column: 1 / -1; margin-top: 8px; }
.form-group label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

.images-preview {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.images-preview img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.btn:hover { background: var(--accent); }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { background: var(--primary-hover); }

/* ===== TOASTS ===== */
#toast-container {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(26, 39, 51, 0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text);
  animation: toast-in 0.2s ease, toast-out 0.3s ease 2s forwards;
  backdrop-filter: blur(8px);
}
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  :root {
    --panel-w: 100vw;
    --floor-sel-w: 44px;
  }

  #unit-panel {
    right: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .floor-btn {
    width: 36px;
    height: 34px;
    font-size: 11px;
  }

  /* ── Full-screen plan on mobile (public mode) ── */
  body.is-public #app-header { display: none; }
  body.is-public #viewer-main { height: 100vh; }
  body.is-public #plan-viewport {
    padding: 0;
  }

  /* Rotate -90° only for Golden Rise (rectangular layout benefits from it) */
  body.is-public[data-building="building"] #plan-container {
    transform: rotate(-90deg) !important;
  }
  body.is-public[data-building="building"] #plan-image {
    max-width: 95vh;
    max-height: 98vw;
  }

  /* Sunset Tower: keep original orientation, just fit screen */
  body.is-public[data-building="sunset-tower"] #plan-image {
    max-width: 98vw;
    max-height: 95vh;
  }
}
