/* =========================================================================
   WORKFLOW TOOLBAR — Map + Dots mode accordion
   ========================================================================= */

.workflow-toolbar {
    position: absolute;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: 800;
    background: rgba(255, 255, 255, 0.75);
    -webkit-backdrop-filter: blur(12px) saturate(1.2);
    backdrop-filter: blur(12px) saturate(1.2);
    border: none;
    border-radius: var(--radius-md);
    padding: var(--space-xs);
    display: flex;
    flex-direction: row-reverse;  /* Segment anchors right, tools expand left */
    flex-wrap: wrap;              /* Sub-panel wraps below */
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 20px rgba(40, 50, 40, 0.10),
                0 1px 6px rgba(40, 50, 40, 0.05),
                0 0 0 1px rgba(0, 0, 0, 0.04),
                inset 0 1px 0 0 rgba(255, 255, 255, 0.5),
                inset 1px 0 0 0 rgba(255, 255, 255, 0.15);
    border: none;
    max-width: 460px;
}

/* Glass noise texture — subtle grain for material feel */
.workflow-toolbar::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: var(--glass-noise);
    border-radius: inherit;
    pointer-events: none;
    z-index: 0;
}

.workflow-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all var(--duration-fast) ease;
    padding: 0;
}

@media (hover: hover) {
    .workflow-btn:hover {
        background: var(--bg-tertiary);
        color: var(--text-primary);
        box-shadow: var(--shadow-sm);
    }
}

.workflow-btn:active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

/* Segmented control — recessed tray behind mode buttons with sliding pill.
   The pill is absolutely positioned and slides via transform in JS. */
.toolbar-segment {
    position: relative;
    display: flex;
    gap: 2px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.toolbar-segment .workflow-btn {
    z-index: 1;              /* Above the pill so icon stays on top */
    width: 34px;
    height: 34px;
}

.toolbar-segment__pill {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 34px;
    height: 34px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 3px rgba(69, 95, 69, 0.3),
                inset 0 1px 2px rgba(0, 0, 0, 0.12);
    transition: transform var(--duration-normal) ease;
    pointer-events: none;    /* Clicks pass through to buttons */
}

/* Pill slides to second position (map button) */
.toolbar-segment__pill.pill-map {
    transform: translateX(calc(34px + 2px));   /* button width + gap */
}

/* Hide pill when no mode is active */
.toolbar-segment__pill.pill-hidden {
    opacity: 0;
    transition: opacity var(--duration-fast) ease,
                transform var(--duration-normal) ease;
}

.workflow-btn.active {
    background: transparent;    /* Pill provides the green background now */
    color: #fff;
    box-shadow: none;
}

/* Inactive mode button inside segment — override for the recessed context */
.toolbar-segment .workflow-btn:not(.active) {
    color: var(--text-secondary);
}

.toolbar-count {
    order: -1;              /* Far right in row-reverse layout */
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--accent);
    width: 52px;            /* Fixed — fits 5 digits without resizing */
    padding: 2px 0;
    text-align: center;
    font-variant-numeric: tabular-nums;  /* Monospace digits prevent jitter */
    background: var(--accent-soft);
    border-radius: 10px;                 /* Pill shape */
    line-height: 1.4;
}

/* Empty or reassigning: keep pill visible, show centered spinner */
.toolbar-count:empty,
.toolbar-count.reassigning {
    color: transparent;
    position: relative;
}

.toolbar-count:empty::after,
.toolbar-count.reassigning::after {
    content: '';
    display: block;
    width: 10px;
    height: 10px;
    border: 2px solid var(--text-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    /* Center with margin:auto instead of translate — keeps transform
       free for the spin animation (translate would get overwritten). */
    position: absolute;
    inset: 0;
    margin: auto;
}

.workflow-tools {
    order: 1;                   /* Left of segment in row-reverse layout */
    display: none;              /* Hidden by default — JS showGroup() sets flex */
    align-items: center;
    gap: 4px;
    padding: 3px 4px;
    border-left: none;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.04);       /* Recessed tray — groups buttons visually */
    opacity: 0;
    transition: opacity var(--duration-normal) ease;
}

.workflow-tools.visible {
    opacity: 1;
}

.workflow-tools .tool-btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--duration-fast) ease;
    padding: 0;
}

@media (hover: hover) {
    .workflow-tools .tool-btn:hover {
        background: var(--bg-tertiary);
        color: var(--text-primary);
        box-shadow: var(--shadow-sm);
    }
}

.workflow-tools .tool-btn:active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.workflow-tools .tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.workflow-tools .tool-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.workflow-tools .sub-status-active {
    color: var(--accent);
    font-weight: 600;
}

/* =========================================================================
   ON-CANVAS STAMP CONTROLS — floating card above the ghost dot grid
   Contains count ±, row ±, settings (gap/rotation), place/cancel buttons.
   Rendered as a Leaflet L.divIcon marker so it moves with the stamp.
   ========================================================================= */
.stamp-canvas-control {
    background: none !important;
    border: none !important;
    overflow: visible !important;
    /* Leaflet sets pointer-events:none on non-interactive markers.
       Re-enable on the card so buttons and slider remain clickable. */
    pointer-events: auto !important;
}

