/* ==========================================================================
   Maplet Share — styles.css
   Apple Maps–inspired split screen (desktop) / bottom sheet (mobile) layout.
   ========================================================================== */

:root {
  --accent: #007AFF;           /* overridden at runtime from folder color (fc) */
  --accent-soft: rgba(0, 122, 255, 0.12);
  --bg: #f2f2f5;
  --card-bg: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #9a9a9e;
  --border: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.10);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --sidebar-width: 400px;
  --sheet-peek: 132px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

/* Author-level display rules (e.g. .layout { display: flex }) would otherwise
   win the cascade over the UA [hidden] rule at equal specificity — force it. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

/* ---------------------------------------------------------------------- */
/* Loading / error states                                                  */
/* ---------------------------------------------------------------------- */

.state-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  background: var(--bg);
  gap: 6px;
}

.state-screen p {
  color: var(--text-secondary);
  margin: 0;
  font-size: 15px;
}

.state-screen h1 {
  font-size: 20px;
  margin: 18px 0 4px;
  max-width: 320px;
}

.state-subtext {
  max-width: 320px;
  margin-bottom: 20px !important;
}

.state-icon {
  color: var(--text-tertiary);
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  margin-bottom: 8px;
}

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

/* ---------------------------------------------------------------------- */
/* Buttons                                                                  */
/* ---------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.15s ease, filter 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover { filter: brightness(1.06); }

.btn-ghost {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-ghost:hover { filter: brightness(0.97); }

.btn-block { width: 100%; }

/* ---------------------------------------------------------------------- */
/* Layout — desktop split screen                                           */
/* ---------------------------------------------------------------------- */

.layout {
  display: flex;
  width: 100%;
  height: 100%;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--card-bg);
  box-shadow: var(--shadow-md);
  z-index: 20;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.sheet-handle { display: none; }

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.folder-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.folder-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.folder-title-text { min-width: 0; }

.folder-name {
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 2px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.folder-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-actions .btn-primary { flex: 1; }

.location-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 32px;
  -webkit-overflow-scrolling: touch;
}

.location-list:empty::after {
  content: "No locations in this folder yet.";
  display: block;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
  padding: 40px 0;
}

.map-wrap {
  flex: 1;
  position: relative;
  height: 100%;
}

#map {
  position: absolute;
  inset: 0;
}

/* MapLibre attribution tidy-up */
.maplibregl-ctrl-bottom-right { z-index: 5; }

/* ---------------------------------------------------------------------- */
/* Location cards                                                           */
/* ---------------------------------------------------------------------- */

.location-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.location-card:hover,
.location-card:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.location-card.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: var(--shadow-sm);
}

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}

.pin-badge {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.card-title-wrap { min-width: 0; flex: 1; }

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.category-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.rating {
  font-size: 12px;
  color: #d9a600;
  letter-spacing: 1px;
}

.rating .star-empty { color: var(--border); }

.visited-badge {
  font-size: 11px;
  font-weight: 600;
  color: #2ea043;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.card-address,
.card-notes {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 4px 0 0;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.card-notes {
  color: var(--text-tertiary);
  font-style: italic;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.action-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  transition: background 0.15s ease;
}

.action-btn:hover { background: var(--accent-soft); color: var(--accent); }

.action-btn svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ---------------------------------------------------------------------- */
/* Custom map markers                                                       */
/* ---------------------------------------------------------------------- */

.map-marker {
  width: 30px;
  height: 40px;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform 0.18s ease;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.map-marker svg { display: block; width: 100%; height: 100%; }

.map-marker .marker-pin-fill { fill: var(--accent); }

.marker-number {
  position: absolute;
  top: 6px;
  left: 0;
  width: 30px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  pointer-events: none;
}

.map-marker:hover,
.map-marker.is-highlighted {
  transform: scale(1.18);
  z-index: 30;
}

.map-marker.is-highlighted .marker-pin-fill { fill: #fff; }
.map-marker.is-highlighted .marker-pin-stroke { stroke: var(--accent); }
.map-marker.is-highlighted .marker-number { color: var(--accent); }

/* ---------------------------------------------------------------------- */
/* Mobile — bottom sheet                                                    */
/* ---------------------------------------------------------------------- */

@media (max-width: 768px) {
  .layout {
    display: block;
  }

  .map-wrap {
    position: fixed;
    inset: 0;
    height: 100%;
    width: 100%;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: 88vh;
    height: 88dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
    transform: translateY(calc(100% - var(--sheet-peek)));
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
    touch-action: none;
    z-index: 40;
  }

  .sidebar.is-dragging { transition: none; }
  .sidebar.is-expanded { transform: translateY(0); }

  .sheet-handle {
    display: flex;
    justify-content: center;
    padding: 8px 0 4px;
    flex-shrink: 0;
    cursor: grab;
  }

  .sheet-handle span {
    width: 36px;
    height: 5px;
    border-radius: 100px;
    background: var(--border);
  }

  .sidebar-header { padding: 4px 20px 14px; }

  .folder-title-row { margin-bottom: 12px; }

  .location-list { touch-action: pan-y; }
}

@media (max-width: 420px) {
  .header-actions { flex-wrap: wrap; }
  .header-actions .btn-ghost { flex: 1; }
}
