/* =========================================================
   LiveAge Event Map - Mobile Wizard (≤768px)
   ========================================================= */

/* Hide wizard by default (desktop) */
.lae-mobile-wizard { display: none; }

@media (max-width: 768px) {
    /* --- Hide desktop UI chrome on mobile --- */
    .liveage-map-container .corner-border,
    .liveage-map-container #menu2,
    .liveage-map-container #centerPlus,
    .liveage-map-container #dragTooltip {
        display: none !important;
    }

    /* Desktop widget only shows when explicitly marked visible (for SavedMaps etc.) */
    .liveage-map-container #unifiedWidget {
        display: none !important;
    }
    .liveage-map-container.lae-step-result-active #unifiedWidget.visible {
        display: flex !important;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        height: auto;
        max-height: 65vh;
        z-index: 30;
        transform: none !important;
    }
    .liveage-map-container.lae-step-result-active #unifiedWidget.visible .widget-panel {
        max-height: 65vh;
        width: 100%;
        border-radius: 18px 18px 0 0;
        padding: 18px 14px;
        overflow-y: auto;
        box-sizing: border-box;
    }
    .liveage-map-container.lae-step-result-active #unifiedWidget .widget-content {
        overflow: visible;
    }
    .liveage-map-container.lae-step-result-active #unifiedWidget .widget-metrics-columns {
        flex-direction: column;
        gap: 0;
    }
    .liveage-map-container.lae-step-result-active #unifiedWidget .widget-metrics-col {
        width: 100%;
    }
    .liveage-map-container.lae-step-result-active #unifiedWidget .widget-metrics-footer {
        flex-direction: column;
        gap: 10px;
    }
    .liveage-map-container.lae-step-result-active #unifiedWidget .widget-metrics-footer button {
        width: 100%;
    }

    .liveage-map-container #mapContainer {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.4s ease;
    }

    /* When in result step — reveal the canvas */
    .liveage-map-container.lae-step-result-active #mapContainer {
        opacity: 1;
        pointer-events: auto;
    }
    .liveage-map-container.lae-step-result-active #centerPlus {
        display: block !important;
    }

    /* Hide desktop tooltips on mobile (they overlap the list) */
    .liveage-map-container .metric-tooltip,
    .liveage-map-container .persistent-tooltip,
    .liveage-map-container .star-tooltip,
    .liveage-map-container .widget-tooltip,
    .liveage-map-container .widget-metric-tooltip,
    .liveage-map-container .star-persistent-tooltip {
        display: none !important;
    }

    /* Hide desktop corner category badges that leak into mobile result view */
    .liveage-map-container .widget-category-header,
    .liveage-map-container .widget-category-name {
        display: none !important;
    }

    /* --- Wizard container --- */
    .lae-mobile-wizard {
        display: flex;
        flex-direction: column;
        position: absolute;
        inset: 0;
        z-index: 20;
        padding: 20px 18px 24px;
        color: #41ffd2;
        font-family: 'Geist Mono', monospace;
        box-sizing: border-box;
    }

    .lae-mobile-wizard[data-step="result"] {
        pointer-events: none;
        background: transparent;
    }
    .lae-mobile-wizard[data-step="result"] .lae-mobile-header {
        pointer-events: auto;
        z-index: 50;
        position: relative;
    }
    .lae-mobile-wizard[data-step="result"] .lae-mobile-header * {
        pointer-events: auto;
    }

    /* --- Header --- */
    .lae-mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 22px;
        min-height: 60px;
    }

    .lae-mobile-logo {
        flex-shrink: 0;
    }

    .lae-mobile-logo img {
        display: block;
        width: auto;
        height: 60px;
        max-width: 140px;
    }

    /* --- Back-to-menu bar (replaces top-right X) --- */
    .lae-mobile-back {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 10px;
        background: transparent;
        border: none;
        color: #41ffd2;
        cursor: pointer;
        font-family: 'Geist Mono', monospace;
        font-size: 12px;
        font-weight: 600;
        letter-spacing: 1.8px;
        padding: 0 4px;
        margin-bottom: 14px;
        align-self: flex-end;
    }

    .lae-mobile-back[hidden] { display: none !important; }

    .lae-mobile-back-x {
        position: relative;
        width: 22px;
        height: 22px;
        flex-shrink: 0;
    }

    .lae-mobile-back-x::before,
    .lae-mobile-back-x::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 0;
        right: 0;
        height: 2.5px;
        background: #41ffd2;
        border-radius: 2px;
        transform-origin: center center;
    }

    .lae-mobile-back-x::before { transform: translateY(-50%) rotate(45deg); }
    .lae-mobile-back-x::after  { transform: translateY(-50%) rotate(-45deg); }

    .lae-mobile-back:active { opacity: 0.6; }

    /* --- Steps --- */
    .lae-step {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .lae-step[hidden] { display: none !important; }

    .lae-step-menu {
        flex: 0 1 auto;
    }

    /* --- Terminal step --- */
    .lae-terminal-box {
        flex: 1;
        border: 1.5px solid #41ffd2;
        border-radius: 22px;
        padding: 28px 26px;
        color: #41ffd2;
        font-family: 'Geist Mono', monospace;
        font-size: 15px;
        line-height: 1.5;
        min-height: 420px;
        cursor: text;
    }

    .lae-terminal-info,
    .lae-terminal-output {
        background: transparent !important;
        color: #41ffd2;
        font-family: 'Geist Mono', monospace;
        border: 0;
        padding: 0;
    }

    .lae-terminal-info {
        margin: 0 0 16px;
        font-size: 15px;
        line-height: 1.45;
        white-space: pre-wrap;
    }

    .lae-terminal-output {
        white-space: pre-wrap;
        margin: 0 0 8px;
        font-size: 14px;
    }

    .lae-terminal-prompt {
        font-size: 28px;
        font-weight: 400;
        display: flex;
        align-items: baseline;
        gap: 10px;
        color: #41ffd2;
        line-height: 1;
    }

    .lae-terminal-prompt-sign {
        display: inline-block;
        font-weight: 500;
    }

    .lae-terminal-input {
        outline: none;
        min-width: 4px;
        display: inline-block;
        caret-color: #41ffd2;
        font-size: 16px;
        line-height: 1;
    }

    .lae-terminal-cursor {
        display: inline-block;
        width: 16px;
        height: 3px;
        background: #41ffd2;
        vertical-align: baseline;
        animation: lae-blink 1s steps(2) infinite;
        margin-left: 0;
        align-self: flex-end;
        margin-bottom: 4px;
    }

    @keyframes lae-blink {
        50% { opacity: 0; }
    }

    /* --- Icon grid (2×4) --- */
    .lae-icon-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0;
        border: 1.5px solid #41ffd2;
        background: transparent;
    }

    .lae-icon-btn {
        aspect-ratio: 1 / 0.7;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 6px;
        background: transparent;
        border: 0.75px solid #41ffd2;
        cursor: pointer;
        transition: background 0.2s;
        padding: 8px 6px;
    }

    .lae-icon-btn:active {
        background: rgba(65, 255, 210, 0.15);
    }

    .lae-icon-btn-primary {
        background: rgba(65, 255, 210, 0.12);
    }

    .lae-icon-btn-primary .lae-icon-label {
        color: #fff;
        font-weight: 700;
    }

    .lae-icon-btn-primary svg {
        stroke: #fff !important;
    }

    .lae-icon-btn-wide {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
        width: 100%;
        margin-top: 0;
        padding: 14px 16px;
        background: transparent;
        border: 1.5px solid #41ffd2;
        border-top: 0;
        color: #41ffd2;
        font-family: 'Geist Mono', monospace;
        font-size: 12px;
        font-weight: 600;
        letter-spacing: 2px;
        text-transform: uppercase;
        cursor: pointer;
    }

    .lae-icon-btn-wide svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }

    .lae-icon-btn-wide:active {
        background: rgba(65, 255, 210, 0.15);
    }

    .lae-icon-btn img,
    .lae-icon-btn svg {
        width: 32px;
        height: 32px;
    }

    .lae-icon-btn svg {
        stroke: #41ffd2;
        fill: none;
    }

    .lae-icon-label {
        font-family: 'Geist Mono', monospace;
        font-size: 10px;
        font-weight: 500;
        letter-spacing: 1.5px;
        color: #41ffd2;
        text-transform: uppercase;
    }

    /* --- Categories step --- */
    .lae-cat-list {
        display: grid;
        gap: 0;
        border: 1.5px solid #41ffd2;
    }

    .lae-cat-btn {
        padding: 26px 16px;
        border: 0.75px solid #41ffd2;
        background: transparent;
        font-family: 'Geist Mono', monospace;
        font-size: 20px;
        font-weight: 700;
        letter-spacing: 1px;
        cursor: pointer;
        text-align: center;
    }

    .lae-cat-btn.lae-cat-komun { color: #19FF00; }
    .lae-cat-btn.lae-cat-even  { color: #8068E9; }
    .lae-cat-btn.lae-cat-decyz { color: #007AFF; }
    .lae-cat-btn.lae-cat-bran  { color: #FFA300; }

    /* --- Metrics step --- */
    .lae-metrics-box {
        flex: 1;
        border: 1.5px solid #41ffd2;
        border-radius: 18px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .lae-metrics-title {
        margin: 0;
        padding: 12px 14px;
        font-size: 16px;
        font-weight: 700;
        text-align: center;
        letter-spacing: 1.5px;
        border-bottom: 1px solid rgba(65, 255, 210, 0.35);
        flex-shrink: 0;
    }

    .lae-metrics-title.lae-cat-komun { color: #19FF00; }
    .lae-metrics-title.lae-cat-even  { color: #8068E9; }
    .lae-metrics-title.lae-cat-decyz { color: #007AFF; }
    .lae-metrics-title.lae-cat-bran  { color: #FFA300; }

    .lae-metrics-list {
        overflow-y: auto;
        flex: 1;
        min-height: 0;
    }

    .lae-metric-row {
        display: block;
        border-bottom: 1px solid rgba(65, 255, 210, 0.2);
        color: #41ffd2;
        font-family: 'Geist Mono', monospace;
        font-size: 11px;
        line-height: 1.35;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    .lae-metric-main {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 10px 10px 14px;
        cursor: pointer;
    }

    .lae-metric-row:last-child {
        border-bottom: none;
    }

    .lae-metric-row:active .lae-metric-main {
        background: rgba(65, 255, 210, 0.08);
    }

    .lae-metric-toggle {
        flex-shrink: 0;
        width: 24px;
        height: 24px;
        border: 1px solid rgba(65, 255, 210, 0.35);
        background: transparent;
        border-radius: 50%;
        color: #41ffd2;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        padding: 0;
        transition: transform 0.25s ease, background 0.2s;
    }

    .lae-metric-toggle svg {
        width: 12px;
        height: 12px;
    }

    .lae-metric-toggle:active {
        background: rgba(65, 255, 210, 0.15);
    }

    .lae-metric-row.expanded .lae-metric-toggle {
        transform: rotate(180deg);
        background: rgba(65, 255, 210, 0.12);
    }

    .lae-metric-desc {
        max-height: 0;
        overflow: hidden;
        padding: 0 14px 0 38px;
        font-size: 10.5px;
        line-height: 1.5;
        color: rgba(65, 255, 210, 0.75);
        transition: max-height 0.3s ease, padding-bottom 0.3s ease;
    }

    .lae-metric-row.expanded .lae-metric-desc {
        max-height: 400px;
        padding-bottom: 10px;
    }

    .lae-metric-shape {
        flex-shrink: 0;
        width: 12px;
        height: 12px;
        position: relative;
    }

    .lae-metric-shape.circle {
        border-radius: 50%;
        border: 2px solid currentColor;
    }

    .lae-metric-shape.diamond {
        transform: rotate(45deg);
        border: 2px solid currentColor;
    }

    .lae-metric-row.selected .lae-metric-shape {
        background: currentColor;
    }

    /* Category-colored shapes in metrics list */
    .lae-metrics-list[data-cat="a"] .lae-metric-shape { color: #19FF00; }
    .lae-metrics-list[data-cat="b"] .lae-metric-shape { color: #8068E9; }
    .lae-metrics-list[data-cat="c"] .lae-metric-shape { color: #007AFF; }
    .lae-metrics-list[data-cat="d"] .lae-metric-shape { color: #FFA300; }

    .lae-metric-label {
        flex: 1;
    }

    /* Metrics action buttons */
    .lae-metrics-actions {
        display: grid;
        grid-template-columns: 70px 1fr;
        gap: 10px;
        margin-top: 12px;
    }

    .lae-btn-back,
    .lae-btn-add,
    .lae-btn-generate {
        font-family: 'Geist Mono', monospace;
        border: 1.5px solid #41ffd2;
        cursor: pointer;
        color: #41ffd2;
    }

    .lae-btn-back {
        background: transparent;
        padding: 10px 0;
        font-size: 15px;
    }

    .lae-btn-add {
        background: rgba(65, 255, 210, 0.22);
        padding: 10px 14px;
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 1.5px;
    }

    .lae-btn-generate {
        display: block;
        width: 100%;
        margin-top: 10px;
        padding: 14px 14px;
        background: rgba(65, 255, 210, 0.22);
        font-size: 14px;
        font-weight: 700;
        letter-spacing: 2px;
    }

    .lae-btn-add:active,
    .lae-btn-generate:active,
    .lae-btn-back:active {
        background: rgba(65, 255, 210, 0.4);
    }

    .lae-btn-generate.lae-btn-disabled {
        opacity: 0.45;
        cursor: not-allowed;
        background: transparent;
    }

    .lae-btn-generate-cat {
        margin-top: 16px;
    }

    /* --- Result step: minimal, map takes over --- */
    .lae-step-result {
        display: none !important;
    }

    /* --- Toast --- */
    .lae-toast {
        position: fixed;
        left: 50%;
        bottom: 40px;
        transform: translateX(-50%) translateY(20px);
        padding: 14px 22px;
        background: rgba(65, 255, 210, 0.95);
        color: #000;
        font-family: 'Geist Mono', monospace;
        font-size: 13px;
        font-weight: 600;
        border-radius: 6px;
        max-width: 86vw;
        text-align: center;
        z-index: 100;
        opacity: 0;
        transition: opacity 0.25s ease, transform 0.25s ease;
        pointer-events: none;
    }

    .lae-toast.visible {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Krótkie ekrany — agresywniejsza kompresja menu */
@media (max-width: 768px) and (max-height: 760px) {
    .lae-mobile-wizard {
        padding: 12px 14px 14px;
    }
    .lae-mobile-header {
        margin-bottom: 12px;
        min-height: 44px;
    }
    .lae-mobile-logo img {
        height: 44px;
        max-width: 110px;
    }
    .lae-mobile-back {
        margin-bottom: 8px;
        font-size: 11px;
    }
    .lae-icon-btn {
        aspect-ratio: 1 / 0.55;
        gap: 4px;
        padding: 6px 4px;
    }
    .lae-icon-btn img,
    .lae-icon-btn svg {
        width: 26px;
        height: 26px;
    }
    .lae-icon-label {
        font-size: 9px;
        letter-spacing: 1.2px;
    }
    .lae-icon-btn-wide {
        padding: 10px 14px;
        font-size: 11px;
    }
    .lae-icon-btn-wide svg {
        width: 16px;
        height: 16px;
    }
}
