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

:root {
  --yale-blue: #00356b;
  --yale-mid: #286dc0;
  --yale-light: #63aaff;
  --amber: #f59e0b;
  --amber-bg: #fffbeb;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.18);
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--yale-blue);
  color: white;
  padding: 14px 24px;
  display: flex;
  align-items: baseline;
  gap: 16px;
  box-shadow: var(--shadow);
}

header h1 { font-size: 1.25rem; font-weight: 700; }
header p  { font-size: 0.85rem; opacity: 0.75; }

/* ── Status bar ──────────────────────────────────────────────────────────── */
#api-status {
  background: var(--yale-mid);
  color: white;
  font-size: 0.8rem;
  padding: 6px 24px;
  animation: pulse 1.5s ease-in-out infinite;
}
#api-status.hidden { display: none; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.6} }

/* ── Layout ──────────────────────────────────────────────────────────────── */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 52px);
}

/* ── Filter sidebar ──────────────────────────────────────────────────────── */
#filter-panel {
  width: 240px;
  min-width: 240px;
  background: white;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.22s ease, min-width 0.22s ease;
}

#filter-panel.collapsed {
  width: 42px;
  min-width: 42px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 10px 8px 16px;
  flex-shrink: 0;
}

#filter-panel h2 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-600);
  white-space: nowrap;
  overflow: hidden;
}

#sidebar-toggle {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}
#sidebar-toggle:hover { background: var(--gray-200); }

.panel-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

#filter-panel.collapsed .panel-inner { display: none; }
#filter-panel.collapsed .panel-header { padding-left: 8px; }
#filter-panel.collapsed h2 { display: none; }

#program-search {
  margin: 0 12px 8px;
  padding: 7px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  transition: border-color .15s;
}
#program-search:focus { border-color: var(--yale-mid); }

#program-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 8px 8px;
}

.program-item {
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background .1s, color .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.program-item:hover { background: var(--gray-100); }
.program-item.active { background: var(--yale-blue); color: white; }
.no-results { font-size: 0.8rem; color: var(--gray-400); padding: 8px; }

/* Filter badge */
#filter-badge {
  margin: 0 12px 8px;
  padding: 6px 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #1e40af;
}
#filter-badge .badge-name {
  font-weight: 600;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#filter-badge .badge-count {
  font-size: 0.72rem;
  color: #3b82f6;
}
#filter-badge.hidden { display: none; }

#clear-filter {
  display: block;
  margin: 0 12px 12px;
  padding: 6px;
  background: none;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--gray-600);
  transition: background .1s;
}
#clear-filter:hover { background: var(--gray-100); }

/* ── Map area ────────────────────────────────────────────────────────────── */
#map-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px;
  gap: 12px;
}

/* Room tabs */
.tab-bar {
  display: flex;
  gap: 8px;
}

.tab-btn {
  padding: 7px 16px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: white;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--gray-600);
  transition: background .1s, color .1s, border-color .1s;
}
.tab-btn:hover { background: var(--gray-100); }
.tab-btn.active {
  background: var(--yale-blue);
  color: white;
  border-color: var(--yale-blue);
}

/* Room panels */
.room-panel { flex: 1; overflow: auto; }
.room-panel.hidden { display: none; }

/* Photo strip */
.photo-strip {
  display: flex;
  gap: 4px;
  height: 120px;
  flex-shrink: 0;
  border-radius: var(--radius);
  overflow: hidden;
}

.photo-thumb {
  flex: 1;
  object-fit: cover;
  cursor: zoom-in;
  border-radius: 4px;
  transition: opacity .15s, transform .15s;
}
.photo-thumb:hover { opacity: .88; transform: scale(1.01); }

/* Photo lightbox */
#photo-lightbox { background: rgba(0,0,0,.88); }

.lightbox-content {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
}

#lightbox-img {
  display: block;
  max-width: 92vw;
  max-height: 88vh;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}

#photo-close {
  position: absolute;
  top: -38px;
  right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  opacity: .8;
  padding: 0 4px;
}
#photo-close:hover { opacity: 1; }

/* Main room SVG */
#lab-svg {
  display: block;
  max-height: 100%;
  max-width: 100%;
  margin: 0 auto;
}

/* Computer nodes in SVG */
.computer-node { cursor: pointer; }

.computer-node .node-rect {
  transition: fill .2s, opacity .2s;
}
@media (hover: hover) {
  .computer-node:hover .node-rect { fill: var(--yale-mid); }
}

.computer-node.has-filter .node-rect  { fill: #f59e0b; stroke: #d97706; }
.computer-node.lacks-filter .node-rect { fill: #94a3b8; stroke: #64748b; }
.computer-node.lacks-filter { opacity: 0.45; }

.loading-dot { animation: blink 1s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.2} }

/* Overflow room */
#overflow-computers {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  padding: 24px;
  align-items: flex-start;
}

.computer-card {
  width: 130px;
  background: white;
  border: 2px solid var(--yale-blue);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s, opacity .2s;
  box-shadow: var(--shadow);
}
.computer-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.computer-card .card-icon { font-size: 2rem; margin-bottom: 6px; }
.computer-card .card-label { font-size: 1rem; font-weight: 700; font-family: monospace; color: var(--yale-blue); }
.computer-card .card-full-name { font-size: 0.65rem; color: var(--gray-400); margin-top: 4px; word-break: break-all; }

.computer-card.has-filter  { border-color: var(--amber); background: var(--amber-bg); }
.computer-card.lacks-filter { opacity: 0.35; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-content {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--yale-blue);
  color: white;
}

.modal-header h2 { font-size: 1rem; font-family: monospace; font-weight: 700; }

#modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  opacity: .8;
  padding: 0 4px;
}
#modal-close:hover { opacity: 1; }

#modal-programs {
  overflow-y: auto;
  padding: 16px 20px;
  flex: 1;
}

#modal-programs ul { list-style: none; }

#modal-programs li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.85rem;
}
.prog-name { flex: 1; color: var(--gray-800); }
.prog-detail { font-size: 0.75rem; color: var(--gray-400); white-space: nowrap; }

.loading-msg, .empty-msg {
  font-size: 0.85rem;
  color: var(--gray-400);
  padding: 12px 0;
}

/* ── Mobile layout ───────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  main {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  #filter-panel {
    width: 100%;
    min-width: 100%;
    border-right: none;
    border-top: 1px solid var(--gray-200);
    order: 2;
    /* start collapsed on mobile so map gets full screen */
    max-height: 44px;
    transition: max-height 0.25s ease;
    overflow: hidden;
  }

  #filter-panel.mobile-open {
    max-height: 55vh;
  }

  /* override desktop collapsed behaviour on mobile */
  #filter-panel.collapsed {
    width: 100%;
    min-width: 100%;
  }
  #filter-panel.collapsed .panel-inner { display: flex; }
  #filter-panel.collapsed h2 { display: block; }

  .panel-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-200);
    cursor: pointer;
  }

  #sidebar-toggle {
    /* repurpose as expand/collapse chevron on mobile */
    transform: rotate(90deg);
    transition: transform 0.22s ease;
  }
  #filter-panel.mobile-open #sidebar-toggle {
    transform: rotate(-90deg);
  }

  .panel-inner { overflow-y: auto; }

  #map-container {
    order: 1;
    overflow: visible;
    padding: 10px;
  }

  .room-panel {
    overflow: visible;
  }

  #lab-svg {
    max-height: 65vh;
    width: 100%;
  }

  .photo-strip {
    height: 80px;
  }

  .tab-btn {
    font-size: 0.78rem;
    padding: 6px 10px;
  }
}
