/* ============================================================================
   Iterris - Modern Clean Styles
   ============================================================================ */

/* CSS Custom Properties (Design Tokens) */
:root,
[data-theme="light"] {
    /* Typography */
    --font-display: "Instrument Serif", Georgia, serif;
    --font-body: "Inter", system-ui, -apple-system, sans-serif;

    /* Spacing Scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md:
        0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg:
        0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    /* Colors - Light Theme: one main color (midnight blue) for text/signage,
       a cyan-to-white gradient reserved for a few background surfaces only —
       never on anything clickable (buttons/active states stay flat fills). */
    --color-bg: #f7f6f2;
    --color-surface: #ffffff;
    --color-surface-2: #f7f7f7;
    --color-border: #e2e2e2;
    --color-divider: #d8d8d8;
    --color-text: #16203a;
    --color-text-muted: #5b6a8c;
    --color-text-faint: #99a2b8;
    --color-text-inverse: #ffffff;
    --color-primary: #1e3a6b;
    --color-primary-hover: #16294f;
    --color-primary-light: #e3ebf7;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-danger: #ef4444;
    --color-map-water: #dce8e8;
    /* Floating boxes (Trips/Categories/Trip detail) sit at ~80% opacity
       over the map. */
    --color-surface-translucent: rgba(255, 255, 255, 0.8);

    /* Background-only gradient (canvas / topbar / modals) — cyan to white. */
    --color-bg-tint: #d7f3f6;
    --gradient-bg: linear-gradient(160deg, var(--color-bg-tint), #ffffff 60%);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
}

[data-theme="dark"] {
    /* Colors - Dark Theme: same blue family as light, moved to a deep
       blue-black canvas (rather than a warm neutral) with restrained chrome
       gradients on background surfaces only, in the spirit of Slack's dark
       theme — never on anything clickable. */
    --color-bg: #0b1220;
    --color-surface: #101a2e;
    --color-surface-2: #16223b;
    --color-border: #24324f;
    --color-divider: #1c2740;
    --color-text: #dbe6f5;
    --color-text-muted: #94a3c2;
    --color-text-faint: #5f6f95;
    --color-text-inverse: #0b1220;
    --color-primary: #5b8def;
    --color-primary-hover: #7ba3f2;
    --color-primary-light: #16294a;
    --color-danger: #ef4444;
    --color-map-water: #142238;
    --color-surface-translucent: rgba(16, 26, 46, 0.8);

    /* Background-only gradient (canvas / topbar / modals). */
    --color-bg-tint: #0c1730;
    --gradient-bg: linear-gradient(160deg, var(--color-bg-tint), #05070f);

    /* Shadows (deeper in dark mode so popups/modals keep a readable elevation) */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg:
        0 10px 15px -3px rgba(0, 0, 0, 0.45), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
}

/* ============================================================================
   RESET & BASE
   ============================================================================ */

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

/* Form controls don't inherit color/font from the page by default (browser
   UA styles), so themed text quietly fell back to a near-black default on
   every button-based row — invisible in light mode by coincidence, broken in
   dark mode. This is the standard reset for it. */
button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

html,
body {
    height: 100%;
    width: 100%;
}

body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--gradient-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================================================
   LAYOUT - Main App Structure
   ============================================================================ */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* ============================================================================
   TOP BAR
   ============================================================================ */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    flex-shrink: 0;
    padding: 0 var(--space-4);
    background: var(--gradient-bg);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 1001;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.app-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* ============================================================================
   TRIP WORKSPACE — Wanderlog-style split: map (main-content) | itinerary
   ============================================================================ */

.trip-workspace-resizer {
    display: none;
    width: 6px;
    cursor: col-resize;
    flex-shrink: 0;
    background: transparent;
    position: relative;
    z-index: 960;
    order: 2;
}

.trip-workspace-resizer::after {
    content: "";
    position: absolute;
    inset: 0;
    width: 2px;
    left: 2px;
    background: var(--color-border);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

body.trip-workspace-open .trip-workspace-resizer {
    display: block;
}

body.trip-workspace-open .trip-workspace-resizer:hover::after,
body.is-resizing-workspace .trip-workspace-resizer::after {
    opacity: 1;
    background: var(--color-primary);
}

body.is-resizing-workspace {
    cursor: col-resize;
    user-select: none;
}

.trip-workspace {
    display: none;
    flex-direction: column;
    width: min(480px, 48vw);
    min-width: 300px;
    max-width: 560px;
    height: 100%;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    z-index: 950;
    order: 3; /* map left, resizer, panel right */
}

.trip-workspace.is-open {
    display: flex;
}

.trip-workspace-heading {
    min-width: 0;
    flex: 1;
}

.trip-workspace-title-input {
    width: 100%;
    font-size: 1.15rem;
    font-weight: 600;
    font-family: var(--font-display);
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    cursor: pointer;
    white-space: nowrap;
}

.btn-sm.btn-primary {
    background: var(--color-primary);
    color: var(--color-text-inverse);
    border-color: var(--color-primary);
}

.btn-sm.btn-secondary {
    background: var(--color-surface-2);
    color: var(--color-text);
}

.btn-danger-text {
    color: var(--color-danger) !important;
}

.itinerary-day-section {
    margin-bottom: var(--space-3);
}

.itinerary-day-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    position: sticky;
    top: 0;
    background: var(--color-surface);
    z-index: 2;
    border-bottom: 1px solid var(--color-border);
}

.itinerary-day-header h3 {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.itinerary-item-meta {
    font-size: 0.75rem;
    color: var(--color-text-faint);
    margin-top: 2px;
}

.itinerary-item-remove {
    flex-shrink: 0;
    margin-left: auto;
}

.itinerary-empty {
    padding: var(--space-6) var(--space-4);
}

.itinerary-workspace-tools {
    padding: var(--space-4);
    border-top: 1px solid var(--color-border);
}

.itinerary-workspace-item[draggable="true"] {
    cursor: grab;
}

.itinerary-workspace-item.dragging {
    opacity: 0.5;
}

.day-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: var(--space-2);
}

.itinerary-day-header-left {
    display: flex;
    align-items: center;
}

.itinerary-route-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    margin: 0 var(--space-3);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    list-style: none;
    cursor: grab;
}

.route-mode-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.route-edit-row {
    display: flex;
    gap: var(--space-2);
    width: 100%;
    align-items: center;
}

.route-mode-select {
    width: auto;
    min-width: 6rem;
    flex-shrink: 0;
    font-size: 0.8rem;
    padding: 0.25rem 0.4rem;
}

.route-title-input {
    flex: 1;
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
}

.itinerary-day-tools {
    padding: var(--space-1) var(--space-4) var(--space-3);
}

.itinerary-day-empty {
    padding: var(--space-3) var(--space-4);
    list-style: none;
    font-size: 0.85rem;
}

body.trip-workspace-open .main-content {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
}

body.trip-workspace-open .floating-box-stack {
    display: none !important;
}

body.trip-workspace-open .trip-detail-panel {
    display: none !important;
}

.trip-workspace-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.trip-workspace-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-family: var(--font-display);
    color: var(--color-text);
}

