/* ============================================================
   SANA CON IMANES — ESTILOS PREMIUM MOBILE-FIRST
   ============================================================ */

:root {
    --red:       #c0392b;
    --red-dark:  #a93226;
    --red-light: #fadbd8;
    --blue:      #2980b9;
    --blue-dark: #2471a3;
    --green:     #27ae60;
    --bg:        #f2f3f5;
    --surface:   #ffffff;
    --border:    #e0e2e7;
    --text:      #1a1d23;
    --text2:     #5f6a7d;
    --radius:    14px;
    --shadow:    0 2px 12px rgba(0,0,0,.09);
    --shadow-lg: 0 8px 30px rgba(0,0,0,.13);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

/* ---- OVERLAY ---- */
#pdfLoadOverlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 999;
    backdrop-filter: blur(4px);
}
.overlay-inner {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2.5rem 3rem;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.overlay-inner p { margin-top: .75rem; color: var(--text2); }

.spinner {
    width: 48px; height: 48px;
    border: 5px solid var(--border);
    border-top-color: var(--red);
    border-radius: 50%;
    animation: spin .85s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- HEADER ---- */
header {
    position: sticky; top: 0; z-index: 100;
    background: var(--red);
    padding: .85rem 1.1rem;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.header-left { display: flex; align-items: center; gap: .75rem; }
.header-logo {
    height: 65px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
    background: #ffffff;
    padding: 5px 10px;
    border-radius: 10px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}
header h1 { color: #fff; font-size: 1.1rem; font-weight: 700; line-height: 1.2; }
.subtitle { color: rgba(255,255,255,.75); font-size: .72rem; display: block; }
.install-btn {
    background: rgba(255,255,255,.2);
    color: #fff; border: 1px solid rgba(255,255,255,.4);
    padding: .45rem .9rem; border-radius: 8px;
    font-size: .8rem; font-weight: 600; cursor: pointer;
}

/* ---- MAIN ---- */
#app { padding: .9rem; max-width: 900px; margin: 0 auto; }

.view { animation: fadeUp .25s ease; }
.view.hidden { display: none !important; }
.view.active { display: block; }

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

/* ---- TOP BAR ---- */
.top-bar {
    display: flex; gap: .6rem; align-items: center;
    margin-bottom: .8rem;
    flex-wrap: wrap;
}
.top-buttons {
    display: flex; gap: .5rem; flex-wrap: wrap;
}
.search-wrap {
    flex: 1; position: relative; min-width: 220px;
}
.search-icon {
    position: absolute; left: .85rem; top: 50%; transform: translateY(-50%);
    width: 18px; color: var(--text2); pointer-events: none;
}
#searchInput {
    width: 100%;
    padding: .8rem .9rem .8rem 2.5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: .95rem;
    background: var(--surface);
    outline: none;
    transition: border-color .2s;
    box-shadow: var(--shadow);
}
#searchInput:focus { border-color: var(--red); }

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: .4rem;
    padding: .7rem 1.2rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: .88rem;
    cursor: pointer;
    border: none;
    transition: background .18s, transform .1s, opacity .18s;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--red);    color: #fff; }
.btn-primary:hover  { background: var(--red-dark); }
.btn-secondary { background: var(--blue);  color: #fff; }
.btn-secondary:hover { background: var(--blue-dark); }
.btn-outline   { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-pdf       { background: #fff; color: var(--red); border: 1.5px solid var(--red); font-size: .8rem; padding: .65rem .9rem; }
.btn-open-report { background: #fff; color: var(--blue); border: 1.5px solid var(--blue); font-size: .8rem; padding: .65rem .9rem; }
.btn-open-report:hover { background: #ebf5fb; }
.btn:disabled  { background: #c8ccd4; cursor: not-allowed; }
.full-width    { width: 100%; }
input[type="file"].hidden { display: none; }

/* ---- ACTION BAR ---- */
.action-bar {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--surface);
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: .8rem;
    box-shadow: var(--shadow);
    position: sticky; top: 64px; z-index: 80;
}
.action-buttons { display: flex; gap: .5rem; }
.count-badge {
    background: var(--red-light);
    color: var(--red-dark);
    padding: .35rem .75rem;
    border-radius: 30px;
    font-size: .82rem;
    font-weight: 700;
}

/* ---- CARDS ---- */
.cards-container {
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

.par-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: stretch;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .18s, box-shadow .18s, transform .1s;
    -webkit-user-select: none; user-select: none;
}
.par-card:active { transform: scale(.99); }
.par-card.selected {
    border-color: var(--red);
    box-shadow: 0 2px 16px rgba(192,57,43,.18);
    background: #fff9f9;
}

/* Left: número + checkbox */
.card-check {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-width: 52px;
    background: #f7f8fa;
    padding: .7rem .5rem;
    border-right: 1px solid var(--border);
    gap: .4rem;
}
.par-card.selected .card-check { background: var(--red-light); }
.card-num {
    font-size: .85rem; font-weight: 700;
    color: var(--text2);
}
.par-card.selected .card-num { color: var(--red-dark); }
.card-chk {
    width: 20px; height: 20px;
    accent-color: var(--red);
    cursor: pointer;
}

/* Image */
.card-img-wrap {
    width: 130px; min-width: 130px;
    background: #ffffff;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    border-right: 1px solid var(--border);
}
.card-img-wrap canvas,
.card-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.img-placeholder {
    width: 130px; height: 100%;
    min-height: 85px;
    display: flex; align-items: center; justify-content: center;
    color: #bdc3c7;
    font-size: 1.8rem;
}

/* Content */
.card-body {
    flex: 1;
    padding: .75rem .9rem;
    display: flex;
    flex-direction: column;
    gap: .3rem;
    min-width: 0;
}
.card-pares {
    font-size: .97rem; font-weight: 700;
    color: var(--text);
    line-height: 1.3;
}
.card-patogeno {
    font-size: .8rem; font-weight: 600;
    color: var(--red-dark);
    background: var(--red-light);
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 20px;
    width: fit-content;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.card-carac {
    font-size: .8rem;
    color: var(--text2);
    line-height: 1.45;
}
.card-carac.clamped {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.card-carac.expanded {
    display: block;
}
.btn-read-more {
    background: none;
    border: none;
    color: var(--red-dark);
    font-weight: 700;
    font-size: .78rem;
    cursor: pointer;
    padding: .15rem 0;
    width: fit-content;
    text-decoration: underline;
    align-self: flex-start;
}
.btn-read-more:hover {
    color: var(--red);
}

.no-results { text-align: center; color: var(--text2); padding: 2.5rem 1rem; }

/* ---- REPORT VIEW ---- */
.report-options-bar {
    background: var(--surface);
    padding: .6rem 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: .8rem;
    border: 1px solid var(--border);
}
.toggle-desc-label {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: .88rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
}
.toggle-desc-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--red);
    cursor: pointer;
}
.ri-carac-full {
    font-size: .82rem;
    color: #4a5568;
    background: #f7fafc;
    padding: .45rem .65rem;
    border-radius: 6px;
    border-left: 3px solid var(--red);
    line-height: 1.4;
    margin-top: .2rem;
}
.report-topbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.report-topbar h2 { font-size: 1.05rem; font-weight: 700; }

.report-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    padding: .85rem 1.1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    border-left: 4px solid var(--red);
}

.report-corner-date {
    font-size: .88rem;
    font-weight: 700;
    color: var(--red-dark);
    background: var(--red-light);
    padding: .35rem .75rem;
    border-radius: 20px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: .3rem;
}

.loaded-file-tag {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    background: #ebf5fb;
    color: var(--blue-dark);
    font-size: .82rem;
    font-weight: 600;
    padding: .25rem .65rem;
    border-radius: 6px;
    border: 1px solid #aed6f1;
    margin-top: .3rem;
    margin-bottom: .3rem;
}

.report-meta { color: var(--text2); font-size: .82rem; margin-bottom: 0; }

.report-actions-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: .5rem;
    margin-bottom: 1rem;
}

.btn-save { background: #27ae60; color: #fff; }
.btn-save:hover { background: #1e8449; }
.btn-whatsapp { background: #25D366; color: #fff; }
.btn-whatsapp:hover { background: #1ebc57; }
.btn-print { background: #8e44ad; color: #fff; }
.btn-print:hover { background: #732d91; }

.report-content {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    margin-bottom: 1rem;
}

.report-item {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: none;
    overflow: hidden;
    display: flex;
    align-items: center;
    padding: .45rem .85rem;
    gap: .75rem;
    border: 1px solid var(--border);
}

.ri-num {
    background: var(--red);
    color: #fff;
    font-size: .85rem;
    font-weight: 800;
    min-width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.ri-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .4rem;
    min-width: 0;
}
.ri-pares {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}
.ri-boxes {
    display: flex;
    gap: .45rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: .2rem;
}
.ri-box {
    width: 26px;
    height: 26px;
    border: 2px solid #b2bec3;
    border-radius: 5px;
    background: #ffffff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    font-weight: bold;
    user-select: none;
    transition: all .15s ease;
}
.ri-box:hover {
    border-color: var(--red);
}
.ri-box.checked {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
}
.ri-box.checked::after {
    content: "✓";
}

.report-footer { padding-top: .5rem; }

/* ---- HIDDEN UTIL ---- */
.hidden { display: none !important; }

/* ---- RESPONSIVE ---- */
@media (max-width: 480px) {
    .card-carac { -webkit-line-clamp: 3; }
    .top-bar { flex-wrap: wrap; }
    .btn-pdf { width: 100%; }
    .card-img-wrap { width: 100px; min-width: 100px; }
    .ri-img { width: 110px; min-width: 110px; }
}

/* ---- PRINT / EXPORT PDF STYLES ---- */
@media print {
    header, .top-bar, .action-bar, .report-topbar button, .report-actions-bar, .install-btn {
        display: none !important;
    }
    body, #app {
        background: #fff !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
    }
    .report-item {
        box-shadow: none !important;
        border: 1px solid #999 !important;
        page-break-inside: avoid;
        margin-bottom: .5rem !important;
        padding: .5rem .8rem !important;
    }
    .ri-box {
        border: 1.5px solid #000 !important;
        background: #ffffff !important;
        color: #000000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .ri-box.checked {
        background: var(--red) !important;
        border-color: var(--red-dark) !important;
        color: #ffffff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .ri-box.checked::after {
        content: "✓" !important;
        color: #ffffff !important;
        font-weight: bold !important;
        font-size: 1rem !important;
    }
}
