/* Base styles */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}

/* Sidebar */
#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 250px;
    height: 100vh;
    background-color: #f0f0f0;
    padding: 20px;
    box-sizing: border-box;
    z-index: 100;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    transition: transform 0.3s ease;
}

#sidebar h2 {
    margin-top: 0;
    color: #333;
    font-size: 18px;
    border-bottom: 2px solid #007bff;
    padding-bottom: 10px;
}

#sidebar button {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 10px;
}

#sidebar button.primary {
    background-color: #007bff;
}

#sidebar button.primary:hover {
    background-color: #0056b3;
}

#sidebar button.btn-success {
    background-color: #28a745;
}

#sidebar button.btn-success:hover {
    background-color: #218838;
}

/* Building/Floor selector buttons (distinct from door selector) */
#sidebar button.btn-selector {
    background-color: #6f42c1;
}

#sidebar button.btn-selector:hover {
    background-color: #59359c;
}

/* Back-compat: older markup still uses btn-success on selector buttons */
#sidebar button#buildingSelector {
    background-color: #6f42c1;
}

#sidebar button#buildingSelector:hover {
    background-color: #59359c;
}

#sidebar button.btn-black {
    background-color: #000;
}

#sidebar button.btn-black:hover {
    background-color: #222;
}

#sidebar button.secondary {
    background-color: #17a2b8;
}

#sidebar button.secondary:hover {
    background-color: #138496;
}

#sidebar button.disabled,
#sidebar button:disabled {
    background-color: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    box-shadow: none;
}

#sidebar button.disabled:hover,
#sidebar button:disabled:hover {
    background-color: #e9ecef;
}

/* Canvas - dimensions controlled by JS */
#canvas {
    display: block;
    position: absolute;
    top: 0;
    right: 0;
    margin: 0;
    padding: 0;
}

/* Sidebar hidden state */
#sidebar.hidden {
    transform: translateX(-100%);
}

/* Mobile sidebar behavior is platform-based (UA), not viewport-width based. */
html[data-bme-platform="mobile"] #sidebar {
    transform: translateX(-100%);
    width: 280px;
}

html[data-bme-platform="mobile"] #sidebar.open {
    transform: translateX(0);
}

@media screen and (max-width: 480px) {
    html[data-bme-platform="mobile"] #sidebar {
        width: 100%;
    }
}

/* Menu toggle button - always visible */
.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 200;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.menu-toggle:hover {
    background-color: #0056b3;
}

