/* Layout */
* {
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f0f0;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
}

.app-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    z-index: 900;
}

.app-header h1 {
    margin: 0;
    font-size: 18px;
    flex: 1;
}

.menu-toggle, .menu-close, .analytics-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.menu-toggle:active, .menu-close:active, .analytics-close:active {
    background-color: rgba(255,255,255,0.2);
}

.header-spacer {
    width: 40px;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    display: flex;
}

.sidebar.active {
    pointer-events: auto;
}

.sidebar-overlay {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar.active .sidebar-overlay {
    opacity: 0.5;
    background: rgba(0,0,0,0.5);
}

.sidebar-content {
    position: relative;
    background: white;
    width: 280px;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar.active .sidebar-content {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 15px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 18px;
}

.menu-close {
    color: white;
    background: none;
    font-size: 28px;
}

.info-panel {
    padding: 15px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.section {
    margin-bottom: 18px;
}

.section h3 {
    margin: 0 0 12px 0;
    font-size: 15px;
    color: #333;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
}

#position-info p {
    margin: 8px 0;
    font-size: 13px;
    color: #555;
    word-break: break-word;
}

#position-info span {
    font-weight: bold;
    color: #667eea;
}

select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 10px;
    box-sizing: border-box;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,%3Csvg fill='%23333' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 20px;
    padding-right: 32px;
}

.button-group {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.button-group .btn {
    flex: 1;
    min-height: 44px;
    padding: 10px 12px;
    font-size: 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background-color: #667eea;
    color: white;
}

.btn-primary:active {
    background-color: #5568d3;
}

.btn-danger {
    background-color: #d32f2f;
    color: white;
}

.btn-danger:active {
    background-color: #b71c1c;
}

.info-note {
    font-size: 12px;
    color: #666;
    margin: 0;
    padding: 12px;
    background-color: #f5f5f5;
    border-left: 3px solid #667eea;
    border-radius: 4px;
    line-height: 1.5;
}

/* Map */
.map-container {
    flex: 1;
    width: 100%;
    position: relative;
    overflow: hidden;
}

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

.leaflet-popup-content {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 13px;
}

.leaflet-popup {
    margin-bottom: 0;
}

/* Переместить кнопки зума в правый нижний угол */
.leaflet-top {
    top: auto !important;
    bottom: 10px !important;
}

.leaflet-left {
    left: auto !important;
    right: 10px !important;
}

.leaflet-control-zoom {
    box-shadow: 0 1px 5px rgba(0,0,0,0.65) !important;
    border-radius: 6px !important;
}

.leaflet-control-zoom a {
    min-width: 40px;
    min-height: 40px;
}

/* Analytics table */
.analytics-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 3px solid #667eea;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
    z-index: 500;
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    transition: max-height 0.3s ease;
}

.analytics-container.collapsed {
    max-height: 50px;
}

.analytics-container.collapsed #analytics-content {
    display: none;
}

.analytics-container.collapsed #analytics-expand {
    display: block !important;
}

.analytics-container.collapsed #analytics-collapse {
    display: none !important;
}

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    flex-shrink: 0;
    border-bottom: 1px solid #eee;
    min-height: 50px;
    box-sizing: border-box;
}

.analytics-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
}

.analytics-controls {
    display: flex;
    gap: 5px;
}

.analytics-toggle {
    background: none;
    border: none;
    color: #667eea;
    font-size: 18px;
    cursor: pointer;
    padding: 6px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.analytics-toggle:active {
    background-color: #f0f0f0;
}

.table-wrapper {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    min-height: 0;
}

#analytics-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 11px;
}

#analytics-table thead {
    position: sticky;
    top: 0;
}

#analytics-table th, #analytics-table td {
    border: 1px solid #ddd;
    padding: 6px 4px;
    text-align: left;
    word-break: break-word;
}

#analytics-table th {
    background-color: #667eea;
    color: white;
    font-weight: 600;
    white-space: nowrap;
    text-align: center;
}

#analytics-table td {
    white-space: normal;
}

#analytics-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

#analytics-table tr:hover {
    background-color: #f0f0f0;
}

/* Mobile table adaptation */
@media (max-width: 768px) {
    .analytics-container {
        max-height: 45vh;
    }
    
    .analytics-header h3 {
        font-size: 14px;
    }
    
    #analytics-table {
        font-size: 10px;
    }
    
    #analytics-table th, #analytics-table td {
        padding: 4px 3px;
    }
    
    .table-wrapper {
        padding: 6px;
    }
}

@media (max-width: 480px) {
    .analytics-container {
        max-height: 40vh;
    }
    
    .analytics-header h3 {
        font-size: 13px;
    }
    
    #analytics-table {
        font-size: 9px;
    }
    
    #analytics-table th, #analytics-table td {
        padding: 3px 2px;
    }
    
    .table-wrapper {
        padding: 4px;
    }
}

/* Desktop Layout */
@media (min-width: 769px) {
    .app-header {
        padding: 12px 15px;
    }

    .app-header h1 {
        font-size: 20px;
    }

    .menu-toggle {
        display: none;
    }

    .header-spacer {
        display: none;
    }

    .sidebar {
        position: absolute;
        width: 320px;
        height: auto;
        left: 10px;
        top: 60px;
        pointer-events: auto;
        display: block;
        background: none;
        z-index: 900;
    }

    .sidebar-overlay {
        display: none;
    }

    .sidebar-content {
        transform: translateX(0) !important;
        width: 100%;
        background: white;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        max-height: calc(100vh - 100px);
        overflow-y: auto;
    }

    .sidebar-header {
        display: none;
    }

    .info-panel {
        padding: 15px;
    }

    .map-container {
        flex: 1;
    }

    .analytics-container {
        position: absolute;
        bottom: 10px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        max-width: calc(100% - 40px);
        max-height: 40vh;
        border-radius: 8px;
        border-top: 1px solid #ddd;
    }

    .analytics-close {
        display: none;
    }

    #analytics-table {
        font-size: 12px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .app-header h1 {
        font-size: 16px;
    }

    .sidebar-content {
        width: 75vw;
        max-width: 280px;
    }

    .section h3 {
        font-size: 14px;
    }

    select {
        font-size: 16px;
        padding: 12px;
    }

    .button-group .btn {
        font-size: 13px;
        min-height: 40px;
    }

    .info-note {
        font-size: 11px;
    }

    #analytics-table {
        font-size: 11px;
    }

    #analytics-table th, #analytics-table td {
        padding: 6px 4px;
    }
}