/* ---------------------------------------------------------------
   Design tokens
   Aihe: LoRaWAN-anturit kiinteistön pohjapiirroksessa.
   Ilme lainaa arkkitehtipiirustuksilta (blueprint) - tumma
   sinivihreä pohja, ohuet piirroslinjat, mittaustieto mono-fontilla.
   ------------------------------------------------------------- */
:root {
  --bg:            #0F1720;
  --panel:         #16212B;
  --panel-border:  #263542;
  --line:          #3B4E5E;   /* pohjapiirroksen seinälinjat */
  --line-soft:     #24333F;   /* apuruudukko */

  --text:          #E7ECF2;
  --text-dim:      #8A97A6;
  --text-faint:    #56636F;

  --accent-climate: #4FB286;  /* huoneanturi: teal */
  --accent-door:    #5B8DEF;  /* ovianturi: sininen */
  --accent-warn:    #E0A345;  /* huomio */
  --accent-offline: #E1614F;  /* ei yhteyttä */

  --radius: 6px;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-data: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

/* Varmistetaan, että hidden-attribuutti VOITTAA aina komponenttien omat
   display-säännöt. Ilman tätä esim. "display: flex" jossain komponentin
   luokassa jättäisi elementin näkyviin, vaikka JS asettaisi sen
   hidden-attribuutin - tämä aiheutti aiemmin mm. raahausvihjeen ja
   "ei pohjapiirroskuvaa" -viestin jäämisen näkyviin virheellisesti. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------------- Topbar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel);
}

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

.topbar__mark {
  font-size: 22px;
  color: var(--accent-climate);
  line-height: 1;
}

.topbar h1 {
  font-size: 16px;
}

.topbar__subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.topbar__controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar__field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar__field label {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

#property-select,
#view-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--font-ui);
  font-size: 13.5px;
}

/* ---------------- Näkymät (Asetukset / tulevat) ---------------- */

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.view-placeholder {
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.view-placeholder__card {
  max-width: 420px;
  text-align: center;
  color: var(--text-dim);
}

.view-placeholder__card h2 {
  color: var(--text);
  font-size: 18px;
  margin-bottom: 10px;
}

.move-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--accent-warn);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
}

.move-banner .btn {
  border-color: var(--bg);
  color: var(--bg);
}

/* ---------------- Layout ---------------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  min-height: 0;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 55vh) 1fr;
  }
}

/* ---------------- Floor plan panel ---------------- */

.floorplan-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--panel-border);
}

@media (max-width: 860px) {
  .floorplan-panel { border-right: none; border-bottom: 1px solid var(--panel-border); }
}

.floorplan-panel__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}

.place-toggle {
  background: transparent;
  border: 1px solid var(--accent-climate);
  color: var(--accent-climate);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12.5px;
  font-family: var(--font-ui);
  cursor: pointer;
}

.place-toggle.is-active {
  background: var(--accent-climate);
  color: var(--bg);
}

/* ---------------- Anturityyppipalkki (raahauksen lähde) ---------------- */

.sensor-palette-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 12px;
  flex-wrap: wrap;
}

.sensor-palette-bar__label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.sensor-palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.palette-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--panel);
  cursor: grab;
  touch-action: none;
  user-select: none;
  font-size: 12.5px;
}

