/* ─────────────────────────────────────────────────────────────
   Vastuujakotaulukko — design system
   Warm cream + corporate blue palette (kiinteistotahkola.fi brand)
   ───────────────────────────────────────────────────────────── */

:root {
  --vj-bg:          #f0f0e9;
  --vj-surface:     #ffffff;
  --vj-sunken:      #ebe2cf;
  --vj-soft:        #f0e8d6;

  --vj-ink:         #15212c;
  --vj-ink-2:       #34424e;
  --vj-ink-muted:   #6c7682;
  --vj-ink-soft:    #9aa3ab;

  --vj-border:        #ddd2b8;
  --vj-border-strong: #c5b896;

  /* Yhtiö (housing company) — corporate blue */
  --vj-y:      #1e5680;
  --vj-y-deep: #143e5e;
  --vj-y-soft: #d4e0e9;
  --vj-y-tint: #ebf1f5;

  /* Osakas (shareholder/resident) — warm rust */
  --vj-o:      #9d4f1f;
  --vj-o-deep: #743813;
  --vj-o-tint: #f7ead8;

  --vj-shadow-sm: 0 1px 2px rgba(20,30,45,.04), 0 2px 6px rgba(20,30,45,.03);
  --vj-shadow-md: 0 6px 16px rgba(20,30,45,.06), 0 1px 3px rgba(20,30,45,.04);
  --vj-shadow-lg: 0 24px 48px rgba(20,30,45,.10), 0 4px 12px rgba(20,30,45,.05);

  --vj-radius:    6px;
  --vj-radius-lg: 10px;

  --vj-font-sans:    "Manrope", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --vj-font-display: "Manrope", "Inter", system-ui, -apple-system, sans-serif;
}

/* ─── reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--vj-font-sans);
  color: var(--vj-ink);
  background: var(--vj-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#vj-root { min-height: 100vh; }

button { font: inherit; cursor: pointer; }

/* ─── frame ────────────────────────────────────────────────── */
.vj-frame {
  font-family: var(--vj-font-sans);
  color: var(--vj-ink);
  background: var(--vj-bg);
}

.vj-frame.is-standalone {
  height: auto;
  overflow: visible;
}

/* ─── V3 root ──────────────────────────────────────────────── */
.v3-root {
  position: relative;
  background: var(--vj-bg);
  overflow: hidden;
  padding: 32px 96px 36px;
  min-height: 100vh;
}

/* Decorative SVG background shapes */
.v3-root::before,
.v3-root::after {
  content: "";
  position: absolute;
  pointer-events: none;
  z-index: 0;
  background-repeat: no-repeat;
  background-size: contain;
}

.v3-root::before {
  top: 0; right: 0;
  width: 880px; height: 845px;
  background-image: url("../images/bg-shape-top-right.svg");
  background-position: top right;
  opacity: 0.28;
}

.v3-root::after {
  bottom: 0; left: 0;
  width: 880px; height: 845px;
  background-image: url("../images/bg-shape-bottom-left.svg");
  background-position: bottom left;
  opacity: 0.28;
}

.v3-root > * {
  position: relative;
  z-index: 1;
  max-width: 1480px;
  margin-left: auto;
  margin-right: auto;
}

@media (max-width: 720px) {
  .v3-root::before,
  .v3-root::after {
    width: 480px;
    height: 460px;
    opacity: 0.28;
  }
}

/* ─── Page header — white card with filter on right ────────── */
.v3-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 32px;
  background: var(--vj-surface);
  border: 1px solid var(--vj-border);
  border-radius: 10px;
  padding: 26px 32px;
  margin-bottom: 24px;
  box-shadow: var(--vj-shadow-sm);
}

.v3-head-text { max-width: 640px; min-width: 0; }

.v3-eyebrow {
  display: inline-block;
  color: var(--vj-y);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .22em;
  text-transform: uppercase;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--vj-y);
}

.v3-head h1 {
  font-family: var(--vj-font-display);
  font-size: 34px;
  line-height: 1.0;
  margin: 0 0 6px;
  color: var(--vj-y);
  letter-spacing: -.025em;
  font-weight: 800;
}

.v3-head p {
  margin: 0;
  color: var(--vj-ink-2);
  font-size: 13px;
  line-height: 1.45;
  max-width: 600px;
}

@media (max-height: 860px) {
  .v3-head p { display: none; }
  .v3-root { padding-top: 16px; }
}

/* ─── Filter controls (inside header) ─────────────────────── */
.v3-controls {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.v3-filter {
  display: inline-flex;
  background: transparent;
  border: 0;
  padding: 0;
  gap: 10px;
}

.v3-filter-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--vj-surface);
  border: 1px solid var(--vj-y);
  padding: 10px 36px 10px 16px;
  border-radius: 4px;
  color: var(--vj-y);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .005em;
  transition: background 140ms, color 140ms, border-color 140ms, box-shadow 140ms;
}

