/* ===== CSS Variables (Design System) ===== */
:root {
    /* Colors - Organic Modern (CoffeeGo Style) */

    /* Base */
    --color-bg: rgb(240, 235, 230);
    /* Slightly lighter beige for freshness */
    --color-surface: #FFFFFF;

    /* Brand */
    --color-primary: #5D4037;
    /* Warm Brown */
    --color-primary-dark: #3E2723;
    --color-accent: #8D6E63;
    /* Soft Clay/Mocha */

    /* Text */
    --color-text-main: #2C2C2C;
    --color-text-muted: #6D6D6D;
    /* Softer grey */
    --color-text-light: #FFFFFF;

    /* Borders */
    --color-border: rgba(93, 64, 55, 0.1);
    --color-border-hover: rgba(93, 64, 55, 0.3);

    /* Spacing */
    --spacing-xs: 8px;
    --spacing-sm: 16px;
    --spacing-md: 24px;
    --spacing-lg: 40px;

    /* Typography */
    --font-stack: 'Outfit', sans-serif;

    /* Effects - Organic Softness */
    --radius-sm: 12px;
    --radius-md: 24px;
    --radius-lg: 40px;
    /* Large friendly corners */
    --radius-pill: 100px;

    --shadow-card: 0 4px 20px rgba(93, 64, 55, 0.05);
    /* Very subtle float */
    --shadow-hover: 0 8px 30px rgba(93, 64, 55, 0.1);

    /* Transitions */
    --transition: cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s;
    /* Bouncy active feel */
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    font-family: var(--font-stack);
}

body {
    background-color: var(--color-bg);
    color: var(--color-text-main);
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== Typography ===== */
h1,
h2,
h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
    /* Tighter for modern feel */
    color: var(--color-primary);
}

/* ===== Header (Clean & Centered) ===== */
.app-header {
    padding: var(--spacing-lg) 0 var(--spacing-md);
    text-align: center;
}

.logo-container {
    height: 140px;
    /* Big Brand Presence */
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.app-logo {
    height: 100%;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.05));
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.app-logo:hover {
    transform: scale(1.02) rotate(1deg);
}

/* ===== Container ===== */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

/* ===== Navigation (Floating Pill Toggle) ===== */
.tab-nav {
    display: flex;
    justify-content: center;
    background: var(--color-surface);
    width: fit-content;
    margin: 0 auto var(--spacing-lg);
    padding: 6px;
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-card);
    position: sticky;
    top: 20px;
    z-index: 100;
}

.tab-btn {
    padding: 12px 32px;
    border: none;
    background: transparent;
    font-family: var(--font-stack);
    font-weight: 600;
    font-size: 1rem;
    color: var(--color-text-muted);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-btn.active {
    background-color: var(--color-primary);
    color: var(--color-text-light);
    box-shadow: 0 4px 12px rgba(93, 64, 55, 0.2);
}

.tab-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5px;
}

/* ===== Main Content Area ===== */
.main-content {
    padding-bottom: 100px;
}

/* Visibility Logic */
.tab-content {
    display: none;
    animation: fadeScale 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tab-content.active {
    display: block;
}

@keyframes fadeScale {
    from {
        opacity: 0;
        transform: scale(0.98);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===== Identify Card (White Soft Card) ===== */
.identify-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-sm);
    /* Tight padding like the reference photo card */
    box-shadow: var(--shadow-card);
    max-width: 500px;
    margin: 0 auto;
    overflow: hidden;
}

.camera-container {
    background: #000;
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    aspect-ratio: 1;
    margin-bottom: var(--spacing-md);
}

#camera {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-frame {
    width: 70%;
    height: 70%;
    border: 3px solid rgba(255, 255, 255, 0.9);
    border-radius: var(--radius-md);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.3);
}

/* ===== Buttons: Friendly & Rounded ===== */
.button-group {
    display: flex;
    gap: var(--spacing-sm);
    padding: 0;
}

.btn {
    flex: 1;
    padding: 16px;
    border-radius: var(--radius-pill);
    /* Full pill shape */
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    border: none;
}

/* Primary: Dark Brown Fill */
.btn-primary {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 4px 15px rgba(93, 64, 55, 0.2);
}

