:root {
    --brand: #9D162E;
    --brand-dark: #7a1024;
    --bg: #f8fafc;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ── Cabecera ─────────────────────────────────────────────────────────────── */
.tp-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.5rem;
    background: var(--brand);
    color: white;
}

.tp-header-marca {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
}

.tp-header-title {
    font-size: 1.05rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.tp-header-sub {
    font-size: 0.85rem;
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tp-header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.tp-header-email { font-size: 0.85rem; opacity: 0.9; }

.tp-btn {
    background: white;
    color: var(--brand);
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.5rem 1.1rem;
    border-radius: 0.4rem;
    cursor: pointer;
    transition: background 0.15s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.tp-btn:hover { background: #f1f5f9; }

.tp-btn-ghost {
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
}
.tp-btn-ghost:hover { background: rgba(255, 255, 255, 0.15); }

.tp-btn-secundario {
    background: white;
    color: var(--brand);
    border: 1px solid var(--border);
}
.tp-btn-secundario:hover { background: #f8fafc; }

/* ── Login a pantalla completa ────────────────────────────────────────────── */
.tp-login {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.tp-login-card {
    background: white;
    border-radius: 0.9rem;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 24rem;
}

.tp-login-logo {
    text-align: center;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--brand);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tp-login-lead {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    margin: 0.5rem 0 1.6rem;
    line-height: 1.5;
}

.tp-form { display: flex; flex-direction: column; gap: 1rem; }

.tp-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
}

.tp-form input {
    font-size: 0.95rem;
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 0.45rem;
}
.tp-form input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(157, 22, 46, 0.12);
}

.tp-form-btn {
    width: 100%;
    background: var(--brand);
    color: white;
    border: none;
    font-size: 0.95rem;
    font-weight: 700;
    padding: 0.65rem;
    border-radius: 0.45rem;
    cursor: pointer;
    margin-top: 0.4rem;
    transition: background 0.15s ease;
}
.tp-form-btn:hover { background: var(--brand-dark); }
.tp-form-btn:disabled { opacity: 0.6; cursor: default; }

.tp-error {
    color: #dc2626;
    font-size: 0.82rem;
    margin: 0;
}

.tp-login-nota {
    margin: 1.4rem 0 0;
    font-size: 0.75rem;
    color: var(--muted);
    text-align: center;
    line-height: 1.5;
}

/* ── Listado de proyectos ─────────────────────────────────────────────────── */
.tp-main { flex: 1; padding: 1.75rem 1.5rem; }

.tp-main-titulo {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 1.25rem;
}

.tp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
    gap: 1.1rem;
}

.tp-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 1.15rem 1.2rem;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.tp-card:hover {
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.1);
    transform: translateY(-2px);
    border-color: #cbd5e1;
}

.tp-card-ref {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--brand);
    letter-spacing: 0.03em;
}
.tp-card-nombre { font-size: 1rem; font-weight: 700; line-height: 1.3; }
.tp-card-cliente { font-size: 0.85rem; color: var(--muted); }
.tp-card-meta {
    margin-top: 0.4rem;
    font-size: 0.75rem;
    color: var(--muted);
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.tp-vacio {
    color: var(--muted);
    font-size: 0.9rem;
    padding: 2rem 0;
    text-align: center;
}

/* ── Visor de proyecto (árbol izq + PDF der) ─────────────────────────────── */
.tp-shell {
    flex: 1;
    display: flex;
    align-items: stretch;
    min-height: 0;
    overflow: hidden;
}

.tp-arbol {
    width: 19rem;
    min-width: 15rem;
    flex-shrink: 0;
    background: white;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 0.75rem 0;
}

.tp-arbol-grupo { margin-bottom: 0.35rem; }

.tp-arbol-grupo-tit {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 0.55rem 1.1rem 0.3rem;
}

.tp-arbol-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 1.1rem;
    font-size: 0.88rem;
    cursor: pointer;
    border-left: 3px solid transparent;
    line-height: 1.3;
}
.tp-arbol-item:hover { background: #f1f5f9; }
.tp-arbol-item.activo {
    background: #fdf2f4;
    border-left-color: var(--brand);
    font-weight: 600;
    color: var(--brand);
}

.tp-arbol-item-icono { flex-shrink: 0; opacity: 0.7; }
.tp-arbol-item-nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-arbol-item-ver { font-size: 0.68rem; color: var(--muted); margin-left: auto; flex-shrink: 0; }

/* ── Panel visor ──────────────────────────────────────────────────────────── */
.tp-visor {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #eef1f5;
}

.tp-visor-barra {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 1.1rem;
    background: white;
    border-bottom: 1px solid var(--border);
}

.tp-visor-doc-nombre {
    font-size: 0.92rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tp-visor-lienzo {
    flex: 1;
    overflow: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.tp-visor-lienzo canvas {
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.15);
    background: white;
    max-width: 100%;
}

.tp-visor-vacio {
    margin: auto;
    color: var(--muted);
    text-align: center;
    font-size: 0.95rem;
    line-height: 1.6;
}

.tp-visor-cargando { margin: auto; color: var(--muted); font-size: 0.9rem; }

/* ── Footer ───────────────────────────────────────────────────────────────── */
.tp-footer {
    flex-shrink: 0;
    padding: 0.9rem 1.5rem;
    text-align: center;
    font-size: 0.72rem;
    color: var(--muted);
    background: white;
    border-top: 1px solid var(--border);
}
.tp-footer p { margin: 0.15rem 0; }

[hidden] { display: none !important; }

@media (max-width: 720px) {
    .tp-arbol { position: absolute; z-index: 5; height: 100%; box-shadow: 4px 0 16px rgba(0,0,0,0.1); }
    .tp-header-sub { display: none; }
}
