/**
 * Energy Monitor - Hauptstyles
 */

/* === RESET & BASIC === */
body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    overflow: hidden;
}

* {
    box-sizing: border-box;
}

/* === MAP === */
#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    z-index: 1; /* Niedrig, damit Buttons darüber liegen */
    pointer-events: auto; /* Map sollte Klicks empfangen, aber Buttons haben höheren z-index */
}

/* === SIDEBAR === */
.sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100%;
    background: white;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
    z-index: 5000;
    /* Safari-compatible transition */
    -webkit-transition: left 0.3s ease;
    transition: left 0.3s ease;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
}

.sidebar.open {
    left: 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 4000;
}

.sidebar-overlay.visible {
    display: block;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 20px;
    color: #333;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
}

/* === CARD LIST === */
.card-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: #f8f9fa;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.card-item:hover {
    background: #e9ecef;
    border-color: #2196f3;
}

.card-item.active {
    background: #e3f2fd;
    border-color: #2196f3;
}

.card-item-icon {
    font-size: 24px;
    margin-right: 12px;
}

.card-item-content {
    flex: 1;
    min-width: 0;
}

.card-item-name {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-item-type {
    font-size: 12px;
    color: #666;
}

.card-item-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.card-item:hover .card-item-actions {
    opacity: 1;
}

.card-action-btn {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.card-action-btn:hover {
    background: #f0f0f0;
    border-color: #999;
}

/* === HAMBURGER BUTTON === */
.hamburger-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 10000 !important; /* Sehr hoch, damit er immer klickbar ist */
    background: white;
    border: none;
    border-radius: 8px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.2s;
    pointer-events: auto !important; /* Sicherstellen dass Klicks funktionieren */
    -webkit-user-select: none;
    user-select: none;
}

.hamburger-btn:hover {
    background: #f0f0f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* === EDIT BUTTON (neben Hamburger) === */
.edit-card-btn {
    position: fixed;
    top: 10px;
    left: 64px;
    z-index: 3000;
    background: white;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    transition: all 0.2s;
}

.edit-card-btn:hover {
    background: #f0f0f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* === DIALOGS === */
.dialog-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 6000;
    align-items: center;
    justify-content: center;
}

.dialog-overlay.visible {
    display: flex;
}

.dialog {
    background: white;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.dialog-header h2 {
    margin: 0;
    font-size: 20px;
    color: #333;
}

.dialog-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.dialog-footer {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: #f8f9fa;
}

.dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

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

/* === BUTTONS === */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #2196f3;
    color: white;
}

.btn-primary:hover {
    background: #1976d2;
}

.btn-secondary {
    background: #f5f5f5;
    color: #666;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-full {
    width: 100%;
}

/* === FORMS === */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: #666;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #2196f3;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

/* === CARD TYPE SELECTOR === */
.card-type-options {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.card-type-option {
    flex: 1;
    position: relative;
}

.card-type-option input[type="radio"] {
    position: absolute;
    opacity: 0;
}

.card-type-label {
    display: block;
    padding: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.card-type-label .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.card-type-label .name {
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.card-type-option input:checked + .card-type-label {
    border-color: #2196f3;
    background: #e3f2fd;
}

.card-type-label:hover {
    border-color: #2196f3;
}

/* === CARD TYPE PREVIEW === */
.card-type-preview {
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-top: 16px;
}

/* === COLOR STOPS EDITOR === */
#color-stops-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.color-stop-item {
    display: flex;
    gap: 8px;
    align-items: center;
}

.color-stop-item input[type="number"] {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.color-stop-item input[type="color"] {
    width: 60px;
    height: 36px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.color-stop-item button {
    background: #ff5252;
    color: white;
    border: none;
    border-radius: 4px;
    width: 32px;
    height: 36px;
    cursor: pointer;
    font-size: 16px;
}

/* === LOADING === */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px 40px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    text-align: center;
}

/* === LOCATION BUTTON === */
.location-control {
    position: absolute;
    top: 200px;
    right: 10px;
    z-index: 1000;
}

.location-btn {
    background: white;
    border: none;
    border-radius: 4px;
    width: 29px;
    height: 29px;
    cursor: pointer;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.location-btn:hover {
    background: #f0f0f0;
}

.location-btn.active {
    color: #2196f3;
}

.location-btn.loading {
    animation: pulse 1s infinite;
}

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

.user-location-marker {
    width: 20px;
    height: 20px;
    background: #2196f3;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* === ZOOM DISPLAY === */
.zoom-display {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    font-family: 'Courier New', monospace;
}

.zoom-display #zoom-value {
    color: #2196f3;
    font-weight: bold;
}

/* === HEATMAP LEGEND === */
.heatmap-legend {
    position: absolute;
    bottom: 70px;
    left: 20px;
    background: white;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    min-width: 180px;
    max-width: 250px;
}

.heatmap-legend.hidden {
    display: none;
}

.heatmap-legend-title {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

.heatmap-legend-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.heatmap-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.heatmap-legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1.5px solid #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.heatmap-legend-label {
    font-size: 11px;
    color: #555;
    font-weight: 500;
}

/* === POPUPS === */
.maplibregl-popup-content {
    padding: 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.popup-header {
    background: #f5f5f5;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.popup-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
}

.popup-nav-btn {
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 12px;
    color: #333;
    line-height: 1;
    width: 24px;
    text-align: center;
}

.popup-nav-btn:hover {
    background: #e0e0e0;
}

.popup-counter {
    font-size: 11px;
    color: #666;
    font-weight: normal;
    margin-right: 4px;
    white-space: nowrap;
}

.popup-body {
    padding: 12px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 12px;
}

/* === DETAILS OVERLAY === */
#details-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 4000;
    justify-content: center;
    align-items: center;
}

.details-modal {
    background: white;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.details-header h2 {
    margin: 0;
    font-size: 18px;
    color: #333;
}

.details-content {
    padding: 0;
    overflow-y: auto;
}

.details-table {
    width: 100%;
    border-collapse: collapse;
}

.details-table th,
.details-table td {
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    text-align: left;
    font-size: 14px;
}

.details-table th {
    background: #f8f9fa;
    width: 40%;
    color: #555;
    font-weight: 600;
}

.details-table tr:last-child td,
.details-table tr:last-child th {
    border-bottom: none;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        left: -100%;
    }
    
    .edit-card-btn {
        left: auto;
        right: 10px;
        top: 10px;
    }
}
