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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f3f4f6;
    color: #1f2937;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
}

.app-container {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: #2563eb;
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-logo {
    width: 32px;
    height: 32px;
}

.header-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-icon {
    background: transparent;
    padding: 0.5rem;
    position: relative;
}

.modal-header .btn-icon {
    background: #3b82f6;
    color: white;
    opacity: 1;
}

.modal-header .btn-icon:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #6b7280;
}

.btn-secondary:hover {
    background: #4b5563;
}

/* Views */
.view {
    display: none;
    flex: 1;
    overflow: hidden;
    opacity: 0;
    animation: fadeIn 0.3s ease-out forwards;
}

.view.active {
    display: flex;
    flex-direction: column;
}

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

/* Home View */
.trips-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.trip-card {
    background: white;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.trip-card:hover {
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.trip-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.drag-handle {
    cursor: grab;
    color: #9ca3af;
    display: flex;
    align-items: center;
}

.drag-handle:hover {
    color: #6b7280;
}

.drag-handle:active {
    cursor: grabbing;
}

.trip-info {
    flex: 1;
}

.trip-info h3 {
    font-size: 1.125rem;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.trip-info p {
    font-size: 0.875rem;
    color: #6b7280;
}

.trip-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0; /* Prevent shrinking on Android */
}

.add-trip-btn {
    position: fixed;
    bottom: 2rem;
    bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    right: 2rem;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    z-index: 1001; /* Above map controls which are at 1000 */
}

/* Additional padding for Android navigation bar */
@supports (padding: max(0px)) {
    .add-trip-btn {
        bottom: max(2rem, calc(2rem + env(safe-area-inset-bottom, 0px)));
    }
}

/* Day View */
.day-header {
    background: white;
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.tabs {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.tab {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}

.day-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Ensure FAB is visible over map */
.view.active {
    position: relative;
}

/* Map */
#map {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Change cursor to grab when dragging */
.leaflet-dragging #map {
    cursor: move;
}

.custom-div-icon {
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Leaflet popup styles */
.leaflet-popup-content-wrapper {
    border-radius: 0.5rem;
}

.leaflet-popup-content {
    margin: 0.75rem;
}

/* Map controls */
.map-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: white;
    border-radius: 0.5rem;
    padding: 0.75rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: #4b5563;
}

.toggle-control input[type="checkbox"] {
    cursor: pointer;
}

.toggle-control .material-icons {
    font-size: 1.25rem;
    color: #6b7280;
}

.loading-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: #6b7280;
}

.error-message {
    color: #ef4444;
    font-size: 0.75rem;
}

.hidden {
    display: none !important;
}

/* POI List */
.poi-list {
    display: none;
    flex-direction: column;
    height: 100%;
    background: #f3f4f6;
}

.poi-list.active {
    display: flex;
}

.poi-items {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    padding-bottom: 5rem; /* Space for FAB button */
}

.poi-item {
    background: white;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: start;
}

.poi-item.base {
    border: 2px solid #3b82f6;
}

.poi-info h4 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.poi-info p {
    font-size: 0.875rem;
    color: #6b7280;
}

.poi-actions {
    display: flex;
    gap: 0.5rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 0.5rem;
    padding: 1.5rem;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-header h2 {
    font-size: 1.25rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 1rem;
}

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

/* POI Search Results */
.search-results {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    margin-top: 0.5rem;
}

.search-result-item {
    padding: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: #f9fafb;
}

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

/* Loading */
.loading {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid #f3f4f6;
    border-radius: 50%;
    border-top-color: #3b82f6;
    animation: spin 1s ease-in-out infinite;
}

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

/* FAB Menu */
.fab-menu {
    position: fixed;
    bottom: 2rem;
    bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    right: 2rem;
    z-index: 100;
}

/* Additional padding for Android navigation bar */
@supports (padding: max(0px)) {
    .fab-menu {
        bottom: max(2rem, calc(2rem + env(safe-area-inset-bottom, 0px)));
    }
}

.fab-options {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.fab-options.active {
    display: flex;
}

.fab-option {
    background: white;
    color: #2563eb;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.fab-option:hover {
    transform: scale(1.1);
}

.fab-label {
    position: absolute;
    right: 3.5rem;
    background: #1f2937;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.fab-option:hover .fab-label {
    opacity: 1;
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #6b7280;
}

.empty-state .material-icons {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

/* PWA specific styles */
@media (display-mode: standalone) {
    .header {
        padding-top: env(safe-area-inset-top);
    }
}

/* iOS PWA fixes */
.app-container {
    padding-bottom: env(safe-area-inset-bottom);
}

/* Smooth transitions */
.tab {
    position: relative;
}

.tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: #2563eb;
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.tab.active::after {
    transform: scaleX(1);
}


/* Mobile optimizations */
@media (hover: none) {
    .btn:hover {
        transform: none;
    }
    
    .trip-card:hover {
        transform: none;
    }
}

/* Responsive */
@media (max-width: 640px) {
    .header h1 {
        font-size: 1.25rem;
    }
    
    /* Remove the problematic rule that hides all spans */
    /* .btn span {
        display: none;
    } */
    
    /* Mobile-friendly button sizes */
    .btn {
        min-height: 44px; /* iOS minimum touch target */
        min-width: 44px;
        padding: 0.75rem 1rem;
        justify-content: center; /* Center content horizontally */
    }
    
    .btn-icon {
        width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center; /* Center icon */
    }
    
    /* Trip card improvements */
    .trip-card {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .trip-info {
        padding-right: 0.5rem;
    }
    
    /* Modal improvements */
    .modal-content {
        margin: 0.5rem;
        max-height: calc(100vh - 1rem);
        max-height: calc(100dvh - 1rem);
        padding: 1rem;
    }
    
    /* Form improvements */
    .form-group input,
    .form-group textarea,
    .form-group select {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* POI list improvements */
    .poi-item {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .poi-actions {
        gap: 0.25rem;
    }
    
    /* FAB adjustments */
    .fab-option {
        width: 48px;
        height: 48px;
    }
    
    /* Map controls on mobile */
    .poi-controls {
        padding: 0.5rem;
        gap: 0.75rem;
        font-size: 0.875rem;
    }
    
    .poi-controls label {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    
    /* Tab improvements */
    .tab {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
    
    /* Route menu on mobile */
    .route-menu {
        right: -0.5rem !important;
        min-width: 280px !important;
    }
    
    .map-controls {
        top: 0.5rem;
        right: 0.5rem;
        font-size: 0.75rem;
    }
}

/* Small mobile screens */
@media (max-width: 480px) {
    /* Stack trip info and actions vertically */
    .trip-card {
        flex-direction: column;
        gap: 0.75rem;
        padding: 1rem;
    }
    
    .trip-info {
        width: 100%;
    }
    
    .trip-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    /* Hide drag handle on very small screens */
    .drag-handle {
        display: none;
    }
    
    /* POI items on very small screens */
    .poi-item {
        padding: 0.75rem;
        flex-wrap: wrap;
    }
    
    /* Row 1: Large image + buttons */
    .poi-item > img {
        order: 1;
        width: 120px !important;
        height: 120px !important;
        margin-right: auto; /* Push buttons to the right */
    }
    
    .poi-actions {
        order: 2;
        flex: 0 0 auto;
        display: flex;
        gap: 0.25rem;
        margin-left: 0.5rem;
    }
    
    /* Row 2: Full width info */
    .poi-info {
        order: 3;
        width: 100%;
        margin-top: 0.75rem;
    }
    
    .poi-actions .btn-icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    
    /* Smaller tabs with just icons */
    .tab {
        padding: 0.5rem;
        font-size: 0.75rem;
    }
    
    .tab span:not(.material-icons) {
        display: none;
    }
    
    /* Smaller header */
    .header h1 {
        font-size: 1.125rem;
    }
    
    /* Full width modals */
    .modal-content {
        margin: 0;
        border-radius: 0;
        max-height: 100vh;
        max-height: 100dvh;
    }
}