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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
    color: white;
    padding: 2rem 1.5rem 1.5rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.app-header h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.app-header p {
    opacity: 0.9;
    font-size: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.5rem;
}

/* Search Container */
.search-container {
    margin-bottom: 2rem;
}

.search-box {
    display: flex;
    background: #f8f9fa;
    border-radius: 25px;
    padding: 0.5rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.search-box:focus-within {
    border-color: #4A90E2;
    box-shadow: 0 4px 15px rgba(74, 144, 226, 0.2);
}

#searchInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    outline: none;
    color: #333;
}

#searchInput::placeholder {
    color: #999;
}

#searchBtn {
    background: #4A90E2;
    border: none;
    border-radius: 20px;
    padding: 0.75rem;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-btn {
    background: transparent;
    border: none;
    color: #888;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    padding: 0.5rem;
    cursor: pointer;
    margin-right: 0.25rem;
}

.clear-btn:hover {
    background: rgba(0,0,0,0.05);
}

#searchBtn:hover {
    background: #357ABD;
    transform: scale(1.05);
}

#searchBtn:active {
    transform: scale(0.95);
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 2rem 1rem;
}

.welcome-message h2 {
    color: #4A90E2;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.welcome-message p {
    color: #666;
    margin-bottom: 2rem;
    font-size: 1rem;
}

/* Quick Categories */
.quick-categories {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 300px;
    margin: 0 auto;
}

.category-btn {
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 15px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.category-btn:hover {
    border-color: #4A90E2;
    background: #f8f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
}

/* Results */
.results-container {
    min-height: 200px;
}

.food-item {
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    border-left: 4px solid #4A90E2;
    animation: slideIn 0.3s ease;
}

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

.food-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #333;
}