.v3-filter-btn::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 12px; height: 12px;
  transform: translateY(-50%);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231e5680' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M7 17 17 7M9 7h8v8'/></svg>");
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0.85;
  transition: opacity 140ms;
}

.v3-filter-btn:hover {
  background: var(--vj-y-tint);
  color: var(--vj-y-deep);
}

.v3-filter-btn.is-on {
  background: var(--vj-y);
  color: #fff;
  border-color: var(--vj-y);
  box-shadow: 0 4px 14px rgba(30,86,128,.25);
}

.v3-filter-btn.is-on::after {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M7 17 17 7M9 7h8v8'/></svg>");
  opacity: 1;
}

.v3-filter-btn.v3-filter-y.is-on { background: var(--vj-y); }
.v3-filter-btn.v3-filter-o.is-on { background: var(--vj-o); border-color: var(--vj-o); box-shadow: 0 4px 14px rgba(157,79,31,.25); }

.v3-filter-dot   { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }
.v3-filter-dot-y { background: var(--vj-y); }
.v3-filter-dot-o { background: var(--vj-o); }
.v3-filter-btn.is-on .v3-filter-dot { background: rgba(255,255,255,.9); }

.v3-filter-count {
  font-variant-numeric: tabular-nums;
  color: var(--vj-ink-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--vj-sunken);
}
.v3-filter-btn.is-on .v3-filter-count {
  color: #fff;
  background: rgba(255,255,255,.18);
}

/* ─── Card grid ────────────────────────────────────────────── */
.v3-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 20px;
}

@media (max-width: 1500px) {
  .v3-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .v3-root { padding-left: 40px; padding-right: 40px; }
  .v3-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .v3-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
}
@media (max-width: 640px) {
  .v3-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
}
@media (max-width: 460px) {
  .v3-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ─── Room card — vertical layout ─────────────────────────── */
.v3-card {
  background: var(--vj-surface);
  border: 1px solid #e9e1cc;
  border-radius: 10px;
  min-width: 0;
  overflow: hidden;
  transition: border-color 200ms, transform 200ms, box-shadow 200ms, opacity 200ms;
  box-shadow: 0 1px 2px rgba(20, 30, 45, 0.03);
}

.v3-card:hover {
  border-color: var(--vj-y-soft);
  box-shadow: 0 8px 24px rgba(20, 30, 45, 0.08), 0 2px 6px rgba(20, 30, 45, 0.04);
  transform: translateY(-2px);
}

.v3-card.is-dim { opacity: .4; }

/* The entire card face is a button */
.v3-card-head {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100%;
  min-width: 0;
  padding: 0;
  background: transparent;
  border: 0;
  text-align: left;
  height: 100%;
}

/* Title row — at the top */
.v3-card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 12px 14px 10px;
  font-family: var(--vj-font-display);
  font-size: 16px;
  color: var(--vj-y);
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -.005em;
  min-height: 36px;
}

.v3-card-title > span:first-child {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.v3-card-arrow {
  color: var(--vj-y);
  opacity: .6;
  display: inline-flex;
  flex-shrink: 0;
  transition: opacity 160ms, transform 160ms;
}

.v3-card:hover .v3-card-arrow {
  opacity: 1;
  transform: translate(2px, -2px);
}

/* Photo — full-width, square, shows full illustration */
.v3-card-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #ffffff;
  border-top: 1px solid var(--vj-border);
  border-bottom: 1px solid var(--vj-border);
}

.v3-card-photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: transform 400ms ease;
}

.v3-card:hover .v3-card-photo img { transform: scale(1.03); }

/* Meter bar — at the bottom */
.v3-card-foot {
  padding: 8px 14px 10px;
}

/* ─── Split-meter bar ──────────────────────────────────────── */
.v3-meter { display: grid; gap: 4px; }

.v3-meter-track {
  display: flex;
  height: 5px;
  background: var(--vj-sunken);
  border-radius: 999px;
  overflow: hidden;
}

.v3-meter-fill { height: 100%; transition: width 200ms ease, opacity 200ms; }
.v3-meter-y    { background: var(--vj-y); }
.v3-meter-o    { background: var(--vj-o); }

.v3-meter-legend {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--vj-ink-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.v3-meter-legend b { color: var(--vj-ink); font-weight: 600; }

/* ─── Modal overlay ────────────────────────────────────────── */
.v3-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  animation: vj-fade 160ms ease;
}

@keyframes vj-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.v3-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20,30,45,.55);
  backdrop-filter: blur(4px);
  border: 0;
  cursor: pointer;
  padding: 0;
}

