/* ============================================================
   PTC Indoor Navigation — Public Styles
   ============================================================ */
:root {
  --primary: #dc3545;
  --primary-dark: #b02a37;
  --primary-light: #f8d7da;
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --header-h: 60px;
}

.dark {
  --bg: #111215;
  --bg-card: #1a1d21;
  --text: #e8e8e8;
  --text-muted: #8a8d93;
  --border: #2a2d33;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

/* ---- Layout ---- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
}

/* ---- Header ---- */
.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  white-space: nowrap;
  order: -1; /* always first */
}
.header-brand svg { color: var(--primary); }

/* ---- Department Selector ---- */
.dept-selector-wrap {
  flex: 1;
  max-width: 420px;
  position: relative;
}

.dept-selector-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--transition);
}
.dept-selector-btn:hover { border-color: var(--text-muted); }
.dept-selector-btn svg:first-child { color: var(--text-muted); flex-shrink: 0; }
.dept-selector-btn svg:last-child { color: var(--text-muted); flex-shrink: 0; margin-left: auto; }
#dept-label { flex: 1; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dept-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 420px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}
.dept-dropdown.open { display: block; }

.dept-dropdown-header {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.dept-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
  text-align: start;
}
.dept-item:last-child { border-bottom: none; }
.dept-item:hover { background: var(--bg); }
.dept-item.active { background: var(--primary); color: #fff; }
.dept-item.active .dept-item-building { color: rgba(255,255,255,0.7); }
.dept-item.active .dept-item-count { background: rgba(255,255,255,0.2); color: #fff; }

.dept-item-info { flex: 1; min-width: 0; }
.dept-item-name { font-weight: 700; font-size: 14px; }
.dept-item-building { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.dept-item-count {
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Show All button */
.dept-item-all {
  font-weight: 600;
  color: var(--primary);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.dept-item-all:hover { background: var(--primary-light); }

/* Highlighted room — red blinking continuous */
.room-label-highlight rect {
  animation: room-blink 1s ease-in-out infinite !important;
}
@keyframes room-blink {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.4; }
}

/* Navigate popup — floating circle button */
.nav-popup {
  animation: popup-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
}
@keyframes popup-in {
  from { opacity: 0; transform: scale(0) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.nav-popup:hover .nav-popup-btn { fill: #c82333 !important; }

.nav-btn-glow {
  animation: btn-glow-pulse 2s ease-in-out infinite;
}
@keyframes btn-glow-pulse {
  0%, 100% { r: attr(r); opacity: 0.3; }
  50% { opacity: 0.6; stroke-width: 4; }
}

/* ---- Map Selector Dropdown ---- */
.map-selector-wrap {
  position: relative;
}

.map-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: none;
  overflow: hidden;
}
.map-dropdown.open { display: block; }

.map-dropdown-header {
  padding: 12px 16px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.map-dropdown-group {
  padding: 4px 0;
  border-top: 1px solid var(--border);
}
.map-dropdown-group:first-of-type { border-top: none; }

.map-dropdown-group-title {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
}

.map-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background var(--transition);
  text-align: start;
}
.map-dropdown-item:hover { background: var(--bg); }
.map-dropdown-item.active {
  background: var(--primary);
  color: #fff;
}
.map-dropdown-item.active .map-item-dot { background: #fff; }
.map-dropdown-item.disabled {
  color: var(--text-muted);
  cursor: default;
  opacity: 0.5;
}
.map-dropdown-item.disabled:hover { background: transparent; }

.map-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.map-item-badge {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--border);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--border); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---- Building Tabs (portrait only) ---- */
.building-tabs {
  display: none;
  overflow-x: auto;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}

.building-tab {
  flex: 1;
  padding: 12px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: all 0.2s;
}
.building-tab:hover { color: var(--text); background: var(--bg); }
.building-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

/* Building tabs + top panel ONLY on kiosk (very tall portrait screens) */
@media (orientation: portrait) and (min-height: 1800px) {
  .building-tabs { display: flex; }
  .floor-title { display: none; }
}

/* ---- Floor Title (landscape) ---- */
.floor-title {
  text-align: center;
  padding: 10px 16px;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

/* ---- Map Area (Full Screen) ---- */
.map-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  cursor: grab;
}
.map-area:active { cursor: grabbing; }

.map-container {
  position: absolute;
  transform-origin: 0 0;
  will-change: transform;
}

.map-container img {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.map-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---- Room Labels (SVG) ---- */
.room-label { cursor: pointer; pointer-events: all; }
.room-label rect { transition: opacity var(--transition), stroke-width var(--transition); }
/* room-label text — fill set via JS style.fill to ensure black color */
.room-label:hover rect { opacity: 0.25 !important; }

.room-highlighted {
  animation: room-highlight-pulse 1s ease-in-out infinite;
}
@keyframes room-highlight-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.45; }
}

/* Navigation room highlight */
.nav-room-highlight {
  animation: nav-highlight-flash 0.5s ease 3;
}
@keyframes nav-highlight-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---- Navigation Route ---- */

/* Full route trail (faded background) */
.nav-trail {
  fill: none;
  stroke: var(--primary);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.12;
}

/* Marching ants dashed path — stroke-width and dasharray set by JS based on image size */
.nav-path {
  fill: none;
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: dash-march 0.8s linear infinite;
}
@keyframes dash-march { to { stroke-dashoffset: -60; } }

/* Labels */
.nav-label {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(255,255,255,0.9));
}
.dark .nav-label { filter: drop-shadow(0 1px 2px rgba(0,0,0,0.9)); }
.nav-label-dest {
  font-size: 13px;
  fill: var(--primary);
}

/* Destination pulsing */
.nav-pulse {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2;
  animation: pulse-ring 1.5s ease-out infinite;
}
@keyframes pulse-ring {
  0% { r: 14; opacity: 1; }
  100% { r: 35; opacity: 0; }
}

.destination-marker {
  fill: var(--primary);
  animation: dest-pulse 1.2s ease-in-out infinite;
}
@keyframes dest-pulse {
  0%, 100% { r: 10; opacity: 1; }
  50% { r: 14; opacity: 0.7; }
}

.destination-glow {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2.5;
  opacity: 0.3;
  animation: glow-expand 2s ease-out infinite;
}
@keyframes glow-expand {
  0% { r: 16; opacity: 0.3; }
  100% { r: 40; opacity: 0; }
}

/* ---- Traveling Dot ---- */
.nav-dot-core {
  filter: drop-shadow(0 0 4px rgba(220,53,69,0.6));
}

/* ---- Map Controls ---- */
.map-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 30;
}

.map-ctrl-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: background var(--transition);
}
.map-ctrl-btn:hover { background: var(--bg); }
.map-ctrl-btn svg { width: 18px; height: 18px; }

/* ---- Navigation Info Bar ---- */
.nav-info {
  position: relative;
  width: 100%;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 30;
  flex-shrink: 0;
}
.nav-info.visible { display: flex; }
.nav-info-text { font-size: 14px; font-weight: 500; }
.nav-info-dest { color: var(--primary); font-weight: 700; }

.nav-close-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: var(--border);
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition);
}
.nav-close-btn:hover { background: var(--primary-light); }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  :root { --header-h: 56px; }
  .brand-text { display: none; }
  .header-search { max-width: none; }
  .floor-selector { display: none; }
  .search-input { font-size: 13px; height: 38px; }
  .nav-info { padding: 10px 14px; }
}