.trip-workspace-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: flex-end;
}

.trip-workspace-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2) 0 var(--space-6);
}

.itinerary-workspace-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.itinerary-workspace-item {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    transition: background var(--transition-fast);
}

.itinerary-workspace-item:hover,
.itinerary-workspace-item.is-selected {
    background: var(--color-primary-light);
}

.itinerary-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-text-inverse);
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.itinerary-item-title {
    font-weight: 600;
    color: var(--color-text);
    font-size: 0.95rem;
}

.itinerary-item-note {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

/* Numbered map markers for shared / trip view */
.trip-num-marker-wrap {
    background: transparent !important;
    border: none !important;
}

.trip-num-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    box-shadow: var(--shadow-md);
    border: 2px solid #fff;
}

.trip-num-marker--active {
    background: #a85e2d;
    transform: scale(1.1);
}

.btn-topbar {
    padding: 0.4rem 0.85rem;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: none;
    white-space: nowrap;
}

.btn-topbar.btn-secondary {
    background: var(--color-surface-2);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-topbar.btn-primary {
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.auth-modal-close {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius-md);
}

.auth-modal-close:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}

.auth-card {
    position: relative;
}

/* Guest empty-state: layers + search still work; library hidden via JS */

@media (max-width: 768px) {
    .trip-workspace-resizer {
        display: none !important;
    }

    .trip-workspace {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100% !important;
        max-width: none;
        min-width: 0;
        height: 48%;
        border-left: none;
        border-top: 1px solid var(--color-border);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        order: 0;
    }

    body.trip-workspace-open .main-content {
        height: 52%;
    }

    .btn-topbar {
        padding: 0.35rem 0.6rem;
        font-size: 0.8rem;
    }

    .trip-workspace-actions {
        flex-wrap: wrap;
    }
}

/* ============================================================================
   FLOATING BOXES — replace the old docked sidebar. Fixed position (not
   user-draggable), translucent, content-hugging up to a max-height then
   internally scrollable. Trips box sits above Categories; the trip detail
   panel (styles.css further down) shares this same component.
   ============================================================================ */

