/* ========================================
   Locate Cinemas — Theater Map Styles
   Modern, app-like UI
   ======================================== */

/* Base layout */
.tm-wrap, .tm-wrap * { box-sizing: border-box; }
.tm-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Hide any external search bar — map uses only the in-map magnifying glass */
.tm-searchbar, #tm-search, .tm-toolbar .tm-search-input { display: none !important; }

/* Safe-area custom properties */
:root {
  --tm-safe-top: env(safe-area-inset-top, 0px);
  --tm-safe-right: env(safe-area-inset-right, 0px);
  --tm-safe-bottom: env(safe-area-inset-bottom, 0px);
  --tm-safe-left: env(safe-area-inset-left, 0px);
  --tm-accent: #4f46e5;
  --tm-accent-light: #6366f1;
  --tm-bg: #ffffff;
  --tm-bg-subtle: #f8fafc;
  --tm-border: #e2e8f0;
  --tm-text: #1e293b;
  --tm-text-muted: #64748b;
  --tm-radius: 10px;
  --tm-shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --tm-shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --tm-transition: 0.2s cubic-bezier(.4,0,.2,1);
}

/* ---- Toolbar ---- */
.tm-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 12px 0 10px;
  padding: 10px 14px;
  background: var(--tm-bg-subtle);
  border: 1px solid var(--tm-border);
  border-radius: var(--tm-radius);
}

#tm-country {
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--tm-border);
  border-radius: 8px;
  background: var(--tm-bg);
  font-size: 14px;
  color: var(--tm-text);
  cursor: pointer;
  transition: border-color var(--tm-transition), box-shadow var(--tm-transition);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#tm-country:focus {
  outline: none;
  border-color: var(--tm-accent);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}

/* ---- Buttons ---- */
.tm-btn {
  background: var(--tm-bg);
  border: 1px solid var(--tm-border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--tm-text);
  transition: all var(--tm-transition);
  user-select: none;
}
.tm-btn:hover:not(:disabled) {
  background: var(--tm-accent);
  color: #fff;
  border-color: var(--tm-accent);
  box-shadow: var(--tm-shadow-sm);
  transform: translateY(-1px);
}
.tm-btn:active:not(:disabled) {
  transform: translateY(0);
}
.tm-btn:disabled {
  opacity: .4;
  cursor: default;
}

/* ---- Map ---- */
#tm-map {
  position: relative;
  width: 100%;
  height: 62vh;
  min-height: 360px;
  border-radius: var(--tm-radius);
  overflow: hidden;
  border: 1px solid var(--tm-border);
  box-shadow: var(--tm-shadow-md);
  transition: box-shadow 0.3s ease;
}

/* ---- Summary / Pager ---- */
.tm-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 4px;
  font-size: 14px;
  color: var(--tm-text-muted);
}
#tm-summary {
  font-weight: 600;
  color: var(--tm-text);
}
.tm-pager {
  display: flex;
  align-items: center;
  gap: 8px;
}
#tm-page {
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: center;
}

