/* ===== CSS Variables & Reset ===== */
:root {
    /* Premium Blue-Indigo Theme */
    --primary: #4f46e5;
    /* Deep Indigo */
    --primary-dark: #4338ca;
    /* Darker Indigo */
    --primary-light: #6366f1;
    /* Lighter Indigo */
    --primary-glow: rgba(79, 70, 229, 0.15);
    /* Subtle glow */

    --success: #059669;
    /* Emerald 600 */
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #d97706;
    /* Amber 600 */
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #dc2626;
    /* Red 600 */

    /* Light Theme Backgrounds */
    --bg-dark: #f8fafc;
    /* Slate 50 (Page BG) */
    --bg-card: #ffffff;
    /* Pure White (Card BG) */
    --bg-card-light: #f1f5f9;
    /* Slate 100 (Secondary BG) */
    --bg-input: #ffffff;
    /* White Input */

    /* Text Colors */
    --text-primary: #1e293b;
    /* Slate 800 (Main Text) */
    --text-secondary: #475569;
    /* Slate 600 (Secondary Text) */
    --text-muted: #94a3b8;
    /* Slate 400 (Muted Text) */

    /* Borders & Shadows */
    --border: #e2e8f0;
    /* Slate 200 */
    --border-light: #f1f5f9;
    /* Slate 100 */

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Softer, more diffused shadows for light theme */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
    --shadow-glow: 0 0 20px var(--primary-glow);

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    /* Updated font stack suggestion */
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== App Container ===== */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at top right, rgba(99, 102, 241, 0.05) 0%, transparent 40%),
        radial-gradient(circle at bottom left, rgba(139, 92, 246, 0.05) 0%, transparent 40%),
        var(--bg-dark);
}

/* ===== Header ===== */
.header {
    padding: 1rem 1.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.8);
    /* Semi-transparent white */
    backdrop-filter: blur(12px);
    position: sticky;
    /* Sticky header for convenience */
    top: 0;
    z-index: 100;
    transition: padding 0.3s ease;
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.beta-badge {
    font-size: 0.7rem;
    background: var(--primary-glow);
    color: var(--primary);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-weight: 700;
    margin-top: -2px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--primary-glow);
    color: white;
    /* Ensure icon remains white */
}

.logo-icon svg {
    width: 28px;
    height: 28px;
    color: white;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.main-nav {
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
}

.main-nav ul {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    list-style: none;
    padding: 0;
    background: rgba(255, 255, 255, 0.5);
    padding: 0.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    display: inline-flex;
    /* Center the nav pill */
}

.main-nav a {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.main-nav a svg {
    width: 16px;
    height: 16px;
}

.main-nav li.active a {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.main-nav a:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.8);
    color: var(--primary);
}

.main-nav a.disabled {
    opacity: 0.5;
    cursor: default;
}

.hero-section {
    margin-top: 1rem;
}

.hero-section h2 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* ===== Input Section ===== */
.input-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    /* overflow: hidden; Removed to allow dropdown to show */
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    background: var(--bg-card-light);
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.card-header h2 svg {
    width: 22px;
    height: 22px;
    color: var(--primary-light);
}

.badge {
    background: var(--primary);
    color: white;
    padding: 0.35rem 0.85rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.input-wrapper {
    padding: 1.5rem;
}

#ingredientInput {
    width: 100%;
    min-height: 150px;
    max-height: 300px;
    padding: 1.25rem;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.7;
    resize: vertical;
    transition: var(--transition);
}

/* Collapsed State Styles */
.input-section.collapsed .input-wrapper {
    display: none;
}

.input-section.collapsed .card-header {
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border-bottom: none;
}

.header-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    animation: fadeIn 0.3s ease;
}

.summary-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.summary-title {
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-glow);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.hidden {
    display: none !important;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* Metadata Inputs */
.metadata-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

.metadata-input {
    width: 100%;
    padding: 0.8rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

.metadata-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.brand-input-wrapper {
    position: relative;
    position: relative;
    width: 100%;
}

.dropdown-toggle-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: var(--transition);
    z-index: 10;
    /* Ensure it stays on top of input */
}

.dropdown-toggle-btn:hover {
    background: var(--bg);
    color: var(--primary);
}

.dropdown-toggle-btn svg {
    width: 16px;
    height: 16px;
}

.brand-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-height: 220px;
    /* Approx 6 items */
    overflow-y: auto;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    margin-top: 4px;
}

.brand-dropdown.hidden {
    display: none;
}

.brand-option {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: background 0.2s;
}

.brand-option:last-child {
    border-bottom: none;
}

.brand-option:hover {
    background: var(--bg-card-light);
    color: var(--primary);
}

.brand-option .highlight {
    color: var(--primary);
    font-weight: 700;
}

/* Actions Layout */
.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
}

.action-group-left,
.action-group-right {
    display: flex;
    gap: 0.75rem;
}

/* History Section */
.history-section {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    margin-top: 2rem;
    overflow: hidden;
    animation: slideDown 0.3s ease;
}