/* Wrapper is the single visual unit — glass panel with shadow.
   Card and settings are transparent sections within it.
   transform centers horizontally and pushes above the anchor point. */
.stamp-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    transform: translate(-50%, -100%) translateY(-10px);
    pointer-events: auto;
    background: rgba(255, 255, 255, 0.75);
    -webkit-backdrop-filter: blur(12px) saturate(1.2);
    backdrop-filter: blur(12px) saturate(1.2);
    border-radius: var(--radius-md);
    border: none;
    box-shadow: 0 4px 20px rgba(40, 50, 40, 0.10),
                0 1px 6px rgba(40, 50, 40, 0.05),
                0 0 0 1px rgba(0, 0, 0, 0.04),
                inset 0 1px 0 0 rgba(255, 255, 255, 0.5),
                inset 1px 0 0 0 rgba(255, 255, 255, 0.15);
    padding: var(--space-xs);
}

.stamp-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: var(--glass-noise);
    border-radius: inherit;
    pointer-events: none;
    z-index: 0;
}

.stamp-card {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    border-radius: 0;
    padding: 2px 3px;
    box-shadow: none;
    white-space: nowrap;
    pointer-events: auto;
}

/* stamp-card-expanded class no longer needed — wrapper handles shape */

/* All stamp buttons — uniform size and shape */
.stamp-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Lucide icons inside stamp buttons — sized to fit */
.stamp-btn svg {
    width: 14px;
    height: 14px;
    padding: 0;
    transition: background var(--duration-fast) ease;
}

@media (hover: hover) {
    .stamp-btn:hover {
        background: var(--bg-tertiary);
    }
}

.stamp-btn:active {
    background: var(--bg-tertiary);
}

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

/* Touch devices: expand stamp button touch area to 44px without
   changing visual size. The ::after pseudo-element is invisible
   but captures touch events in the padded area around the button. */
@media (pointer: coarse) {
    .stamp-btn {
        position: relative;
    }
    .stamp-btn::after {
        content: '';
        position: absolute;
        inset: -8px; /* 28px + 16px padding = 44px touch target */
    }
}

/* Green accent buttons (row ▼/▲ and confirm ✓) */
.stamp-btn-accent {
    background: var(--accent);
    color: #fff;
    font-size: 9px;
}

@media (hover: hover) {
    .stamp-btn-accent:hover {
        background: var(--accent-hover);
    }
}

.stamp-btn-accent:active {
    background: var(--accent-hover);
}

.stamp-btn-confirm {
    background: var(--accent);
    color: #fff;
}

@media (hover: hover) {
    .stamp-btn-confirm:hover {
        background: var(--accent-hover);
    }
}

.stamp-btn-confirm:active {
    background: var(--accent-hover);
}

/* Danger button (cancel ×) */
.stamp-btn-danger {
    color: var(--danger);
}

@media (hover: hover) {
    .stamp-btn-danger:hover {
        background: var(--danger-soft);
    }
}

.stamp-btn-danger:active {
    background: var(--danger-soft);
}

/* Count display between -/+ */
.stamp-count {
    min-width: 28px;
    text-align: center;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

/* Divider between button groups */
.stamp-divider {
    width: 1px;
    height: 18px;
    background: var(--border-light);
    flex-shrink: 0;
}

/* =========================================================================
   STAMP SETTINGS PANEL — Expandable gap/rotation controls below stamp card
   Shown when user taps ⚙ gear on the stamp card. Progressive disclosure:
   primary actions (count/rows/confirm) always visible, settings on demand.
   ========================================================================= */

/* Settings section — transparent within the glass wrapper.
   Separated by a thin border-top. Label-left, controls-right. */
.stamp-settings {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding: 5px 3px 2px;
    white-space: nowrap;
    pointer-events: auto;
}

.stamp-setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.stamp-setting-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 50px;
}

.stamp-setting-controls {
    display: flex;
    align-items: center;
    gap: 3px;
}

.stamp-setting-value {
    min-width: 36px;
    text-align: center;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 4px;
    padding: 2px 6px;
}

/* Setting ± buttons — compact, matches glass context */
.stamp-settings .stamp-btn {
    width: 22px;
    height: 22px;
    font-size: 11px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.05);
}

/* Gear button: accent when settings open or non-default values active */
.stamp-btn-settings-active {
    color: var(--accent) !important;
}


/* =========================================================================
   RESPONSIVE — Phone (< 480px)
   Toolbar must not overflow past viewport edge on small screens.
   ========================================================================= */

@media (max-width: 480px) {
    .workflow-toolbar {
        max-width: calc(100vw - 24px);
        right: var(--space-sm);
    }

    .toolbar-segment .workflow-btn {
        width: 30px;
        height: 30px;
    }

    .toolbar-segment__pill {
        width: 30px;
        height: 30px;
    }

    .toolbar-segment__pill.pill-map {
        transform: translateX(calc(30px + 2px));
    }

    .workflow-tools .tool-btn {
        width: 28px;
        height: 28px;
    }

    .gap-slider-group {
        min-width: 80px;
    }

    .toolbar-count {
        width: 44px;
        padding: 1px 0;
    }
}