@media (min-width: 641px) and (max-width: 1024px) {
  .brand-text { display: none; }
  .header-search { max-width: 360px; }
}

@media (min-width: 1800px) {
  .dept-selector-wrap { max-width: 600px; }
}

/* ---- Top Panel (portrait — department list above map) ---- */
.top-panel {
  display: none; /* hidden on landscape */
  flex-direction: column;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 35vh;
  overflow: hidden;
}

.top-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.top-panel-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.top-panel-toggle {
  padding: 6px 14px;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  transition: background 0.2s;
}
.top-panel-toggle:hover { background: var(--primary-dark); }

.top-panel-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.bp-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: start;
  transition: background 0.2s;
}
.bp-item:last-child { border-bottom: none; }
.bp-item:hover { background: var(--bg); }
.bp-item.active { background: var(--primary-light); }

.bp-item-info { flex: 1; min-width: 0; }
.bp-item-dept { font-weight: 700; font-size: 15px; color: var(--text); }
.bp-item-building { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.bp-item-count {
  padding: 3px 10px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.bp-item-go {
  padding: 8px 16px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  transition: background 0.2s;
}
.bp-item-go:hover { background: var(--primary-dark); }

/* Show top panel on portrait screens */
/* Top panel + hide header selectors ONLY on kiosk */
@media (orientation: portrait) and (min-height: 1800px) {
  .top-panel { display: flex; }
  .dept-selector-wrap { display: none; }
  .map-selector-wrap { display: none; }
}

/* ---- Kiosk / Vertical Touch Screen (min-height 1800px = 4K portrait) ---- */
@media (orientation: portrait) and (min-height: 1800px) {
  :root { --header-h: 70px; }

  .header {
    padding: 12px 20px;
  }

  .header-brand img { width: 36px; height: 36px; }
  .brand-text { display: inline; font-size: 20px; }

  /* Building tabs kiosk sizing */
  .building-tab { padding: 16px 12px; font-size: 16px; }

  /* Top panel kiosk sizing */
  .top-panel { max-height: 35vh; }
  .top-panel-header { padding: 14px 20px; }
  .top-panel-title { font-size: 22px; }
  .top-panel-toggle { font-size: 15px; padding: 10px 20px; border-radius: 20px; }
  .bp-item { padding: 16px 20px; }
  .bp-item-dept { font-size: 19px; }
  .bp-item-building { font-size: 14px; }
  .bp-item-count { font-size: 14px; padding: 4px 12px; }
  .bp-item-go { font-size: 15px; padding: 12px 24px; border-radius: 20px; }

  .dept-item {
    padding: 14px 16px;
    font-size: 16px;
  }
  .dept-item-name { font-size: 17px; }
  .dept-item-building { font-size: 13px; }
  .dept-item-count { font-size: 13px; padding: 3px 10px; }

  .floor-title {
    font-size: 22px;
    padding: 12px 16px;
  }

  .icon-btn {
    width: 48px;
    height: 48px;
  }
  .icon-btn svg { width: 24px; height: 24px; }

  .map-ctrl-btn {
    width: 56px;
    height: 56px;
  }
  .map-ctrl-btn svg { width: 24px; height: 24px; }

  .map-controls {
    top: 16px;
    bottom: auto;
    right: 16px;
    gap: 8px;
  }

  .nav-info {
    padding: 16px 24px;
    font-size: 18px;
  }
  .nav-info-text { font-size: 17px; }

  .nav-close-btn {
    padding: 10px 24px;
    font-size: 16px;
  }

  .map-dropdown {
    width: 320px;
  }
  .map-dropdown-item {
    padding: 14px 18px;
    font-size: 16px;
  }
}

  /* Auth screens for kiosk */
  .auth-box { max-width: 480px; padding: 50px 40px; }
  .auth-title { font-size: 28px; }
  .auth-subtitle { font-size: 16px; }
  .auth-input { padding: 16px 20px; font-size: 17px; }
  .auth-btn { padding: 16px; font-size: 17px; }
  .auth-logo img { width: 80px !important; height: 80px !important; }
}

/* Extra large kiosk (4K vertical) */
@media (orientation: portrait) and (min-height: 1800px) {
  :root { --header-h: 90px; }

  .brand-text { font-size: 26px; }
  .header-brand img { width: 48px; height: 48px; }

  .building-tab { padding: 20px 16px; font-size: 20px; }

  .dept-item {
    padding: 18px 20px;
  }
  .dept-item-name { font-size: 20px; }
  .dept-item-building { font-size: 15px; }

  .floor-title {
    font-size: 28px;
    padding: 16px 20px;
  }

  .icon-btn { width: 60px; height: 60px; }
  .icon-btn svg { width: 28px; height: 28px; }

  .map-ctrl-btn { width: 70px; height: 70px; }
  .map-ctrl-btn svg { width: 30px; height: 30px; }

  .map-controls { top: 24px; bottom: auto; right: 24px; gap: 10px; }

  .nav-info { padding: 20px 32px; }
  .nav-info-text { font-size: 22px; }
  .nav-close-btn { padding: 14px 32px; font-size: 19px; }
}

/* ---- Loading ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 999;
  transition: opacity 0.5s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loader-logo {
  width: 80px;
  height: 80px;
  animation: logo-bounce 1s ease-in-out infinite;
}
.loader-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@keyframes logo-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-18px) scale(1.05); }
  50% { transform: translateY(0) scale(0.95); }
  70% { transform: translateY(-8px) scale(1.02); }
}

.loader-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Auth Overlay ---- */
.auth-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.auth-overlay.hidden { display: none; }

.auth-box {
  text-align: center; max-width: 380px; width: 90%; padding: 40px 30px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg);
}

.auth-logo { margin-bottom: 16px; }
.auth-logo img { object-fit: contain; }

.auth-title { font-size: 22px; font-weight: 800; margin-bottom: 6px; color: var(--text); }
.auth-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; }

.auth-input {
  width: 100%; padding: 12px 16px; border: 1.5px solid var(--border);
  border-radius: 10px; background: var(--bg); color: var(--text);
  font-size: 14px; outline: none; font-family: inherit; margin-bottom: 12px;
  transition: border-color 0.2s;
}
.auth-input:focus { border-color: var(--primary); }
.auth-input::placeholder { color: var(--text-muted); }

.auth-btn {
  width: 100%; padding: 12px; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 700;
  border: none; cursor: pointer; transition: background 0.2s;
}
.auth-btn:hover { background: var(--primary-dark); }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-error {
  margin-top: 12px; font-size: 13px; color: #dc3545; min-height: 20px;
}

.auth-form-group { text-align: start; margin-bottom: 14px; }
.auth-label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text); }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