.history-section.hidden {
    display: none;
}

.history-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card-light);
}

.history-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem;
}

.history-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    cursor: pointer;
    transition: var(--transition);
    border-radius: var(--radius-md);
}

.history-item:hover {
    background: var(--bg-card-light);
}

.history-meta h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.history-meta p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.history-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
}

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

/* Button Variants */
.btn-text {
    background: transparent;
    color: var(--text-muted);
    padding: 0.75rem 1rem;
}

.btn-text:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

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

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

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-success:hover:not(:disabled) {
    background: #047857;
    transform: translateY(-2px);
}

.btn-success:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    /* Center icon */
}

.btn-icon:hover {
    background: var(--bg-card-light);
    color: var(--text-primary);
}

.btn-icon svg {
    width: 20px;
    height: 20px;
}

#ingredientInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

#ingredientInput::placeholder {
    color: var(--text-muted);
}

.input-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: flex-end;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

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

.btn-secondary {
    background: var(--bg-card-light);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

/* ===== Results Section ===== */
.results-section {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: var(--bg-card-light);
    border-bottom: 1px solid var(--border);
}

.results-header h2 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.results-header h2 svg {
    width: 22px;
    height: 22px;
    color: var(--success);
}

.results-stats {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.stat-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
}

.stat.matched .stat-icon {
    background: var(--success-bg);
    color: var(--success);
}

.stat.unmatched .stat-icon {
    background: var(--warning-bg);
    color: var(--warning);
}

.results-container {
    padding: 1.5rem;
    /* Remove max-height to prevent double scrollbars since inner columns scroll independently */
    /* max-height: 600px; */
    /* overflow-y: auto; */
}

/* Custom Scrollbar */
.results-container::-webkit-scrollbar {
    width: 8px;
}

.results-container::-webkit-scrollbar-track {
    background: var(--bg-input);
    border-radius: 4px;
}

.results-container::-webkit-scrollbar-thumb {
    background: var(--bg-card-light);
    border-radius: 4px;
}

.results-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: var(--bg-card-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-icon svg {
    width: 40px;
    height: 40px;
    color: var(--text-muted);
}

/* ===== Ingredient Cards ===== */
.ingredients-grid {
    display: grid;
    gap: 0.75rem;
}

.ingredient-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1rem;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    transition: var(--transition);
}

.ingredient-card:hover {
    background: var(--bg-card-light);
    border-color: var(--border);
}

.ingredient-card.matched {
    border-left: 3px solid var(--success);
}

.ingredient-card.unmatched {
    border-left: 3px solid var(--warning);
}

.ingredient-number {
    width: 32px;
    height: 32px;
    background: var(--bg-card-light);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.ingredient-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.ingredient-name {
    font-weight: 500;
    color: var(--text-primary);
    word-break: break-word;
}

.ingredient-english {
    font-size: 0.85rem;
    color: var(--text-secondary);
    word-break: break-word;
}

.ingredient-status {
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.ingredient-card.matched .ingredient-status {
    background: var(--success-bg);
    color: var(--success);
}

.ingredient-card.unmatched .ingredient-status {
    background: var(--warning-bg);
    color: var(--warning);
}

/* ===== Trade Names Section ===== */
/* Old tradenames-section style removed */

.tradenames-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-light);
    margin-bottom: 1rem;
}

.tradenames-title svg {
    width: 22px;
    height: 22px;
    color: var(--primary-light);
}

.tradenames-grid {
    display: grid;
    gap: 0.75rem;
}

/* Trade Name Card Interactive Styles */
/* Softer card aesthetics */
.tradename-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    /* border-left: 3px solid var(--primary); Remove heavy left border */
    border-left: 2px solid rgba(79, 70, 229, 0.4);
    /* Much subtle accent */
    border-radius: var(--radius-md);
    padding: 1.25rem;
    transition: var(--transition);
}

.tradename-card.has-alternatives {
    cursor: pointer;
}

.tradename-card:hover {
    background: var(--bg-card);
    /* Keep white */
    border-color: var(--primary-light);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    /* Soft shadow on hover */
    transform: translateY(-2px);
}

.tradename-card.active {
    background: var(--bg-card-light);
    border-color: var(--primary);
}

.tradename-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.tradename-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tradename-title-row {
    display: flex;
    align-items: center;
}

