html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Be Vietnam Pro', sans-serif;
}
body {
    height: 100vh;
    background: #0b1220;
    color: #e6f0ff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: none;
}
#map {
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.4s ease;
}
#map-loading {
    position: absolute;
    inset: 0;
    background: rgba(10, 18, 32, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 600;
    color: #7cc0ff;
    z-index: 999;
    pointer-events: none;
}
.topbar {
    height: 50px;
    background: linear-gradient(90deg, #0a1a33, #0d2447);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    padding: 0 12px;
    border-bottom: 1px solid #1f3b66;
    gap: 10px;
}
.logo {
    font-weight: bold;
    font-size: 17px;
    white-space: nowrap;
}
.settings-wrapper {
    display: flex;
    align-items: center;
    position: relative;
}
.settings-btn {
    font-size: 22px;
    font-weight: 800;
    background: none;
    border: none;
    color: #e6f0ff;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    transition: transform 0.18s ease;
}
.search-bar .settings-btn {
    background: none;
    padding: 4px 8px;
    border-radius: 0;
}
.settings-btn:hover {
    transform: scale(1.08);
}
.tooltip {
    position: absolute;
    top: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: #12284a;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    transition: 0.2s ease;
}
.settings-wrapper:hover .tooltip {
    opacity: 1;
}
.settings-panel {
    position: absolute;
    top: 140%;
    right: 0;
    left: auto;
    background: #0c1b33;
    border: 1px solid #1f3b66;
    border-radius: 10px;
    padding: 10px;
    width: 200px;
    display: none;
    z-index: 1000;
}
.settings-panel.active {
    display: block;
}
.setting-title {
    color: #9fc9ff;
    font-weight: 600;
    margin-bottom: 6px;
}
.setting-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.settings-panel .setting-options button {
    background: #ffffff;
    color: #0b1220;
    border: 1px solid #d7e4ff;
    border-radius: 6px;
    padding: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.settings-panel .setting-options button.active {
    background: #1e90ff;
    color: white;
    border-color: #1e90ff;
}
.search-bar {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: nowrap;
    min-width: 0;
}
.search-bar input {
    padding: 5px 8px;
    border-radius: 8px;
    border: none;
    outline: none;
    width: 200px;
    height: 30px;
    font-size: 13px;
    min-width: 0;
}
.search-bar button {
    padding: 4px 8px;
    height: 30px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background-color: #1e90ff;
    font-size: 13px;
}
.search-wrapper {
    position: relative;
    min-width: 0;
}
.suggest-box {
    position: absolute;
    top: 110%;
    left: 0;
    right: 0;
    background: #0c1b33;
    border: 1px solid #1f3b66;
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
}
.suggest-item {
    padding: 8px 10px;
    cursor: pointer;
    font-size: 14px;
}
.suggest-item:hover {
    background: #1e90ff;
}
.container {
    flex: 1;
    position: relative;
    min-height: 0;
}
#main-view {
    position: relative;
    min-height: 0;
    height: 100%;
}
.sidebar {
    width: 340px;
    background: linear-gradient(180deg, #0c1b33, #081426);
    border-left: 1px solid #1f3b66;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    min-height: 0;
}
.panel {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid #1f3b66;
    border-radius: 8px;
    padding: 10px;
}
.panel h2 {
    margin-bottom: 8px;
    font-size: 16px;
}
.info-box {
    min-height: 80px;
    font-size: 14px;
    color: #cfe3ff;
}
.fav-btn {
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: #1e90ff;
    color: white;
}
.ask-btn {
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: #00b894;
    color: white;
}
.ask-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.panel.chatbot {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.chat-log {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border-radius: 6px;
    padding: 8px;
    overflow-y: auto;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 5px;
    margin-bottom: 5px;
    margin-left: 10px;
    margin-right: 10px;
}
.chat-message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    animation: fadeIn 0.25s ease;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.chat-message.user {
    align-self: flex-end;
    background: #4a90e2;
    color: white;
}
.chat-message.bot {
    align-self: flex-start;
    background: #e0e0e0;
    color: black;
}
.chat-message.typing {
    font-style: italic;
    opacity: 0.7;
    white-space: nowrap;
}
.chat-message.typing::after {
    content: "...";
    display: inline-block;
    margin-left: 4px;
    width: 0;
    overflow: hidden;
    vertical-align: bottom;
    animation: typingDots 1s steps(4, end) infinite;
}
.chat-input {
    margin-top: 4px;
    margin-bottom: 5px;
    display: flex;
    gap: 5px;
    width: 100%;
    padding: 0 10px 8px 10px;
}
.chat-input input {
    flex: 1;
    min-width: 0;
    padding: 6px;
    border-radius: 10px;
    border: none;
}
.chat-input button {
    padding: 6px 12px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background-color: #1e90ff;
}
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@keyframes typingDots {
    to {
        width: 1.2em;
    }
}
body.hide-sidebar .sidebar {
    display: none !important;
}
body.disable-hover .tooltip {
    display: none !important;
}
body.hide-chatbot .chatbot-panel {
    display: none !important;
}
.control-rail {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 56px;
    background: linear-gradient(180deg, #0c2a57, #0a1f3f);
    border: 1px solid #1f3b66;
    border-radius: 0 14px 14px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 6px;
    gap: 10px;
    z-index: 1200;
}
.rail-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    align-items: center;
}
.rail-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.08);
    color: #e6f0ff;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.18s ease, background-color 0.18s ease;
}
.rail-btn:hover {
    transform: scale(1.06);
    background: rgba(255, 255, 255, 0.16);
}
.control-rail .settings-panel {
    top: 60px;
    left: calc(100% + 10px);
    right: auto;
}
.favorites-panel {
    position: absolute;
    top: 200px;
    left: calc(100% + 10px);
    right: auto;
    background: #0c1b33;
    border: 1px solid #1f3b66;
    border-radius: 10px;
    padding: 10px;
    width: 220px;
    display: none;
    z-index: 1100;
}
.favorites-panel.active {
    display: block;
}
.intro-panel {
    position: absolute;
    top: 320px;
    left: calc(100% + 10px);
    right: auto;
    background: #0c1b33;
    border: 1px solid #1f3b66;
    border-radius: 10px;
    padding: 10px;
    width: 240px;
    display: none;
    z-index: 1100;
}
.intro-panel.active {
    display: block;
}
.intro-card {
    margin-bottom: 10px;
}
.intro-image {
    height: 120px;
    border-radius: 8px;
    --intro-image-url: none;
    background-image: linear-gradient(135deg, rgba(30, 144, 255, 0.6), rgba(10, 42, 85, 0.6)), var(--intro-image-url);
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e6f0ff;
    font-size: 13px;
    margin-bottom: 8px;
}
.intro-image.has-photo span {
    display: none;
}
.intro-image span {
    background: rgba(12, 27, 51, 0.7);
    padding: 4px 8px;
    border-radius: 6px;
}
.intro-text {
    font-size: 13px;
    color: #cfe3ff;
    line-height: 1.4;
}
.intro-text .intro-section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: #9fc9ff;
    margin: 8px 0 6px;
}
.intro-text .intro-paragraph {
    margin: 6px 0;
}
.intro-text .intro-divider {
    height: 1px;
    background: rgba(159, 201, 255, 0.25);
    margin: 8px 0;
}
.intro-text .intro-list {
    margin: 4px 0 8px;
    padding-left: 16px;
}
.intro-text .intro-list li {
    margin: 4px 0;
}
.favorites-actions {
    display: flex;
    justify-content: flex-end;
    margin: 4px 0 8px;
}
.favorites-clear {
    background: transparent;
    border: 1px solid #1f3b66;
    color: #9fc9ff;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}
.favorites-clear:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e6f0ff;
}
.favorites-clear:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.favorites-section {
    margin-top: 6px;
}
.favorites-section-title {
    font-size: 12px;
    color: #9fc9ff;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.favorites-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    max-height: 220px;
    overflow-y: auto;
}
.favorite-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid transparent;
    color: #e6f0ff;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.favorite-item:hover {
    background: rgba(30, 144, 255, 0.2);
    border-color: #1e90ff;
}
.favorite-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.favorite-type {
    font-size: 11px;
    color: #9fc9ff;
    background: rgba(31, 59, 102, 0.6);
    padding: 2px 6px;
    border-radius: 999px;
}
.favorite-remove {
    background: none;
    border: none;
    color: #ff9f9f;
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.favorite-remove:hover {
    color: #ffd1d1;
}
.favorites-section-empty {
    font-size: 12px;
    color: #7aa1d6;
    padding: 4px 6px;
}
.favorites-empty {
    margin-top: 8px;
    color: #9fc9ff;
    font-size: 13px;
}
.info-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 56px;
    width: 280px;
    background: rgba(12, 27, 51, 0.96);
    border: 1px solid #1f3b66;
    border-radius: 10px;
    padding: 10px;
    z-index: 1100;
    max-height: 100%;
    overflow-y: auto;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-12px);
    transition: transform 0.2s ease, opacity 0.2s ease, width 0.2s ease;
}
.info-panel.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}
.info-panel.collapsed {
    width: 56px;
    padding: 8px 6px;
}
.info-panel.collapsed .panel-header span,
.info-panel.collapsed .intro-card,
.info-panel.collapsed .info-box,
.info-panel.collapsed .fav-btn,
.info-panel.collapsed .ask-btn,
.info-panel.collapsed .panel-close {
    display: none;
}
.info-toggle {
    position: absolute;
    left: calc(56px + 280px + 6px);
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 44px;
    border-radius: 14px;
    border: 1px solid #1f3b66;
    background: #0c1b33;
    color: #e6f0ff;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1101;
}
.info-panel.active + .info-toggle {
    opacity: 1;
    pointer-events: auto;
}
.info-panel.collapsed + .info-toggle {
    left: calc(56px + 56px + 6px);
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    margin-bottom: 8px;
    margin-top: 5px;
    margin-left: 10px;
}
.panel-close {
    background: none;
    border: none;
    color: #e6f0ff;
    font-size: 18px;
    cursor: pointer;
}
.chatbot-panel {
    position: absolute;
    right: 16px;
    bottom: 16px;
    width: 320px;
    height: 420px;
    background: rgba(12, 27, 51, 0.96);
    border: 1px solid #1f3b66;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    resize: none;
    overflow: hidden;
    z-index: 1300;
    min-width: 240px;
    min-height: 280px;
    max-width: 70vw;
    max-height: 70vh;
}
.chatbot-panel .panel-header {
    cursor: move;
    user-select: none;
    gap: 8px;
}
.chatbot-panel .panel-header .panel-close {
    margin-left: auto;
}
#chatbotRailBtn {
}
#chatbotRailBtn.active {
    background: rgba(30, 144, 255, 0.28);
    border-color: rgba(30, 144, 255, 0.8);
}
.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.resize-handle {
    position: absolute;
    z-index: 1301;
    background: transparent;
}
.handle-n {
    top: -6px;
    left: 12px;
    right: 12px;
    height: 12px;
    cursor: n-resize;
}
.handle-s {
    bottom: -6px;
    left: 12px;
    right: 12px;
    height: 12px;
    cursor: s-resize;
}
.handle-e {
    right: -6px;
    top: 12px;
    bottom: 12px;
    width: 12px;
    cursor: e-resize;
}
.handle-w {
    left: -6px;
    top: 12px;
    bottom: 12px;
    width: 12px;
    cursor: w-resize;
}
.handle-ne,
.handle-se,
.handle-sw,
.handle-nw {
    width: 14px;
    height: 14px;
}
.handle-ne {
    right: -7px;
    top: -7px;
    cursor: ne-resize;
}
.handle-se {
    right: -7px;
    bottom: -7px;
    cursor: se-resize;
}
.handle-sw {
    left: -7px;
    bottom: -7px;
    cursor: sw-resize;
}
.handle-nw {
    left: -7px;
    top: -7px;
    cursor: nw-resize;
}
@media (max-width: 900px) {
    #chatbotRailBtn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Mobile resize grip */
    .handle-n,
    .handle-w,
    .handle-ne,
    .handle-sw,
    .handle-nw {
        display: none;
    }
    .handle-e,
    .handle-s,
    .handle-se {
        display: none;
        background: rgba(255, 255, 255, 0.18);
        border: 1px solid rgba(255, 255, 255, 0.35);
        border-radius: 8px;
    }
    .handle-se::after,
    .handle-e::after,
    .handle-s::after {
        content: "";
        position: absolute;
        inset: 5px;
        border-right: 2px solid rgba(255, 255, 255, 0.7);
        border-bottom: 2px solid rgba(255, 255, 255, 0.7);
    }
    .handle-e::after {
        border-bottom: none;
        border-right: 2px solid rgba(255, 255, 255, 0.7);
    }
    .handle-s::after {
        border-right: none;
        border-bottom: 2px solid rgba(255, 255, 255, 0.7);
    }

    /* Mobile chatbot handles */
    .handle-n,
    .handle-s {
        height: 22px;
    }
    .handle-e,
    .handle-w {
        width: 22px;
    }
    .handle-ne,
    .handle-se,
    .handle-sw,
    .handle-nw {
        width: 26px;
        height: 26px;
    }

    body {
        height: 100dvh;
    }
    .topbar {
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 8px 10px;
    }
    .logo {
        text-align: left;
        font-size: 16px;
    }
    .search-bar {
        width: auto;
    }
    .search-bar input {
        width: clamp(120px, 40vw, 190px);
        height: 28px;
        font-size: 12px;
    }
    .search-bar button {
        height: 28px;
        font-size: 12px;
    }
    .control-rail {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: auto;
        height: 56px;
        flex-direction: row;
        border-radius: 14px 14px 0 0;
        padding: 6px 10px;
        justify-content: center;
    }
    .rail-actions {
        flex-direction: row;
        gap: 12px;
    }
    .control-rail .settings-panel {
        top: auto;
        bottom: 64px;
        left: 12px;
        right: 12px;
        width: auto;
        max-height: 60vh;
        overflow-y: auto;
    }
    .favorites-panel,
    .intro-panel {
        top: auto;
        bottom: 64px;
        left: 12px;
        right: 12px;
        width: auto;
        max-height: 60vh;
        overflow-y: auto;
    }
    .info-panel {
        top: auto;
        left: 0;
        right: 0;
        bottom: 56px;
        width: auto;
        border-radius: 14px 14px 0 0;
        transform: translateY(12px);
    }
    .info-panel.active {
        transform: translateY(0);
    }
    .info-panel.collapsed {
        width: auto;
        height: 56px;
        padding: 8px 10px;
    }
    .info-toggle {
        left: 50%;
        top: auto;
        bottom: 56px;
        transform: translateX(-50%);
    }
    .chatbot-panel {
        left: 8px;
        right: 8px;
        bottom: 64px;
        width: auto;
        height: 55vh;
        max-width: none;
        max-height: 70vh;
    }
    .resize-handle { display: none; }
    .chatbot-panel .panel-header { cursor: default; }
    #map-loading {
        font-size: 18px;
    }
}
@media (max-width: 640px) {
    .search-bar {
        gap: 4px;
    }
    .search-bar input {
        width: clamp(90px, 42vw, 150px);
        height: 26px;
        font-size: 11px;
    }
    .search-bar button {
        height: 26px;
        font-size: 11px;
        padding: 3px 8px;
    }
    .logo {
        font-size: 15px;
    }
    .chatbot-panel {
        height: 60vh;
    }
    .info-panel {
        padding: 10px 12px;
    }
    .panel-header {
        margin-left: 0;
    }
}

.chatbot-panel,
.chatbot-panel .panel-header,
.resize-handle {
    touch-action: none;
}
@media (max-width: 900px) {
    .chatbot-panel,
    .chatbot-panel .panel-header,
    .resize-handle {
        touch-action: auto;
    }
}
@media (max-width: 900px) {
    #map {
        width: 100%;
        margin-left: 0;
    }
    #map-loading {
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
    }
}
