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

:root {
    --green: #2D7F5E;
    --green-light: #3DA87A;
    --green-dark: #1B5E42;
    --green-glow: rgba(45,127,94,0.25);
    --bg: #FAFDFB;
    --card: #FFFFFF;
    --text: #1A2E25;
    --text2: #5A7D6B;
    --text3: #9BB5A8;
    --border: #E0EDE6;
    --danger: #E74C3C;
    --warning: #F39C12;
    --success: #27AE60;
    --r: 20px;
    --safe-top: env(safe-area-inset-top, 20px);
    --safe-bottom: env(safe-area-inset-bottom, 20px);
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ===== Screens ===== */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease;
    transform: translateX(30px);
    overflow: hidden;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    transform: translateX(0);
}

.screen.slide-out {
    opacity: 0;
    transform: translateX(-30px);
}

/* ===== HOME SCREEN ===== */
.home-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, #E8F5EF 0%, #F5FBF8 40%, #FAFDFB 100%);
    z-index: 0;
}

#homeScreen {
    padding: calc(var(--safe-top) + 16px) 24px calc(var(--safe-bottom) + 24px);
    overflow-y: auto;
}

#homeScreen > * { position: relative; z-index: 1; }

.home-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0 24px;
}

.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 1.6rem; }
.logo-text { font-family: 'Playfair Display', serif; font-size: 1.4rem; font-weight: 700; color: var(--text); }
.logo-ai { font-family: 'Inter', sans-serif; font-weight: 800; font-size: 0.85rem; color: var(--green); }

.home-hero { text-align: center; padding: 16px 0 32px; }

.home-plant-emoji {
    font-size: 5rem;
    margin-bottom: 16px;
    display: block;
    animation: floatPlant 4s ease-in-out infinite;
}

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

.home-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.9rem;
    line-height: 1.25;
    color: var(--text);
    margin-bottom: 12px;
}

.home-subtitle {
    font-size: 1rem;
    color: var(--text2);
    line-height: 1.6;
    max-width: 300px;
    margin: 0 auto;
}

.home-actions { display: flex; flex-direction: column; gap: 12px; margin-bottom: 28px; }

.btn-main-camera, .btn-main-upload {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    border-radius: 18px;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    width: 100%;
}

.btn-main-camera {
    background: linear-gradient(135deg, var(--green), var(--green-light));
    color: white;
    box-shadow: 0 6px 24px var(--green-glow);
}

.btn-main-upload {
    background: var(--card);
    color: var(--text);
    border: 1.5px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.btn-main-camera:active, .btn-main-upload:active { transform: scale(0.97); }

.btn-main-icon { font-size: 1.8rem; flex-shrink: 0; }
.btn-main-title { font-size: 1rem; font-weight: 700; margin-bottom: 2px; }
.btn-main-sub { font-size: 0.8rem; opacity: 0.7; }
.btn-main-arrow { margin-left: auto; font-size: 1.6rem; opacity: 0.5; line-height: 1; }

.home-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 20px;
    background: var(--card);
    border-radius: 18px;
    border: 1.5px solid var(--border);
}

.home-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.home-stat-n { font-size: 1.3rem; font-weight: 800; color: var(--green); }
.home-stat-l { font-size: 0.75rem; color: var(--text3); font-weight: 500; }
.home-stat-div { width: 1px; height: 32px; background: var(--border); }

/* ===== CAMERA SCREEN ===== */
#cameraScreen { background: #000; }

#cameraFeed {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-ui {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--safe-top) + 12px) 20px 12px;
}

.camera-back-btn {
    position: absolute;
    left: 20px;
    top: calc(var(--safe-top) + 12px);
    background: rgba(0,0,0,0.4);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    padding-right: 3px;
}

.camera-hint {
    background: rgba(0,0,0,0.4);
    color: white;
    padding: 6px 16px;
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 500;
    backdrop-filter: blur(10px);
}

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

.camera-frame-box { width: 72%; aspect-ratio: 1; position: relative; }

.corner { position: absolute; width: 28px; height: 28px; border-color: white; border-style: solid; opacity: 0.85; }
.corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

.camera-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 20px 40px calc(var(--safe-bottom) + 24px);
    background: linear-gradient(transparent, rgba(0,0,0,0.5));
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.camera-tip { color: rgba(255,255,255,0.8); font-size: 0.8rem; max-width: 100px; line-height: 1.4; }

.shutter-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid white;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease;
    flex-shrink: 0;
}

.shutter-btn:active { transform: scale(0.92); }
.shutter-inner { width: 56px; height: 56px; border-radius: 50%; background: white; }
.shutter-btn:active .shutter-inner { background: #ccc; }

/* ===== PREVIEW SCREEN ===== */
#previewScreen { background: #000; }

#previewImg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-top {
    position: relative;
    z-index: 10;
    padding: calc(var(--safe-top) + 12px) 20px 12px;
}

.preview-back {
    background: rgba(0,0,0,0.45);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 100px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.preview-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 24px 24px calc(var(--safe-bottom) + 24px);
    background: linear-gradient(transparent, rgba(0,0,0,0.65));
    text-align: center;
}

.preview-hint { color: rgba(255,255,255,0.85); font-size: 0.95rem; margin-bottom: 14px; }

.btn-analyze-main {
    width: 100%;
    padding: 17px;
    background: linear-gradient(135deg, var(--green), var(--green-light));
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 20px var(--green-glow);
    transition: transform 0.15s ease;
}

.btn-analyze-main:active { transform: scale(0.97); }

/* ===== LOADING SCREEN ===== */
#loadingScreen { align-items: center; justify-content: center; }

.loading-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, #E8F5EF, #FAFDFB);
}

