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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: #2c3e50;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.5rem;
}

#stats {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.stat-dot.active { background: #e74c3c; }
.stat-dot.resolved { background: #27ae60; }
.stat-dot.unknown { background: #95a5a6; }
.stat-dot.paused { background: #9b59b6; }

#main-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

#map {
    flex: 1;
    height: 100%;
}

#sidebar {
    width: 350px;
    background: white;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sidebar-header {
    padding: 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#sidebar-header h2 {
    font-size: 1.1rem;
    color: #333;
}

#filter-section {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#filter-section input,
#filter-section select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

#filter-section input:focus,
#filter-section select:focus {
    outline: none;
    border-color: #3498db;
}

#locations-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.location-item {
    background: #f9f9f9;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    border-left: 4px solid #95a5a6;
    transition: all 0.2s;
}

.location-item:hover {
    background: #f0f0f0;
    transform: translateX(2px);
}

.location-item.active {
    border-left-color: #e74c3c;
    background: #fdf2f2;
}

.location-item.resolved {
    border-left-color: #27ae60;
    background: #f2fdf4;
}

.location-item .ip {
    font-family: monospace;
    font-weight: bold;
    color: #2c3e50;
}

.location-item .name {
    font-size: 0.85rem;
    color: #666;
    margin-top: 4px;
}

.location-item .notes {
    font-size: 0.8rem;
    color: #888;
    margin-top: 4px;
    font-style: italic;
}

.location-item .status-badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 6px;
}

.status-badge.active {
    background: #e74c3c;
    color: white;
}

.status-badge.resolved {
    background: #27ae60;
    color: white;
}

.status-badge.unknown {
    background: #95a5a6;
    color: white;
}

.location-item .no-coords {
    font-size: 0.75rem;
    color: #e67e22;
    margin-top: 4px;
}

.location-item.monitoring-disabled {
    opacity: 0.6;
}

.location-item .monitoring-paused {
    font-size: 0.75rem;
    color: #9b59b6;
    margin-top: 4px;
    font-style: italic;
}

.location-item .last-change {
    font-size: 0.75rem;
    color: #888;
    margin-top: 3px;
}

/* Monitoring toggle button */
.monitoring-toggle {
    padding: 6px 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.monitoring-toggle.enabled {
    background: #27ae60;
    color: white;
}

.monitoring-toggle.enabled:hover {
    background: #e74c3c;
}

.monitoring-toggle.enabled:hover::after {
    content: ' - Приостановить';
}

.monitoring-toggle.disabled {
    background: #9b59b6;
    color: white;
}

.monitoring-toggle.disabled:hover {
    background: #27ae60;
}

.monitoring-toggle.disabled:hover::after {
    content: ' - Включить';
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

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

.btn-danger:hover {
    background: #c0392b;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: #2c3e50;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #999;
}

.close-btn:hover {
    color: #333;
}

/* Form */
form {
    padding: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
    color: #333;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
}

.form-row {
    display: flex;
    gap: 15px;
}

.form-row .form-group {
    flex: 1;
}

.hint {
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
    margin-bottom: 15px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

/* Detail modal */
#detail-content {
    padding: 20px;
}

#detail-content .detail-row {
    margin-bottom: 12px;
}

#detail-content .detail-label {
    font-size: 0.8rem;
    color: #666;
    text-transform: uppercase;
}

#detail-content .detail-value {
    font-size: 1rem;
    color: #333;
    margin-top: 2px;
}

#detail-content .detail-value.ip {
    font-family: monospace;
    font-size: 1.2rem;
    font-weight: bold;
}

/* Leaflet popup customization */
.leaflet-popup-content {
    margin: 10px 15px;
}

.popup-ip {
    font-family: monospace;
    font-weight: bold;
    font-size: 1.1rem;
}

.popup-status {
    margin-top: 5px;
}

.popup-link {
    display: block;
    margin-top: 8px;
    color: #3498db;
    cursor: pointer;
}

.popup-yandex {
    margin-top: 6px;
    font-size: 0.78rem;
    color: #7f8c8d;
    font-style: italic;
}

/* History timeline */
.history-timeline {
    margin-top: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    border-left: 2px solid #ddd;
    margin-left: 6px;
    padding-left: 15px;
    position: relative;
}

.history-item:last-child {
    border-left-color: transparent;
}

.history-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #95a5a6;
    position: absolute;
    left: -7px;
    top: 10px;
}

.history-item.active .history-dot {
    background: #e74c3c;
}

.history-item.resolved .history-dot {
    background: #27ae60;
}

.history-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-status {
    font-weight: 500;
    font-size: 0.9rem;
}

.history-date {
    font-size: 0.8rem;
    color: #666;
}

.history-source {
    font-size: 0.75rem;
    color: #999;
    font-style: italic;
}

.no-history {
    color: #999;
    font-style: italic;
    padding: 10px 0;
}

.detail-chart-container {
    margin-top: 8px;
    background: #f9f9f9;
    border-radius: 8px;
    padding: 10px 10px 0;
    min-height: 120px;
    position: relative;
    overflow: hidden;
}

.detail-ping-chart {
    min-height: 150px;
}

/* Stats box */
.stats-box {
    display: flex;
    gap: 20px;
    margin-top: 8px;
}

.stat-item-detail {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 15px;
    background: #f5f5f5;
    border-radius: 8px;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: bold;
    color: #2c3e50;
}

.stat-label {
    font-size: 0.75rem;
    color: #666;
    text-align: center;
}