.tradename-comp-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tradename-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.tradename-count {
    color: var(--success);
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.tradename-toggle-icon {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    transition: transform 0.3s ease;
    margin-top: 0.25rem;
    /* Align with text */
    flex-shrink: 0;
}

.tradename-card.active .tradename-toggle-icon {
    transform: rotate(180deg);
}

/* Composition section (now just for alternatives) */
.tradename-composition {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0;
    /* removed margin-top since header has padding bottom if needed, or we add margin-top when visible */
    border-top: 1px solid var(--border);
    margin-top: 1rem;
    padding-top: 1rem;
    animation: slideDown 0.3s ease;
}

/* Hide border/margin if empty (no alternatives) implies no .visible is toggled anyway */


.tradename-composition.visible {
    display: flex;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alt-label,
.comp-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.alt-list,
.comp-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Unified subtle chips */
.alt-item,
.comp-item {
    background: var(--bg-card-light);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
}

.alt-item:hover,
.comp-item.clickable:hover {
    background: white;
    border-color: var(--primary-light);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.comp-item.clickable {
    cursor: pointer;
    border-color: var(--primary-glow);
}

.comp-item.clickable:hover {
    background: var(--primary-glow);
    color: var(--primary-light);
    border-color: var(--primary);
    transform: translateY(-1px);
}

/* Highlight Animation */
@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
        border-color: var(--success);
        background: var(--success-bg);
    }

    50% {
        box-shadow: 0 0 20px 0 rgba(16, 185, 129, 0.4);
        border-color: var(--success);
        background: var(--success-bg);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.highlight-pulse {
    animation: pulseGlow 2s ease-out;
    /* Ensure it stays somewhat highlighted or just flashes? 
       Let's stick to the visual style of matched cards but stronger. */
    border-color: var(--success) !important;
    background: var(--success-bg) !important;
}

/* ===== Footer ===== */
.footer {
    padding: 1.5rem;
    text-align: center;
    border-top: 1px solid var(--border);
    background: rgba(26, 26, 46, 0.5);
}

.footer p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.footer strong {
    color: var(--text-secondary);
}

.separator {
    margin: 0 0.75rem;
    color: var(--border);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 26, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

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

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header {
        padding: 1.5rem 1rem;
    }

    .header h1 {
        font-size: 1.4rem;
    }

    .logo {
        gap: 0.75rem;
    }

    .logo-icon {
        width: 40px;
        height: 40px;
    }

    .main-content {
        padding: 1rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

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

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

    .btn {
        justify-content: center;
    }

    .ingredient-card {
        grid-template-columns: auto 1fr;
        gap: 0.75rem;
    }

    .ingredient-status {
        grid-column: 1 / -1;
        justify-self: start;
    }
}

/* ===== Analysis Layout (Side-by-Side) ===== */
.analysis-layout {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    /* Ingredients left (larger), Trade Names right (smaller) */
    gap: 1.5rem;
    align-items: start;
    height: 700px;
    /* Fixed height for the container */
}

/* Clean, borderless columns with elegant titles */
.analysis-column {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    height: 100%;
    overflow: hidden;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.5);
    /* Subtle column background */
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    /* Very subtle border */
}

.column-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ingredients-grid {
    display: grid;
    gap: 0.75rem;
    overflow-y: auto;
    /* Enable vertical scrolling */
    padding-right: 0.5rem;
    /* Space for scrollbar */
    height: 100%;
    /* Fill remaining space */
}

/* Custom Scrollbar for inner grids */
.ingredients-grid::-webkit-scrollbar,
.tradenames-grid::-webkit-scrollbar {
    width: 6px;
}

.ingredients-grid::-webkit-scrollbar-track,
.tradenames-grid::-webkit-scrollbar-track {
    background: var(--bg-input);
    border-radius: 4px;
}

.ingredients-grid::-webkit-scrollbar-thumb,
.tradenames-grid::-webkit-scrollbar-thumb {
    background: var(--bg-card-light);
    border-radius: 4px;
}

.ingredients-grid::-webkit-scrollbar-thumb:hover,
.tradenames-grid::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Ensure trade names section fits in the column - remove distinct background */
.tradenames-section {
    margin-bottom: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* No border or background here to match left side */
}

/* Hide internal title if we rely on column title, but let's keep it simple and just style the grid */
/* Restore title visibility */
.tradenames-title {
    display: flex;
    /* Restore flex display defined earlier */
}

.tradenames-grid {
    display: grid;
    gap: 1rem;
    /* More spacing for luxury feel */
    overflow-y: auto;
    padding-right: 0.5rem;
    flex: 1;
    min-height: 0;
    padding-bottom: 1rem;
}

.tradenames-empty {
    padding: 2rem;
    text-align: center;
    background: var(--bg-card-light);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border);
    color: var(--text-muted);
}

.tradenames-empty p {
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.tradenames-empty small {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* Responsive adjustments for Analysis Layout */
@media (max-width: 768px) {
    .analysis-layout {
        grid-template-columns: 1fr;
        /* Stack vertically on smaller screens */
        height: auto;
        /* Auto height for mobile */
    }

    .analysis-column {
        height: auto;
        max-height: 500px;
        /* Limit height on mobile too? */
    }

    .ingredients-grid,
    .tradenames-grid {
        height: auto;
        max-height: 500px;
    }
}

/* Additions for CosIng data */
.ingredient-header {
    margin-bottom: 0.5rem;
}

.ingredient-functions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}

.function-tag {
    font-size: 0.75rem;
    background: var(--primary-glow);
    color: var(--primary-dark);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}

.ingredient-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.2rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.meta-item.restriction {
    color: var(--danger);
    font-weight: 600;
    background: var(--warning-bg);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}