/* Global Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

/* Body Styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #1a1a1a;
    color: #fff;
    overscroll-behavior: none; /* Prevent pull-to-refresh */
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height - accounts for browser UI */
}

/* Authentication States */
body.authenticated {
    visibility: visible; /* Show only when authenticated */
}

body:not(.authenticated) {
    visibility: hidden; /* Hide everything until auth check completes */
}

/* Map Container */
#map {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height - adjusts when browser UI shows/hides */
    display: block;
}

/* Status Indicator */
.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 5px;
    animation: pulse 2s infinite;
}

.status-indicator.active {
    background: #4caf50;
}

.status-indicator.error {
    background: #f44336;
}

/* Connection Status */
.connection-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.connection-dot.connected {
    background: #4caf50;
    box-shadow: 0 0 4px #4caf50;
}

.connection-dot.connecting {
    background: #ff9800;
    animation: pulse 1s infinite;
}

.connection-dot.disconnected {
    background: #9e9e9e;
}

.connection-dot.error {
    background: #f44336;
    animation: pulse 0.5s infinite;
}

.connection-text {
    vertical-align: middle;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* MapLibre Popup Customization */
.maplibregl-popup-content {
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    border-radius: 8px;
    padding: 8px 24px 8px 8px;
}

/* Restore triangular tip with correct color per anchor */
.maplibregl-popup-tip {
    border-top-color: transparent;
    border-bottom-color: transparent;
    border-left-color: transparent;
    border-right-color: transparent;
}

.maplibregl-popup-anchor-top .maplibregl-popup-tip {
    border-bottom-color: rgba(0, 0, 0, 0.9);
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
    border-top-color: rgba(0, 0, 0, 0.9);
}

.maplibregl-popup-anchor-left .maplibregl-popup-tip {
    border-right-color: rgba(0, 0, 0, 0.9);
}

.maplibregl-popup-anchor-right .maplibregl-popup-tip {
    border-left-color: rgba(0, 0, 0, 0.9);
}

.maplibregl-popup-anchor-top-left .maplibregl-popup-tip {
    border-bottom-color: rgba(0, 0, 0, 0.9);
}

.maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
    border-bottom-color: rgba(0, 0, 0, 0.9);
}

.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip {
    border-top-color: rgba(0, 0, 0, 0.9);
}

.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
    border-top-color: rgba(0, 0, 0, 0.9);
}

.maplibregl-popup-close-button {
    color: #fff;
    font-size: 18px;
    padding: 4px 8px 0 0;
}

.maplibregl-popup-close-button:hover {
    background: transparent;
}