.palette-chip:active {
  cursor: grabbing;
  border-color: var(--accent-climate);
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

.drag-ghost.dot--climate { background: var(--accent-climate); color: var(--accent-climate); }
.drag-ghost.dot--door { background: var(--accent-door); color: var(--accent-door); }

.floorplan-wrap.drop-armed {
  outline: 2px dashed var(--accent-climate);
  outline-offset: -2px;
}

.legend {
  display: flex;
  gap: 16px;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.zoom-hint {
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot--climate { background: var(--accent-climate); }
.dot--door { background: var(--accent-door); }
.dot--offline { background: var(--accent-offline); }

.floorplan-wrap {
  position: relative;
  flex: 1;
  overflow: auto;
  padding: 8px;
}

.floorplan {
  width: 100%;
  height: 100%;
  min-height: 320px;
  display: block;
}

.floorplan-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.6;
}

/* SVG-elementit (piirretään JS:ssä, tyylit tässä jotta pysyvät yhdenmukaisina) */

.floorplan image {
  pointer-events: none; /* klikkaus menee aina SVG:lle, ei kuvalle */
}

.floorplan.is-placing {
  cursor: crosshair;
}

.floorplan {
  touch-action: none;
  cursor: grab;
}

.floorplan.is-panning {
  cursor: grabbing;
}

.sensor-marker circle.halo {
  fill: none;
  stroke-width: 1;
  opacity: 0.35;
}

.sensor-marker circle.core {
  stroke: var(--bg);
  stroke-width: 1.5;
  cursor: pointer;
}

.sensor-marker.type-room_climate circle.core,
.sensor-marker.type-room_climate circle.halo { fill: var(--accent-climate); stroke: var(--accent-climate); }

.sensor-marker.type-door_contact circle.core,
.sensor-marker.type-door_contact circle.halo { fill: var(--accent-door); stroke: var(--accent-door); }

.sensor-marker.status-offline circle.core { fill: var(--accent-offline); }

.sensor-marker.pending circle.core {
  stroke: var(--bg);
  stroke-width: 2;
  stroke-dasharray: 3 2;
  opacity: 0.9;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar__header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--panel-border);
}

.sidebar__header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar__header h2 {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: none;
  font-weight: 600;
}

.btn--small {
  padding: 4px 9px;
  font-size: 11.5px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.filter-chip {
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text-dim);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: var(--font-ui);
  cursor: pointer;
}

.filter-chip.is-active {
  border-color: var(--accent-climate);
  color: var(--text);
}

.sensor-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  overflow-y: auto;
  flex: 1;
}

.sensor-list__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  border-left: 2px solid transparent;
}

.sensor-list__item:hover,
.sensor-list__item.is-active {
  background: var(--panel);
  border-left-color: var(--accent-climate);
}

.sensor-list__meta {
  flex: 1;
  min-width: 0;
}

.sensor-list__name {
  font-size: 13px;
}

.sensor-list__room {
  font-size: 11.5px;
  color: var(--text-dim);
}

.sensor-list__value {
  font-family: var(--font-data);
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

.sensor-list__empty {
  padding: 20px 16px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}

/* ---------------- Detail panel (klikattu anturi) ---------------- */

.detail-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 280px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

@media (max-width: 860px) {
  .detail-panel { left: 16px; right: 16px; width: auto; }
}

.detail-panel__close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}

.detail-panel h3 {
  font-size: 14px;
  margin-bottom: 2px;
}

.detail-panel .detail-room {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-top: 1px solid var(--panel-border);
  font-size: 13px;
}

.detail-row:first-of-type { border-top: none; }

.detail-row__key { color: var(--text-dim); }
.detail-row__value { font-family: var(--font-data); }

.detail-panel__actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--panel-border);
}

.detail-panel__actions .btn {
  flex: 1;
}

/* ---------------- Sijoita anturi -lomake ---------------- */

.place-form {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 280px;
  background: var(--panel);
  border: 1px solid var(--accent-climate);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (max-width: 860px) {
  .place-form { left: 16px; right: 16px; width: auto; }
}

.place-form h3 {
  font-size: 14px;
  margin-bottom: 4px;
}

.place-form__type {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  font-size: 12.5px;
  width: fit-content;
}

.place-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.place-form__optional {
  color: var(--text-faint);
  font-weight: 400;
}

.place-form__hint {
  font-size: 12px;
  color: var(--text-dim);
  margin: -2px 0 0;
  line-height: 1.5;
}

.place-form__error {
  font-size: 12.5px;
  color: var(--accent-offline);
  margin: -4px 0 0;
}

.place-form input[type="file"] {
  padding: 6px;
  font-size: 12.5px;
}

.place-form input,
.place-form select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 7px 9px;
  font-family: var(--font-ui);
  font-size: 13px;
}

.place-form__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.btn {
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 12.5px;
  font-family: var(--font-ui);
  cursor: pointer;
  border: 1px solid transparent;
}

.btn--ghost {
  background: transparent;
  border-color: var(--panel-border);
  color: var(--text-dim);
}

.btn--primary {
  background: var(--accent-climate);
  color: var(--bg);
  font-weight: 600;
}

.btn--danger {
  background: transparent;
  border-color: var(--accent-offline);
  color: var(--accent-offline);
}

.btn--danger:hover {
  background: var(--accent-offline);
  color: var(--bg);
}

/* ---------------- Siirtotilan merkin tyyli ---------------- */

.sensor-marker.is-moving circle.core {
  stroke: var(--accent-warn);
  stroke-width: 2.5;
  stroke-dasharray: 4 2;
  cursor: grab;
}

.sensor-marker.is-moving:active circle.core {
  cursor: grabbing;
}