.loading-content { position: relative; z-index: 1; text-align: center; padding: 40px 32px; }

.loading-plant-wrap {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 32px;
}

.loading-ring-outer {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--green);
    animation: spin 1s linear infinite;
}

.loading-ring-inner {
    position: absolute;
    inset: 12px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-bottom-color: var(--green-light);
    animation: spin 1.5s linear infinite reverse;
}

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

.loading-plant-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.loading-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 24px; color: var(--text); }

.loading-steps-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 260px;
    margin: 0 auto;
}

.lstep { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; color: var(--text3); transition: color 0.3s; }
.lstep.active { color: var(--green); font-weight: 600; }
.lstep.done { color: var(--success); }

.lstep-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.3s, box-shadow 0.3s;
}

.lstep.active .lstep-dot { background: var(--green); box-shadow: 0 0 8px var(--green-glow); animation: pulse 1s infinite; }
.lstep.done .lstep-dot { background: var(--success); }

/* ===== RESULTS SCREEN ===== */
#resultsScreen { overflow-y: auto; }

.result-hero { position: relative; height: 260px; flex-shrink: 0; }
#resultHeroImg { width: 100%; height: 100%; object-fit: cover; }

.result-hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.6) 100%);
}

.result-back-btn {
    position: absolute;
    top: calc(var(--safe-top) + 12px);
    left: 16px;
    background: rgba(0,0,0,0.4);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    padding-right: 3px;
}

.result-hero-info { position: absolute; bottom: 16px; left: 20px; right: 20px; }
.r-plant-name { font-family: 'Playfair Display', serif; font-size: 1.7rem; color: white; text-shadow: 0 2px 8px rgba(0,0,0,0.3); margin-bottom: 4px; }
.r-scientific { font-style: italic; color: rgba(255,255,255,0.8); font-size: 0.9rem; }

.score-badge-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.score-badge {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--green), var(--green-light));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 12px var(--green-glow);
}

.score-badge.danger { background: linear-gradient(135deg, #E74C3C, #C0392B); box-shadow: 0 4px 12px rgba(231,76,60,0.3); }
.score-badge.warning { background: linear-gradient(135deg, #F39C12, #E67E22); box-shadow: 0 4px 12px rgba(243,156,18,0.3); }

.score-badge-num { font-size: 1.3rem; font-weight: 800; line-height: 1; }
.score-badge-label { font-size: 0.6rem; font-weight: 600; opacity: 0.9; text-transform: uppercase; letter-spacing: 0.05em; }
.score-status { font-size: 1rem; font-weight: 700; color: var(--text); }

.results-scroll { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }

.res-section { background: var(--card); border-radius: var(--r); padding: 16px; margin-bottom: 12px; border: 1px solid var(--border); }
.res-section-title { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 12px; }

.diag-item {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    margin-bottom: 8px;
    background: #F8FBF9;
}

.diag-item:last-child { margin-bottom: 0; }
.diag-item.sev-critique, .diag-item.sev-eleve { background: #FFF5F5; border-left: 3px solid var(--danger); }
.diag-item.sev-moyen { background: #FFFCF0; border-left: 3px solid var(--warning); }
.diag-item.sev-faible { background: #F0FFF5; border-left: 3px solid var(--success); }

.diag-tag {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 8px;
    border-radius: 100px;
    white-space: nowrap;
    height: fit-content;
    margin-top: 1px;
}

.sev-critique .diag-tag, .sev-eleve .diag-tag { background: var(--danger); color: white; }
.sev-moyen .diag-tag { background: var(--warning); color: white; }
.sev-faible .diag-tag { background: var(--success); color: white; }

.diag-content h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 3px; }
.diag-content p { font-size: 0.82rem; color: var(--text2); line-height: 1.5; }

.rec-item {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    margin-bottom: 8px;
    background: #F8FBF9;
}

.rec-item:last-child { margin-bottom: 0; }

.rec-tag {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 8px;
    border-radius: 100px;
    white-space: nowrap;
    height: fit-content;
    margin-top: 1px;
    background: var(--green);
    color: white;
}

.rec-item.prio-immediate .rec-tag { background: var(--danger); }
.rec-item.prio-court-terme .rec-tag { background: var(--warning); }
.rec-item.prio-long-terme .rec-tag { background: #3498DB; }

.rec-content h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 3px; }
.rec-content p { font-size: 0.82rem; color: var(--text2); line-height: 1.5; }

.care-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.care-chip { background: #F0F7F4; border-radius: 12px; padding: 10px 12px; }
.care-chip-header { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 700; color: var(--green); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.care-chip p { font-size: 0.8rem; color: var(--text2); line-height: 1.4; }

.fun-fact-card {
    background: linear-gradient(135deg, var(--green), var(--green-light));
    border-radius: var(--r);
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.fun-fact-emoji { font-size: 1.5rem; flex-shrink: 0; }
.fun-fact-card p { font-size: 0.88rem; color: white; line-height: 1.6; }

.btn-new-analysis {
    width: 100%;
    padding: 15px;
    background: var(--card);
    color: var(--green);
    border: 2px solid var(--green);
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 12px;
    transition: background 0.15s, color 0.15s;
}

.btn-new-analysis:active { background: var(--green); color: white; }

/* Error */
.error-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 32px;
    gap: 16px;
    height: 100%;
}

.error-screen .error-emoji { font-size: 4rem; }
.error-screen h3 { font-size: 1.3rem; font-weight: 700; }
.error-screen p { font-size: 0.9rem; color: var(--text2); line-height: 1.6; }

.btn-retry {
    padding: 14px 32px;
    background: linear-gradient(135deg, var(--green), var(--green-light));
    color: white;
    border: none;
    border-radius: 100px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
}
