/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #ffffff;
  --surface:     #f5f5f5;
  --surface2:    #ebebeb;
  --border:      #d0d0d0;
  --text:        #111111;
  --text-muted:  #666666;
  --accent:      #1a1a1a;
  --green:       #2d8a4e;
  --yellow:      #c8930a;
  --red:         #b33a3a;
  --gray:        #888888;
  --sidebar-w:   340px;
  --header-h:    48px;
  --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono:        "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  z-index: 10;
}

#header h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

#header h1 span {
  font-weight: 400;
  color: var(--text-muted);
}

#header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Layout ────────────────────────────────────────────── */
#app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow: hidden;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}

#breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

#breadcrumb .crumb {
  cursor: pointer;
  color: var(--text-muted);
  text-decoration: underline;
}
#breadcrumb .crumb:hover { color: var(--text); }
#breadcrumb .sep { color: var(--border); }
#breadcrumb .active { color: var(--text); font-weight: 500; text-decoration: none; cursor: default; }

#sidebar-body { flex: 1; overflow-y: auto; }

/* ── Building List ─────────────────────────────────────── */
.building-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--surface2);
  cursor: pointer;
  transition: background 0.1s;
}
.building-item:hover { background: var(--surface); }
.building-item.active { background: var(--accent); color: #fff; }

.building-item .bld-id {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  width: 36px;
  flex-shrink: 0;
}
.building-item.active .bld-id { color: rgba(255,255,255,0.7); }

.building-item .bld-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.building-item .bld-units {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
}
.building-item.active .bld-units { color: rgba(255,255,255,0.7); }

/* ── Floor List ────────────────────────────────────────── */
.building-detail { padding: 14px; }
.building-detail h2 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.building-detail .bld-address { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.building-detail .bld-desc { font-size: 13px; line-height: 1.5; color: var(--text-muted); margin-bottom: 14px; }

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.floor-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }

.floor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg);
  transition: background 0.1s, border-color 0.1s;
}
.floor-item:hover { background: var(--surface); border-color: var(--accent); }
.floor-item.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.floor-item .fl-label { font-size: 13px; font-weight: 500; }
.floor-item .fl-units { font-size: 12px; color: var(--text-muted); }
.floor-item.active .fl-units { color: rgba(255,255,255,0.7); }
.floor-item .fl-plan-badge {
  font-size: 10px;
  background: var(--green);
  color: #fff;
  border-radius: 3px;
  padding: 1px 5px;
}
.floor-item.active .fl-plan-badge { background: rgba(255,255,255,0.25); }

/* ── Unit List ─────────────────────────────────────────── */
.floor-detail { padding: 14px; }
.floor-detail h2 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.floor-detail .fl-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }

.unit-list { display: flex; flex-direction: column; gap: 4px; }

.unit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg);
  transition: background 0.1s;
}
.unit-item:hover { background: var(--surface); }
.unit-item.active { border-color: var(--accent); background: var(--surface); }

.unit-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.unit-dot.available     { background: var(--green); }
.unit-dot.leased        { background: var(--gray); }
.unit-dot.not_available { background: var(--red); }
.unit-dot.unknown       { background: var(--yellow); }

