/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4CAF50;
    --primary-dark: #388E3C;
    --secondary-color: #2196F3;
    --danger-color: #F44336;
    --light-color: #f5f5f5;
    --dark-color: #333;
    --text-color: #555;
    --border-color: #ddd;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --border-radius: 4px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f9f9f9;
    color: var(--dark-color);
}

/* Header */
header {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem;
    box-shadow: var(--shadow);
    position: relative;
    z-index: 1000;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-align: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: center;
    margin-bottom: 0.5rem;
}

/* Offline Indicator */
.offline-indicator {
    background-color: #FF9800;
    color: var(--dark-color);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    margin-top: 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.offline-indicator.offline {
    background-color: var(--danger-color);
    color: white;
    animation: pulse 2s infinite;
}

.offline-icon {
    font-size: 1.125rem;
}

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

/* Main Content */
main {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: calc(100vh - 140px);
    position: relative;
    z-index: 1;
}

/* Mobile Create Button */
.create-btn {
    background-color: white;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    padding: 0.5rem;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    z-index: 500;
    min-width: 44px;
    height: 44px;
    transition: all 0.2s;
}

.create-btn:hover {
    background-color: var(--primary-color);
    color: white;
}

.create-btn span {
    font-size: 1.5rem;
    font-weight: bold;
    line-height: 1;
}

.create-btn:hover {
    background-color: var(--primary-dark);
}

/* App Container - Desktop Layout */
.app-container {
    display: flex;
    flex: 1;
    gap: 1rem;
    min-height: 0;
}

/* Map Container */
.map-container {
    flex: 1;
    height: 100%;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
    min-height: 400px;
}

/* Tree Details Panel - Desktop Sidebar */
.tree-details {
    flex: 1;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    overflow-y: auto;
    min-width: 300px;
    max-width: 500px;
}

/* Mini Tree Preview - Bottom Sheet (Mobile only) */
.tree-preview {
    display: none; /* Hidden by default, shown on mobile */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    padding: 1rem;
    max-height: 70vh;
    overflow-y: auto;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.3s ease-in-out;
    max-width: 600px;
    margin: 0 auto;
}

.tree-preview.visible {
    transform: translateY(0);
}

.tree-preview .preview-content {
    margin-bottom: 1rem;
}

.preview-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
}

.preview-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 0.25rem;
    line-height: 1;
}

.preview-close:hover {
    color: var(--dark-color);
}

.preview-edit {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.875rem;
}

.preview-edit:hover {
    background-color: var(--primary-dark);
}

.details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.details-header h2 {
    font-size: 1.25rem;
    color: var(--primary-color);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 0.25rem;
}

.close-btn:hover {
    color: var(--dark-color);
}

/* Form Styles */
.tree-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.9375rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input.readonly {
    background-color: #f0f0f0;
    cursor: not-allowed;
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

/* Form Actions */
.form-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--light-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

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

/* Location Button */
#locateBtn {
    width: 100%;
    justify-content: center;
}

.icon {
    font-size: 1.125rem;
}

/* Tree List */
.tree-list {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.tree-list h3 {
    margin-bottom: 0.75rem;
    color: var(--primary-color);
    font-size: 1.125rem;
}

.tree-list ul {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
}

.tree-list li {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.tree-list li:last-child {
    border-bottom: none;
}

.tree-list li:hover {
    background-color: #f0f0f0;
}

/* Footer */
footer {
    text-align: center;
    padding: 1rem;
    background-color: white;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
    font-size: 0.875rem;
    color: var(--text-color);
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Responsive Design - Tablet */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
    }

    .map-container {
        flex: none;
        height: 400px;
    }

    .app-container {
        flex-direction: column;
        flex: none;
        height: auto;
    }

    .map-container {
        height: 70vh;
        min-height: 400px;
    }

    .tree-details {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        max-width: 100%;
        border-radius: 0;
        z-index: 1000;
        transform: translateY(100%);
        transition: transform 0.3s ease-in-out;
        padding: 1rem;
        padding-top: calc(1rem + 40px);
    }

    .tree-details.visible {
        transform: translateY(0);
    }

    .tree-form {
        height: calc(100% - 60px);
        overflow-y: auto;
    }
}

/* Responsive Design - Mobile */
@media (max-width: 768px) {
    main {
        padding: 0.5rem;
    }

    header {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
    }

    .search-container {
        flex: 1;
        min-width: 200px;
        max-width: 400px;
    }

    .tree-preview {
        display: block; /* Show on mobile */
    }

    .app-container {
        flex-direction: column;
        flex: none;
        height: 100%;
    }

    .map-container {
        height: 70vh;
        min-height: 400px;
    }

    .tree-details {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        max-width: 100%;
        border-radius: 0;
        z-index: 1000;
        transform: translateY(100%);
        transition: transform 0.3s ease-in-out;
        padding: 1rem;
        padding-top: calc(1rem + 40px);
    }

    .tree-details.visible {
        transform: translateY(0);
    }

    .tree-form {
        height: calc(100% - 60px);
        overflow-y: auto;
    }

    .action-buttons {
        justify-content: space-between;
    }

    .btn {
        flex: 1;
        justify-content: center;
    }

    #locateBtn {
        display: none;
    }

    .tree-list {
        display: none;
    }

    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }
}

/* Marker Icons - Different colors for different tree species */
.leaflet-marker-icon.apfelbaum {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FF5722"><path d="M12 2L13.09 8.26L22 9L13.09 9.74L12 16L10.91 9.74L2 9L10.91 8.26L12 2Z"/></svg>');
}

.leaflet-marker-icon.birnbaum {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FF9800"><path d="M12 2L13.09 8.26L22 9L13.09 9.74L12 16L10.91 9.74L2 9L10.91 8.26L12 2Z"/></svg>');
}

/* Selected marker ring */
.marker-ring {
    width: 44px;
    height: 44px;
    border: 3px solid #4CAF50;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    box-shadow: 0 0 0 2px white, 0 0 4px rgba(76, 175, 80, 0.5);
}

.marker-ring svg {
    width: 24px;
    height: 24px;
}

/* Loading Spinner */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0,0,0,.3);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Notification Toast */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--dark-color);
    color: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 2000;
    animation: slideIn 0.3s ease-out;
}

.notification.success {
    background: var(--primary-color);
}

.notification.error {
    background: var(--danger-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Search Container */
.search-container {
    position: relative;
    max-width: 600px;
    min-width: 200px;
    z-index: 2000;
}

#treeSearch {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    box-shadow: var(--shadow);
    transition: border-color 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#treeSearch:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    box-shadow: var(--shadow);
    max-height: 300px;
    overflow-y: auto;
    z-index: 2000;
}

.search-result-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    color: #333;
    min-width: 100%;
}

.search-result-item:hover {
    background-color: var(--light-color);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-highlight {
    font-weight: bold;
    color: var(--primary-color);
}

.search-species {
    color: #444;
    font-size: 0.9rem;
    font-style: italic;
}

.search-result-active {
    background-color: var(--light-color) !important;
    border-left: 3px solid var(--primary-color);
}

/* Mobile popup styling */
@media (max-width: 768px) {
    .leaflet-popup {
        cursor: pointer;
    }
    .leaflet-popup-content {
        cursor: pointer;
    }
}