.food-status {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.status-safe {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status-unsafe {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status-moderate {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.status-unknown {
    background: #e2e3e5;
    color: #6c757d;
    border: 1px solid #d6d8db;
}

.food-description {
    color: #666;
    line-height: 1.5;
    font-size: 0.95rem;
}

.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.no-results h3 {
    margin-bottom: 1rem;
    color: #4A90E2;
}

.no-results p {
    margin-bottom: 1.5rem;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.suggestion-tag {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 15px;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
}

.suggestion-tag:hover {
    background: #4A90E2;
    color: white;
    border-color: #4A90E2;
}

/* Back Bar */
.back-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0 0 1rem 0;
    padding: 0.5rem 0.25rem;
    background: #ffffff;
    border-bottom: 1px solid #e9ecef;
}

.back-btn {
    background: #f1f3f5;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 0.4rem 0.9rem;
    cursor: pointer;
}

.back-btn:hover {
    background: #e9ecef;
}

.back-title {
    font-weight: 600;
    color: #4A90E2;
}

/* Footer */
.app-footer {
    background: #f8f9fa;
    padding: 1rem;
    text-align: center;
    color: #666;
    font-size: 0.85rem;
    border-top: 1px solid #e9ecef;
}

/* Loading State */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

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

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

/* Responsive Design */
@media (max-width: 480px) {
    .app-container {
        margin: 0;
        box-shadow: none;
    }
    
    .app-header {
        padding: 1.5rem 1rem 1rem;
    }
    
    .app-header h1 {
        font-size: 1.5rem;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .quick-categories {
        max-width: 100%;
    }
    
    .category-btn {
        font-size: 0.85rem;
        padding: 0.6rem 0.8rem;
    }
}

/* PWA Install Button */
.pwa-install-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    backdrop-filter: blur(10px);
}

.pwa-install-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.pwa-install-btn:active {
    transform: translateY(0);
}

.pwa-install-btn svg {
    width: 18px;
    height: 18px;
}

/* iOS Install Instructions */
.ios-install-instructions {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.ios-install-content {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: slideInUp 0.3s ease;
}

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

.ios-install-content h3 {
    color: #4A90E2;
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.ios-install-content p {
    color: #666;
    margin-bottom: 1.5rem;
}

.ios-install-content ol {
    text-align: left;
    color: #333;
    margin-bottom: 2rem;
    padding-left: 1.5rem;
}

.ios-install-content li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.share-icon {
    background: #4A90E2;
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
}

.ios-install-close {
    background: #4A90E2;
    color: white;
    border: none;
    border-radius: 25px;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ios-install-close:hover {
    background: #357ABD;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(74, 144, 226, 0.3);
}

/* Manual Install Instructions */
.manual-install-instructions {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: rgba(74, 144, 226, 0.95);
    border-radius: 15px;
    padding: 1.5rem;
    color: white;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    animation: slideInUp 0.3s ease;
    backdrop-filter: blur(10px);
}

.manual-install-content h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
}

.manual-install-content p {
    margin: 0 0 1rem 0;
    opacity: 0.9;
    font-size: 0.9rem;
}

.install-steps {
    margin-bottom: 1rem;
}

.step {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.4;
}

.step:last-child {
    margin-bottom: 0;
}

.manual-install-close {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}

.manual-install-close:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    }
    
    .app-container {
        background: #1a1a1a;
        color: #e0e0e0;
    }
    
    .search-box {
        background: #2d2d2d;
        border-color: #444;
    }
    .clear-btn { color: #bbb; }
    .clear-btn:hover { background: rgba(255,255,255,0.06); }
    
    #searchInput {
        color: #e0e0e0;
    }
    
    #searchInput::placeholder {
        color: #888;
    }
    
    .food-item {
        background: #2d2d2d;
        border-left-color: #4A90E2;
    }
    
    .food-name {
        color: #e0e0e0;
    }
    
    .food-description {
        color: #b0b0b0;
    }
    
    .app-footer {
        background: #1a1a1a;
        border-top-color: #444;
        color: #b0b0b0;
    }
    
    .ios-install-content {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    .ios-install-content h3 {
        color: #4A90E2;
    }
    
    .ios-install-content p {
        color: #b0b0b0;
    }
    
    .ios-install-content ol {
        color: #e0e0e0;
    }
}

/* Browse Tables and Guidelines */
.cards { display: grid; gap: 1rem; }
.card {
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e9ecef;
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
    overflow: hidden;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1rem;
    background: linear-gradient(180deg, #f9fbff 0%, #f6f8ff 100%);
    border-bottom: 1px solid #eef1f6;
}
.card-title { margin: 0; font-size: 1.05rem; color: #2c3e50; }
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid transparent;
}
.chip-eat { background: #e7f7ed; color: #0f6a35; border-color: #cfeedd; }
.chip-avoid { background: #fde8ea; color: #9b1c1f; border-color: #f7cfd3; }
.chip-limit { background: #fff3d6; color: #8a5a00; border-color: #ffe4a3; }
.card-body { padding: 0.9rem 1rem; }
.three-col { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
.col-block { background: #f9fafb; border: 1px solid #edf0f2; border-radius: 10px; padding: 0.75rem; }
.block-title { font-weight: 700; color: #4A90E2; margin-bottom: 0.4rem; }
.block-list { margin: 0; padding-left: 1.2rem; }
.card-summary { color: #555; margin: 0 0 0.5rem 0; }

/* No horizontal columns in cards; keep vertical stacking on all sizes */

/* Dark mode for new sections */
@media (prefers-color-scheme: dark) {
    .card { background: #242628; border-color: #3a3d40; box-shadow: 0 6px 20px rgba(0,0,0,0.35); }
    .card-header { background: linear-gradient(180deg, #2b2e33 0%, #272a2e 100%); border-bottom-color: #3a3d40; }
    .card-title { color: #e8e8e8; }
    .col-block { background: #2a2d31; border-color: #3a3d40; }
    .block-title { color: #8ab4ff; }
    .block-list { color: #eaeaea; }
    .card-summary { color: #cfcfcf; }
    .chip-eat { background: #163c29; color: #a6f3c6; border-color: #23543b; }
    .chip-avoid { background: #3a1a1b; color: #ffb3b8; border-color: #5a292b; }
    .chip-limit { background: #3a2d12; color: #ffdca3; border-color: #5a431c; }
    .back-btn {
        background: #2a2a2a;
        border-color: #444;
        color: #e0e0e0;
    }
    .back-btn:hover { background: #333; }
    .back-title { color: #8ab4ff; }
    .back-bar { background: #1a1a1a; border-bottom-color: #333; }
}

/* Fallback dark styles for sections without class names */
@media (prefers-color-scheme: dark) {
    #resultsContainer section {
        background: #2d2d2d;
        color: #e8e8e8;
        border: 1px solid #444;
        border-radius: 12px;
        padding: 1rem;
        margin-bottom: 1rem;
    }
    #resultsContainer section h3 { color: #ffffff; }
    #resultsContainer section p { color: #dddddd; }
    #resultsContainer section ul,
    #resultsContainer section li { color: #ececec; }
    #resultsContainer section .subheading { color: #8ab4ff; }
}

/* Browse Tables and Guidelines */
.browse-sections h2,
.guidelines h2 {
    color: #4A90E2;
    margin-bottom: 1rem;
    text-align: center;
}

.section {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.section-title {
    margin: 0 0 0.5rem 0;
    color: #333;
}

.section-summary {
    color: #666;
    margin-bottom: 0.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.col {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 0.75rem;
}

.col-heading {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #4A90E2;
}

.col-list {
    margin: 0;
    padding-left: 1.2rem;
}

.subheading {
    font-weight: 600;
    color: #4A90E2;
    margin-top: 0.5rem;
    margin-bottom: 0.25rem;
}

.subtopic {
    margin-top: 0.5rem;
}

@media (max-width: 600px) {
    .grid-3 {
        grid-template-columns: 1fr;
    }
}
