/* ═══════════════════════════════════════
   Sembrai — Estilos principales
   Aesthetic: Organic warmth + clean tech
   ═══════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=Playfair+Display:wght@500;700&display=swap');

:root {
    --green-50: #f0fdf4;
    --green-100: #dcfce7;
    --green-200: #bbf7d0;
    --green-300: #86efac;
    --green-400: #4ade80;
    --green-500: #22c55e;
    --green-600: #16a34a;
    --green-700: #15803d;
    --green-800: #166534;
    --green-900: #14532d;
    --green-950: #052e16;

    --earth-50: #faf8f5;
    --earth-100: #f5f0e8;
    --earth-200: #e8dfd2;
    --earth-300: #d4c5ae;
    --earth-400: #b8a080;
    --earth-500: #9a7d5a;
    --earth-600: #7d6347;
    --earth-700: #5e4a35;

    --coral: #e8634a;
    --amber: #f59e0b;
    --sky: #0ea5e9;

    --bg: #faf9f7;
    --bg-card: #ffffff;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --border: #e5e2dc;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.1);

    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'DM Sans', system-ui, sans-serif;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* ─── Background Texture ─── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(34,197,94,0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(232,99,74,0.04) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ─── App Container ─── */
.app {
    position: relative;
    z-index: 1;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px;
    min-height: 100dvh;
}

/* ─── Header ─── */
.header {
    text-align: center;
    padding: 40px 0 24px;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.logo-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--green-500), var(--green-700));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: white;
    box-shadow: 0 2px 8px rgba(22,163,74,0.3);
}

.logo-text {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    color: var(--green-900);
    letter-spacing: -0.5px;
}

.tagline {
    font-size: 15px;
    color: var(--text-muted);
    font-weight: 400;
}

/* ─── Upload Card ─── */
.upload-card {
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.upload-card:hover,
.upload-card.dragover {
    border-color: var(--green-400);
    background: var(--green-50);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.upload-card.has-image {
    border-style: solid;
    border-color: var(--green-400);
    padding: 0;
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: var(--green-50);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-icon svg {
    width: 28px;
    height: 28px;
    stroke: var(--green-600);
}

.upload-title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 500;
    color: var(--green-900);
    margin-bottom: 6px;
}

.upload-subtitle {
    font-size: 14px;
    color: var(--text-muted);
}

.upload-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.btn-upload {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-camera {
    background: var(--green-600);
    color: white;
}

.btn-camera:hover { background: var(--green-700); }

.btn-gallery {
    background: var(--green-50);
    color: var(--green-800);
    border: 1px solid var(--green-200);
}

.btn-gallery:hover { background: var(--green-100); }

/* Preview de imagen */
.image-preview {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: 14px;
    display: none;
}

.upload-card.has-image .image-preview { display: block; }
.upload-card.has-image .upload-placeholder { display: none; }

/* ─── Context Input ─── */
.context-section {
    margin-top: 16px;
    display: none;
}

.context-section.visible { display: block; }

.context-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text);
    background: var(--bg-card);
    resize: none;
    transition: border-color 0.2s;
}

.context-input:focus {
    outline: none;
    border-color: var(--green-400);
}

.context-input::placeholder { color: var(--earth-400); }

/* ─── Diagnose Button ─── */
.btn-diagnose {
    width: 100%;
    padding: 16px;
    margin-top: 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--green-600), var(--green-700));
    color: white;
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(22,163,74,0.25);
}

.btn-diagnose.visible { display: flex; }

.btn-diagnose:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(22,163,74,0.35);
}

