/* Global Styles for Best Places to Retire Abroad */
/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #fafafa;
}

/* Color Palette - Warm Tones */
:root {
    --primary-blue: #5b9bd5;
    --light-blue: #e8f4f8;
    --cream: #faf6f0;
    --light-green: #d4e8d4;
    --warm-gray: #f5f5f0;
    --text-dark: #2c3e50;
    --text-light: #6c757d;
    --accent-orange: #ff9800;
    --accent-green: #4caf50;
    --border-color: #e0e0e0;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.15);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-dark);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.1rem; }
h6 { font-size: 1rem; }

p {
    margin-bottom: 1rem;
    color: var(--text-light);
}

a {
    color: var(--primary-blue);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--accent-orange);
    text-decoration: underline;
}

/* Container and Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Grid System */
.grid {
    display: grid;
    gap: 2rem;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Flexbox Utilities */
.flex {
    display: flex;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.flex-column {
    flex-direction: column;
}

.flex-wrap {
    flex-wrap: wrap;
}

/* Navigation */
header {
    background: linear-gradient(135deg, var(--primary-blue), var(--light-blue));
    color: white;
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px var(--shadow-light);
    transition: all 0.3s ease;
}

header.scrolled {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
}

nav {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 0.5rem 0;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-blue);
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-links a {
    color: var(--text-dark);
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    transition: all 0.3s ease;
}

.nav-links a:hover {
    background-color: var(--light-blue);
    color: var(--primary-blue);
    text-decoration: none;
}

.hamburger {
    display: none;
    flex-direction: column;
    cursor: pointer;
    padding: 0.5rem;
}

.hamburger span {
    width: 25px;
    height: 3px;
    background-color: var(--text-dark);
    margin: 3px 0;
    transition: 0.3s;
    border-radius: 2px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    text-align: center;
    transition: all 0.3s ease;
    text-decoration: none;
}

.btn:hover {
    background-color: var(--accent-orange);
    color: white;
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-medium);
}

.btn-secondary {
    background-color: transparent;
    color: var(--primary-blue);
    border: 2px solid var(--primary-blue);
}

.btn-secondary:hover {
    background-color: var(--primary-blue);
    color: white;
}

.btn-outline {
    background-color: transparent;
    color: var(--accent-green);
    border: 2px solid var(--accent-green);
}

.btn-outline:hover {
    background-color: var(--accent-green);
    color: white;
}

/* Cards */
.card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--shadow-light);
    overflow: hidden;
    transition: all 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px var(--shadow-medium);
}

.card-header {
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--light-blue), var(--cream));
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    background-color: var(--warm-gray);
    border-top: 1px solid var(--border-color);
}

/* City Cards */
.city-card {
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 5px 20px var(--shadow-light);
    transition: all 0.3s ease;
    cursor: pointer;
}

.city-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 40px var(--shadow-medium);
}

.city-card-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.city-card-content {
    padding: 1.5rem;
}

.city-name {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
}

.city-country {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.city-highlights {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.highlight-tag {
    background-color: var(--light-green);
    color: var(--text-dark);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.city-rating {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rating-stars {
    color: var(--accent-orange);
}

.rating-score {
    font-weight: bold;
    color: var(--text-dark);
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-dark);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.1);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 5px 15px var(--shadow-light);
}

.table th,
.table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background-color: var(--light-blue);
    font-weight: 600;
    color: var(--text-dark);
}

.table tbody tr:hover {
    background-color: var(--warm-gray);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 15px;
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
    position: relative;
    animation: modalSlideIn 0.3s ease;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-light);
    z-index: 1;
}

.modal-close:hover {
    color: var(--text-dark);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Footer */
footer {
    background-color: var(--text-dark);
    color: white;
    padding: 3rem 0 1rem;
    margin-top: 4rem;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-section h3 {
    color: white;
    margin-bottom: 1rem;
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: 0.5rem;
}

.footer-section a {
    color: #ccc;
    transition: color 0.3s ease;
}

.footer-section a:hover {
    color: white;
}

.footer-bottom {
    border-top: 1px solid #555;
    padding-top: 1rem;
    text-align: center;
    color: #ccc;
}

/* Utility Classes */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.mb-5 { margin-bottom: 3rem; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mt-5 { margin-top: 3rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }
.p-5 { padding: 3rem; }

.hidden { display: none; }
.show { display: block; }

/* Responsive Design */
@media (max-width: 1199px) {
    .container {
        padding: 0 15px;
    }
    
    .grid-4 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    h1 { font-size: 2.2rem; }
    h2 { font-size: 1.8rem; }
}

@media (max-width: 991px) {
    .grid-4,
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .nav-links {
        gap: 1rem;
    }
    
    h1 { font-size: 2rem; }
    h2 { font-size: 1.6rem; }
}

@media (max-width: 767px) {
    .hamburger {
        display: flex;
    }
    
    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background: white;
        flex-direction: column;
        padding: 1rem;
        box-shadow: 0 5px 15px var(--shadow-light);
        z-index: 1000;
    }
    
    .nav-links.active {
        display: flex;
    }
    
    .nav-links li {
        margin: 0.5rem 0;
    }
    
    .nav-links a {
        padding: 0.75rem 1rem;
        border-radius: 5px;
        transition: background-color 0.3s ease;
    }
    
    .nav-links a:hover {
        background-color: var(--light-blue);
    }
    
    .grid-4,
    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr;
    }
    
    .container {
        padding: 0 10px;
    }
    
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.4rem; }
    h3 { font-size: 1.2rem; }
    
    .footer-content {
        grid-template-columns: 1fr;
        text-align: center;
    }
    
    .city-card-image {
        height: 150px;
    }
    
    .modal-content {
        margin: 1rem;
        max-width: calc(100% - 2rem);
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Touch-friendly button sizes */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1.5rem;
    }
    
    /* Improved mobile navigation */
    .hamburger {
        cursor: pointer;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    .hamburger span {
        transition: all 0.3s ease;
    }
    
    .hamburger.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    
    .hamburger.active span:nth-child(2) {
        opacity: 0;
    }
    
    .hamburger.active span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -6px);
    }
}

