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

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --success-color: #27ae60;
    --text-color: #333;
    --text-light: #666;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.15);
    --header-height: 80px;
    --nav-height: 60px;
    --filter-height: 120px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: env(safe-area-inset-bottom);
}

/* Password Protection Screen */
.password-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color) 0%, #34495e 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.password-box {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    text-align: center;
    max-width: 90%;
    width: 400px;
}

.password-box h2 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.password-box p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.password-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 1rem;
    transition: border-color 0.3s;
}

.password-input:focus {
    outline: none;
    border-color: var(--secondary-color);
}

.password-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

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

.password-btn:active {
    transform: scale(0.98);
}

.password-error {
    color: var(--accent-color);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    min-height: 1.2rem;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #34495e 100%);
    color: white;
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    max-width: 100%;
    text-align: center;
}

.logo {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: var(--header-height);
    z-index: 99;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.nav-tab {
    flex: 1;
    min-width: 80px;
    padding: 0.75rem 0.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-light);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.nav-tab.active {
    color: var(--secondary-color);
    border-bottom-color: var(--secondary-color);
    font-weight: 600;
}

.nav-icon {
    font-size: 1.2rem;
}

.nav-label {
    font-size: 0.75rem;
}

/* Filters */
.filters {
    background: var(--card-bg);
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: calc(var(--header-height) + var(--nav-height));
    z-index: 98;
}

.search-box {
    position: relative;
    margin-bottom: 0.75rem;
}

.search-input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: var(--secondary-color);
}

.search-icon {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.filter-buttons {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.25rem;
}

.filter-buttons::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    background: var(--card-bg);
    border-radius: 20px;
    font-size: 0.85rem;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-color);
}

.filter-btn.active {
    background: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
}

/* Main Content */
.main-content {
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* Palace List */
.palaces-list {
    display: grid;
    gap: 1rem;
}

.palace-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    border-left: 4px solid var(--secondary-color);
}

.palace-card:active {
    transform: scale(0.98);
}

.palace-card.has-interior {
    border-left-color: var(--success-color);
}

.palace-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.palace-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    flex: 1;
}

.palace-code {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    margin-left: 0.5rem;
}

.palace-code.A {
    background: var(--success-color);
    color: white;
}

.palace-code.A\/w {
    background: #f39c12;
    color: white;
}

.palace-code.B,
.palace-code.C {
    background: var(--text-light);
    color: white;
}

.palace-address {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.palace-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-light);
}

.palace-info-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.palace-interior-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--success-color);
    color: white;
    border-radius: 12px;
    font-size: 0.75rem;
    margin-top: 0.5rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    margin: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

.modal-close:active {
    background: rgba(0,0,0,0.7);
}

.modal-body {
    padding: 2rem 1.5rem 1.5rem;
}

.palace-detail-header {
    margin-bottom: 1.5rem;
}

.palace-detail-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.palace-detail-address {
    font-size: 1.1rem;
    color: var(--text-light);
    margin-bottom: 1rem;
}

.palace-detail-section {
    margin-bottom: 1.5rem;
}

.palace-detail-section h3 {
    font-size: 1rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.palace-detail-info {
    display: grid;
    gap: 0.75rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-label {
    font-weight: 600;
    color: var(--text-light);
}

.detail-value {
    text-align: right;
    color: var(--text-color);
}

.palace-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.action-btn {
    flex: 1;
    min-width: 120px;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.action-btn.maps {
    background: var(--secondary-color);
    color: white;
}

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

.action-btn.photos {
    background: var(--success-color);
    color: white;
    width: 100%;
    margin-bottom: 1rem;
}

.action-btn:active {
    transform: scale(0.95);
}

/* Photos Gallery */
.photos-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.photo-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s;
}

.photo-item:active {
    transform: scale(0.95);
}

.photo-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    display: block;
}

.no-photos {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
}

/* Photo Viewer */
.photo-viewer {
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-viewer-content {
    position: relative;
    max-width: 100%;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.photo-viewer-content img {
    max-width: 100%;
    max-height: calc(100vh - 100px);
    object-fit: contain;
    border-radius: 8px;
}

.photo-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

.photo-nav-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.photo-nav-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.9);
}

.photo-counter {
    color: white;
    font-size: 1rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
}

.photos-modal .modal-content {
    max-height: 90vh;
}

/* Map View */
.map-container {
    width: 100%;
    height: calc(100vh - var(--header-height) - var(--nav-height) - var(--filter-height));
    min-height: 400px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.map {
    width: 100%;
    height: 100%;
}

/* Routes View */
.routes-container {
    max-width: 100%;
}

.routes-container h2 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

.route-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.route-card h3 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.route-list {
    list-style: none;
    margin-top: 1rem;
}

.route-list li {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

/* About View */
.about-container {
    max-width: 100%;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.about-container h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.about-container h3 {
    color: var(--primary-color);
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.about-container ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.about-container li {
    margin-bottom: 0.5rem;
}

.about-container a {
    color: var(--secondary-color);
    text-decoration: none;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border-color);
}

.stat-item {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--secondary-color);
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* Loading */
.loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 2000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive adjustments for very small screens */
@media (max-width: 360px) {
    .logo {
        font-size: 1.5rem;
    }
    
    .nav-label {
        font-size: 0.7rem;
    }
    
    .palace-name {
        font-size: 1rem;
    }
}

/* Map links */
.map-link:active {
    transform: scale(0.95);
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
    .header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .main-content {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* Touch optimizations for mobile */
@media (hover: none) and (pointer: coarse) {
    .palace-card,
    .action-btn,
    .filter-btn,
    .nav-tab {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    .palace-card:active {
        background: #f0f0f0;
    }
}

/* No results */
.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-light);
    font-size: 1.1rem;
}

/* Print styles */
@media print {
    .nav-tabs,
    .filters,
    .modal-close {
        display: none;
    }
    
    .palace-card {
        break-inside: avoid;
    }
}