.v3-modal-card {
  position: relative;
  width: min(1100px, 100%);
  max-height: calc(100vh - 48px);
  background: var(--vj-surface);
  border-radius: var(--vj-radius-lg);
  box-shadow: var(--vj-shadow-lg);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

/* Side nav arrows (hidden on narrow viewports) */
.v3-modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 0;
  background: rgba(255,255,255,.95);
  color: var(--vj-y);
  display: grid;
  place-items: center;
  box-shadow: var(--vj-shadow-md);
  cursor: pointer;
  transition: transform 140ms, background 140ms;
}

.v3-modal-nav:hover {
  background: #fff;
  transform: translateY(-50%) scale(1.06);
}

.v3-modal-nav-prev { left: 20px; }
.v3-modal-nav-next { right: 20px; }

@media (max-width: 920px) {
  .v3-modal-nav { display: none; }
}

/* Modal header */
.v3-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--vj-border);
}

.v3-modal-head-text { display: grid; gap: 6px; min-width: 0; }

.v3-modal-kicker {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--vj-ink-muted);
  font-weight: 600;
}

.v3-modal-head h2 {
  font-family: var(--vj-font-display);
  font-size: 30px;
  line-height: 1.1;
  margin: 0;
  color: var(--vj-y);
  font-weight: 700;
  letter-spacing: -.01em;
}

.v3-modal-counts {
  display: inline-flex;
  gap: 16px;
  font-size: 13px;
  color: var(--vj-ink-2);
  margin-top: 4px;
  flex-wrap: wrap;
}

.v3-modal-counts span { display: inline-flex; align-items: center; gap: 6px; }

.v3-dot      { width: 8px; height: 8px; border-radius: 999px; display: inline-block; flex-shrink: 0; }
.v3-dot-y    { background: var(--vj-y); }
.v3-dot-o    { background: var(--vj-o); }

.v3-modal-close {
  background: var(--vj-sunken);
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--vj-ink-2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 120ms, color 120ms;
}

.v3-modal-close:hover { background: var(--vj-border); color: var(--vj-ink); }

/* Modal body — two-column: photo stage + item list */
.v3-modal-body {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 22px;
  padding: 22px 26px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--vj-bg);
}

/* Mobile Kuva / Lista toggle — hidden on desktop where both panes show */
.v3-mobile-switch { display: none; }

@media (max-width: 820px) {
  .v3-modal-body {
    grid-template-columns: 1fr;
    padding: 14px 14px 18px;
    gap: 14px;
  }
  .v3-mobile-switch {
    display: inline-flex;
    align-self: center;
    background: #fff;
    border: 1px solid var(--vj-border);
    border-radius: 999px;
    padding: 4px;
    gap: 2px;
    box-shadow: 0 1px 2px rgba(20,33,44,.06);
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .v3-mobile-switch-btn {
    appearance: none;
    background: transparent;
    border: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 999px;
    color: var(--vj-ink-2);
    font: 500 14px/1 var(--vj-font-sans);
    transition: background 140ms, color 140ms;
    min-height: 40px;
  }
  .v3-mobile-switch-btn:hover { color: var(--vj-ink); }
  .v3-mobile-switch-btn.is-on { background: var(--vj-ink); color: #fff; }

  .v3-mobile-switch-count {
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    color: var(--vj-ink-muted);
    background: var(--vj-bg);
    padding: 2px 7px;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
  }
  .v3-mobile-switch-btn.is-on .v3-mobile-switch-count {
    background: rgba(255,255,255,.18);
    color: #fff;
  }

  /* Show only the active pane */
  .v3-modal-body[data-mobile-view="image"] .v3-detail-list { display: none; }
  .v3-modal-body[data-mobile-view="list"]  .v3-detail-stage { display: none; }

  /* Image fills full width on mobile — no viewport-height cap */
  .v3-detail-stage { max-width: none; }
}

/* Photo stage with pins — locked to image's native ratio (3376×4880)
   so hotspot percentages land on the correct features */
.v3-detail-stage {
  position: relative;
  background: #ffffff;
  border: 1px solid var(--vj-border);
  border-radius: var(--vj-radius);
  overflow: visible;
  aspect-ratio: 3376 / 4880;
  width: 100%;
  max-width: calc((100vh - 280px) * var(--v3-stage-aspect, 0.692));
  margin: 0 auto;
  align-self: start;
  cursor: default;
}

.v3-detail-stage img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--vj-radius);
}

/* Numbered pins on the photo */
.v3-pin {
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid #fff;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  cursor: pointer;
  transition: transform 140ms, box-shadow 140ms, opacity 140ms;
}

.v3-pin-y { background: var(--vj-y); }
.v3-pin-o { background: var(--vj-o); }

.v3-pin.is-hidden { opacity: .15; pointer-events: none; }

