@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@500;600;700;800&display=swap");

:root {
  --bg: #f5f8f4;
  --surface: #ffffff;
  --border: #e2e8e0;
  --text: #1c231e;
  --text-muted: #64705f;
  --accent: #5ca747;
  --accent-hover: #4c8f3a;
  --accent-soft: #eaf6e5;
  --danger: #dc2626;
  --radius: 10px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

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

h1, h2, h3 {
  font-family: "Poppins", -apple-system, sans-serif;
  font-weight: 700;
  letter-spacing: -0.01em;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.5rem;
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
header > div {
  display: flex;
  align-items: center;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 1.25rem;
  font-family: "Poppins", sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.brand-icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}
.brand span { color: var(--accent); font-weight: 600; }
header a {
  color: var(--text);
  text-decoration: none;
  margin-right: 1rem;
  font-weight: 600;
  position: relative;
  transition: color 0.15s var(--ease);
}
header a:hover { color: var(--accent); }
header a::after {
  content: "";
  position: absolute;
  left: 0; bottom: -3px;
  width: 0;
  height: 2px;
  background: var(--accent);
  transition: width 0.2s var(--ease);
}
header a:hover::after { width: 100%; }

button {
  cursor: pointer;
  font-family: "Poppins", inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease);
}
button:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}
button:active { transform: scale(0.97); }

form button[type="submit"],
.login-box button {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
form button[type="submit"]:hover,
.login-box button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: white;
  box-shadow: var(--shadow-md);
}

main {
  padding: 1.75rem 1.25rem;
  max-width: 1000px;
  margin: 0 auto;
}

#map {
  height: 70vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.property-marker {
  background: transparent;
  border: none;
}

.login-box {
  max-width: 340px;
  margin: 4.5rem auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: rise-in 0.4s var(--ease);
}
.login-box h2 { margin: 0 0 0.25rem; font-size: 1.3rem; }

.login-box input, .login-box button, form input, form select, form button, form textarea {
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.login-box input:focus, form input:focus, form select:focus, form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

form { display: flex; flex-direction: column; gap: 0.65rem; }

form label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: -0.35rem;
}

details {
  margin-top: 0.85rem;
  font-size: 0.9rem;
}
details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
}
.inline-add {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.65rem;
}
.inline-add input, .inline-add select { flex: 1; }
.inline-add button { width: auto; }

#customer-properties {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: -0.35rem;
}
#customer-properties ul {
  list-style: none;
  margin: 0.25rem 0 0;
  padding-left: 0;
  display: inline-grid;
  grid-template-columns: max-content max-content;
  column-gap: 0.75rem;
  row-gap: 0.4rem;
  align-items: center;
}
#customer-properties ul li { display: contents; }
#customer-properties a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
#customer-properties a:hover { color: var(--accent-hover); text-decoration: underline; }
#customer-properties .no-pin { color: var(--danger); }
#customer-properties button.delete-property {
  width: auto;
  padding: 0.1rem 0.5rem;
  font-size: 0.75rem;
  background: none;
  color: var(--danger);
  border: 1px solid var(--border);
}
#customer-properties button.delete-property:hover { border-color: var(--danger); background: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
  animation: rise-in 0.35s var(--ease);
}
.card:hover { box-shadow: var(--shadow-md); }
.card h2, .card h3 { margin-top: 0; }

.room-list a {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  transition: border-color 0.15s var(--ease), transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.room-list a:hover {
  border-color: var(--accent);
  transform: translateX(3px);
  box-shadow: var(--shadow-sm);
}

.error {
  color: var(--danger);
  min-height: 1.2em;
  font-size: 0.9rem;
}
.error:not(:empty) { animation: shake 0.35s var(--ease); }

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.user-row button {
  background: none;
  color: var(--danger);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  width: auto;
}
.user-row button:hover { border-color: var(--danger); background: none; }

#marks-panel {
  position: fixed;
  top: 4.25rem; left: 0;
  width: 300px;
  height: calc(100% - 4.25rem);
  background: var(--surface);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  z-index: 150;
}
#marks-panel .panel-header {
  justify-content: flex-start;
}
body.room-page main {
  margin-left: 300px;
  max-width: calc(100% - 300px);
}

#viewer {
  width: 100%;
  height: 75vh;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
/* While a mark panel is open the only marker left visible is the selected
   one (see updateMarkersVisibility in room.js) -- it can still paint on top
   of the fixed-position panel (CSS3D markers ignore z-index/overflow on
   some mobile browsers), so pointer events are dropped here to stop it
   swallowing taps meant for the panel underneath. */
.marker-panel-open .psv-marker { pointer-events: none; }

