:root {
    --bg-color: #0c0f1a;
    --card-bg: rgba(20, 25, 40, 0.45);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-sec: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent-red: #f43f5e;
    --accent-green: #10b981;
    --border: rgba(255, 255, 255, 0.1);
    --border-hover: rgba(99, 102, 241, 0.4);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    --glass-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
}

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

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 1rem;
    position: relative;
    overflow-x: hidden;
}

/* Background animated orbs */
.bg-orbs {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(circle at center, #0B0E14 0%, #05050A 100%);
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 20s infinite ease-in-out alternate;
}

.orb-1 {
    width: 400px; height: 400px;
    background: rgba(99, 102, 241, 0.4); /* Indigo */
    top: -10%; left: -10%;
    animation-delay: 0s;
}

.orb-2 {
    width: 300px; height: 300px;
    background: rgba(236, 72, 153, 0.3); /* Pink */
    bottom: 10%; right: -5%;
    animation-delay: -5s;
}

.orb-3 {
    width: 500px; height: 500px;
    background: rgba(16, 185, 129, 0.2); /* Emerald */
    top: 40%; left: 40%;
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(50px, 30px) scale(1.1); }
    100% { transform: translate(-30px, 60px) scale(0.9); }
}

.app-container {
    width: 100%;
    max-width: 1280px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 2rem);
    margin: auto;
    z-index: 1;
}

.app-header {
    text-align: center;
    flex-shrink: 0;
    margin-bottom: 1.5rem;
}

.main-grid {
    display: grid;
    grid-template-columns: 500px 1fr;
    gap: 1.5rem;
    flex-grow: 1;
    min-height: 0; /* Important for flex children scrolling */
}

.left-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    padding-right: 0.5rem; /* For scrollbar */
}

/* Custom Scrollbar */
.left-panel::-webkit-scrollbar, .right-panel::-webkit-scrollbar {
    width: 6px;
}
.left-panel::-webkit-scrollbar-track, .right-panel::-webkit-scrollbar-track {
    background: transparent;
}
.left-panel::-webkit-scrollbar-thumb, .right-panel::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
}

.right-panel {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-radius: var(--radius-lg);
    background: rgba(0, 0, 0, 0.1);
    border: 1px dashed var(--border);
    padding: 1rem;
    position: relative;
}

/* Make right panel cards stretch to fill space if needed */
.right-panel .card {
    min-height: max-content;
    flex-grow: 1;
}

.header-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.header-logo h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.card {
    background-color: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-md), var(--glass-shadow);
    border: 1px solid var(--card-border);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box; /* Crucial for preventing horizontal cutoff */
    flex-shrink: 0;
}

.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
}

.hover-tilt {
    transform-style: preserve-3d;
    transform: perspective(1000px);
}

.card h2 {
    font-size: 1.15rem; /* Reduced font size */
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.emoji-icon {
    font-size: 1.1rem; /* Reduced emoji size */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.gradient-text {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Accordion Styles for Settings */
.settings-header {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid transparent;
    transition: all 0.3s ease;
}

.settings-header.collapsed {
    border-bottom-color: transparent;
    padding-bottom: 0;
}

.settings-header h2 {
    margin-bottom: 0;
}

.toggle-icon {
    font-size: 1.2rem;
    color: var(--text-sec);
    transition: transform 0.3s ease;
    display: inline-block;
}

.toggle-icon.collapsed {
    transform: rotate(-90deg);
}

.settings-content {
    max-height: 500px;
    opacity: 1;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out, margin-top 0.3s ease;
    margin-top: 1rem;
}

.settings-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    pointer-events: none;
}

.settings-desc {
    color: var(--text-sec);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

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

input[type="password"],
.form-select,
#user-notes {
    width: 100%;
    box-sizing: border-box; /* Prevent input overflow */
    padding: 0.6rem 0.8rem; /* Reduced padding */
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    font-family: inherit;
    font-size: 0.85rem; /* Reduced font size */
    transition: all 0.3s ease;
    background-color: rgba(0, 0, 0, 0.2);
    color: var(--text-main);
}

input[type="password"]:focus,
.form-select:focus,
#user-notes:focus {
    border-color: var(--primary);
    background-color: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

#user-notes {
    resize: vertical;
    min-height: 80px;
    box-sizing: border-box; /* Double ensure textarea sizing */
}

.form-select option {
    background-color: var(--bg-color);
    color: var(--text-main);
}

.btn {
    padding: 0.6rem 1.2rem; /* Reduced padding */
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.85rem; /* Reduced font size */
    cursor: pointer;
    border: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.025em;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary) 0%, #818cf8 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
    background: linear-gradient(135deg, var(--primary-hover) 0%, #6366f1 100%);
}

.secondary-btn {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border);
    width: 100%;
    margin-top: 1.5rem;
}