/* ---- Draw "Finish shape" ---- */
.tm-finish-draw {
  position: absolute;
  top: 8px; left: 50%; transform: translateX(-50%);
  z-index: 10000; display: none;
  background: var(--tm-bg); color: var(--tm-text); border: 1px solid var(--tm-border);
  padding: 8px 16px; border-radius: 8px; font-size: 14px; line-height: 1;
  box-shadow: var(--tm-shadow-md);
  cursor: pointer; user-select: none;
  transition: all var(--tm-transition);
}
.tm-finish-draw.show { display: inline-block; }
.tm-finish-draw:hover { background: var(--tm-accent); color: #fff; border-color: var(--tm-accent); }
.tm-finish-draw:active { transform: translateX(-50%) translateY(1px); }

/* ---- In-map geocoder ---- */
.leaflet-control-geocoder {
  z-index: 1000;
  box-shadow: var(--tm-shadow-md);
  border-radius: 10px;
  overflow: hidden;
  max-width: min(420px, calc(100% - 12px));
}
.leaflet-control-geocoder .leaflet-control-geocoder-icon {
  width: 38px; height: 38px; background-size: 20px 20px;
}
.leaflet-control-geocoder-expanded { width: min(420px, calc(100% - 12px)); }
.leaflet-control-geocoder-form input { height: 38px; font-size: 16px; padding: 0 10px; }
.leaflet-control-geocoder-alternatives { max-width: 100%; overflow: auto; }

/* ---- Table (desktop) ---- */
.tm-table-wrap { width: 100%; overflow-x: hidden; }
.tm-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.tm-table th,
.tm-table td {
  padding: 12px 14px;
  border-top: 1px solid var(--tm-border);
  vertical-align: top;
  text-align: left;
  transition: background var(--tm-transition);
}
.tm-table th {
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tm-text-muted);
  background: var(--tm-bg-subtle);
  border-top: none;
  position: sticky;
  top: 0;
  z-index: 1;
}
.tm-table tbody tr {
  transition: background var(--tm-transition);
}
.tm-table tbody tr:hover {
  background: rgba(79, 70, 229, .04);
}
.tm-table td a {
  color: var(--tm-accent);
  text-decoration: none;
  transition: color var(--tm-transition);
}
.tm-table td a:hover {
  color: var(--tm-accent-light);
  text-decoration: underline;
}