.btn-diagnose:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* ─── Loading State ─── */
.loading-overlay {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.loading-overlay.visible { display: flex; }

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid var(--green-100);
    border-top-color: var(--green-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    margin-top: 16px;
    font-size: 15px;
    color: var(--text-muted);
}

.loading-text .dots::after {
    content: '';
    animation: dots 1.5s steps(4) infinite;
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* ─── Results Card ─── */
.results {
    display: none;
    margin-top: 20px;
    padding-bottom: 40px;
    animation: fadeUp 0.5s ease;
}

.results.visible { display: block; }

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

.result-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 14px;
}

.result-header {
    padding: 20px;
    background: linear-gradient(135deg, var(--green-800), var(--green-950));
    color: white;
}

.plant-name {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.plant-scientific {
    font-size: 13px;
    opacity: 0.7;
    font-style: italic;
    margin-top: 2px;
}

.plant-type-badge {
    display: inline-block;
    margin-top: 10px;
    padding: 4px 12px;
    background: rgba(255,255,255,0.15);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Diagnóstico status */
.status-section {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.saludable { background: var(--green-500); box-shadow: 0 0 8px rgba(34,197,94,0.4); }
.status-dot.leve { background: var(--amber); box-shadow: 0 0 8px rgba(245,158,11,0.4); }
.status-dot.moderado { background: #f97316; box-shadow: 0 0 8px rgba(249,115,22,0.4); }
.status-dot.grave { background: var(--coral); box-shadow: 0 0 8px rgba(232,99,74,0.4); }

.status-text {
    font-weight: 500;
    font-size: 15px;
}

.status-confidence {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--earth-50);
    padding: 2px 10px;
    border-radius: 12px;
}

/* Sections */
.result-section {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.result-section:last-child { border-bottom: none; }

.section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--green-700);
    margin-bottom: 10px;
}

.section-content {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
}

/* Treatment Steps */
.treatment-step {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    align-items: flex-start;
}

.treatment-step:last-child { margin-bottom: 0; }

.step-number {
    width: 28px;
    height: 28px;
    background: var(--green-50);
    color: var(--green-700);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    margin-top: 1px;
}

.step-text {
    font-size: 14px;
    line-height: 1.5;
}

/* Product Recommendation */
.product-card {
    background: var(--earth-50);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    border-left: 3px solid var(--green-500);
}

.product-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.product-type {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.product-usage {
    font-size: 13px;
    color: var(--earth-600);
}

/* Care Info */
.care-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.care-item {
    text-align: center;
    padding: 12px 8px;
    background: var(--green-50);
    border-radius: var(--radius-sm);
}

.care-icon {
    font-size: 20px;
    margin-bottom: 4px;
}

.care-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.care-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--green-800);
    margin-top: 2px;
}

/* Fun Fact */
.fun-fact {
    background: linear-gradient(135deg, var(--green-50), var(--earth-50));
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--earth-700);
    line-height: 1.6;
    position: relative;
    margin: 0 20px 20px;
}

.fun-fact::before {
    content: '💡';
    position: absolute;
    top: -10px;
    left: 16px;
    font-size: 18px;
    background: var(--bg-card);
    padding: 0 4px;
    border-radius: 6px;
}

/* ─── New Diagnosis Button ─── */
.btn-new {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--green-200);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--green-700);
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-new:hover {
    background: var(--green-50);
    border-color: var(--green-400);
}

/* ─── Remaining Uses ─── */
.uses-counter {
    text-align: center;
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

/* ─── Footer ─── */
.footer {
    text-align: center;
    padding: 24px 0;
    font-size: 13px;
    color: var(--earth-400);
}

.footer a {
    color: var(--green-600);
    text-decoration: none;
}

/* ─── Error State ─── */
.error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-top: 12px;
    display: none;
}

.error-message.visible { display: block; }

/* ─── My Plants Section ─── */
.my-plants-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.my-plants-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.my-plants-title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 500;
    color: var(--green-900);
}

.my-plants-count {
    font-size: 13px;
    color: var(--text-muted);
    margin-left: 8px;
}

.btn-clear-all {
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-clear-all:hover {
    color: var(--coral);
    border-color: var(--coral);
}

.my-plants-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 14px;
}

.my-plants-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

/* Plant Card */
.plant-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    position: relative;
}

.plant-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.plant-card:active {
    transform: scale(0.97);
}

.plant-card-img-wrap {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--green-50);
}

.plant-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.plant-card-img-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    background: var(--green-50);
}

.plant-card-status {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 14px;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.plant-card-info {
    padding: 8px 10px;
}

.plant-card-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plant-card-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.plant-card-delete {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 24px;
    height: 24px;
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s;
}

.plant-card:hover .plant-card-delete {
    display: flex;
}

.plant-card-delete:hover {
    background: var(--coral);
}

/* ─── History Banner ─── */
.history-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--green-50);
    border: 1px solid var(--green-200);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--green-800);
}

.history-banner-close {
    background: none;
    border: none;
    color: var(--green-600);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.history-banner-close:hover {
    color: var(--green-900);
}

/* ─── Responsive ─── */
@media (max-width: 380px) {
    .upload-buttons { flex-direction: column; }
    .care-grid { grid-template-columns: 1fr; }
    .my-plants-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── PWA / Safe Areas ─── */
@supports (padding-top: env(safe-area-inset-top)) {
    .header { padding-top: calc(40px + env(safe-area-inset-top)); }
    .footer { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}
