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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Screens */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: block;
}

/* Container */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

.container.center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
}

/* Typography */
h1 {
    font-size: 28px;
    margin-bottom: 24px;
    color: #1a1a1a;
}

h2 {
    font-size: 22px;
    margin-bottom: 16px;
    color: #1a1a1a;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 14px;
    color: #555;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="file"],
select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus {
    outline: none;
    border-color: #007AFF;
}

input[type="file"] {
    padding: 8px;
}

small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #777;
}

.privacy-hint {
    color: #ff9500;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-text {
    padding: 14px 24px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    width: 100%;
    margin-top: 8px;
}

.btn-primary {
    background: #007AFF;
    color: white;
}

.btn-primary:active {
    background: #0056b3;
}

.btn-secondary {
    background: #8E8E93;
    color: white;
}

.btn-secondary:active {
    background: #6e6e73;
}

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

.btn-danger:active {
    background: #d32f2f;
}

.btn-text {
    background: transparent;
    color: #007AFF;
    padding: 8px 16px;
    width: auto;
}

/* Map Preview */
#mapPreview {
    margin-top: 12px;
    border-radius: 8px;
    overflow: hidden;
}

#mapPreview img {
    width: 100%;
    height: auto;
    display: block;
}

/* Map Screen */
#mapScreen {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#mapHeader {
    background: white;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    flex-shrink: 0;
}

#mapHeader h2 {
    margin: 0;
    font-size: 18px;
}

.event-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 6px;
    font-size: 12px;
    color: #666;
}

.event-meta .clickable {
    color: #007AFF;
    cursor: pointer;
    text-decoration: underline;
    font-weight: 600;
}

.event-meta .clickable:active {
    opacity: 0.6;
}

#mapContainer {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #f0f0f0;
    min-height: 0;
}

#mapScrollContainer {
    width: 100%;
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    display: flex;
}

#mapScrollContainer.landscape {
    align-items: center;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
}

#mapScrollContainer.portrait {
    align-items: flex-start;
    justify-content: center;
    overflow-x: hidden;
    overflow-y: auto;
}

#mapScrollContainer.zoomed {
    align-items: flex-start;
    justify-content: flex-start;
    overflow: auto !important;
}

#mapImage {
    display: block;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    transition: transform 0.2s ease-out;
    transform-origin: top left;
}

#mapScrollContainer.landscape #mapImage {
    height: 100%;
    width: auto;
}

#mapScrollContainer.portrait #mapImage {
    width: 100%;
    height: auto;
}

#stationsLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.station-marker {
    position: absolute;
    transform: translate(-50%, -100%);
    font-size: 32px;
    cursor: pointer;
    pointer-events: auto;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
    transition: transform 0.2s;
    z-index: 10;
}

.station-marker:active {
    transform: translate(-50%, -100%) scale(1.2);
}

.station-marker.new-station {
    animation: pulse 0.6s ease-in-out 3;
}

@keyframes pulse {
    0%, 100% { transform: translate(-50%, -100%) scale(1); }
    50% { transform: translate(-50%, -100%) scale(1.3); }
}

.house-number {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    color: #333;
    font-size: 11px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

#mapControls {
    background: white;
    padding: 12px 16px;
    padding-bottom: 0;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

#mapControls button {
    margin: 0;
    padding: 12px 16px;
    font-size: 15px;
}

#mapFooter {
    background: white;
    padding: 8px 16px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    text-align: center;
    font-size: 11px;
    color: #999;
    flex-shrink: 0;
}

#mapFooter p {
    margin: 0;
}

#resetZoomBtn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 50;
    background: white;
    border: 2px solid #007AFF;
    color: #007AFF;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: all 0.2s;
}

#resetZoomBtn:active {
    background: #007AFF;
    color: white;
}

/* Add Station Mode */
#addStationMode {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.info-banner {
    background: #007AFF;
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
}

.info-banner button {
    background: rgba(255,255,255,0.3);
    color: white;
    padding: 6px 12px;
    margin: 0;
    width: auto;
    font-size: 13px;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    padding: 24px;
    animation: slideUp 0.3s;
    position: relative;
}

.modal-content.modal-list {
    max-height: 80vh;
    padding: 20px 0;
}

.modal-content.modal-list h2 {
    padding: 0 20px 16px 20px;
    margin: 0;
    border-bottom: 1px solid #e0e0e0;
}

.modal-content.modal-list #stationsListContainer {
    padding: 0;
    max-height: calc(80vh - 80px);
    overflow-y: auto;
}

.stations-list {
    display: flex;
    flex-direction: column;
}

.station-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.station-list-item:active {
    background: #f9f9f9;
}

.station-list-item:last-child {
    border-bottom: none;
}

.station-list-emoji {
    font-size: 32px;
    flex-shrink: 0;
}

.station-list-info {
    flex: 1;
    min-width: 0;
}

.station-list-name {
    font-weight: 600;
    font-size: 15px;
    color: #1a1a1a;
    margin-bottom: 4px;
}

.station-list-address {
    font-size: 13px;
    color: #666;
    margin-bottom: 2px;
}

.station-list-ages {
    font-size: 12px;
    color: #999;
}

.station-list-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: #f0f0f0;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon:active {
    background: #007AFF;
    transform: scale(0.95);
}

.no-stations {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 14px;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal .close {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal .close:active {
    background: #f0f0f0;
}

.station-details {
    background: #f9f9f9;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.station-details p {
    margin-bottom: 12px;
}

.station-details p:last-child {
    margin-bottom: 0;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

/* Loading Overlay */
#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007AFF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive */
@media (min-width: 768px) {
    .modal-content {
        border-radius: 16px;
        margin: 20px;
        max-height: calc(100vh - 40px);
    }
    
    #mapControls {
        flex-direction: row;
    }
    
    #mapControls button {
        flex: 1;
    }
    
    .modal-actions {
        flex-direction: row;
    }
    
    .modal-actions button {
        flex: 1;
    }
}
