/* The sidebar shell is a flex column, so each panel has to own its own
   padding and scrolling - without this the editor's map + fields overflow
   past the bottom of the screen and the Save button becomes unreachable. */
.places-panel {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem 1.1rem calc(1rem + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

/* An author-origin `display` always beats the UA stylesheet's [hidden]
   rule, so without this the hidden panel stays on screen behind the other. */
.places-panel[hidden],
.places-empty[hidden],
.places-hint[hidden] {
    display: none;
}

.places-add-btn {
    width: 100%;
    flex-shrink: 0;
}

.places-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.places-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.7rem 0.85rem;
    background-color: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    color: inherit;
    font-family: inherit;
    text-align: start;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.places-item:hover {
    background-color: var(--card-bg-hover);
    border-color: var(--border);
}

.places-item-pin {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background-color: var(--entity-place-soft, rgba(74, 222, 128, 0.12));
    font-size: 0.95rem;
}

.places-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.places-item-name {
    font-weight: 600;
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: start;
    unicode-bidi: isolate;
}

.places-item-meta {
    font-size: 0.74rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* "1.5 km" is a latin number+unit run - inside RTL text the browser reorders
   it to "km 1.5" unless that run is bidi-isolated on its own. */
.places-measure {
    unicode-bidi: isolate;
    direction: ltr;
}

.places-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 2rem 1rem;
    margin: 0;
}

.places-empty-icon {
    font-size: 1.6rem;
    opacity: 0.55;
}

/* Search sits above the map so the map stays tappable. Results stay in
   flow (not overlayed) - Leaflet panes use z-index 400-1000 and would
   paint over an absolutely positioned dropdown. */
.places-map-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.places-map-search {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.places-search-field {
    position: relative;
}

.places-search-icon {
    position: absolute;
    inset-inline-start: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.places-search-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

.places-search-field > input {
    width: 100%;
    flex: none;
    box-sizing: border-box;
    padding-inline-start: 2.4rem;
}

.places-search-results {
    position: relative;
    z-index: 2;
    max-height: 220px;
    overflow-y: auto;
    margin: 0;
    padding: 0.3rem;
    list-style: none;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 20px -12px rgba(0, 0, 0, 0.45);
}

.places-search-results[hidden] {
    display: none;
}

.places-search-hit {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    width: 100%;
    padding: 0.55rem 0.6rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font-family: inherit;
    text-align: start;
    cursor: pointer;
}

.places-search-hit:hover,
.places-search-hit.is-active {
    background-color: var(--card-bg-hover, var(--bg-elevated));
}

.places-search-hit-pin {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    margin-top: 0.05rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--entity-place-soft, rgba(74, 222, 128, 0.12));
    font-size: 0.85rem;
}

.places-search-hit-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.08rem;
}

.places-search-hit-title {
    font-weight: 600;
    font-size: 0.88rem;
    unicode-bidi: plaintext;
}

.places-search-hit-sub {
    font-size: 0.74rem;
    color: var(--text-muted);
    unicode-bidi: plaintext;
}

.places-search-empty,
.places-search-status {
    margin: 0;
    padding: 0.65rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.places-map-wrap {
    position: relative;
    z-index: 0;
    isolation: isolate;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    direction: ltr;
}

.places-map {
    height: 260px;
    width: 100%;
    cursor: crosshair;
}

.places-map .leaflet-marker-icon,
.places-map .leaflet-marker-shadow {
    cursor: grab;
}

.places-map-address {
    margin: 0;
    font-size: 0.78rem;
    color: var(--text-muted);
    unicode-bidi: plaintext;
}

.places-locate-btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.places-locate-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.places-locate-btn.is-locating {
    animation: places-pulse 1.1s ease-in-out infinite;
}

@keyframes places-pulse {
    50% { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
    .places-locate-btn.is-locating { animation: none; }
}

.places-hint {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin: 0;
}

.places-radius-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.places-radius-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.6rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.places-radius-value {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    unicode-bidi: isolate;
    direction: ltr;
}

#placeRadiusInput {
    width: 100%;
    accent-color: var(--accent);
}

.places-editor-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 0.4rem;
}

/* Pushes Delete to the opposite edge from Save/Cancel, mirroring in RTL. */
.places-delete-btn {
    margin-inline-end: auto;
    max-width: 100%;
}

.places-delete-btn span {
    white-space: normal;
    line-height: 1.25;
    text-align: start;
}

/* Leaflet renders its own light-themed tiles and controls; tone the chrome
   down so it doesn't glow against the app's dark surfaces. */
.places-map .leaflet-control-attribution {
    background-color: rgba(0, 0, 0, 0.55);
    color: #cbd5e1;
    font-size: 9px;
}

.places-map .leaflet-control-attribution a {
    color: #cbd5e1;
}

:root[data-theme="light"] .places-map .leaflet-control-attribution {
    background-color: rgba(255, 255, 255, 0.75);
    color: #475569;
}

:root[data-theme="light"] .places-map .leaflet-control-attribution a {
    color: #475569;
}

/* No-places state inside the reminder dialog's place mode. */
.schedule-no-places {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0;
}

/* ── Motion ────────────────────────────────────────────────────────────────
   Short, single-purpose transitions. Everything here is disabled wholesale
   under prefers-reduced-motion at the bottom of this block. */

/* Panel swap (list <-> editor). */
.places-panel.is-entering {
    animation: places-panel-in 0.24s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes places-panel-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* List rows fade up in sequence; delay is set per row in JS and capped. */
.places-item {
    animation: places-row-in 0.26s ease both;
}

@keyframes places-row-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.places-item:active {
    transform: scale(0.985);
}

/* The row that was just saved, so the result of Save is visible. */
.places-item.is-justsaved {
    animation: places-row-in 0.26s ease both, places-flash 1.1s ease 0.26s;
}

@keyframes places-flash {
    0%, 100% { border-color: var(--border-soft); background-color: var(--card-bg); }
    25% { border-color: var(--accent); background-color: var(--accent-soft); }
}

/* Map fades in once Leaflet has painted its tiles. */
.places-map {
    animation: places-fade 0.3s ease both;
}

@keyframes places-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Radius circle follows the slider smoothly instead of snapping. */
.places-map path.leaflet-interactive {
    transition: d 0.12s linear;
}

/* Pin appears, used on open and whenever the location jumps. Leaflet owns the
   marker's inline `transform` for positioning, so this animates opacity only -
   touching transform here would fight it and misplace the pin. */
.leaflet-marker-icon.is-dropping {
    animation: places-pin-in 0.3s ease both;
}

@keyframes places-pin-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.places-empty {
    animation: places-fade 0.3s ease both;
}

/* ── Quick pick + radius chips ─────────────────────────────────────────── */

.places-quickpick {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.places-quickpick-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.places-quickpick-row,
.places-radius-presets {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.places-chip {
    flex: 1 1 auto;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    padding: 0.42rem 0.65rem;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.places-chip:hover {
    color: var(--text-main);
    border-color: var(--accent);
}

.places-chip:active {
    transform: scale(0.96);
}

.places-chip.is-active {
    background-color: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.places-chip--radius {
    border-radius: var(--radius-md);
    padding: 0.45rem 0.5rem;
}

.places-chip-sub {
    font-size: 0.68rem;
    font-weight: 500;
    opacity: 0.75;
}

.places-hint--quiet {
    font-size: 0.7rem;
    opacity: 0.75;
}

/* Empty-name nudge on Save. */
#placeNameInput.is-invalid {
    border-color: var(--danger);
    animation: places-shake 0.3s ease;
}

@keyframes places-shake {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@media (prefers-reduced-motion: reduce) {
    .places-panel.is-entering,
    .places-item,
    .places-item.is-justsaved,
    .places-map,
    .places-empty,
    .leaflet-marker-icon.is-dropping,
    #placeNameInput.is-invalid {
        animation: none;
    }

    .places-map path.leaflet-interactive,
    .places-chip,
    .places-item {
        transition: none;
    }
}

/* Armed state for the two-step delete: the button says what the next tap does,
   and looks like it means it. */
.places-delete-btn.is-armed {
    flex-basis: 100%;
    animation: place-delete-arm 0.18s ease;
    box-shadow: 0 0 0 2px var(--danger-soft);
}

@keyframes place-delete-arm {
    from { transform: scale(0.97); }
    to { transform: none; }
}

.place-detect-bar {
    margin-top: 0.85rem;
    padding: 1rem 1.05rem 1.05rem;
    background: var(--card-bg);
    border: 2px solid var(--accent, #8b5cf6);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent, #8b5cf6) 18%, transparent);
}

.place-detect-bar[hidden] {
    display: none;
}

.place-detect-kicker {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent, #8b5cf6);
}

.place-detect-name {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
}

.place-detect-copy {
    margin: 0.15rem 0 0;
    font-size: 0.92rem;
    line-height: 1.35;
}

.place-detect-warn {
    margin: 0.15rem 0 0.25rem;
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--danger, #b45309);
}

.place-detect-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.15rem;
}

.place-detect-choices[hidden] {
    display: none;
}

.place-detect-choice {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: inherit;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.place-detect-choice:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.place-detect-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.25rem;
}

.place-detect-btn {
    min-height: 2.5rem;
}
