:root {
    --bg: #ecf2ff;
    --panel: rgba(255, 255, 255, 0.88);
    --panel-border: rgba(10, 28, 78, 0.14);
    --text: #0f172a;
    --muted: #53607a;
    --primary: #0b5be0;
    --primary-strong: #083fa3;
    --danger: #c41e3a;
    --success-bg: #e9fff0;
    --success-text: #0d6b2b;
    --error-bg: #fff0f0;
    --error-text: #9c1235;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: radial-gradient(circle at 15% 20%, #d6e5ff 0%, #ecf2ff 35%, #f7fbff 100%);
    color: var(--text);
    font-family: "Sora", sans-serif;
    overflow: hidden;
}

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 72px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(248, 251, 255, 0.82);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(11, 91, 224, 0.14);
    z-index: 1400;
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    background: linear-gradient(135deg, #1f79ff 0%, #0b5be0 100%);
    font-family: "Space Grotesk", sans-serif;
}

.brand-title {
    margin: 0;
    line-height: 1;
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.brand-subtitle {
    margin: 3px 0 0;
    line-height: 1;
    font-size: 0.67rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.backend-status {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid #c8d8ff;
    background: #f5f8ff;
    color: #134ea9;
    font-size: 0.75rem;
    font-weight: 700;
}

.status-good {
    background: var(--success-bg);
    border-color: #96dfaf;
    color: var(--success-text);
}

.status-bad {
    background: var(--error-bg);
    border-color: #ffc7d1;
    color: var(--error-text);
}

.app-shell {
    height: 100vh;
    padding-top: 72px;
    display: grid;
    grid-template-columns: 380px 1fr;
}

.control-panel {
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    border-right: 1px solid rgba(11, 91, 224, 0.13);
    background: linear-gradient(180deg, rgba(244, 248, 255, 0.92) 0%, rgba(236, 242, 255, 0.86) 100%);
}

.card {
    border-radius: 20px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    box-shadow: 0 14px 30px rgba(36, 70, 128, 0.11);
    padding: 14px;
}

.card h2,
.card h3 {
    margin: 0 0 12px;
    font-size: 0.93rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #223054;
}

.field-stack {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
}

.input-with-button {
    position: relative;
}

input[type="text"] {
    width: 100%;
    height: 46px;
    border-radius: 12px;
    border: 1px solid #c4d6ff;
    background: #f8fbff;
    padding: 0 12px;
    font-family: inherit;
    font-size: 0.92rem;
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus {
    outline: none;
    border-color: #73a5ff;
    box-shadow: 0 0 0 3px rgba(33, 96, 217, 0.15);
}

.input-with-button input {
    padding-right: 84px;
}

.location-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: #0f172a;
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 700;
    height: 30px;
    min-width: 64px;
    padding: 0 10px;
    border-radius: 999px;
    cursor: pointer;
}

button {
    font-family: inherit;
}

#start-nav-btn {
    width: 100%;
    height: 50px;
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: linear-gradient(135deg, var(--primary) 0%, #1f79ff 100%);
    box-shadow: 0 10px 20px rgba(8, 63, 163, 0.25);
    transition: transform 0.15s ease, filter 0.2s ease;
}

#start-nav-btn:hover {
    filter: brightness(1.03);
}

#start-nav-btn:active {
    transform: translateY(1px);
}

.stop-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.stop-btn {
    height: 40px;
    border: 1px solid #cadeff;
    border-radius: 12px;
    background: #eef4ff;
    color: #1e2f54;
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 700;
    transition: all 0.2s ease;
}

.stop-btn:hover {
    background: #e2edff;
    border-color: #9bbfff;
}

.custom-search-container {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

#custom-query-btn {
    height: 46px;
    min-width: 84px;
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    color: #ffffff;
    font-weight: 700;
    background: var(--primary-strong);
}

.convoy-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    margin-bottom: 8px;
}

#convoy-create-btn,
#convoy-join-btn,
#convoy-leave-btn {
    border: 0;
    border-radius: 10px;
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
}

#convoy-create-btn,
#convoy-join-btn {
    padding: 0 12px;
    background: #0d4cc2;
}

#convoy-leave-btn {
    width: 100%;
    height: 40px;
    margin-top: 8px;
    background: var(--danger);
}

.convoy-room-label {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 700;
    color: #1d2f57;
}

#convoy-members-ul,
#stops-ul,
#directions-ul {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
}

#convoy-members-ul li,
#stops-ul li {
    border: 1px solid #d7e4ff;
    border-radius: 10px;
    background: #f9fbff;
    padding: 10px;
    margin-bottom: 8px;
    font-size: 0.86rem;
}

.portfolio-highlights {
    border-style: dashed;
}

.highlights-list {
    margin: 0;
    padding-left: 18px;
    color: #33466e;
    font-size: 0.84rem;
    line-height: 1.45;
}

.highlights-list li {
    margin-bottom: 6px;
}

.legal-note {
    margin: 2px 4px 8px;
    font-size: 0.72rem;
    line-height: 1.4;
    color: #5b6883;
}

.map-container {
    position: relative;
    height: calc(100vh - 72px);
}

#map {
    width: 100%;
    height: 100%;
}

#current-turn-panel {
    position: absolute;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 24px);
    max-width: 620px;
    border-radius: 16px;
    border: 1px solid rgba(7, 61, 153, 0.16);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    box-shadow: 0 15px 28px rgba(6, 37, 98, 0.2);
    padding: 12px 14px;
    z-index: 1100;
    pointer-events: none;
}

#current-turn-panel .turn-instruction {
    margin: 0;
    font-family: "Space Grotesk", sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: #0c2d70;
}

#current-turn-panel .next-turn-info {
    margin: 6px 0 0;
    color: #32466f;
    font-size: 0.92rem;
    font-weight: 600;
}

.hidden {
    display: none;
}

.leaflet-tooltip.convoy-label {
    background: #0f172a;
    color: #ffffff;
    border: 0;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    font-weight: 600;
    padding: 4px 8px;
}

.leaflet-tooltip.convoy-label:before {
    border-top-color: #0f172a;
}

@media (max-width: 1024px) {
    body {
        overflow: auto;
    }

    .app-shell {
        display: block;
        height: auto;
        min-height: 100vh;
    }

    .map-container {
        height: 56vh;
        min-height: 56vh;
    }

    .control-panel {
        border-right: 0;
        border-bottom: 1px solid rgba(11, 91, 224, 0.13);
    }
}

@media (max-width: 640px) {
    .topbar {
        height: 66px;
        padding: 10px 12px;
    }

    .brand-subtitle {
        display: none;
    }

    .backend-status {
        max-width: 56%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-shell {
        padding-top: 66px;
    }

    .control-panel {
        padding: 12px;
    }

    .card {
        border-radius: 16px;
        padding: 12px;
    }

    .stop-buttons {
        grid-template-columns: 1fr;
    }

    .convoy-row {
        grid-template-columns: 1fr;
    }
}