.floating-box-stack {
    position: absolute;
    top: 50%;
    left: var(--space-4);
    transform: translateY(-50%);
    z-index: 900;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: 320px;
    max-width: calc(100% - var(--space-8));
}

.floating-box {
    background: var(--color-surface-translucent);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-4);
    overflow-y: auto;
}

/* Hover-revealed resize grip, pinned to the box's visible bottom edge via
   `sticky` regardless of scroll position or internal layout. */
.box-resize-handle {
    position: sticky;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 12px;
    margin-top: calc(var(--space-2) * -1);
    cursor: ns-resize;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 5;
}
.floating-box:hover .box-resize-handle {
    opacity: 1;
}
.box-resize-handle::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-text-faint);
}

#trips-box {
    max-height: 45vh;
}

#categories-box {
    max-height: 40vh;
}

.sidebar-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-primary);
    margin: 0;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--color-surface-2);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.icon-btn:hover {
    background: var(--color-border);
}

.user-label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    padding: var(--space-2) var(--space-4);
    margin: 0;
}

/* ============================================================================
   MAIN CONTENT AREA
   ============================================================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* ============================================================================
   SEARCH BAR — floats over the map instead of a full-width bar
   ============================================================================ */

.search-float {
    position: absolute;
    top: var(--space-4);
    left: 50%;
    transform: translateX(-50%);
    width: min(600px, calc(100% - 2 * var(--space-4)));
    z-index: 1000;
}

.search-float .search-input {
    width: 100%;
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
}

.search-float .search-results {
    left: 0;
    right: 0;
    max-width: none;
}

#hamburger-btn {
    display: flex;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

#hamburger-btn .hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 30px;
    height: 30px;
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--color-text);
    border-radius: 2px;
    transition: all var(--transition-fast);
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

.search-input {
    flex: 1;
    max-width: 600px;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-2);
    color: var(--color-text);
    font-size: 1rem;
    outline: none;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.search-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.search-input::placeholder {
    color: var(--color-text-faint);
}

.search-results {
    position: absolute;
    top: 100%;
    left: var(--space-4);
    right: var(--space-4);
    max-width: calc(100% - 2 * var(--space-12));
    max-height: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    border-bottom: 1px solid var(--color-divider);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--color-surface-2);
}

.search-result-item small {
    display: block;
    color: var(--color-text-faint, #888);
    font-size: 0.7rem;
}
.search-result-saved {
    margin-top: var(--space-1);
    font-size: 0.72rem;
    color: var(--color-primary);
}
.search-result-not-saved {
    margin-top: var(--space-1);
    font-size: 0.72rem;
    color: var(--color-text-faint, #888);
}

/* ============================================================================
   MAP CONTAINER
   ============================================================================ */

.map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.map-container #map {
    width: 100%;
    height: 100%;
    min-height: 0;
}

/* Leaflet specific - ensure it fills the container */
.leaflet-container {
    width: 100%;
    height: 100%;
}

/* ============================================================================
   STATISTICS MAP VIEW — full-screen overlay (no floating boxes, no normal
   markers) with a top mode toggle and a bottom stats bar. `pointer-events`
   is disabled on the overlay itself so the map underneath stays pannable/
   zoomable, and re-enabled only on the two bars.
   ============================================================================ */

.stats-view-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
    z-index: 950;
}

.stats-view-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin: var(--space-4);
    padding: var(--space-2) var(--space-3);
    background: var(--color-surface-translucent);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
}

.stats-view-modes {
    display: flex;
    gap: var(--space-1);
}

.stats-view-mode-btn {
    background: none;
    border: none;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
}
.stats-view-mode-btn.active {
    background: var(--color-primary);
    color: white;
}

.stats-view-actions {
    display: flex;
    gap: var(--space-2);
}

.stats-view-bottombar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-6);
    margin: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface-translucent);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
}

.stats-view-stat {
    text-align: center;
}
.stats-view-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
}
.stats-view-stat-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}
.stats-view-note {
    flex-basis: 100%;
    text-align: center;
    font-size: 0.7rem;
    color: var(--color-text-faint);
}

/* ============================================================================
   STATUS MESSAGE
   ============================================================================ */

.status-message {
    position: fixed;
    bottom: var(--space-4);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-primary);
    color: white;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.status-message.show {
    opacity: 1;
}

/* Sits where the old Leaflet zoom control used to be (now removed). */
.map-layers-box {
    position: absolute;
    top: var(--space-4);
    left: var(--space-4);
    width: 220px;
    z-index: 900;
}

.map-layer-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) 0;
    font-size: 0.8125rem;
    cursor: pointer;
}