/* Floating buttons - shown when sidebar hidden */
.floating-btn {
    display: none;
    position: fixed;
    left: 10px;
    z-index: 200;
    border: none;
    border-radius: 4px;
    width: 44px;
    height: 44px;
    padding: 0;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.floating-btn.visible {
    display: flex;
    align-items: center;
    justify-content: center;
}

.floating-btn.disabled {
    background-color: #e9ecef !important;
    cursor: not-allowed;
    box-shadow: none;
}

.floating-btn.disabled:hover {
    background-color: #e9ecef !important;
}

.floating-btn.disabled .btn-icon {
    filter: grayscale(1) brightness(0.6);
}

/* Floor quick selector (top-right) */
.floor-quick-buttons {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 90; /* behind the sidebar */
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.floor-control-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 8px;
    background-color: #007bff;
    color: white;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    user-select: none;
}

.floor-control-btn:hover {
    background-color: #0056b3;
}

.floor-control-btn.indicator {
    background-color: #28a745;
}

.floor-control-btn.indicator:hover {
    background-color: #218838;
}

.floor-control-btn.disabled,
.floor-control-btn:disabled {
    background-color: #e9ecef !important;
    color: #6c757d;
    cursor: not-allowed;
    box-shadow: none;
}

.floor-control-btn.invisible {
    visibility: hidden;
    pointer-events: none;
}

.floor-control-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.btn-icon {
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(1);
}

.flip-x {
    transform: scaleX(-1);
}

.sidebar-btn-icon {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    vertical-align: middle;
    filter: brightness(0) invert(1);
}

/* Search button - under menu toggle */
.search-btn {
    top: 60px;
    background-color: #007bff;
}

.search-btn:hover {
    background-color: #0056b3;
}

/* Map button - back to map */
.map-btn {
    top: 114px;
    background-color: #000;
}

.map-btn:hover {
    background-color: #222;
}

/* Next arrow button */
.next-btn {
    top: 222px;
    background-color: #007bff;
}

.next-btn:hover {
    background-color: #0056b3;
}

.prev-btn {
    top: 168px;
    background-color: #007bff;
}

.prev-btn:hover {
    background-color: #0056b3;
}

/* Door button */
.door-btn {
    top: 276px;
    background-color: #28a745;
}

.door-btn:hover {
    background-color: #218838;
}

/* Door list in modal */
.door-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.door-item {
    padding: 12px 16px;
    margin: 8px 0;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.door-item:hover {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

.door-item.current {
    background-color: #28a745;
    color: white;
    border-color: #28a745;
}

.door-item.current:hover {
    background-color: #218838;
    border-color: #218838;
}

.door-item .door-name {
    font-weight: bold;
}

.door-item .door-distance {
    font-size: 12px;
    color: #6c757d;
    margin-top: 4px;
}

.door-item:hover .door-distance,
.door-item.current .door-distance {
    color: rgba(255, 255, 255, 0.8);
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: var(--bme-vv-offset-top, 0px);
    width: var(--bme-vv-width, 100%);
    height: var(--bme-vv-height, 100%);
    background-color: rgba(0, 0, 0, 0.5);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 16px;
    box-sizing: border-box;
}

.modal-content {
    background-color: #fefefe;
    margin: 0;
    padding: 20px;
    border: 1px solid #888;
    border-radius: 8px;
    width: min(600px, 100%);
    max-width: 600px;
    max-height: min(80vh, calc(var(--bme-vv-height, 100dvh) - 32px));
    overflow-y: auto;
    box-sizing: border-box;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #007bff;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.modal-search {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    margin-bottom: 10px;
    box-sizing: border-box;
}

.modal-search:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.modal-small {
    max-width: 420px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
    font-size: 14px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.error-message {
    padding: 10px;
    margin-bottom: 15px;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #721c24;
    font-size: 14px;
}

.success-message {
    padding: 10px;
    margin-bottom: 15px;
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 4px;
    color: #155724;
    font-size: 14px;
}

.btn-primary {
    width: 100%;
    padding: 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.btn-primary:hover {
    background-color: #0056b3;
}

/* Building/Floor selector list */
.building-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.building-item {
    padding: 12px 16px;
    margin: 8px 0;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.building-item.top-match {
    background-color: #e2e6ea;
    border-color: #ced4da;
}

.building-item.current {
    background-color: #28a745;
    color: white;
    border-color: #28a745;
}

.building-item.current .building-file {
    color: rgba(255, 255, 255, 0.8);
}

.building-item.current.top-match {
    background-color: #218838;
    color: white;
    border-color: #218838;
}

.building-item.current.top-match .building-file {
    color: rgba(255, 255, 255, 0.8);
}

/* Hover (blue) should override every state */
.building-item:hover,
.building-item.top-match:hover,
.building-item.current:hover,
.building-item.current.top-match:hover {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

.building-item:hover .building-file,
.building-item.top-match:hover .building-file,
.building-item.current:hover .building-file,
.building-item.current.top-match:hover .building-file {
    color: rgba(255, 255, 255, 0.8);
}

.building-item .building-name {
    font-weight: bold;
    font-size: 16px;
}

.building-item .building-file {
    font-size: 12px;
    color: #6c757d;
    margin-top: 4px;
}

.modal-hint {
    font-size: 13px;
    color: #6c757d;
    margin-bottom: 10px;
}

.virtual-list {
    overflow: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    position: relative;
}

.room-search-content {
    display: flex;
    flex-direction: column;
}

.room-search-content .virtual-list {
    flex: 0 0 auto;
    overflow: visible;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.virtual-list-spacer {
    position: relative;
    width: 100%;
}


.virtual-list-item {
    position: absolute;
    left: 0;
    right: 0;
    padding: 0 16px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    box-sizing: border-box;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
}

.virtual-list-item.top-match,
.virtual-list-item[aria-selected="true"] {
    background-color: #e2e6ea;
    border-bottom-color: #ced4da;
}

.virtual-list-item:hover,
.virtual-list-item.top-match:hover,
.virtual-list-item[aria-selected="true"]:hover {
    background-color: #007bff;
    color: white;
}

.room-item-name {
    font-weight: bold;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-item-meta {
    font-size: 12px;
    color: #6c757d;
    margin-left: 8px;
    flex: 0 0 auto;
}

.virtual-list-item:hover .room-item-meta,
.virtual-list-item.top-match:hover .room-item-meta,
.virtual-list-item[aria-selected="true"]:hover .room-item-meta {
    color: rgba(255, 255, 255, 0.85);
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: #000;
}

/* Mobile responsive styles */
@media screen and (max-width: 768px) {
    .modal-content {
        width: calc(100vw - 24px);
        padding: 15px;
        max-height: calc(var(--bme-vv-height, 100dvh) - 24px);
    }

    #sidebar button {
        padding: 14px 16px;
        font-size: 15px;
    }
}

@media screen and (max-width: 480px) {
    .modal-content {
        width: calc(100vw - 16px);
        max-height: calc(var(--bme-vv-height, 100dvh) - 16px);
    }

    .modal-header h3 {
        font-size: 16px;
    }
}

@media screen and (max-height: 600px) {
    .modal-content {
        width: calc(100vw - 24px);
        max-height: calc(var(--bme-vv-height, 100dvh) - 12px);
    }
}

@media screen and (max-height: 480px) {
    .modal-content {
        width: calc(100vw - 16px);
        max-height: calc(var(--bme-vv-height, 100dvh) - 8px);
    }
}
