/* =========================================================================
   JuriDoc Converter — Hoja de estilos
   TECNOINN · Diseño: tinta jurídica + oro notarial
   Tipografía: Space Grotesk (display) · Inter (texto) · JetBrains Mono (código)
   ========================================================================= */

/* ---------- Tokens ---------- */
:root {
    /* Tema claro: papel de despacho */
    --bg:            #F7F6F2;
    --bg-elevated:   #FFFFFF;
    --bg-sunken:     #EFEDE7;
    --ink:           #10192E;
    --ink-soft:      #4B5568;
    --ink-faint:     #8A93A6;
    --border:        #E2DFD6;
    --accent:        #B8962E;   /* oro notarial */
    --accent-ink:    #7A6115;
    --accent-soft:   #F4ECD6;
    --success:       #16A34A;
    --danger:        #DC2626;
    --info:          #2563EB;
    --shadow:        0 1px 3px rgba(16, 25, 46, .08), 0 8px 24px rgba(16, 25, 46, .06);
    --radius:        14px;
    --radius-sm:     9px;

    --font-display:  "Space Grotesk", system-ui, sans-serif;
    --font-body:     "Inter", system-ui, sans-serif;
    --font-mono:     "JetBrains Mono", ui-monospace, monospace;

    --sidebar-w:     272px;
    --speed:         .25s;
}

[data-theme="dark"] {
    /* Tema oscuro: tinta de gaceta */
    --bg:            #0E1420;
    --bg-elevated:   #171F30;
    --bg-sunken:     #0A0F19;
    --ink:           #E9ECF3;
    --ink-soft:      #A8B1C4;
    --ink-faint:     #6B7488;
    --border:        #26314A;
    --accent:        #D4B04A;
    --accent-ink:    #EBCB74;
    --accent-soft:   #2A2716;
    --shadow:        0 1px 3px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    transition: background var(--speed), color var(--speed);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; }

button { font-family: inherit; cursor: pointer; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

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

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.main {
    flex: 1;
    min-width: 0;
    padding: 28px clamp(16px, 4vw, 44px) 60px;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 24px 18px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: transform var(--speed), background var(--speed);
    z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-soft);
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border-radius: 12px;
}

.brand-text strong { display: block; font-family: var(--font-display); font-size: 15px; }
.brand-text small { color: var(--ink-faint); font-size: 11.5px; }

.side-nav { display: flex; flex-direction: column; gap: 4px; }

.side-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border: none; border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-soft);
    font-size: 14px; font-weight: 500;
    transition: background var(--speed), color var(--speed);
}
.side-link:hover { background: var(--bg-sunken); color: var(--ink); }
.side-link.active { background: var(--accent-soft); color: var(--accent-ink); }

.side-section h4 {
    font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
    color: var(--ink-faint); margin-bottom: 10px;
}

.queue-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }

.queue-list li {
    font-size: 12.5px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-sunken);
    color: var(--ink-soft);
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    overflow: hidden;
}
.queue-list li span.q-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-list li .q-state { font-size: 10.5px; font-weight: 600; flex-shrink: 0; }
.queue-list li.q-done .q-state { color: var(--success); }
.queue-list li.q-error .q-state { color: var(--danger); }
.queue-list li.q-active .q-state { color: var(--accent-ink); }
.queue-empty { justify-content: center !important; color: var(--ink-faint) !important; background: transparent !important; }

.side-footer { margin-top: auto; }

.theme-toggle {
    width: 100%;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-soft);
    font-size: 13.5px;
    transition: border-color var(--speed), color var(--speed);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--ink); }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }

.hamburger {
    display: none;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 8px;
    color: var(--ink);
}

.topbar-title h1 { font-size: clamp(19px, 2.4vw, 24px); }
.topbar-title p { color: var(--ink-faint); font-size: 13px; font-family: var(--font-mono); }

/* ---------- Vistas ---------- */
.view { display: none; animation: fadeUp .35s ease; }
.view.active { display: block; }

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

/* ---------- Dropzone ---------- */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    padding: clamp(30px, 6vw, 56px) 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--speed), background var(--speed), transform var(--speed);
    margin-bottom: 28px;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
    transform: scale(1.005);
}

.dropzone-icon {
    width: 60px; height: 60px;
    margin: 0 auto 16px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-ink);
}
.dropzone-icon svg { width: 26px; height: 26px; }

.dropzone h2 { font-size: 19px; margin-bottom: 6px; }
.dropzone p { color: var(--ink-soft); font-size: 13.5px; max-width: 520px; margin: 0 auto 18px; }
.dropzone small { display: block; margin-top: 14px; color: var(--ink-faint); font-size: 12px; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600;
    text-decoration: none;
    transition: transform .15s, box-shadow .15s, background var(--speed), border-color var(--speed);
    user-select: none;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(184, 150, 46, .35); }
.btn-primary:hover { background: var(--accent-ink); }

.btn-outline { border-color: var(--border); color: var(--ink); background: var(--bg-elevated); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-ink); }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { color: var(--danger); }

.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Tarjetas ---------- */
.cards { display: flex; flex-direction: column; gap: 22px; }

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    animation: fadeUp .4s ease;
    transition: background var(--speed), border-color var(--speed);
}

.card-head {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
    margin-bottom: 18px;
}

.card-file { display: flex; align-items: center; gap: 12px; min-width: 0; }