.viewing-map-banner {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    background: var(--color-primary);
    color: white;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ============================================================================
   SIDEBAR CONTENT SECTIONS
   ============================================================================ */

.trips-section,
.stats-section {
    padding: var(--space-3) var(--space-4);
}

.floating-box h2,
.trips-section h2,
.stats-section h2 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-2);
}

/* Select dropdowns */
select {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    color: var(--color-text);
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Form inputs */
input[type="text"],
input[type="password"],
input[type="email"] {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    color: var(--color-text);
    font-size: 0.875rem;
    font-family: inherit;
    width: 100%;
    transition: border-color var(--transition-fast);
}

input:focus {
    outline: none;
    border-color: var(--color-primary);
}

input::placeholder {
    color: var(--color-text-faint);
}

/* Buttons */
.btn-primary,
.btn-secondary {
    padding: var(--space-2) var(--space-4);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

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

.btn-secondary {
    background: var(--color-surface-2);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-border);
}

/* Small text-link-style button, used for section-level actions like
   "Show all" above the categories list. */
.btn-link-sm {
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    padding: var(--space-1);
}

.btn-link-sm:hover {
    text-decoration: underline;
}

/* Small round icon button variant, used inline next to section headings
   (e.g. the "+" add-trip action) instead of a full-width button row. */
.icon-btn-sm {
    width: 26px;
    height: 26px;
    font-size: 1rem;
    background: var(--color-primary);
    color: white;
}

.icon-btn-sm:hover {
    filter: brightness(1.08);
}

/* Flex row pairing a sidebar section's <h2> with an inline action button. */
.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.section-header-row h2 {
    margin-bottom: 0;
}

.section-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* "+" on Trips: small dropdown offering New vs. Import instead of jumping
   straight into a new trip. */
.trip-add-menu-wrap {
    position: relative;
}

.trip-add-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--space-1);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 30;
    display: flex;
    flex-direction: column;
    min-width: 140px;
    overflow: hidden;
}

.trip-add-menu-item {
    background: none;
    border: none;
    padding: var(--space-2) var(--space-3);
    text-align: left;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--color-text);
}

.trip-add-menu-item:hover {
    background: var(--color-surface-2);
}

/* ============================================================================
   CATEGORY TOGGLES
   ============================================================================ */

/* ============================================================================
   CATEGORY ROWS — named list rows (icon + name), replacing the old
   anonymous circle-only bubble grid.
   ============================================================================ */

.category-row-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: 0;
    margin: 0;
    max-height: 260px;
    overflow-y: auto;
}

.categories-empty {
    font-size: 0.875rem;
    padding: var(--space-2);
}

.category-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    background: none;
    border: none;
    border-left: 2px solid transparent;
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin: 0;
    cursor: pointer;
    text-align: left;
    transition:
        background var(--transition-fast),
        border-color var(--transition-fast);
}

.category-row:hover {
    background: var(--color-surface);
}

.category-row--active {
    border-left-color: var(--color-primary);
    background: var(--color-primary-light);
}

.category-row-name {
    flex: 1;
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================================
   EMOJI CIRCLE — the SINGLE shared component used both for sidebar category
   rows and for category map markers, so a category looks identical in the
   tab and on the map. The active/selected state is also identical.
   ============================================================================ */
.emoji-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--color-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    font-family:
        "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
    font-size: 24px;
    line-height: 1;
    transition:
        transform var(--transition-fast),
        box-shadow var(--transition-fast),
        border-color var(--transition-fast);
}

/* Active = sidebar toggle ON, or selected map marker. Ring highlight only —
   the white circle behind the emoji is never painted over. */
.emoji-circle--active {
    border-color: var(--color-primary);
    border-width: 3px;
    box-shadow: 0 0 0 3px var(--color-primary-light);
    transform: scale(1.08);
}

.category-row:hover .emoji-circle {
    transform: scale(1.08);
}

/* Map-marker variant: smaller circle, transparent Leaflet container. */
.emoji-marker {
    background: transparent;
    border: none;
}
.emoji-circle--marker {
    width: 26px;
    height: 26px;
    font-size: 15px;
}

/* Hovering a place in the trip detail panel highlights its marker. */
.place-marker--highlighted {
    transform: scale(1.25);
    box-shadow: 0 0 0 4px var(--color-primary-light);
}

/* Edit / delete actions, right-aligned, revealed on hover (name is always
   visible now, so no floating tooltip/popover is needed for either). */
.cat-actions {
    display: flex;
    gap: var(--space-1);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}
.category-row:hover .cat-actions,
.folder-header:hover .cat-actions {
    opacity: 1;
    pointer-events: auto;
}

