/* =====================================================
   CalTrack 2 — Cute Premium Dark Theme
   ===================================================== */

/* === CSS Variables === */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: rgba(30, 37, 48, 0.65);
    --bg-card-hover: rgba(40, 50, 65, 0.75);
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-pink: #ff9a9e;
    --accent-peach: #fad0c4;
    --accent-mint: #a8edea;
    --accent-lavender: #c3a6f0;
    --accent-coral: #ff6b6b;
    --gradient-primary: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
    --gradient-mint: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    --gradient-lavender: linear-gradient(135deg, #c3a6f0 0%, #f68084 100%);
    --gradient-danger: linear-gradient(135deg, #ff5757 0%, #ff8a8a 100%);
    --glass-blur: 16px;
    --glass-border: rgba(255, 255, 255, 0.08);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 50%;
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(255, 154, 158, 0.15);
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    --nav-height: 72px;
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Animated background blobs */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.12;
    z-index: -1;
    animation: float 20s ease-in-out infinite;
}

body::before {
    width: 400px;
    height: 400px;
    background: var(--accent-pink);
    top: -100px;
    right: -100px;
}

body::after {
    width: 350px;
    height: 350px;
    background: var(--accent-mint);
    bottom: 100px;
    left: -100px;
    animation-delay: -10s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -30px) scale(1.05); }
    66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* === App Layout === */
.app-wrapper {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    padding-bottom: calc(var(--nav-height) + 16px);
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
}

/* === Page Container === */
.page-container {
    padding: 20px 16px;
}

/* === Page Header === */
.page-header {
    text-align: center;
    margin-bottom: 24px;
    padding-top: 8px;
}

.page-header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.page-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
}

/* === Glass Card === */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-card);
    transition: transform var(--transition-smooth), box-shadow var(--transition-smooth);
}

.glass-card:hover {
    box-shadow: var(--shadow-card), var(--shadow-glow);
}

/* === Animate In === */
.animate-in {
    animation: slideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

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

/* === Progress Ring (Dashboard) === */
.progress-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 20px;
    margin-bottom: 24px;
}

.progress-ring-container {
    position: relative;
    width: 180px;
    height: 180px;
    margin-bottom: 12px;
}

.progress-ring {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 8px rgba(255, 154, 158, 0.3));
}

.progress-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.06);
    stroke-width: 10;
}

.progress-fill {
    fill: none;
    stroke-width: 10;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
}

.cal-number {
    font-size: 2.2rem;
    font-weight: 800;
    background: var(--gradient-mint);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
}

.cal-number.over {
    background: var(--gradient-danger);
    -webkit-background-clip: text;
    background-clip: text;
}

.cal-unit {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.over-badge,
.remaining-badge {
    font-size: 0.85rem;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: var(--radius-lg);
}

.over-badge {
    background: rgba(255, 87, 87, 0.15);
    color: var(--accent-coral);
}

.remaining-badge {
    background: rgba(168, 237, 234, 0.1);
    color: var(--accent-mint);
}

/* === Section Header === */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 0 4px;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.meal-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.06);
    padding: 4px 10px;
    border-radius: var(--radius-lg);
    font-weight: 600;
}

/* === Meal List === */
.meal-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.meal-item,
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    transition: transform var(--transition-fast);
}

.meal-item:active,
.history-item:active {
    transform: scale(0.98);
}

.meal-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.meal-thumb {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--glass-border);
}

.meal-thumb-placeholder {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.meal-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.meal-name {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.meal-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.meal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.meal-cal {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--accent-pink);
}

.meal-cal small {
    font-size: 0.7rem;
    font-weight: 600;
    opacity: 0.7;
}

/* === Delete Button === */
.btn-delete {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    border: none;
    background: rgba(255, 87, 87, 0.1);
    color: var(--accent-coral);
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-delete:hover {
    background: rgba(255, 87, 87, 0.25);
    transform: scale(1.1);
}

.btn-delete:active {
    transform: scale(0.9);
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-emoji {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
    animation: bounce 2s ease-in-out infinite;
}

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

.empty-state p {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 4px;
}

.empty-hint {
    color: var(--text-secondary);
    font-size: 0.85rem !important;
    font-weight: 600 !important;
}

/* === Upload Zone (Add Meal) === */
.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    margin-bottom: 20px;
    border: 2px dashed rgba(255, 154, 158, 0.3);
    position: relative;
    min-height: 220px;
    transition: border-color var(--transition-smooth);
}

.upload-zone:hover {
    border-color: rgba(255, 154, 158, 0.6);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    animation: bounce 2s ease-in-out infinite;
}

.upload-text {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 4px;
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.upload-input-label {
    position: absolute;
    inset: 0;
    cursor: pointer;
    z-index: 2;
}

.upload-input-label input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.upload-preview {
    width: 100%;
    max-height: 250px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.preview-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 600;
}

/* === Analyzing State === */
.analyzing-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.analyzing-text {
    font-weight: 700;
    font-size: 1rem;
}

.analyzing-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* === Cute Spinner === */
.spinner-cute {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 154, 158, 0.2);
    border-top-color: var(--accent-pink);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-small {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* === Result Card === */
.result-card {
    margin-bottom: 20px;
}

.result-preview {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

/* === Form === */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 600;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.form-input:focus {
    border-color: var(--accent-pink);
    box-shadow: 0 0 0 3px rgba(255, 154, 158, 0.15);
}

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

/* Remove number input arrows */
.form-input[type="number"]::-webkit-outer-spin-button,
.form-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-input[type="number"] {
    -moz-appearance: textfield;
}

/* === Buttons === */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 14px 24px;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: #1a1a2e;
    font-size: 1rem;
    font-weight: 800;
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    transition: all var(--transition-bounce);
    position: relative;
    z-index: 1;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 154, 158, 0.35);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

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

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 700;
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* === Divider === */
.divider-text {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 24px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}

.divider-text::before,
.divider-text::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--glass-border);
}

/* === Manual Entry === */
.manual-entry {
    margin-bottom: 20px;
}

/* === Error Card === */
.error-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    margin-bottom: 20px;
    border-color: rgba(255, 87, 87, 0.3);
}

.error-card span {
    font-size: 1.5rem;
}

.error-card p {
    font-size: 0.9rem;
    color: var(--accent-coral);
    font-weight: 600;
}

/* === History Page === */
.export-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.btn-export {
    flex: 1;
    padding: 12px 20px;
    background: var(--gradient-mint);
    border: none;
    border-radius: var(--radius-sm);
    color: #1a1a2e;
    font-size: 0.9rem;
    font-weight: 800;
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    transition: all var(--transition-bounce);
}

.btn-export:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(168, 237, 234, 0.3);
}