.v3-pin.is-focus {
  transform: translate(-50%, -50%) scale(1.2);
  z-index: 5;
  box-shadow: 0 0 0 5px rgba(255,255,255,.6), 0 4px 12px rgba(0,0,0,.4);
}

.v3-pin-num { font-variant-numeric: tabular-nums; }

/* Pin tooltip — hidden by default, shown on is-focus */
.v3-pin .v3-pin-tip { display: none; }
.v3-pin.is-focus .v3-pin-tip { display: grid; }

.v3-pin-tip {
  position: absolute;
  left: 50%;
  top: calc(100% + 10px);
  transform: translateX(-50%);
  background: #fff;
  border: 1px solid var(--vj-border);
  border-radius: 8px;
  box-shadow: var(--vj-shadow-md);
  padding: 10px 12px;
  min-width: 180px;
  max-width: 240px;
  gap: 6px;
  z-index: 10;
  pointer-events: none;
  white-space: normal;
  animation: vj-tipfade 120ms ease-out;
}

@keyframes vj-tipfade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Tooltip flipped above pin when near bottom of image */
.v3-pin-tip.is-up {
  top: auto;
  bottom: calc(100% + 10px);
}

/* Tooltip shifted when pin is near right edge */
.v3-pin-tip.is-left {
  left: auto;
  right: 50%;
  transform: none;
}

/* Tooltip shifted when pin is near left edge */
.v3-pin-tip.is-right {
  left: 50%;
  right: auto;
  transform: none;
}

.v3-pin-tip-label {
  font-size: 13px;
  line-height: 1.35;
  color: var(--vj-ink);
  font-weight: 500;
}

.v3-pin-tip-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: .01em;
  align-self: flex-start;
  margin-top: 2px;
}

.v3-pin-tip-tag-y { background: var(--vj-y-tint); color: var(--vj-y-deep); }
.v3-pin-tip-tag-o { background: var(--vj-o-tint); color: var(--vj-o-deep); }

/* Responsibility item list */
.v3-detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  align-content: start;
}

.v3-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 11px 14px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid transparent;
  cursor: default;
  transition: border-color 120ms, background 120ms;
}

.v3-item:hover,
.v3-item.is-focus { border-color: var(--vj-border-strong); }
.v3-item.is-focus  { background: var(--vj-soft); }

.v3-item-num {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.v3-item-y .v3-item-num { background: var(--vj-y); }
.v3-item-o .v3-item-num { background: var(--vj-o); }

.v3-item-label { font-size: 13px; line-height: 1.4; color: var(--vj-ink); }

.v3-item-tag {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: .01em;
  white-space: nowrap;
}

.v3-item-tag-y { background: var(--vj-y-tint); color: var(--vj-y-deep); }
.v3-item-tag-o { background: var(--vj-o-tint); color: var(--vj-o-deep); }

.v3-detail-empty {
  padding: 24px;
  text-align: center;
  color: var(--vj-ink-muted);
  font-size: 13px;
  background: #fff;
  border-radius: 8px;
}

/* Modal footer — prev / tip / next */
.v3-modal-foot {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--vj-border);
  background: var(--vj-surface);
}

.v3-modal-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--vj-border);
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--vj-y);
  font-size: 12px;
  font-weight: 500;
  max-width: 100%;
  min-width: 0;
  justify-self: start;
  transition: background 120ms, border-color 120ms;
}

.v3-modal-step:hover { background: var(--vj-y-tint); border-color: var(--vj-y); }

.v3-modal-step span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.v3-modal-step-next { justify-self: end; }

.v3-modal-tip {
  font-size: 11px;
  color: var(--vj-ink-soft);
  letter-spacing: .04em;
  justify-self: center;
  text-align: center;
  white-space: nowrap;
}

/* ─── Responsive adjustments ───────────────────────────────── */
@media (max-width: 860px) {
  .v3-root { padding: 16px 20px 24px; }
  .v3-head { grid-template-columns: 1fr; }
  .v3-head h1 { font-size: 26px; }
  .v3-controls { flex-wrap: wrap; }
  .v3-filter { flex-wrap: wrap; gap: 8px; }
  .v3-filter-btn { padding: 8px 30px 8px 12px; font-size: 12px; }
}

@media (max-width: 600px) {
  .v3-root { padding: 12px 16px 20px; }
  .v3-modal { padding: 12px; }
  .v3-modal-body { padding: 16px; gap: 16px; }
  .v3-modal-head { padding: 16px 16px 14px; }
  .v3-modal-head h2 { font-size: 22px; }
  .v3-modal-tip { display: none; }
  .v3-modal-foot { grid-template-columns: 1fr 1fr; padding: 12px 14px; }
  .v3-modal-step span { max-width: 100px; }
}