.cat-edit,
.cat-delete {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    padding: 0;
}
.cat-edit:hover,
.cat-delete:hover {
    background: var(--color-border);
}

/* ============================================================================
   EDIT CATEGORY FORM
   ============================================================================ */

.edit-category-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.edit-category-form .form-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.edit-category-form .form-row label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
}

.edit-category-form input[type="text"] {
    width: 100%;
}

/* ============================================================================
   STATS SECTION
   ============================================================================ */

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) 0;
    font-size: 0.875rem;
}

.stat-label {
    color: var(--color-text-muted);
}

.stat-value {
    color: var(--color-text);
    font-weight: 600;
}

/* ============================================================================
   MODAL TABS — generic tabbed-content component for modals (currently used
   by the Profile popup's Account/Settings split).
   ============================================================================ */
.modal-tabs {
    display: flex;
    gap: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-3);
}
.modal-tab {
    background: none;
    border: none;
    padding: var(--space-2) var(--space-1);
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
}
.modal-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}
.modal-tab-panel {
    text-align: left;
}

/* Profile Account tab: large circular avatar (click to change) + username. */
.profile-identity {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}
.profile-avatar-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    padding: 0;
    background: var(--color-surface-2);
    cursor: pointer;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.profile-avatar-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.profile-avatar-placeholder {
    font-size: 2rem;
}
.profile-username-display {
    font-weight: 600;
    font-size: 1rem;
}

/* ============================================================================
   PLACES LIST
   ============================================================================ */

.places-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}

.places-list li {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.places-list li:hover {
    background: var(--color-surface-2);
}

.places-list li .place-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.places-list li .place-name {
    flex: 1;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.places-list li .place-remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
    padding: var(--space-1);
}

.places-list li .place-remove:hover {
    opacity: 1;
}

/* ============================================================================
   TRIPS LIST
   ============================================================================ */

.trips-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    list-style: none;
    padding: 0;
    margin: 0;
    /* Own scroll region: once trips overflow, only this list scrolls — the
       rest of the sidebar (Categories, Import row) stays put and reachable. */
    max-height: 260px;
    overflow-y: auto;
}

.trips-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3);
    border-left: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition:
        background var(--transition-fast),
        border-color var(--transition-fast);
}

.trips-list li:hover {
    background: var(--color-surface);
    border-left-color: var(--color-primary);
}

.trips-list li .trip-name {
    font-size: 0.875rem;
}

.trips-list li .trip-actions {
    display: flex;
    gap: var(--space-2);
}

.trips-list li .trip-edit,
.trips-list li .trip-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    padding: var(--space-1);
    opacity: 0.6;
    transition: opacity var(--transition-fast);
}

.trips-list li .trip-edit:hover,
.trips-list li .trip-delete:hover {
    opacity: 1;
}

.trips-list li.dragging {
    opacity: 0.4;
}

/* ============================================================================
   TRIP FOLDERS — flat (no nesting) folders a trip can carry; folder-less
   trips sit at the tree root. A folder's color surfaces on its header swatch
   and as a left-accent on its trips (row + map markers, see markers.js).
   ============================================================================ */

.trip-folder {
    /* Overrides the flat `.trips-list li` row treatment — a folder wrapper
       stacks its header above its (indented) trip list, it isn't a row. */
    display: block !important;
    padding: 0 !important;
    cursor: default !important;
    border-left: none !important;
    background: none !important;
}

.folder-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.folder-header:hover {
    background: var(--color-surface);
}

.folder-header.drag-over {
    background: var(--color-primary-light);
    outline: 2px dashed var(--color-primary);
}

.folder-chevron {
    width: 12px;
    flex-shrink: 0;
    color: var(--color-text-muted);
    font-size: 0.7rem;
}

.folder-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.folder-name {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-count {
    flex-shrink: 0;
}

.trip-folder-contents {
    max-height: none;
    overflow-y: visible;
    padding-left: var(--space-5);
    margin-top: var(--space-1);
}

/* Always-present unfile target — not conditional on any unfiled trip
   existing, so there's always somewhere to drag a trip out of a folder. */
.unfiled-drop-zone {
    margin-top: var(--space-2);
    padding: var(--space-3);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 0.75rem;
}
.unfiled-drop-zone.drag-over {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
}

/* ============================================================================
   TRIP DETAIL PANEL — floating card, right side of the map. Only ever
   visible when a trip is selected (see ui-renderer.js's toggleSection call).
   ============================================================================ */

.trip-detail-panel {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 50%;
    right: var(--space-4);
    transform: translateY(-50%);
    max-height: calc(100% - var(--space-8));
    width: 320px;
    max-width: calc(100% - var(--space-8));
    z-index: 900;
}

/* Rebuilt on every render (see trips.js's getPanelContent) — kept separate
   from the panel element itself so the resize handle (appended once,
   directly on .trip-detail-panel) never gets wiped by an innerHTML reset. */
.trip-detail-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.trip-detail-title-input {
    margin-bottom: var(--space-2);
}

.trip-detail-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.trip-detail-header h3 {
    flex: 1;
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trip-detail-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.trip-detail-meta {
    margin-bottom: var(--space-3);
}

.trip-detail-body {
    flex: 1;
    overflow-y: auto;
}

.trip-detail-footer {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-border);
}

/* ============================================================================
   AUTH GATE
   ============================================================================ */

.auth-gate {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: var(--space-4);
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: var(--space-6);
    text-align: center;
}

.auth-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    color: var(--color-primary);
    margin-bottom: var(--space-2);
}