.secondary-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.status-msg {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-success { color: var(--accent-green); }
.status-error { color: var(--accent-red); }

.btn-block {
    width: 100%;
    box-sizing: border-box;
    padding: 0.8rem; /* Reduced padding */
    font-size: 0.95rem; /* Reduced font size */
    margin-top: 1.5rem; /* Ensure space above button */
}

.border-dashed {
    border: 2px dashed var(--border);
    background-color: rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
}

.border-dashed:hover, .border-dashed.drag-over {
    border-color: var(--primary);
    background-color: rgba(99, 102, 241, 0.05);
    transform: translateY(-2px);
}

.w-full {
    width: 100%;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.preview-grid img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.preview-grid img.selected-for-analysis {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
    transform: scale(1.05);
}

.image-preview-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 400px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: transparent;
}

#image-preview {
    display: none; /* Uses dynamic grid now */
}

.loading-overlay {
    background: rgba(12, 15, 26, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 3rem 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    margin-top: 1.5rem;
}

.loader-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.loader-circle {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    animation: grow 1s ease-in-out infinite both;
}

.circle-1 { animation-delay: -0.32s; background: #6366f1; }
.circle-2 { animation-delay: -0.16s; background: #a855f7; }
.circle-3 { animation-delay: 0s; background: #ec4899; }

@keyframes grow {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

.loading-text {
    color: var(--text-main);
    font-weight: 500;
    font-size: 1.1rem;
    letter-spacing: 0.05em;
    margin-bottom: 1.5rem;
    background: linear-gradient(90deg, #fff, #93c5fd, #fff);
    background-size: 200% auto;
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
    animation: shine 2s linear infinite;
}

.loading-progress-bar {
    width: 80%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.loading-progress {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #ec4899);
    width: 50%; /* Will animate */
    animation: loading-sweep 2s ease-in-out infinite alternate;
}

@keyframes loading-sweep {
    0% { width: 10%; transform: translateX(0); }
    100% { width: 40%; transform: translateX(200%); }
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.health-score-container {
    position: relative;
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.progress-ring {
    transform: rotate(-90deg) scale(0.75);
    transform-origin: center;
}

.progress-ring-circle {
    transition: stroke-dashoffset 1.5s ease-in-out;
    stroke-linecap: round;
    stroke-dasharray: 213; /* roughly 2 * pi * r (34) */
    stroke-dashoffset: 213; /* start empty */
}

.score-text {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#health-score-val {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
    background: linear-gradient(135deg, #4ade80 0%, #3b82f6 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.score-label {
    font-size: 0.65rem;
    color: var(--text-sec);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

.badge-tag {
    display: inline-block;
    padding: 0.4rem 1rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 2rem;
    border: 1px solid transparent;
    transition: all 0.3s ease;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.serving-size {
    color: var(--text-sec);
    font-size: 1rem;
    margin-top: 0.25rem;
}

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

.nutrition-item {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 1rem 0.5rem;
    text-align: center;
    border: 1px solid var(--border);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.nutrition-item:hover {
    transform: translateY(-5px) scale(1.02);
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(99, 102, 241, 0.05);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.cal-highlight {
    grid-column: span 2;
    background: linear-gradient(135deg, rgba(244, 63, 94, 0.1) 0%, rgba(225, 29, 72, 0.05) 100%);
    border-color: rgba(244, 63, 94, 0.2);
    position: relative;
    overflow: hidden;
}

.cal-highlight::after {
    content: '';
    position: absolute;
    top: 0; left: -100%; width: 50%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
    transform: skewX(-20deg);
    animation: sweep 4s infinite;
}

@keyframes sweep {
    0% { left: -100%; }
    20% { left: 200%; }
    100% { left: 200%; }
}

.nutrition-icon {
    font-size: 1.4rem;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.nutrition-val {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 0.25rem;
    letter-spacing: -0.02em;
}

.cal-highlight .nutrition-val {
    color: var(--accent-red);
    font-size: 1.8rem;
    text-shadow: 0 0 20px rgba(244, 63, 94, 0.4);
}

.nutrition-label {
    font-size: 0.9rem;
    color: var(--text-sec);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.user-context {
    text-align: left;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.user-context label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 0.75rem;
}

.explanation-box {
    margin-top: 1.5rem;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    text-align: left;
    position: relative;
    overflow: hidden;
}

.explanation-box::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at top right, rgba(99,102,241,0.05), transparent 60%);
    pointer-events: none;
}

.explanation-box h3 {
    font-size: 1.1rem;
    color: var(--text-main);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

#ai-explanation {
    color: #cbd5e1;
    font-size: 0.95rem;
    line-height: 1.7;
}

.mt-4 {
    margin-top: 1.5rem;
}

.hidden {
    display: none !important;
}

.app-footer {
    text-align: center;
    color: var(--text-sec);
    font-size: 0.8rem;
    margin-top: 1rem;
}

@media (min-width: 640px) {
    .nutrition-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .cal-highlight {
        grid-column: span 1;
    }
}

@media (max-width: 900px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
    .app-container {
        height: auto;
    }
    .left-panel, .right-panel {
        overflow-y: visible;
    }
    body {
        overflow-y: auto;
    }
}
