/* ============================================================
   Facturas de Compra — Fungi Melena
   Brand carried over from pagos.fungimelena.com: Arimo, #8e44ad
   ============================================================ */

:root {
    --purple: #8e44ad;
    --purple-dark: #7d3c98;
    --purple-soft: #f3ecf7;
    --ink: #2b2b33;
    --ink-soft: #5f6070;
    --ink-faint: #8b8c9b;
    --surface: #ffffff;
    --canvas: #f7f7fb;
    --line: #e4e4ee;
    --line-strong: #cfcfe0;

    --ok: #1e8e5a;
    --ok-soft: #e8f6ef;
    --warn: #a86a12;
    --warn-soft: #fdf3e2;
    --err: #c0392b;
    --err-soft: #fdecea;
    --busy: #4a5bd0;
    --busy-soft: #eceffb;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(20, 20, 45, .08);
    --shadow-lg: 0 8px 28px rgba(20, 20, 45, .14);
    --tap: 44px;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: "Arimo", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

:focus-visible {
    outline: 3px solid var(--purple);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

[hidden] { display: none !important; }

/* ---------------- Buttons ---------------- */
.btn {
    font: inherit;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 11px 20px;
    min-height: var(--tap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color .15s, border-color .15s, color .15s;
}

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

.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--purple-dark); }

.btn-ghost { background: transparent; color: var(--purple); border-color: var(--line-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--purple-soft); border-color: var(--purple); }

.btn-sm { padding: 7px 14px; min-height: 36px; font-size: 14px; }
.btn-block { width: 100%; }

.btn-icon {
    background: transparent;
    color: var(--ink-faint);
    padding: 0;
    width: 36px;
    min-height: 36px;
    border-radius: var(--radius-sm);
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { background: var(--purple-soft); color: var(--purple); }

/* ---------------- Passcode gate ---------------- */
.gate {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px max(16px, env(safe-area-inset-left)) 24px max(16px, env(safe-area-inset-right));
}

.gate-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 28px;
    text-align: center;
}

.gate-logo { height: auto; max-width: 140px; margin-bottom: 20px; }
.gate-title { font-size: 22px; color: var(--purple); margin-bottom: 6px; }
.gate-sub { color: var(--ink-soft); font-size: 15px; margin-bottom: 24px; }

.field { display: block; text-align: left; margin-bottom: 16px; }
.field-label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }

.field input {
    font: inherit;
    width: 100%;
    padding: 12px 14px;
    min-height: var(--tap);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
    outline: none;
    border-color: var(--purple);
    box-shadow: 0 0 0 3px var(--purple-soft);
}

.gate-error {
    color: var(--err);
    background: var(--err-soft);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
    text-align: left;
    margin-bottom: 16px;
}

/* ---------------- Top bar ---------------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 14px max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
}

.topbar-logo { height: auto; max-width: 120px; flex-shrink: 0; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 18px; color: var(--purple); line-height: 1.3; }
.topbar-title p { font-size: 14px; color: var(--ink-soft); }

/* ---------------- Shell ---------------- */
.shell {
    max-width: 820px;
    margin: 0 auto;
    padding: 28px max(16px, env(safe-area-inset-left)) 64px max(16px, env(safe-area-inset-right));
}

/* ---------------- Dropzone ---------------- */
.dropzone {
    background: var(--surface);
    border: 2px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background-color .15s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--purple); background: var(--purple-soft); }
.dropzone.is-over { border-color: var(--purple); background: var(--purple-soft); }

.dz-icon { width: 40px; height: 40px; color: var(--purple); margin-bottom: 12px; }
.dz-primary { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.dz-or { color: var(--ink-faint); font-weight: 400; }
.dz-link { color: var(--purple); text-decoration: underline; text-underline-offset: 3px; }
.dz-secondary { font-size: 14px; color: var(--ink-soft); }

/* ---------------- Summary ---------------- */
.summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.summary-counts { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 14px; font-weight: 500; }
.summary-counts span { display: inline-flex; align-items: center; gap: 6px; }
.summary-counts span::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: currentColor;
}
.count-busy { color: var(--busy); }
.count-ok { color: var(--ok); }
.count-warn { color: var(--warn); }
.count-err { color: var(--err); }

.summary-actions { display: flex; gap: 8px; }

/* ---------------- Queue ---------------- */
.queue { list-style: none; margin: 0; padding: 0; }

.empty { color: var(--ink-faint); font-size: 15px; text-align: center; padding: 32px 16px; }