.auth-subtitle {
    color: var(--color-text-muted);
    margin-bottom: var(--space-6);
    font-size: 0.875rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    text-align: left;
}

.auth-form h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-2);
}

.auth-form input {
    width: 100%;
}

.auth-switch {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: var(--space-2);
}

.auth-switch a {
    color: var(--color-primary);
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.auth-error {
    background: var(--color-error);
    color: white;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: var(--space-4);
}

/* Profile button (topbar) */
.profile-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: 0.875rem;
    transition: background var(--transition-fast);
}

.profile-btn:hover {
    background: var(--color-surface-2);
}

.profile-avatar-small {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.profile-icon {
    font-size: 1.25rem;
    display: none;
}

#user-label {
    text-align: left;
    font-weight: 500;
}

.profile-btn .profile-icon {
    display: inline;
}

/* ============================================================================
   EMOJI PICKER TABS
   ============================================================================ */

.emoji-category-tab {
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    cursor: pointer;
    font-size: 0.75rem;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.emoji-category-tab:hover {
    background: var(--color-border);
}

.emoji-category-tab.active {
    background: var(--color-primary);
    color: white;
    border-color: transparent;
}

/* Emoji square button for category modals */
.emoji-square-btn {
    width: 48px;
    height: 48px;
    font-size: 1.75rem;
    background: var(--color-surface-2);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-square-btn:hover {
    background: var(--color-border);
    border-color: var(--color-primary);
}

/* Emoji grid styling - larger emojis */
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--space-1);
}

.emoji-btn {
    font-size: 1.75rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    transition:
        transform var(--transition-fast),
        background var(--transition-fast);
}

.emoji-btn:hover {
    background: var(--color-primary-light);
    transform: scale(1.15);
}

/* ============================================================================
   MODALS
   ============================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: var(--space-4);
}

.modal {
    background: var(--gradient-bg);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: var(--space-6);
    text-align: center;
}

.modal h3 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    color: var(--color-text);
    margin-bottom: var(--space-4);
}

.modal p {
    color: var(--color-text-muted);
    margin-bottom: var(--space-6);
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.modal-btn {
    padding: var(--space-3) var(--space-4);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-btn-primary {
    background: var(--color-primary);
    color: white;
}

.modal-btn-primary:hover {
    background: var(--color-primary-hover);
}

.modal-btn-cancel {
    background: transparent;
    color: var(--color-text-muted);
    border: none;
}

.modal-btn-cancel:hover {
    color: var(--color-text);
}

.modal-btn-danger {
    background: transparent;
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}
.modal-btn-danger:hover {
    background: var(--color-danger);
    color: white;
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.hidden {
    display: none !important;
}

.hint {
    font-size: 0.75rem;
    color: var(--color-text-faint);
}

/* ============================================================================
   PLACE POPUP CATEGORIES
   ============================================================================ */

.place-popup {
    min-width: 200px;
}

.place-popup-cats {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.cat-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    font-size: 0.75rem;
    transition: all var(--transition-fast);
}

.cat-chip:hover {
    background: var(--color-border);
}

.cat-chip .cat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.cat-chip .cat-icon {
    font-size: 0.875rem;
}

.cat-chip-remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0 var(--space-1);
    opacity: 0.6;
    transition: opacity var(--transition-fast);
    line-height: 1;
}

.cat-chip-remove:hover {
    opacity: 1;
}

/* ----- Place popup (single category select + visited checkbox) ----- */
.place-popup-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-2);
}
.place-popup-header strong {
    flex: 1;
}
.place-popup-actions {
    display: flex;
    gap: var(--space-1);
}
.popup-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: var(--space-2);
    font-size: 0.8125rem;
}
.popup-row select {
    flex: 1;
    padding: 2px 4px;
}
.popup-row--check {
    justify-content: flex-start;
}
.add-place-popup {
    min-width: 200px;
}
.add-place-title-input {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: 600;
}
.add-place-save {
    width: 100%;
    margin-top: var(--space-2);
}