.btn-primary:hover {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
}

/* Secondary: Outline */
.btn-secondary {
    background: transparent;
    border: 2px solid var(--color-border);
    color: var(--color-text-main);
}

.btn-secondary:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* ===== Browse Section ===== */

/* Search (White Pill) */
.search-bar {
    position: relative;
    margin-bottom: var(--spacing-lg);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

#searchInput {
    width: 100%;
    padding: 18px 24px 18px 56px;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--color-surface);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    /* Subtle indentation feel */
    font-size: 1rem;
    color: var(--color-text-main);
    transition: var(--transition);
}

#searchInput:focus {
    outline: none;
    box-shadow: 0 4px 20px rgba(93, 64, 55, 0.1);
}

.search-bar svg {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-accent);
}

/* Filters (Chips) */
.filter-bar {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: var(--spacing-lg);
}

.filter-chip {
    padding: 10px 20px;
    background: transparent;
    border: 1px solid var(--color-border-hover);
    border-radius: var(--radius-pill);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.filter-chip.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-card);
}

/* ===== Chocolate Grid (Organic Cards) ===== */
.chocolate-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    /* Larger cards */
    gap: 20px;
}

.chocolate-item {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    /* Big friendly corners */
    padding: 20px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.chocolate-item:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.chocolate-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    margin-bottom: 16px;
}

.chocolate-info {
    width: 100%;
}

.chocolate-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 6px;
    line-height: 1.3;
}

/* Tags as tiny pills */
.chocolate-tags {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.chocolate-tag {
    font-size: 0.7rem;
    padding: 4px 10px;
    background: var(--color-bg);
    border-radius: var(--radius-pill);
    color: var(--color-text-muted);
    font-weight: 600;
}

/* ===== Result & Loading ===== */
.result-card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    text-align: center;
    animation: fadeScale 0.4s ease;
}

.result-card h3 {
    font-size: 1.5rem;
    margin: 12px 0 6px;
}

.loading-state {
    padding: 40px;
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(93, 64, 55, 0.1);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    margin: 0 auto 16px;
}

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

/* ===== Modal ===== */
.modal {
    background: rgba(93, 64, 55, 0.4);
    backdrop-filter: blur(8px);
}

.modal-content {
    border-radius: var(--radius-lg);
    padding: 0;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-image {
    background: var(--color-bg);
    padding: 40px;
}

.modal-body {
    padding: 32px;
}

.modal-title {
    font-size: 2rem;
    margin-bottom: 16px;
}

.modal-attribute-tag {
    display: inline-block;
    padding: 8px 16px;
    background: var(--color-bg);
    border-radius: var(--radius-pill);
    margin: 0 8px 8px 0;
    font-weight: 600;
    color: var(--color-primary);
}

.modal-close {
    background: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    top: 20px;
    right: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    color: var(--color-text-main);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    padding-bottom: 4px;
    /* Optical center */
}

/* Desktop Polish */
@media (min-width: 768px) {

    /* ===== Result Alternatives ===== */
    .alternatives-section {
        margin-top: 24px;
        padding-top: 16px;
        border-top: 1px solid var(--color-border);
        text-align: left;
    }

    .alternatives-section h4 {
        font-size: 0.9rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--color-text-muted);
        margin-bottom: 12px;
    }

    .alternatives-list {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .alternative-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 8px;
        background: white;
        border-radius: var(--radius-sm);
        cursor: pointer;
        transition: var(--transition);
        border: 1px solid transparent;
    }

    .alternative-item:hover {
        border-color: var(--color-primary);
        transform: translateX(4px);
    }

    .alternative-item img {
        width: 40px;
        height: 40px;
        object-fit: contain;
    }

    .alternative-info {
        flex: 1;
    }

    .alternative-name {
        font-weight: 600;
        font-size: 0.95rem;
        color: var(--color-text-main);
    }

    .alternative-confidence {
        font-size: 0.8rem;
        color: var(--color-text-muted);
    }

    .result-badge {
        background: var(--color-accent);
        color: white;
        font-size: 0.75rem;
        font-weight: 600;
        padding: 4px 12px;
        border-radius: var(--radius-pill);
        display: inline-block;
        margin-bottom: 12px;
    }