@media (max-width: 480px) {
    h1 { font-size: 1.6rem; }
    h2 { font-size: 1.3rem; }
    
    /* 隐藏地图图例和搜索卡片在手机端 */
    .map-legend, .search-card {
        display: none;
    }
    
    /* city-profiles.html 手机端优化 */
    /* 隐藏筛选控件相关的类 */
    .city-profiles .search-filter-section,
    .city-profiles .selection-header,
    .city-profiles .filter-controls,
    .city-profiles .filter-results {
        display: none;
    }
    /* 城市卡片两列布局 */
    .city-profiles .city-grid.grid-3 {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    /* 优化Compare按钮样式，防止文字溢出 */
    .btn-outline {
        padding: 0.4rem 0.8rem;
        font-size: 0.75rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 120px;
    }

    .btn {
        padding: 0.8rem 1.2rem;
        font-size: 0.9rem;
        min-height: 48px;
    }
    
    /* 手机端卡片两列布局 */
    .cities-grid.grid-3 {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    /* 调整卡片内图片大小 */
    .city-card-image {
        height: 120px;
    }
    
    /* 调整卡片内容大小 */
    .city-card-content {
        padding: 0.8rem;
    }
    
    .city-name {
        font-size: 1rem;
        margin-bottom: 0.3rem;
    }
    
    .city-country {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }
    
    .highlight-tag {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
    
    .city-budget {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }
    
    .btn-small {
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* 城市卡片按钮容器优化 */
    .city-actions {
        gap: 0.3rem;
        flex-wrap: wrap;
    }
    
    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.9rem;
    }
    
    /* Improved small screen navigation */
    .nav-container {
        padding: 0 10px;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    /* Better touch targets for small screens */
    .card {
        margin-bottom: 1rem;
    }
    
    .form-control {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Optimized hero section for small screens */
    .hero {
        padding: 2rem 0;
    }
    
    .hero-content h1 {
        font-size: 1.8rem;
        line-height: 1.2;
    }
    
    .hero-subtitle {
        font-size: 1rem;
        line-height: 1.5;
    }
    
    /* Stacked buttons on small screens */
    .hero-buttons {
        flex-direction: column;
        gap: 1rem;
        align-items: center;
    }
    
    .hero-buttons .btn {
        width: 100%;
        max-width: 280px;
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--primary-blue);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus Styles */
*:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

button:focus,
.btn:focus {
    outline: 2px solid var(--accent-orange);
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    header,
    nav,
    footer,
    .btn,
    .modal {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }
}

/* Additional Responsive Enhancements */
@media (max-width: 320px) {
    .container {
        padding: 0 5px;
    }
    
    h1 { font-size: 1.4rem; }
    h2 { font-size: 1.2rem; }
    h3 { font-size: 1.1rem; }
    
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }
    
    .card {
        padding: 1rem;
    }
}

/* Tablet-specific optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
    .grid-4 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .nav-links {
        gap: 0.75rem;
    }
    
    .nav-links a {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .city-card-image {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Dark mode support for reduced eye strain */
@media (prefers-color-scheme: dark) {
    :root {
        --text-dark: #f0f0f0;
        --text-light: #b0b0b0;
        --bg-light: #1a1a1a;
        --light-gray: #2a2a2a;
        --border-light: #3a3a3a;
        --white: #1a1a1a;
        --shadow-light: rgba(0, 0, 0, 0.3);
    }
    
    .nav-links {
        background: #2a2a2a;
    }
    
    .card {
        background: #2a2a2a;
        border-color: #3a3a3a;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn:hover,
    .card:hover,
    .city-card:hover {
        transform: none;
    }
    
    .btn:active,
    .card:active,
    .city-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    /* Increase touch targets */
    .nav-links a {
        padding: 1rem;
        min-height: 48px;
        display: flex;
        align-items: center;
    }
    
    .city-card {
        margin-bottom: 1rem;
    }
    
    /* Better spacing for touch */
    .form-group {
        margin-bottom: 1.5rem;
    }
    
    .filter-group {
        margin-bottom: 1rem;
    }
}