/* Small icon button used in popups, the trip list, and the build list. */
.mini-btn {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8125rem;
    line-height: 1;
    padding: 2px 6px;
    transition: background var(--transition-fast);
}
.mini-btn:hover {
    background: var(--color-border);
}

/* Trip list + trip-build list rows. */
.trip-title-text {
    flex: 1;
    cursor: pointer;
}
.trip-actions {
    display: flex;
    gap: var(--space-1);
}
.trip-share-badge {
    margin-left: var(--space-2);
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-border);
    border-radius: var(--radius-sm);
    padding: 1px var(--space-1);
}
.trip-build-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}
.trip-build-item:hover {
    background: var(--color-surface-2);
}
.trip-build-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Trip detail panel's itinerary, grouped by planned date when any stop has
   one. Each item is draggable (reorder within its group) and links to its
   map marker on hover/click. */
.itinerary-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.itinerary-group {
    padding: var(--space-1) 0;
}
.itinerary-date {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-text-muted);
    margin-bottom: var(--space-1);
}
.itinerary-item {
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-sm);
    transition:
        background var(--transition-fast),
        opacity var(--transition-fast);
}
.itinerary-item-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    font-size: 0.8125rem;
    color: var(--color-text);
    cursor: pointer;
}
.itinerary-item-row:hover {
    background: var(--color-surface-2);
}
.itinerary-item.dragging {
    opacity: 0.4;
}
.itinerary-drag-handle {
    color: var(--color-text-faint);
    cursor: grab;
    flex-shrink: 0;
}
.itinerary-item-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Notes/photos context under a place row — read-only, nothing shows for a
   place with neither. */
.itinerary-item-extra {
    padding: 0 var(--space-2) var(--space-2) calc(var(--space-2) + 1.2em);
}
.itinerary-item-note {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-1);
}
.itinerary-item-photos {
    display: flex;
    gap: var(--space-1);
    flex-wrap: wrap;
}
.itinerary-item-photo {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: var(--radius-sm);
}
.muted {
    color: var(--color-text-faint, #888);
    font-size: 0.8125rem;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 768px) {
    /* The floating box stack (Trips + Categories) is hidden by default on
       mobile — no room to float boxes over a small map — and toggled by the
       hamburger button instead of the old slide-in-panel + backdrop, which
       only made sense for a full-height docked panel. */
    .floating-box-stack {
        display: none;
    }

    .floating-box-stack.floating-box-stack--open {
        display: flex;
        max-width: calc(100% - var(--space-8));
    }

    .main-content {
        width: 100%;
    }

    .search-float {
        width: calc(100% - 2 * var(--space-4));
    }

    /* Show hamburger on mobile */
    #hamburger-btn {
        display: flex;
    }
}

/* Hide hamburger button on desktop */
#hamburger-btn {
    display: none;
}

/* ============================================================================
   LEAFLET — themed, rounded popups + controls. These use the app's CSS
   variables, so popups and controls follow light/dark automatically.
   ============================================================================ */
.leaflet-popup-content-wrapper {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.leaflet-popup-content {
    margin: var(--space-3) var(--space-4);
    font-family: var(--font-body);
    line-height: 1.4;
}
.leaflet-popup-tip {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: none;
}
.leaflet-popup-close-button {
    color: var(--color-text-muted) !important;
}
.leaflet-popup-close-button:hover {
    color: var(--color-text) !important;
}

/* Zoom + attribution controls */
.leaflet-bar,
.leaflet-control-zoom {
    border: none !important;
    border-radius: var(--radius-md) !important;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}
.leaflet-bar a,
.leaflet-control-zoom a {
    background: var(--color-surface);
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border) !important;
}
.leaflet-bar a:hover,
.leaflet-control-zoom a:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}
.leaflet-control-attribution {
    background: var(--color-surface) !important;
    color: var(--color-text-muted) !important;
    border-top-left-radius: var(--radius-sm);
    padding: 0 6px;
}
.leaflet-control-attribution a {
    color: var(--color-primary) !important;
}

/* ============================================================================
   BRAND + PROFILE
   ============================================================================ */
.brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}
.brand-logo {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

/* ============================================================================
   MAP LAYER CONTROL (boundary toggles)
   ============================================================================ */
.layer-control {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: var(--space-2) var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: 0.8125rem;
    color: var(--color-text);
}
.layer-control label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    white-space: nowrap;
}
.layer-control input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* ============================================================================
   PLACE POPUP — note + photo
   ============================================================================ */