.file-badge {
    font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
    background: var(--danger); color: #fff;
    padding: 4px 8px; border-radius: 6px; letter-spacing: .05em;
    flex-shrink: 0;
}

.file-name { font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 48vw; }
.file-meta { color: var(--ink-faint); font-size: 12px; font-family: var(--font-mono); }

/* ---------- Pipeline (firma visual) ---------- */
.pipeline {
    list-style: none;
    display: flex;
    justify-content: space-between;
    position: relative;
    margin: 8px 4px 16px;
}
.pipeline::before {
    content: "";
    position: absolute;
    top: 8px; left: 22px; right: 22px;
    height: 2px;
    background: var(--border);
    z-index: 0;
}

.step {
    position: relative; z-index: 1;
    display: flex; flex-direction: column; align-items: center; gap: 7px;
    flex: 1;
    min-width: 0;
}

.step-dot {
    width: 17px; height: 17px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    transition: all var(--speed);
}

.step-label {
    font-size: 10.5px; font-weight: 600;
    letter-spacing: .03em; text-transform: uppercase;
    color: var(--ink-faint);
    text-align: center;
    transition: color var(--speed);
}

.step.active .step-dot {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: 0 0 0 5px var(--accent-soft);
    animation: pulse 1.4s ease-in-out infinite;
}
.step.active .step-label { color: var(--accent-ink); }

.step.done .step-dot {
    border-color: var(--success);
    background: var(--success);
    position: relative;
}
.step.done .step-dot::after {
    content: "";
    position: absolute; inset: 3px 4px 5px 4px;
    border-left: 2px solid #fff; border-bottom: 2px solid #fff;
    transform: rotate(-45deg) translate(0, -1px);
}
.step.done .step-label { color: var(--success); }

.step.error .step-dot { border-color: var(--danger); background: var(--danger); }
.step.error .step-label { color: var(--danger); }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px var(--accent-soft); }
    50%      { box-shadow: 0 0 0 8px transparent; }
}

/* ---------- Progreso ---------- */
.progress {
    height: 6px;
    background: var(--bg-sunken);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--accent), var(--accent-ink));
    transition: width .45s cubic-bezier(.4, 0, .2, 1);
}

.status-line { font-size: 13px; color: var(--ink-soft); font-family: var(--font-mono); margin-bottom: 16px; }
.status-line.is-error { color: var(--danger); }
.status-line.is-done { color: var(--success); }

/* ---------- Estadísticas ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.stat {
    background: var(--bg-sunken);
    border-radius: var(--radius-sm);
    padding: 12px 10px;
    text-align: center;
    display: flex; flex-direction: column; gap: 3px;
}

.stat-value { font-family: var(--font-display); font-size: 17px; font-weight: 700; color: var(--ink); word-break: break-word; }
.stat-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }

/* ---------- Previsualización ---------- */
.preview-block { margin-bottom: 18px; }

.tabs {
    display: flex; gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
}

.tab {
    border: none;
    background: transparent;
    padding: 9px 16px;
    font-size: 13px; font-weight: 600;
    color: var(--ink-faint);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--speed), border-color var(--speed);
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }

.pane { display: none; }
.pane.active { display: block; animation: fadeUp .25s ease; }

.pdf-frame {
    width: 100%; height: 420px;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    background: var(--bg-sunken);
}

.code-view {
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 420px;
    overflow: auto;
    padding: 16px;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    color: var(--ink-soft);
}

/* ---------- Descargas ---------- */
.card-downloads {
    display: flex; flex-wrap: wrap; gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ---------- Historial ---------- */
.table-wrap { overflow-x: auto; }

.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.history-table th {
    text-align: left;
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-faint);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.history-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--ink-soft);
    white-space: nowrap;
}
.history-table td:first-child { color: var(--ink); font-weight: 500; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.history-table tr:hover td { background: var(--bg-sunken); }
.table-empty { text-align: center; color: var(--ink-faint) !important; padding: 30px !important; }

.tag {
    display: inline-block;
    font-size: 11px; font-weight: 600;
    padding: 3px 9px;
    border-radius: 99px;
    background: var(--accent-soft);
    color: var(--accent-ink);
}

.dl-links { display: flex; gap: 8px; }
.dl-links a { color: var(--info); text-decoration: none; font-weight: 600; font-size: 12px; }
.dl-links a:hover { text-decoration: underline; }

/* ---------- Alertas (toasts) ---------- */
.toasts {
    position: fixed;
    bottom: 22px; right: 22px;
    display: flex; flex-direction: column; gap: 10px;
    z-index: 100;
    max-width: min(380px, calc(100vw - 40px));
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-left: 4px solid var(--info);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 13px 16px;
    font-size: 13.5px;
    color: var(--ink);
    animation: toastIn .3s cubic-bezier(.2, .9, .3, 1.2);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.leaving { animation: toastOut .3s ease forwards; }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateX(30px); }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .hamburger { display: grid; place-items: center; }
    .file-name { max-width: 55vw; }
    .pipeline .step-label { font-size: 9px; }
    .pdf-frame { height: 320px; }
}

@media (max-width: 560px) {
    .main { padding: 18px 14px 50px; }
    .card { padding: 16px; }
    .pipeline { flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
    .pipeline::before { left: 12px; right: 12px; }
    .step { min-width: 62px; }
    .card-downloads .btn { flex: 1 1 45%; }
    .stats { grid-template-columns: repeat(3, 1fr); }
}