.unit-suite { font-size: 13px; font-weight: 600; font-family: var(--mono); min-width: 48px; }
.unit-tenant { font-size: 12px; color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit-sqft { font-size: 11px; color: var(--text-muted); text-align: right; flex-shrink: 0; }

/* ── Unit Detail ───────────────────────────────────────── */
.unit-detail { padding: 14px; }
.unit-detail h2 { font-size: 16px; font-weight: 700; font-family: var(--mono); margin-bottom: 12px; }

.detail-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.detail-row { display: flex; justify-content: space-between; align-items: baseline; }
.detail-row dt { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.detail-row dd { font-size: 13px; font-weight: 500; text-align: right; }

.availability-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 3px;
}
.availability-badge.available     { background: #d4edda; color: var(--green); }
.availability-badge.leased        { background: #e9e9e9; color: var(--gray); }
.availability-badge.not_available { background: #f8d7da; color: var(--red); }
.availability-badge.unknown       { background: #fff3cd; color: var(--yellow); }

.unit-notes {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
  border-top: 1px solid var(--surface2);
  padding-top: 10px;
}

/* ── Main Panel ────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── AppMap ───────────────────────────────────────────────── */
#map { flex: 1; }

/* MapLibre overrides */
.maplibregl-ctrl-attrib { font-size: 10px !important; }
.maplibregl-popup-content {
  font-family: var(--font) !important;
  font-size: 13px !important;
  padding: 10px 14px !important;
  border-radius: 4px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
}
.maplibregl-popup-content strong { font-size: 14px; display: block; margin-bottom: 2px; }
.maplibregl-popup-content small { color: var(--text-muted); }

/* ── Floor Plan View ───────────────────────────────────── */
#floorplan-view {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

#floorplan-view.visible { display: flex; }

#floorplan-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

#floorplan-toolbar .toolbar-label { font-size: 13px; font-weight: 600; flex: 1; }

#floorplan-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  position: relative;
}

#floorplan-img-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
}

#floorplan-img {
  max-width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.unit-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  z-index: 2;
}
.unit-pin::before {
  content: '';
  position: absolute;
  inset: -13px;
}
.unit-pin-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 7px; font-weight: 700; color: #fff;
  transition: transform 0.1s;
}
.unit-pin:hover .unit-pin-dot { transform: scale(1.3); }
.unit-pin-dot.available     { background: var(--green); }
.unit-pin-dot.leased        { background: var(--gray); }
.unit-pin-dot.not_available { background: var(--red); }
.unit-pin-dot.unknown       { background: var(--yellow); }

.unit-pin-label {
  font-size: 9px;
  font-weight: 700;
  font-family: var(--mono);
  white-space: nowrap;
  background: rgba(0,0,0,0.65);
  color: #fff;
  padding: 1px 4px;
  border-radius: 2px;
  margin-top: 2px;
  pointer-events: none;
}

#floorplan-no-image {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}
#floorplan-no-image.visible { display: flex; }
#floorplan-no-image .no-img-icon { font-size: 36px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s, border-color 0.1s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface); border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #333; border-color: #333; }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ── Empty States ──────────────────────────────────────── */
.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}
.empty-state .empty-icon { font-size: 28px; margin-bottom: 8px; }

/* ── Legend ────────────────────────────────────────────── */
#map-legend {
  position: absolute;
  bottom: 28px;
  left: 14px;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 11px;
  z-index: 1;
  pointer-events: none;
}
#map-legend .legend-title { font-weight: 600; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
#map-legend .legend-row { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
#map-legend .legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Search / Filter ───────────────────────────────────── */
#search-bar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
#search-input {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  background: var(--surface);
}
#search-input:focus { border-color: var(--accent); background: var(--bg); }

/* ── Loading ───────────────────────────────────────────── */
.loading {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 1000;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }

/* ── Mobile ────────────────────────────────────────────── */
@media (max-width: 700px) {
  :root { --sidebar-w: 100vw; }

  #app { flex-direction: column; }

  #sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 60vh;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 20;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
  }

  #sidebar.open { transform: translateY(0); }

  /* Drag handle pill at top of sidebar */
  #sidebar-header::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
  }
  #sidebar-header { position: relative; }

  #main { flex: 1; }
  #map { height: 100%; }

  #mobile-toggle {
    display: flex;
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
  }

  #map-legend { display: none; }

  /* Prevent iOS zoom on search input focus */
  #search-input { font-size: 16px; }

  /* Larger back-to-map button touch target */
  #btn-back-to-map { min-height: 44px; padding: 0 14px; }
}

@media (min-width: 701px) {
  #mobile-toggle { display: none; }
}

/* ── Admin Bottom Sheets ────────────────────────────────── */
#sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 30;
}
#sheet-overlay.open { display: block; }

.map-bottom-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
  z-index: 31;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  max-height: 80vh;
  overflow-y: auto;
}
.map-bottom-sheet.open { transform: translateY(0); }

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--surface2);
}
.sheet-title { font-size: 14px; font-weight: 600; }

.sheet-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-group label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.field-group input,
.field-group textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  min-height: 44px;
  box-sizing: border-box;
}
.field-group input:focus,
.field-group textarea:focus { border-color: var(--accent); background: var(--bg); }
.field-group textarea { min-height: 80px; resize: vertical; font-size: 14px; }

.sheet-submit { width: 100%; justify-content: center; min-height: 44px; font-size: 15px; }
.sheet-context { font-size: 12px; color: var(--text-muted); margin: 0; }
.sheet-hint { font-size: 11px; color: var(--text-muted); margin: 0; font-style: italic; }
.sheet-detail-link { width: 100%; justify-content: center; margin-top: 4px; }

.add-unit-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}
.add-unit-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  font-size: 12px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--text);
}
.add-unit-input:focus {
  outline: none;
  border-color: var(--accent);
  border-style: solid;
}
.add-unit-btn {
  border-style: dashed;
  color: var(--text-muted);
  white-space: nowrap;
}
.add-unit-btn:hover {
  border-color: var(--accent);
  color: var(--text);
  border-style: solid;
  background: var(--surface);
}

.btn.admin-action {
  border-style: dashed;
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 12px;
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}
.btn.admin-action:hover {
  border-color: var(--accent);
  color: var(--text);
  border-style: solid;
  background: var(--surface);
}