.mark-icon-wrap {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s var(--ease);
}
.mark-doc-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: orange;
  border: 1px solid var(--surface);
  font-size: 8px;
  line-height: 14px;
  text-align: center;
}
.mark-icon-wrap:hover { transform: scale(1.12); }
.mark-icon-wrap.concealed {
  border-style: dashed;
  opacity: 0.85;
}
.mark-icon-wrap.selected {
  background: orange;
  border-color: var(--surface);
  box-shadow: 0 0 0 3px orange;
}
/* The pulse ring animates transform/opacity on a separate ::after layer
   rather than animating box-shadow directly -- box-shadow is a paint
   property, and PSV's marker icons live inside a CSS3D-transformed (GPU
   layer-promoted) element, where browsers frequently skip repainting an
   animated box-shadow, making the "pulse" silently do nothing even though
   the animation is genuinely running (confirmed via computed styles: the
   selected marker got .selected + the animation, just never visibly
   painted it). transform/opacity are compositor-driven and don't have
   this problem. */
.mark-icon-wrap.selected::after,
.mark-props-icon .mark-icon-wrap::after,
.marks-list li.active .mark-icon-wrap::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 3px solid orange;
  animation: mark-pulse-ring 1.6s var(--ease) infinite;
  pointer-events: none;
}
.mark-icon-wrap img {
  width: 100%;
  height: 100%;
  filter: brightness(0) invert(1);
}

#mark-form-panel,
#mark-properties-panel {
  position: fixed;
  top: 4.25rem; right: 0;
  width: 300px;
  height: calc(100% - 4.25rem);
  background: var(--surface);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  animation: slide-in 0.25s var(--ease);
  z-index: 200;
}
#mark-form-panel[hidden],
#mark-properties-panel[hidden] { display: none; }
#mark-form-panel h3,
#mark-properties-panel h3 { margin-top: 0; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: -1.25rem -1.25rem 0.75rem;
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.panel-header h3 { margin: 0; }
.panel-close {
  flex-shrink: 0;
  padding: 0.4rem 0.9rem;
}

.mark-props dt {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
}
.mark-props dd {
  margin: 0.15rem 0 0;
  font-weight: 500;
}
.mark-props-icon { display: flex; justify-content: center; margin-bottom: 0.5rem; }
.mark-props-icon .mark-icon-wrap {
  width: 48px;
  height: 48px;
  background: orange;
}

.mark-documents { list-style: none; margin: 0.5rem 0; padding: 0; font-size: 0.85rem; }
.mark-documents li { margin-bottom: 0.5rem; color: var(--text-muted); }
#document-form { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }

.marks-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.marks-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.4rem;
  border-radius: 4px;
  cursor: pointer;
}
.marks-list li:hover { background: var(--surface-hover, rgba(0, 0, 0, 0.04)); }
.marks-list li.active {
  background: rgba(255, 165, 0, 0.18);
  outline: 1px solid orange;
}
.marks-list .mark-icon-wrap { width: 26px; height: 26px; }
.marks-list li.active .mark-icon-wrap {
  background: orange;
}

.document-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.2rem; height: 1.2rem;
  border-radius: 50%;
  font-size: 0.7rem;
  margin-right: 0.3rem;
}

#document-preview {
  position: fixed;
  width: 360px;
  height: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  border-radius: 6px;
  padding: 0.5rem;
  z-index: 200;
}
#document-preview[hidden] { display: none; }
#document-preview-content { width: 100%; height: 100%; }
#document-preview-content img { width: 100%; height: 100%; object-fit: contain; }
#document-preview-content iframe { width: 100%; height: 100%; border: none; }

.icon-legend { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.5rem; }
.icon-legend .mark-icon-wrap { width: 24px; height: 24px; }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@keyframes mark-pulse-ring {
  0% { transform: scale(1); opacity: 0.6; }
  70% { transform: scale(1.9); opacity: 0; }
  100% { transform: scale(1.9); opacity: 0; }
}

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

@media (max-width: 640px) {
  header {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
  }
  header a { margin-right: 0.75rem; }

  main { padding: 1rem 0.85rem; }

  .login-box { margin: 2rem auto; max-width: 100%; }

  .inline-add { flex-wrap: wrap; }
  .inline-add input, .inline-add select, .inline-add button { flex: 1 1 100%; }

  #map { height: 60vh; }
  #viewer { height: 55vh; }

  body.room-page main { margin-left: 0; max-width: 100%; }
  #marks-panel {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-height: 40vh;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  #mark-form-panel,
  #mark-properties-panel {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    max-height: 50vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
  }

  #document-preview {
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100%;
    height: 65vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .mark-props {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.75rem;
    row-gap: 0.4rem;
    align-items: baseline;
  }
  .mark-props dt {
    margin-top: 0;
  }
  .mark-props dd {
    margin: 0;
  }
}
