/* ============================================================
   CSS Custom Properties
   ============================================================ */
:root {
  --color-primary: #00b4c5;
  --color-primary-dark: #009aaa;
  --color-primary-light: #e6f8fa;
  --color-badge-dc: #00b4c5;
  --color-badge-gp: #88ad97;
  --color-badge-gh: #88ad97;
  --color-badge-pi: #c8a84e;
  --color-badge-on: #757575;
  --color-text: #333333;
  --color-text-light: #666666;
  --color-border: #e0e0e0;
  --color-background: #ffffff;
  --color-background-hover: #f5f5f5;
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-popup: 0 4px 16px rgba(0, 0, 0, 0.15);

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --base-font-size: 14px;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-family);
  font-size: var(--base-font-size);
  color: var(--color-text);
  background: var(--color-background);
}

button {
  font-family: inherit;
  font-size: inherit;
}

a {
  color: inherit;
}

/* ============================================================
   App Layout – Mobile First (stacked: map top, list bottom)
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#map-container {
  position: static;
  height: 60vh;
  height: 60dvh;
  flex-shrink: 0;
}

#map {
  width: 100%;
  height: 100%;
}

#panel {
  position: static;
  background: var(--color-background);
  border-radius: 0;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Drag handle hidden on mobile (no drawer) */
#panel-handle {
  display: none;
}

.handle-bar {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: #dddddd;
}

/* ============================================================
   Search Area
   ============================================================ */
#search-area {
  padding: 8px 12px 12px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  position: relative;
}

#search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#search-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}

#search-input {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-background);
  outline: none;
  transition: border-color 0.2s;
  /* Prevent iOS zoom */
  font-size: 16px;
}

@media (min-width: 768px) {
  #search-input {
    font-size: 14px;
  }
}

#search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 180, 197, 0.15);
}

#search-input::placeholder {
  color: var(--color-text-light);
}

#search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-light);
  font-size: 14px;
  line-height: 1;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
}

#search-clear:hover {
  color: var(--color-text);
  background: var(--color-background-hover);
}

#location-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-background);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-light);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

#location-btn:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

#filter-btn {
  flex: 1 0 100%;
  padding: 0 12px;
  height: 40px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0;
  white-space: nowrap;
  transition: background 0.2s;
}

#filter-btn:hover {
  background: var(--color-primary-dark);
}

#filter-btn[aria-expanded="true"] {
  background: var(--color-primary-dark);
}

#filter-count {
  background: white;
  color: var(--color-primary);
  border-radius: 9px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
  margin-left: 6px;
  line-height: 18px;
  min-width: 18px;
  text-align: center;
}

/* ============================================================
   Filter Dropdown
   ============================================================ */
#filter-dropdown {
  position: absolute;
  top: calc(100% - 1px);
  right: 12px;
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-popup);
  padding: 8px;
  min-width: 280px;
  z-index: 200;
}

#filter-dropdown[hidden] {
  display: none;
}

#filter-dropdown label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 13px;
  color: var(--color-text);
  transition: background 0.15s;
}

#filter-dropdown label:hover {
  background: var(--color-background-hover);
}

#filter-dropdown input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 0;
  font-size: 11px;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1.5;
  flex-shrink: 0;
}

.badge-dc {
  background: var(--color-badge-dc);
}

.badge-gp {
  background: var(--color-badge-gp);
}

.badge-gh {
  background: var(--color-badge-gh);
}

.badge-pi {
  background: var(--color-badge-pi);
}

.badge-on {
  background: var(--color-badge-on);
}

/* ============================================================
   Results Header
   ============================================================ */
#results-header {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--color-text-light);
  border-bottom: 1px solid var(--color-border);
  background: #fafafa;
  flex-shrink: 0;
}

#results-count {
  font-weight: 500;
}

/* ============================================================
   Results List
   ============================================================ */
#results-list {
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Loading state */
.loading-message {
  padding: 32px 24px;
  text-align: center;
  color: var(--color-text-light);
  font-size: 14px;
}

.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* No results state */
.no-results {
  padding: 32px 24px;
  text-align: center;
  color: var(--color-text-light);
  font-size: 14px;
}

.no-results-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.no-results p {
  margin-bottom: 4px;
}

.no-results-sub {
  font-size: 12px;
}

/* ============================================================
   Institute Cards
   ============================================================ */
.institute-card {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.institute-card:hover {
  background: var(--color-background-hover);
}

.institute-card.active {
  background: var(--color-primary-light);
  border-left: 3px solid var(--color-primary);
  padding-left: 13px; /* compensate for 3px border */
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}

.card-distance {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.card-competency {
  font-size: 12px;
  color: var(--color-text-light);
  margin-bottom: 4px;
  line-height: 1.4;
}

.card-address {
  font-size: 12px;
  color: var(--color-text-light);
  line-height: 1.4;
}

.card-contact {
  font-size: 12px;
  margin-top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.card-contact a {
  color: var(--color-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 3px;
  transition: color 0.15s;
}

.card-contact a:hover {
  color: var(--color-primary-dark);
  text-decoration: underline;
}

/* ============================================================
   Desktop Layout (≥768px)
   ============================================================ */
@media (min-width: 768px) {
  #app {
    display: flex;
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
    position: static;
  }

  #panel {
    flex: 0 0 33.333%;
    width: 33.333%;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
    position: static;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    transform: none !important;
    /* Reset mobile bottom sheet */
    bottom: auto;
    left: auto;
    right: auto;
  }

  #panel-handle {
    display: none;
  }

  #map-container {
    position: static;
    height: auto;
    flex: 1;
  }

  #map {
    width: 100%;
    height: 100%;
  }

  #filter-dropdown {
    right: 0;
    left: auto;
  }
}

/* ============================================================
   Google Maps InfoWindow tweaks
   ============================================================ */

.gm-style .gm-style-iw-c {
  padding: 0 !important;
}

.gm-style .gm-style-iw-d {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  padding: 0 !important;
  /* Mobile: map is 60dvh, subtract InfoWindow chrome + marker + tail (~110px) */
  max-height: calc(60dvh - 110px) !important;
}

@media (min-width: 768px) {
  .gm-style .gm-style-iw-d {
    /* Desktop: map is full viewport height */
    max-height: calc(100dvh - 110px) !important;
  }
}

/* ============================================================
   Scrollbar Styling (webkit)
   ============================================================ */
#results-list::-webkit-scrollbar {
  width: 4px;
}

#results-list::-webkit-scrollbar-track {
  background: transparent;
}

#results-list::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

#results-list::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}

/* ============================================================
   Google Places Autocomplete Dropdown
   ============================================================ */
.pac-container {
  font-family: var(--font-family) !important;
  font-size: 14px !important;
  border: 1px solid var(--color-border) !important;
  border-radius: 6px !important;
  box-shadow: var(--shadow-popup) !important;
  margin-top: 2px;
}

.pac-item {
  padding: 8px 12px !important;
  cursor: pointer;
}

.pac-item:hover {
  background: var(--color-background-hover) !important;
}

.pac-item-selected {
  background: var(--color-primary-light) !important;
}

.pac-matched {
  font-weight: 600;
}