.row {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-top: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.row-main { display: flex; align-items: flex-start; gap: 12px; padding: 14px 12px 14px 16px; }

.row-icon {
    width: 22px; height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 2px;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
}

.row-body { flex: 1; min-width: 0; }

.row-name {
    font-weight: 600;
    font-size: 15px;
    word-break: break-word;
}

.row-status { font-size: 14px; color: var(--ink-soft); margin-top: 2px; }

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

/* Real upload progress — never a fake animation */
.row-progress {
    height: 4px;
    background: var(--line);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}
.row-progress-bar {
    height: 100%;
    width: 0;
    background: var(--busy);
    border-radius: 2px;
    transition: width .2s linear;
}

/* State colours */
.row[data-state="pending"] .row-icon { background: var(--line); color: var(--ink-faint); }
.row[data-state="uploading"] .row-icon,
.row[data-state="processing"] .row-icon { background: var(--busy-soft); color: var(--busy); }
.row[data-state="done"] .row-icon { background: var(--ok-soft); color: var(--ok); }
.row[data-state="blocked"] .row-icon { background: var(--warn-soft); color: var(--warn); }
.row[data-state="duplicate"] .row-icon { background: var(--purple-soft); color: var(--purple); }
.row[data-state="error"] .row-icon { background: var(--err-soft); color: var(--err); }

.row[data-state="done"] .row-status { color: var(--ok); font-weight: 500; }
.row[data-state="blocked"] .row-status { color: var(--warn); font-weight: 500; }
.row[data-state="error"] .row-status { color: var(--err); font-weight: 500; }

/* Spinner for in-flight rows */
.row[data-state="processing"] .row-icon::after {
    content: "";
    width: 12px; height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.row-toggle svg { transition: transform .15s; }
.row-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

/* ---------------- Row detail ---------------- */
.row-detail {
    border-top: 1px solid var(--line);
    padding: 14px 16px;
    background: var(--canvas);
    font-size: 14px;
}

.detail-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 16px;
    margin-bottom: 12px;
}
.detail-grid dt { color: var(--ink-soft); }
.detail-grid dd { margin: 0; font-weight: 500; word-break: break-word; }

.detail-list { margin: 0 0 12px; padding-left: 18px; color: var(--ink-soft); }
.detail-list li { margin-bottom: 3px; }

.detail-json {
    margin: 0;
    padding: 12px;
    background: #2b2b33;
    color: #e8e8f0;
    border-radius: var(--radius-sm);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.5;
    overflow-x: auto;
    max-height: 320px;
}

.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------------- Drag overlay ---------------- */
.drag-overlay {
    position: fixed;
    inset: 0;
    background: rgba(142, 68, 173, .12);
    backdrop-filter: blur(2px);
    display: grid;
    place-items: center;
    padding: 24px;
    z-index: 50;
}

.drag-overlay-inner {
    background: var(--surface);
    border: 2px dashed var(--purple);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px 56px;
    text-align: center;
    color: var(--purple);
    font-size: 18px;
    font-weight: 600;
}
.drag-overlay-inner svg { width: 40px; height: 40px; margin-bottom: 8px; }

/* ---------------- Mobile ---------------- */
@media (max-width: 560px) {
    .topbar { gap: 12px; padding-top: 12px; padding-bottom: 12px; }
    .topbar-logo { max-width: 92px; }
    .topbar-title h1 { font-size: 16px; }
    .topbar-title p { display: none; }
    .shell { padding-top: 20px; }
    .dropzone { padding: 32px 18px; }
    .dz-primary { font-size: 16px; }
    .row-main { padding: 12px 8px 12px 12px; }
    .row-actions { flex-direction: column; }
    .detail-grid { grid-template-columns: 1fr; gap: 2px; }
    .detail-grid dd { margin-bottom: 8px; }
}

/* ---------------- Motion / contrast ---------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

@media (prefers-contrast: more) {
    :root { --line: #9a9ab0; --line-strong: #6a6a80; --ink-soft: #3c3d4c; }
}

/* ---------------- Test-mode banner ----------------
   Deliberately loud and non-dismissible: the operator must always
   know which company the ERP write is landing in. */
.mode-banner {
    background: var(--warn-soft);
    border-bottom: 2px solid var(--warn);
    color: var(--warn);
    padding: 10px max(16px, env(safe-area-inset-left));
    text-align: center;
    font-size: 14.5px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    align-items: center;
    justify-content: center;
}
.mode-banner b { color: inherit; }

.detail-hint {
    margin: 0 0 12px;
    padding: 10px 12px;
    background: var(--purple-soft);
    border-radius: var(--radius-sm);
    color: var(--ink);
}
.detail-hint b { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