/* Event Popup */
.event-popup {
    min-width: 200px;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.popup-header h3 {
    margin: 0;
    color: #ff9800;
    font-size: 14px;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.popup-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.popup-time {
    color: #aaa;
    font-size: 11px;
    white-space: nowrap;
}

.popup-link {
    font-size: 14px;
    text-decoration: none;
    line-height: 1;
    flex-shrink: 0;
}

/* Desktop tweaks: slightly smaller header text to prevent wrapping */
@media (min-width: 769px) {
    .popup-header h3 {
        font-size: 13px;
    }
}

.popup-field {
    margin: 0 !important;
    font-size: 12px;
    line-height: 1.15;
}

.popup-field + .popup-field {
    margin-top: 3px !important;
}

.popup-field strong {
    color: #aaa;
}

.event-popup p {
    margin: 0 !important;
}

.popup-divider {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    margin: 6px 0 !important;
}

.popup-message {
    margin: 0 !important;
    font-size: 12px;
    line-height: 1.3;
    color: #ddd;
}

.event-popup a {
    color: #4fc3f7;
    text-decoration: none;
}

.event-popup a:hover {
    text-decoration: underline;
}

/* MapLibre Control Buttons */
.maplibregl-ctrl-group button.active {
    background: #c4e7ff;
    color: inherit;
}

/* Panel Icon */
.panel-icon {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #4fc3f7 0%, #1976d2 100%);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: all 0.3s ease;
    font-size: 16px;
    opacity: 0.9;
}

.panel-icon.show {
    display: flex;
}

.panel-icon:hover {
    transform: scale(1.15);
    opacity: 1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Messages Panel */
.messages-panel {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 8px;
    z-index: 1000;
    width: 90vw;
    max-width: 400px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    touch-action: auto;
    overscroll-behavior: contain;
    transition: all 0.3s ease;
}

/* Icon mode - hide panel, show icon */
.messages-panel.icon-mode {
    display: none;
}

.messages-panel.icon-mode ~ .panel-icon {
    display: flex;
}

/* Status mode - show stats only */
.messages-panel.status-mode .messages-list {
    display: none;
}

/* Full mode - show everything */
.messages-panel.full-mode .messages-list {
    display: block;
}

/* Messages Header */
.messages-header {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.header-top h2 {
    font-size: 14px;
    color: #4fc3f7;
    margin: 0;
    flex: 1;
}

.header-actions {
    display: flex;
    gap: 6px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
    white-space: nowrap;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.close-btn {
    padding: 2px 8px;
    font-size: 16px;
    line-height: 1;
}

/* Stats Section */
.stats-section {
    font-size: 11px;
    line-height: 1.4;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 12px;
}

.stats-row {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 6px;
}

.stats-label {
    color: #aaa;
    font-size: 10px;
    white-space: nowrap;
}

.stats-value {
    font-weight: bold;
    color: #fff;
    font-size: 11px;
    text-align: right;
}

/* Messages List */
.messages-list {
    overflow-y: auto;
    flex: 1;
    padding: 10px;
    overscroll-behavior: contain;
}

.message-item {
    background: rgba(255, 255, 255, 0.05);
    border-left: 3px solid #4fc3f7;
    padding: 6px 8px;
    margin-bottom: 4px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.message-item.no-events {
    border-left-color: #666;
    opacity: 0.6;
}

.message-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.message-item.expanded {
    background: rgba(79, 195, 247, 0.1);
}

.message-item:not(.has-overflow).expanded {
    background: rgba(255, 255, 255, 0.05);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    margin-bottom: 4px;
}

.message-time {
    color: #aaa;
    white-space: nowrap;
}

.message-icons {
    display: flex;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.event-icon {
    font-size: 14px;
    line-height: 1;
}

.event-count {
    font-size: 9px;
    color: #888;
    vertical-align: super;
    margin-left: 1px;
}

.message-header-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.message-header-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #aaa;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 9px;
    white-space: nowrap;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s;
}

.message-header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.message-preview {
    font-size: 11px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #ddd;
}

.message-item.expanded .message-preview {
    white-space: normal;
}

/* Custom Scrollbar */
.messages-list::-webkit-scrollbar {
    width: 6px;
}

.messages-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.messages-list::-webkit-scrollbar-thumb {
    background: rgba(79, 195, 247, 0.5);
    border-radius: 3px;
}

.messages-list::-webkit-scrollbar-thumb:hover {
    background: rgba(79, 195, 247, 0.7);
}

/* Install Icon */
.install-icon {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #4fc3f7 0%, #1976d2 100%);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    transition: all 0.3s ease;
    font-size: 16px;
    opacity: 0.8;
}

.install-icon.show {
    display: flex;
}

.install-icon:hover {
    transform: scale(1.15);
    opacity: 1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Install Card */
.install-card {
    position: fixed;
    bottom: 60px;
    left: 20px;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    border: 2px solid #4fc3f7;
    border-radius: 12px;
    padding: 20px;
    max-width: 280px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    z-index: 2001;
    display: none;
    flex-direction: column;
    gap: 16px;
}

.install-card.show {
    display: flex;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.install-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.install-card-icon {
    font-size: 40px;
    flex-shrink: 0;
}

.install-card-text {
    flex: 1;
}

.install-card-title {
    font-size: 16px;
    font-weight: bold;
    color: #4fc3f7;
    margin-bottom: 6px;
}

.install-card-description {
    font-size: 13px;
    color: #ccc;
    line-height: 1.4;
}

.install-card-close {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 24px;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.install-card-close:hover {
    color: #fff;
}

.install-card-btn {
    background: linear-gradient(135deg, #4fc3f7 0%, #1976d2 100%);
    border: none;
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(79, 195, 247, 0.3);
}

.install-card-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 195, 247, 0.5);
}

/* Debug Overlay */
#debug-overlay {
    position: fixed;
    bottom: 10px;
    left: 10px;
    max-width: 90vw;
    max-height: 40vh;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.8);
    color: #8ef58e;
    font: 11px/1.4 monospace;
    padding: 8px;
    border-radius: 6px;
    z-index: 3000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* Authentication Styles */
.auth-box {
    background: rgba(26, 26, 26, 0.98);
    padding: 30px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
    border: 1px solid rgba(79, 195, 247, 0.3);
}

.auth-box h2 {
    color: #4fc3f7;
    margin-bottom: 15px;
    font-size: 20px;
}

.auth-box p {
    color: #ccc;
    margin-bottom: 20px;
    font-size: 14px;
}

.auth-box input {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    margin-bottom: 15px;
}

.auth-box input:focus {
    outline: none;
    border-color: #4fc3f7;
}

.auth-box button {
    width: 100%;
    padding: 12px;
    background: #4fc3f7;
    border: none;
    border-radius: 6px;
    color: #000;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.auth-box button:hover {
    background: #6dd5fa;
}

.auth-box button:disabled {
    background: #666;
    cursor: not-allowed;
}

.auth-error {
    color: #f44336;
    font-size: 13px;
    margin-top: 10px;
    min-height: 20px;
}

.auth-status {
    color: #4fc3f7;
    font-size: 13px;
    margin-top: 10px;
    min-height: 20px;
    text-align: center;
}

.turnstile-wrapper {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    min-height: 65px;
}

.disclaimer-box {
    max-width: 500px;
}

.disclaimer-content {
    background: rgba(255, 152, 0, 0.1);
    padding: 15px;
    border-radius: 6px;
    border-left: 3px solid #ff9800;
    margin-bottom: 20px;
}

.disclaimer-content ul {
    margin: 10px 0 0 20px;
    color: #ccc;
}

.disclaimer-content li {
    margin: 8px 0;
    font-size: 13px;
    line-height: 1.5;
}

.disclaimer-content strong {
    color: #ff9800;
}

.hidden {
    display: none;
}

/* Login Page Specific */
body.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    visibility: visible;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .messages-panel {
        top: 5px;
        left: 5px;
        right: 5px;
        width: calc(100vw - 10px);
        max-width: none;
        max-height: max(calc(100px + 3 * 60px), 25vh); /* Minimum 280px OR 25% of viewport */
    }

    .messages-panel.collapsed {
        max-height: auto;
    }

    .messages-header {
        padding: 10px;
    }

    .header-top h2 {
        font-size: 14px;
    }

    .toggle-btn {
        font-size: 11px;
        padding: 4px 8px;
    }

    .message-item {
        padding: 8px;
    }

    .install-icon {
        bottom: 12px;
        left: 12px;
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .install-card {
        bottom: 50px;
        left: 12px;
        right: 12px;
        max-width: none;
    }
}