/* Login screen */
.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.login-screen.hidden {
    display: none;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.login-box h2 {
    color: #2c3e50;
    margin-bottom: 5px;
    text-align: center;
}

.login-box p {
    color: #666;
    text-align: center;
    margin-bottom: 30px;
}

.login-error {
    background: #fdf2f2;
    color: #e74c3c;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 0.9rem;
}

.btn-block {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}

#logout-btn {
    margin-left: 20px;
}

#export-btn {
    margin-left: auto;
}

#show-charts-btn {
    margin-left: 10px;
}

.hidden {
    display: none !important;
}

/* Large modal for stats */
.modal-large {
    max-width: 1400px;
    width: 95%;
}

.charts-container {
    display: flex;
    gap: 20px;
    padding: 20px;
    flex-wrap: wrap;
}

.chart-box {
    flex: 1;
    min-width: 300px;
    background: #f9f9f9;
    border-radius: 8px;
    padding: 15px;
}

.chart-box h4 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1rem;
}

.chart-box canvas {
    max-height: 350px;
}

#district-list {
    padding: 0 20px 20px;
}

#district-list table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#district-list th,
#district-list td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

#district-list th {
    background: #f5f5f5;
    font-weight: 600;
    color: #2c3e50;
}

#district-list tr:hover {
    background: #fafafa;
}

#district-list .count-active {
    color: #e74c3c;
    font-weight: 500;
}

#district-list .count-resolved {
    color: #27ae60;
    font-weight: 500;
}

.stats-actions {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: center;
}

.stats-section {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}

.stats-section h4 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.chart-wide {
    width: 100%;
    min-height: 280px;
}

.chart-wide canvas {
    max-height: 300px;
}

.timeline-controls {
    margin-bottom: 10px;
}

.timeline-controls select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    #main-container {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: 40%;
        border-left: none;
        border-top: 1px solid #ddd;
    }

    #map {
        height: 60%;
    }

    .login-box {
        margin: 20px;
    }
}

/* Clustering Settings Panel */
.clustering-panel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1000;
    min-width: 280px;
    max-width: 320px;
}

.clustering-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #3498db;
    color: white;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    user-select: none;
}

.clustering-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.toggle-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.clustering-content {
    padding: 15px;
    max-height: 400px;
    overflow-y: auto;
}

.clustering-content.collapsed {
    display: none;
}

.setting-group {
    margin-bottom: 15px;
}

.setting-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
    color: #2c3e50;
}

.setting-group small {
    display: block;
    font-size: 11px;
    color: #7f8c8d;
    margin-top: 3px;
}

.setting-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ecf0f1;
    outline: none;
    -webkit-appearance: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
}

.setting-group input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: none;
}

.checkbox-group {
    display: flex;
    align-items: center;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    cursor: pointer;
    font-weight: 400;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.btn-small {
    width: 100%;
    padding: 8px;
    font-size: 12px;
    margin-top: 5px;
}

@media (max-width: 768px) {
    .clustering-panel {
        bottom: 10px;
        right: 10px;
        left: 10px;
        min-width: auto;
        max-width: none;
    }
}

/* Timeline Slider */
.timeline-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid #3498db;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.15);
    z-index: 1000;
    padding: 12px 20px;
}

.timeline-container.hidden {
    display: none;
}

.timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    gap: 15px;
}

.timeline-title {
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
    flex-shrink: 0;
}

.timeline-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #666;
    flex: 1;
}

.timeline-options {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.timeline-select {
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
    background: white;
    cursor: pointer;
    color: #2c3e50;
}

.timeline-select:focus {
    outline: none;
    border-color: #3498db;
}

#timeline-date {
    font-weight: 500;
    color: #3498db;
}

#timeline-count {
    color: #666;
}

.timeline-separator {
    color: #ddd;
}

.timeline-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.timeline-close-btn:hover {
    color: #e74c3c;
}

.timeline-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.timeline-btn {
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.timeline-btn:hover {
    background: #2980b9;
}

.timeline-btn.playing {
    background: #e74c3c;
}

.timeline-btn.playing:hover {
    background: #c0392b;
}

.timeline-btn-now {
    width: auto;
    padding: 0 12px;
    font-size: 12px;
    background: #27ae60;
}

.timeline-btn-now:hover {
    background: #229954;
}

.timeline-slider-wrapper {
    flex: 1;
    position: relative;
    height: 36px;
    display: flex;
    align-items: center;
}

#timeline-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: #ecf0f1;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

#timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.1s;
}

#timeline-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

#timeline-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

#timeline-markers {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 8px;
    pointer-events: none;
    transform: translateY(-50%);
}

.timeline-marker {
    position: absolute;
    width: 3px;
    height: 12px;
    background: #e74c3c;
    border-radius: 2px;
    top: 50%;
    transform: translate(-50%, -50%);
}

.timeline-marker.resolved {
    background: #27ae60;
}

@media (max-width: 768px) {
    .timeline-container {
        padding: 10px 12px;
    }

    .timeline-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .timeline-title {
        order: 1;
    }

    .timeline-info {
        order: 3;
        width: 100%;
        font-size: 12px;
    }

    .timeline-options {
        order: 2;
        margin-left: auto;
    }

    .timeline-select {
        font-size: 11px;
        padding: 3px 6px;
    }

    .timeline-btn {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    .timeline-btn-now {
        padding: 0 10px;
        font-size: 11px;
    }
}