.popup-note {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-top: var(--space-2);
}
.popup-note-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}
.popup-note-input {
    width: 100%;
    resize: vertical;
    font-family: var(--font-body);
    font-size: 0.8125rem;
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    color: var(--color-text);
    box-sizing: border-box;
}
.popup-note-save {
    align-self: flex-end;
}
.popup-photo {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-3);
}
.popup-photo-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}
.popup-photo-thumb {
    position: relative;
    width: 90px;
    height: 90px;
}
.popup-photo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    display: block;
}
.popup-photo-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    line-height: 1;
    padding: 2px 5px;
}
.popup-photo-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
}

/* View mode: read-only note text + photo thumbnails, plus the Edit toggle
   shared by both modes. */
.popup-note-view {
    margin-top: var(--space-2);
    font-size: 0.8125rem;
    color: var(--color-text);
    white-space: pre-wrap;
}
.popup-photo-view {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}
.popup-edit-toggle {
    margin-top: var(--space-3);
    width: 100%;
}

/* ============================================================================
   PLACE SHEET — side panel (desktop) / bottom sheet (mobile)
   ============================================================================ */

.place-sheet {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(380px, 100%);
    z-index: 980;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    flex-direction: column;
}

.place-sheet.is-open {
    display: flex;
}

.place-sheet-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.place-sheet-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.place-sheet-title {
    margin: 0;
    font-size: 1.2rem;
    font-family: var(--font-display);
    flex: 1;
    min-width: 0;
}

.place-sheet-name-input {
    width: 100%;
    font-size: 1.1rem;
    font-weight: 600;
}

.place-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.place-sheet-footer {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

.place-sheet-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.place-sheet-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.status-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.status-chip {
    border: 1px solid var(--color-border);
    background: var(--color-surface-2);
    color: var(--color-text);
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.status-chip.is-active {
    background: var(--color-primary);
    color: var(--color-text-inverse);
    border-color: var(--color-primary);
}

.place-sheet-textarea {
    width: 100%;
    resize: vertical;
    min-height: 4rem;
}

.place-sheet-note-view {
    margin: 0;
    white-space: pre-wrap;
    color: var(--color-text);
}

.place-sheet-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.place-sheet-thumb {
    position: relative;
    width: 88px;
    height: 88px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--color-surface-2);
}

.place-sheet-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.place-sheet-photo-remove {
    position: absolute;
    top: 2px;
    right: 2px;
}

.place-sheet-coords {
    font-family: ui-monospace, monospace;
    font-size: 0.75rem;
}

/* Connections */
.conn-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.conn-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.conn-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.conn-name-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-align: left;
    color: var(--color-primary);
    flex: 1;
}

.conn-name-btn:hover {
    text-decoration: underline;
}

#btn-connections {
    position: relative;
}

.conn-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--color-danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

@media (max-width: 768px) {
    .place-sheet {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 55%;
        border-left: none;
        border-top: 1px solid var(--color-border);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }
}

/* Stats / timeline */
.stats-view-side {
  position: absolute;
  top: 56px;
  left: var(--space-4);
  bottom: 90px;
  width: min(300px, 40vw);
  background: var(--color-surface-translucent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
  overflow-y: auto;
  z-index: 1001;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: auto;
}

.stats-view-side h3 {
  margin: 0 0 var(--space-2);
  font-size: 1rem;
}

.stats-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.stats-timeline-item {
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stats-timeline-item:hover {
  background: var(--color-primary-light);
}

.stats-cluster-wrap {
  background: transparent !important;
  border: none !important;
}

.stats-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  border: 2px solid #fff;
  box-shadow: var(--shadow-md);
}

.map-layers-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: var(--space-3) 0 var(--space-2);
}

.map-layers-section-title:first-child {
  margin-top: 0;
}

.basemap-select {
  width: 100%;
  font-size: 0.85rem;
  margin-bottom: var(--space-2);
}

.map-layer-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.35rem;
  margin-bottom: var(--space-2);
  font-size: 0.875rem;
}

.map-layer-hint {
  flex-basis: 100%;
  padding-left: 1.4rem;
  font-size: 0.7rem;
  color: var(--color-text-faint);
}

.trip-status-select {
  width: auto;
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
  max-width: 7.5rem;
}

.trip-status-badge {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  vertical-align: middle;
}

.trip-status-done {
  background: #dcfce7;
  color: #166534;
}

[data-theme="dark"] .trip-status-done {
  background: #14532d;
  color: #bbf7d0;
}

.route-gpx-btn {
  cursor: pointer;
  flex-shrink: 0;
}
