/* mpmap — mobile-first styles. One stylesheet for login.html and index.html. */

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #eef0f3;
  --border: #d7dbe1;
  --text: #1a1d23;
  --text-dim: #656d78;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fde8e8;
  --ok: #16a34a;
  --shadow: 0 2px 10px rgba(20, 22, 30, 0.12);

  /* kind tints (subtle fills over SVG paths) */
  --kind-room: #bfdbfe;
  --kind-meeting: #ddd6fe;
  --kind-lift: #fde68a;
  --kind-stairs: #fdba74;
  --kind-wc-women: #fbcfe8;
  --kind-wc-men: #bae6fd;
  --kind-kitchen: #bbf7d0;
  --kind-other: #e5e7eb;
}

* { box-sizing: border-box; }

/* `hidden` must always win over any display rule below (e.g. .loading/.export-menu
   set display:flex, which would otherwise override the attribute's default). */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------- login page ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
  text-align: center;
}

.login-card p.sub {
  margin: 0 0 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  font-size: 16px; /* avoid iOS zoom-on-focus */
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  width: 100%;
}

.btn-primary:active { opacity: 0.85; }

.error-banner {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  text-align: center;
}

/* ---------- app shell ---------- */

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-wrap: nowrap;
  overflow-x: auto;
}

.floor-btns {
  display: flex;
  gap: 4px;
}

.floor-btn {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.floor-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.topbar .spacer { flex: 1; }

.icon-btn {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 0 10px;
  cursor: pointer;
  white-space: nowrap;
}

.icon-btn.on {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.icon-btn.danger {
  color: var(--danger);
}

/* ---------- map area ---------- */

.map-area {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #dfe3e8;
  touch-action: none;
}

.map-area .svg-holder {
  position: absolute;
  inset: 0;
}

.map-area svg {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* we drive pan/zoom ourselves via pointer events */
}

.map-area .loading,
.map-area .empty-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
  pointer-events: none;
}

/* room path states -- applied to injected <path> elements */
path.room-shape {
  cursor: pointer;
  stroke: #8a93a3;
  stroke-width: 1;
  fill: transparent;
  transition: fill 0.15s ease;
}

path.room-shape.is-fragment {
  opacity: 0.25;
}

path.room-shape.mapped {
  fill-opacity: 0.55;
}

path.room-shape[data-kind="room"] { fill: var(--kind-room); }
path.room-shape[data-kind="meeting"] { fill: var(--kind-meeting); }
path.room-shape[data-kind="lift"] { fill: var(--kind-lift); }
path.room-shape[data-kind="stairs"] { fill: var(--kind-stairs); }
path.room-shape[data-kind="wc-women"] { fill: var(--kind-wc-women); }
path.room-shape[data-kind="wc-men"] { fill: var(--kind-wc-men); }
path.room-shape[data-kind="kitchen"] { fill: var(--kind-kitchen); }
path.room-shape[data-kind="other"] { fill: var(--kind-other); }

path.room-shape.broken {
  fill: #fca5a5 !important;
  stroke: var(--danger);
  stroke-width: 1.5;
}

path.room-shape.selected {
  stroke: var(--accent);
  stroke-width: 3;
  vector-effect: non-scaling-stroke; /* stay crisp regardless of pan-zoom scale */
}

/* tint an empty (unmapped) contour when selected so the tap is obvious */
path.room-shape.selected:not(.mapped) {
  fill: rgba(37, 99, 235, 0.18);
}

g.room-labels text {
  font-size: 10px;
  font-weight: 600;
  fill: #111318;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 3px;
  stroke-linejoin: round;
}

g.room-labels {
  display: none;
  pointer-events: none; /* labels must never intercept taps meant for a path */
}

g.room-labels.visible {
  display: block;
}

/* ---------- warning banner ---------- */

.banner {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 8px;
  z-index: 30;
  background: #fffbeb;
  border: 1px solid #fbbf24;
  color: #92400e;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
}

.banner.error {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- bottom sheet edit panel ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 22, 0.35);
  z-index: 40;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
  max-height: 86vh;
  overflow-y: auto;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin: 0 auto 12px;
}

.sheet .key-row {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.sheet h2 {
  font-size: 16px;
  margin: 0 0 12px;
}

.field-group {
  margin-bottom: 14px;
}

.field-group > label,
.field-group > .label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}

.kind-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.kind-opt {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 10px 8px;
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  min-height: 44px;
}

.kind-opt.selected {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.code-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}

.code-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  font-size: 16px;
}

.code-row .code-tag {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 44px;
}

.code-row .rm-btn {
  border: none;
  background: none;
  color: var(--danger);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 8px;
  min-width: 32px;
}

.add-code-btn {
  border: 1px dashed var(--border);
  background: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  width: 100%;
}

.text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  font-size: 16px;
}

textarea.text-input {
  min-height: 70px;
  resize: vertical;
}

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

.checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.sheet-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 12px;
}

.sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.sheet-actions .btn {
  flex: 1;
}

.btn-secondary {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--surface);
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* ---------- export menu ---------- */

.export-menu {
  position: absolute;
  top: 52px;
  right: 8px;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}

.export-menu a {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
}

.export-menu a:active {
  background: var(--surface-alt);
}

@media (max-width: 380px) {
  .icon-btn, .floor-btn { font-size: 12px; }
}