@media (min-width: 821px) {
  .tm-table th:nth-child(1), .tm-table td:nth-child(1) { width: 28%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tm-table th:nth-child(2), .tm-table td:nth-child(2) { width: 42%; }
  .tm-table th:nth-child(3), .tm-table td:nth-child(3) { width: 14%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tm-table th:nth-child(4), .tm-table td:nth-child(4) { width: 16%; }
  .tm-table td:nth-child(4) a { display: inline-block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ---- Loading skeleton ---- */
@keyframes tm-shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.tm-skeleton-row td {
  position: relative;
}
.tm-skeleton-bar {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 800px 100%;
  animation: tm-shimmer 1.5s ease infinite;
}
.tm-skeleton-bar.w60 { width: 60%; }
.tm-skeleton-bar.w80 { width: 80%; }
.tm-skeleton-bar.w40 { width: 40%; }
.tm-skeleton-bar.w30 { width: 30%; }

/* ---- Fade-in for loaded rows ---- */
@keyframes tm-fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tm-table tbody tr:not(.tm-skeleton-row) {
  animation: tm-fadeIn 0.3s ease both;
}
.tm-table tbody tr:nth-child(1)  { animation-delay: 0ms; }
.tm-table tbody tr:nth-child(2)  { animation-delay: 30ms; }
.tm-table tbody tr:nth-child(3)  { animation-delay: 60ms; }
.tm-table tbody tr:nth-child(4)  { animation-delay: 90ms; }
.tm-table tbody tr:nth-child(5)  { animation-delay: 120ms; }
.tm-table tbody tr:nth-child(6)  { animation-delay: 150ms; }
.tm-table tbody tr:nth-child(7)  { animation-delay: 180ms; }
.tm-table tbody tr:nth-child(8)  { animation-delay: 210ms; }
.tm-table tbody tr:nth-child(9)  { animation-delay: 240ms; }
.tm-table tbody tr:nth-child(10) { animation-delay: 270ms; }

/* ---- Mobile cards ---- */
@media (max-width: 820px) {
  .tm-wrap { padding: 0 8px; }
  #tm-map { height: 58vh; }

  .tm-toolbar {
    padding: 8px 10px;
    gap: 6px;
  }

  /* Zoom bottom-left */
  .leaflet-bottom.leaflet-left .leaflet-control-zoom {
    margin: 8px;
    margin-bottom: calc(8px + var(--tm-safe-bottom));
    margin-left: calc(8px + var(--tm-safe-left));
  }

  /* Geocoder top-right */
  .leaflet-top.leaflet-right .leaflet-control-geocoder {
    right: calc(6px + var(--tm-safe-right)); left: auto; width: auto; max-width: min(420px, calc(100% - 12px));
  }
  .leaflet-control-geocoder-expanded { width: min(420px, calc(100% - 12px)) !important; }

  /* Card layout */
  .tm-table thead { display: none; }
  .tm-table, .tm-table tbody, .tm-table tr, .tm-table td { display: block; width: 100%; }
  .tm-table tr {
    margin: 10px 0;
    padding: 14px 12px;
    border: 1px solid var(--tm-border);
    border-radius: 12px;
    background: var(--tm-bg);
    box-shadow: var(--tm-shadow-sm);
    transition: box-shadow var(--tm-transition), transform var(--tm-transition);
  }
  .tm-table tr:active {
    transform: scale(0.99);
    box-shadow: var(--tm-shadow-md);
  }
  .tm-table td { display: flex; gap: 10px; align-items: flex-start; padding: 6px 4px; border: none; }
  .tm-table td::before { content: attr(data-label) ": "; flex: 0 0 auto; font-weight: 600; color: var(--tm-text-muted); font-size: 13px; }
  .tm-table td.tm-name-value { font-weight: 600; color: var(--tm-text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .tm-table td.tm-address-value { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
  .tm-table td.tm-country-value,
  .tm-table td.tm-website-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tm-table td.tm-website-value a { display: inline-block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; word-break: break-all; }

  /* Mobile skeleton */
  .tm-table tr.tm-skeleton-row {
    padding: 16px 12px;
  }
}

/* ---- Bubble/cluster cosmetics ---- */
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background: transparent; }
.marker-cluster div {
  background: var(--tm-bg);
  border: 2px solid var(--tm-border);
  color: var(--tm-text);
  font-weight: 700;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
  transition: transform var(--tm-transition), box-shadow var(--tm-transition);
}
.marker-cluster div:hover {
  transform: scale(1.08);
  box-shadow: 0 3px 10px rgba(0,0,0,.25);
}
.tm-bubble { filter: drop-shadow(0 1px 3px rgba(0,0,0,.2)); }
.tm-popup {
  line-height: 1.4;
  font-size: 14px;
}
.tm-popup b {
  color: var(--tm-text);
}

/* ---- Polygon loading message ---- */
.tm-shape-loading {
  background: rgba(15, 23, 42, .9);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--tm-shadow-md);
  backdrop-filter: blur(4px);
}

/* ---- Mini fullscreen control ---- */
.leaflet-bottom.leaflet-right .tm-fs-wrap {
  margin: 8px;
  margin-right: calc(8px + var(--tm-safe-right));
  margin-bottom: calc(8px + var(--tm-safe-bottom));
}
.tm-fs-btn {
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--tm-bg); border: 1px solid var(--tm-border); border-radius: 8px;
  box-shadow: var(--tm-shadow-sm); cursor: pointer; text-decoration: none;
  transition: all var(--tm-transition);
}
.tm-fs-btn:hover {
  box-shadow: var(--tm-shadow-md);
  transform: translateY(-1px);
}
.tm-fs-btn svg { width: 18px; height: 18px; display: block; }

/* ---- Red "searched address" pin ---- */
.tm-search-pin { display: flex; align-items: center; justify-content: center; }
.tm-search-pin .dot {
  width: 18px; height: 18px; border-radius: 999px; background: #ef4444; border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(239,68,68,.4);
  animation: tm-pulse 2s ease infinite;
}
@keyframes tm-pulse {
  0%, 100% { box-shadow: 0 2px 6px rgba(239,68,68,.4); }
  50% { box-shadow: 0 2px 16px rgba(239,68,68,.6); }
}

/* ---- Loading spinner (used in JS) ---- */
.tm-spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--tm-border);
  border-top-color: var(--tm-accent);
  border-radius: 50%;
  animation: tm-spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes tm-spin {
  to { transform: rotate(360deg); }
}