.btn-export:active {
    transform: scale(0.98);
}

.copied-badge {
    background: rgba(168, 237, 234, 0.15);
    color: var(--accent-mint);
    padding: 8px 14px;
    border-radius: var(--radius-lg);
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
}

.date-group {
    margin-bottom: 20px;
}

.date-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 4px;
    margin-bottom: 8px;
}

.date-label {
    font-weight: 700;
    font-size: 0.9rem;
}

.date-total {
    font-size: 0.8rem;
    color: var(--accent-pink);
    font-weight: 800;
    background: rgba(255, 154, 158, 0.1);
    padding: 4px 10px;
    border-radius: var(--radius-lg);
}

.date-group .glass-card {
    margin-bottom: 8px;
}

/* === Report Page === */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    text-align: center;
    padding: 20px 12px;
}

.stat-emoji {
    font-size: 1.8rem;
    display: block;
    margin-bottom: 8px;
}

.stat-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 700;
    margin-top: 4px;
    display: block;
}

.chart-card {
    margin-bottom: 20px;
    padding: 20px;
}

.chart-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.chart-container {
    height: 220px;
    position: relative;
}

/* === Daily Breakdown === */
.breakdown-card {
    padding: 20px;
}

.breakdown-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.breakdown-row:last-child {
    border-bottom: none;
}

.breakdown-date {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    width: 50px;
    flex-shrink: 0;
}

.breakdown-bar-container {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 4px;
    overflow: hidden;
}

.breakdown-bar {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.breakdown-bar.over {
    background: var(--gradient-danger);
}

.breakdown-value {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--accent-pink);
    width: 45px;
    text-align: right;
    flex-shrink: 0;
}

.breakdown-value.over {
    color: var(--accent-coral);
}

/* === Bottom Navigation === */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: rgba(13, 17, 23, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 1000;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--text-muted);
    transition: all var(--transition-fast);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.nav-item:hover {
    color: var(--text-secondary);
}

.nav-item.active {
    color: var(--accent-pink);
}

.nav-item.active .nav-icon {
    transform: scale(1.15);
}

.nav-icon {
    font-size: 1.4rem;
    transition: transform var(--transition-bounce);
    line-height: 1;
}

.nav-icon.add-btn {
    background: var(--gradient-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 15px rgba(255, 154, 158, 0.3);
    margin-top: -12px;
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* === Loading Screen === */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    gap: 16px;
}

.loading-mascot {
    font-size: 4rem;
    animation: bounce 1.5s ease-in-out infinite;
}

.loading-text {
    font-family: 'Nunito', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.loading-dots {
    display: flex;
    gap: 6px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-pink);
    animation: dotPulse 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* === Blazor Error UI === */
#blazor-error-ui {
    background: var(--accent-coral);
    color: white;
    padding: 12px;
    text-align: center;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    display: none;
    position: fixed;
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    z-index: 9999;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    margin-left: 12px;
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* === Media Queries === */
@media (min-width: 480px) {
    .main-content {
        padding: 0 16px;
    }
}

@media (prefers-color-scheme: light) {
    /* Keep dark mode always — this is a dark-mode-only app */
}

/* Safe area insets for iOS */
@supports (padding: max(0px)) {
    .bottom-nav {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .main-content {
        padding-bottom: calc(var(--nav-height) + max(16px, env(safe-area-inset-bottom)));
    }
}

/* === Stagger animation delay for lists === */
.meal-list .meal-item:nth-child(1) { animation-delay: 0s; }
.meal-list .meal-item:nth-child(2) { animation-delay: 0.05s; }
.meal-list .meal-item:nth-child(3) { animation-delay: 0.1s; }
.meal-list .meal-item:nth-child(4) { animation-delay: 0.15s; }
.meal-list .meal-item:nth-child(5) { animation-delay: 0.2s; }
.meal-list .meal-item:nth-child(6) { animation-delay: 0.25s; }
.meal-list .meal-item:nth-child(n+7) { animation-delay: 0.3s; }

.date-group:nth-child(2) { animation-delay: 0.05s; }
.date-group:nth-child(3) { animation-delay: 0.1s; }
.date-group:nth-child(4) { animation-delay: 0.15s; }
.date-group:nth-child(5) { animation-delay: 0.2s; }