/* ===================================
   CSS Variables & Theme System
   =================================== */
:root {
    /* Color Palette - Dark Modern Theme */
    --primary-color: #e94560;
    --primary-hover: #ff6b6b;
    --secondary-color: #0f3460;
    --accent-color: #16213e;

    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-card: rgba(22, 33, 62, 0.8);

    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #6b7280;

    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);

    /* Layout & Spacing */
    --max-width: 1200px;
    --border-radius: 20px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme Variables */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    --border-color: #334155;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

.app-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(20px);
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
}

.header-content {
    max-width: var(--max-width);
    margin: 0 auto;
    text-align: center;
}

.app-title {
    font-size: 3rem;
    font-weight: 800;
    margin: 0 0 0.5rem 0;
    background: linear-gradient(135deg, #e94560 0%, #ff6b6b 50%, #feca57 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.app-subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 400;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
    box-sizing: border-box;
}

/* Search Section */
.search-section {
    margin-bottom: 2rem;
}

.search-container {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.input-group {
    display: flex;
    gap: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.search-input {
    flex: 1;
    padding: 1rem 1.5rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    background: rgba(15, 52, 96, 0.5);
    color: var(--text-primary);
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(233, 69, 96, 0.2);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.search-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(233, 69, 96, 0.6);
}

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

/* Results Section */
.results-section {
    margin-bottom: 2rem;
}

.weather-card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    min-height: 200px;
    border: 1px solid var(--border-color);
}

/* Favorites Section */
.favorites-section {
    margin-bottom: 2rem;
}

.favorites-container {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.section-title {
    font-size: 1.8rem;
    margin: 0 0 1.5rem 0;
    color: var(--text-primary);
    font-weight: 700;
}

.favorites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
}

.favorite-item {
    background: rgba(15, 52, 96, 0.5);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem 1rem;
    position: relative;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.favorite-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.favorite-item-image {
    width: 100%;
    max-width: 250px;
    height: 150px;
    object-fit: cover;
    object-position: center;
    border-radius: 12px;
    margin-bottom: 1rem;
    background: rgba(15, 52, 96, 0.3);
}

.favorite-item-info {
    width: 100%;
    text-align: center;
}

.favorite-item-info h3 {
    font-size: 1.1rem;
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
}

.favorite-item-info p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0.25rem 0;
}

.favorite-item-type {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--primary-color);
    color: white;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.remove-favorite-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: rgba(233, 69, 96, 0.9);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.remove-favorite-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

.empty-favorites {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem;
    font-size: 1.1rem;
}

/* Chart Section */
.chart-section {
    margin-bottom: 2rem;
}

.chart-container {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    border: 1px solid var(--border-color);
}

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

.chart-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.chart-type-select {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: rgba(15, 52, 96, 0.5);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.chart-type-select:hover {
    border-color: var(--primary-color);
}

.chart-type-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(233, 69, 96, 0.2);
}

.chart-title {
    font-size: 1.5rem;
    margin: 0;
    color: var(--text-primary);
}

.clear-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}

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

.chart-wrapper {
    position: relative;
    height: 400px;
}

/* Footer */
.app-footer {
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(20px);
    padding: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

#categories {
    margin-top: 1rem;
    margin-bottom: 1rem;
}

#categories button {
    padding: 0.6rem 1rem;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
}

#categories input {
    padding: 0.6rem 1rem;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.app-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem;
}

/* ===================================
   Header
   =================================== */
.header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    padding: 2.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    animation: slideDown 0.5s ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.header-content {
    flex: 1;
}

.app-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

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

.header-controls {
    display: flex;
    gap: 1rem;
}

/* ===================================
   API Selection Panel
   =================================== */
.api-selection {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    animation: fadeIn 0.5s ease-out 0.1s both;
}

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

.api-selection h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.api-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.api-option {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    padding: 1.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.api-option:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.api-option.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-color: var(--primary-color);
}

.api-icon {
    font-size: 2rem;
}

.api-name {
    font-weight: 600;
    font-size: 0.9rem;
}

/* ===================================
   Controls Panel
   =================================== */
.controls-panel {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    animation: fadeIn 0.5s ease-out 0.2s both;
}

.search-section {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.filter-section {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.filter-select {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

.filter-select:hover {
    border-color: var(--primary-color);
}

.view-toggle {
    display: flex;
    gap: 0.5rem;
}

.view-btn {
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1.2rem;
    transition: var(--transition);
}

.view-btn:hover {
    background: var(--bg-tertiary);
}

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

/* ===================================
   Main Content - Dual Panel Layout
   =================================== */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.api-panel {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    min-height: 600px;
    animation: fadeIn 0.5s ease-out 0.3s both;
}

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

.panel-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.item-count {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

/* ===================================
   Loading & Error States
   =================================== */
.loading-state, .error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
}

.loading-state.hidden, .error-state.hidden {
    display: none;
}

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

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

.error-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.error-message {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* ===================================
   Data Grid
   =================================== */
.data-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.data-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    cursor: pointer;
    position: relative;
    animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.data-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-xl);
}

.card-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 1rem;
}

.card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.favorite-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    position: absolute;
    top: 1rem;
    right: 1rem;
}

.favorite-btn:hover {
    transform: scale(1.2);
}

.favorite-btn.active {
    filter: drop-shadow(0 0 5px gold);
}

/* ===================================
   Pagination
   =================================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding-top: 1rem;
}

.pagination.hidden {
    display: none;
}

.page-info {
    font-weight: 600;
    color: var(--text-secondary);
}

/* ===================================
   Buttons
   =================================== */
.btn-primary, .btn-secondary, .btn-icon, .btn-page, .btn-retry, .btn-clear {
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-size: 0.95rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

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

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    font-size: 1.2rem;
    width: 45px;
    height: 45px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
}

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

.btn-retry, .btn-clear {
    background: var(--accent-color);
    color: white;
}

.btn-retry:hover, .btn-clear:hover {
    background: #db2777;
}

/* ===================================
   Favorites Sidebar
   =================================== */
.favorites-sidebar {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    margin-bottom: 2rem;
    animation: fadeIn 0.5s ease-out 0.4s both;
}

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

.sidebar-header h3 {
    font-size: 1.3rem;
}

.favorites-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.favorite-item {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--border-radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.favorite-item:hover {
    background: var(--bg-tertiary);
}

/* ===================================
   Detail Modal
   =================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--bg-secondary);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--accent-color);
    color: white;
}

/* ===================================
   Statistics Footer
   =================================== */
.stats-footer {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 2rem;
    animation: fadeIn 0.5s ease-out 0.5s both;
}

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

.stat-value {
    display: block;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===================================
   Responsive Design
   =================================== */
@media (max-width: 768px) {
    .app-title {
        font-size: 1.8rem;
    }

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

    .main-content {
        padding: 1rem;
    }

    .input-group {
        flex-direction: column;
    }

    .search-btn {
        width: 100%;
        justify-content: center;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .chart-wrapper {
        height: 300px;
    }

    .app-header {
        padding: 1.5rem;
    }

    .search-container,
    .chart-container,
    .weather-card {
        padding: 1.5rem;
    }
}

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

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

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
