:root {
    --bg: #020617;
    --panel: #0f172a;
    --muted: #94a3b8;
    --text: #f8fafc;
    --accent: #38bdf8;
    --btn: #1e293b;
    --btn-hover: #334155;
    --border: #1e293b;
    --highlight: #facc15;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
}

.app {
    display: grid;
    grid-template-rows: auto 1fr;
    height: 100vh;
    width: 100vw;
    position: relative;
}

.toolbar {
    grid-row: 1;
    display: flex;
    gap: .5rem;
    align-items: center;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #0b0e13, #0b0e13aa);
    z-index: 200;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.toolbar .title {
    font-weight: 600;
    margin-right: auto;
    white-space: nowrap;
}

.stage {
    grid-row: 2;
    position: relative;
    overflow: hidden;
    background: var(--bg) !important;
    touch-action: none;
    width: 100%;
    height: 100%;
}

.map-wrap {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    cursor: grab;
    touch-action: none;
    z-index: 10;
}

.map-wrap.dragging {
    cursor: grabbing;
}

svg {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: visiblePainted;
}

svg text {
    fill: var(--text) !important;
    font-weight: 700;
    paint-order: stroke fill;
    stroke: var(--bg);
    stroke-width: 0.25px;
    stroke-linecap: round;
    stroke-linejoin: round;
    text-shadow: none !important;
    filter: none !important;


    transition: none;

    pointer-events: all;
    cursor: pointer;
    font-size: 10px;

    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;

    user-select: none;
    -webkit-user-select: none;
}

.clickable {
    transform-box: fill-box;
    transform-origin: center;
    cursor: pointer;
    /* REMOVIDO: transition */
    transition: none;
}

circle.clickable:hover {
    fill: var(--highlight) !important;
    stroke: none;
    cursor: pointer;
}

text.clickable:hover {
    fill: var(--highlight) !important;

    filter: none !important;
}

.active-station {
    fill: var(--highlight) !important;

    stroke: none !important;
    stroke-width: 0 !important;
    opacity: 1 !important;
    filter: none !important;


    transform: none !important;
}

.panel {
    grid-row: 2;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 460px;
    max-width: 100%;
    background: var(--panel);
    border-left: 1px solid var(--border);
    padding: 80px 1rem 1rem 1rem;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 150;
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
}

.panel.closed {
    transform: translateX(100%);
}

.btn {
    background: var(--btn);
    color: var(--text);
    border: 1px solid var(--border);
    padding: .5rem .75rem;
    border-radius: .6rem;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    white-space: nowrap;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.btn:active {
    transform: translateY(1px);
}

.sep {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 .5rem;
}

.field {
    display: flex;
    align-items: center;
}

.field input {
    background: #0f172a;
    border: 1px solid var(--border);
    color: var(--text);
    padding: .5rem .75rem;
    border-radius: .6rem;
    min-width: 200px;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .8rem;
    background: #0f172a;
    border: 1px solid var(--border);
    padding: .25rem .55rem;
    border-radius: 999px;
}

.toast {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: #0f172a;
    border: 1px solid var(--border);
    padding: 1rem 1.5rem;
    border-radius: .6rem;
    color: var(--text);
    pointer-events: none;
    opacity: 0;
    transition: opacity .25s ease;
    z-index: 2000;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    font-weight: 600;
}

.toast.show {
    opacity: 1;
}

@media (max-width: 768px) {
    .app {
        grid-template-rows: auto 1fr;
        transition: grid-template-rows 0.3s ease;
    }

    .app.has-panel-open {
        grid-template-rows: auto 55vh;
        /* Map height when panel is open */
    }

    .toolbar {
        padding: 0.75rem;
        gap: 0.5rem;
        justify-content: flex-start;
        flex-wrap: nowrap;
    }

    .toolbar .title {
        display: block;
        /* Restore title */
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex-shrink: 0;
    }

    .toolbar .sep {
        display: none;
    }

    .field {
        flex: 1;
        width: auto;
        min-width: 0;
        /* Allow shrinking */
        max-width: 140px;
        /* Force smaller size */
    }

    .field input {
        width: 100%;
        min-width: 50px;
        /* Allow shrinking below default */
    }

    #togglePanel {
        display: flex;
        width: auto;
        min-width: unset;
        /* Remove min-width constraint */
        padding: 0.5rem;
        /* Reduce padding */
        flex-shrink: 0;
    }

    #zoomIn,
    #zoomOut,
    #zoomReset,
    #centerActive {
        position: fixed;
        bottom: 1.5rem;
        z-index: 180;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
        background: var(--panel);
        border: 1px solid var(--border);
        transition: bottom 0.3s ease;
        /* Animate with panel */
    }

    .app.has-panel-open #zoomIn {
        bottom: calc(45vh + 3.5rem);
    }

    .app.has-panel-open #zoomOut {
        bottom: 45vh;
    }

    .app.has-panel-open #zoomReset {
        bottom: 45vh;
    }

    .app.has-panel-open #centerActive {
        bottom: 45vh;
    }


    #centerActive {
        left: 1rem;
        border-radius: 2rem;
        padding: 0 1.2rem;
    }

    #zoomReset {
        left: 50%;
        transform: translateX(-50%);
        border-radius: 2rem;
        padding: 0 1.2rem;
    }

    #zoomIn {
        right: 1rem;
        bottom: 4.5rem;
        border-radius: 50%;
        width: 44px;
        height: 44px;
        padding: 0;
    }

    #zoomOut {
        right: 1rem;
        border-radius: 50%;
        width: 44px;
        height: 44px;
        padding: 0;
    }

    .panel {
        grid-row: 2;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 45vh;
        /* Reduced height */
        border-left: none;
        border-top: 1px solid var(--border);
        transform: translateY(110%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding-bottom: 20px;
        position: fixed;
        /* Fix to bottom */
        z-index: 900;
    }

    .panel.closed {
        transform: translateY(110%);
    }

    .panel:not(.closed) {
        transform: translateY(0);
    }

    svg text {
        font-size: 8px;
        stroke-width: 0.15px;
    }
}



.bottom-help {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    border: 1px solid var(--border);
    padding: 0.5rem 1.2rem;
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 500;
    pointer-events: none;
    user-select: none;
    z-index: 100;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

@media (max-width: 768px) {
    .bottom-help {
        bottom: 5rem;
        font-size: 0.75rem;
        padding: 0.4rem 1rem;
        width: 90%;
        text-align: center;
        white-space: normal;
    }
}

.cappra-logo {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    width: 150px;
    height: auto;
    pointer-events: none;
}

@media (max-width: 768px) {
    .cappra-logo {
        width: 100px;
        bottom: 10px;
        right: 10px;
    }
}