/* ================================================================
   Portal interno BF Rechazo DTE — Layout y componentes globales
   Bootstrap 5.3 como base, CSS personalizado encima.
   ================================================================ */

:root {
    --sidebar-w: 235px;
    --sidebar-bg: #1F4E3D;
    --sidebar-text: #a8c4b0;
    --sidebar-hover: rgba(255,255,255,0.06);
    --sidebar-active-bg: rgba(201,154,46,0.14);
    --sidebar-active-border: #C99A2E;
    --topbar-h: 54px;
    --body-bg: #f1f3f7;
}

/* ── Reset / base ─────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

body {
    margin: 0;
    font-size: 14px;
    background: var(--body-bg);
    color: #212529;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: linear-gradient(180deg, #1F4E3D 0%, #0e2a1c 55%, #081208 100%);
    position: fixed;
    top: 0; left: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-brand {
    display: block;
    padding: 1rem 1.2rem;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.88rem;
    letter-spacing: 0.01em;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    line-height: 1.3;
}

.sidebar-brand-sub {
    display: block;
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--sidebar-text);
    margin-top: 2px;
}

.sidebar-section {
    padding: 1.1rem 1.2rem 0.3rem;
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #6a9070;
    font-weight: 600;
}

.sidebar .nav-link {
    padding: 0.48rem 1.2rem;
    color: var(--sidebar-text);
    font-size: 0.84rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    border-left: 3px solid transparent;
    transition: color 0.15s, background 0.15s;
    text-decoration: none;
}

.sidebar .nav-link:hover {
    background: var(--sidebar-hover);
    color: #e9ecef;
}

.sidebar .nav-link.active {
    background: var(--sidebar-active-bg);
    color: #fff;
    border-left-color: var(--sidebar-active-border);
    font-weight: 600;
}

.sidebar-icon {
    width: 18px;
    font-size: 1rem;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.75;
    line-height: 1;
}

.sidebar .nav-link.active .sidebar-icon { opacity: 1; }

/* ── Main wrapper ─────────────────────────────────────── */
.main-wrapper {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: clip; /* evita que el overflow de tablas suba a body */
}

/* ── Top bar ──────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: #212529;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ── Page content ─────────────────────────────────────── */
.page-content {
    padding: 1.5rem;
    flex: 1;
    min-width: 0; /* permite al flex item shrink para que table-responsive maneje el overflow */
}

/* ── Flash alerts ─────────────────────────────────────── */
.flash-area {
    margin-bottom: 1rem;
}

/* ── Stat cards ───────────────────────────────────────── */
.stat-card {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: border-color .15s, box-shadow .15s;
}

a.stat-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

a.stat-card-link:hover .stat-card {
    border-color: #0d6efd;
    box-shadow: 0 2px 8px rgba(13,110,253,.12);
}

.stat-card-value {
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1;
}

.stat-card-label {
    font-size: 0.78rem;
    color: #6c757d;
}

/* ── Content card ─────────────────────────────────────── */
.content-card {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
}

.content-card-header {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid #dee2e6;
    font-weight: 600;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Filtro local por tabla */
.content-card-header-sticky {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #fff;
}

.table-filter-input {
    font-weight: 400;
    min-width: 100px;
    width: 190px;
}

.table-filter-counter {
    font-size: 0.78rem;
    font-weight: 400;
    white-space: nowrap;
    color: #6c757d;
}

.content-card-body {
    padding: 1.25rem;
}

/* ── Responsive table containers ─────────────────────── */

/* Contenedor global responsivo — scroll horizontal dentro del bloque */
.bf-table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Las tablas dentro de cualquier wrapper llenan el ancho */
.bf-table-responsive > table,
.table-responsive > table {
    width: 100%;
}

/* Min-width para tablas con muchas columnas */
.table-wide    { min-width: 960px;  }
.table-medium  { min-width: 580px;  }
.table-dte-doc { min-width: 1040px; } /* tablas de documentos DTE con columna Fechas */

/* Utilidades de columna — genéricas */
.col-nowrap { white-space: nowrap; }
.col-wrap   { white-space: normal; word-break: break-word; min-width: 110px; }
.col-text   { white-space: normal; word-break: break-word; min-width: 150px; max-width: 280px; }
.col-razon-social { max-width: 160px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.col-compact      { font-size: 0.5625rem; }

/* Utilidades de columna — tablas de documentos DTE */
.col-proveedor  { min-width: 220px; }
.col-documento  { min-width: 150px; }
.col-fechas     { min-width: 140px; white-space: nowrap; }
.col-monto      { min-width: 120px; text-align: right; }
.col-estado-sii { min-width: 150px; }
.col-sap        { min-width: 150px; }
.col-acciones   { min-width: 90px;  white-space: nowrap; }

/* ── Tooltip razón social ─────────────────────────────── */
.tooltip-plain .tooltip-inner {
    background: #fff;
    color: #212529;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.5625rem;
    font-weight: 500;
    max-width: 320px;
    text-align: left;
}
.tooltip-plain .tooltip-arrow { display: none; }

/* ── Tables ───────────────────────────────────────────── */
.table-portal {
    font-size: 0.8rem;
    margin: 0;
    width: 100%;
}

.table-portal thead th {
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6c757d;
    font-weight: 600;
    border-bottom: 2px solid #dee2e6;
    padding: 0.5rem 0.65rem;
    white-space: nowrap;
}

.table-portal tbody tr:hover { background: #f8f9fa; }
.table-portal td { padding: 0.48rem 0.65rem; vertical-align: middle; }

/* ── Encabezados ordenables (parcial _SortableHeader, transversal a todas las grillas) ── */
.sortable-link { cursor: pointer; }
.sortable-link:hover,
.sortable-link:focus { color: var(--bs-primary, #0d6efd) !important; }
.sortable-link:hover .bi { color: inherit !important; }
.sortable-link:focus-visible {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
    border-radius: 2px;
}
/* La columna con orden activo se resalta también por peso, no solo por el ícono. */
th[aria-sort="ascending"] .sortable-link,
th[aria-sort="descending"] .sortable-link { font-weight: 700; }

/* ── Grouped cell pattern (stacked primary + secondary) ── */
.cell-main  { line-height: 1.4;  font-weight: 500; }
.cell-muted { font-size: 0.85em; color: #6c757d; line-height: 1.3; margin-top: 0.15rem; }
.table-portal .badge,
.table-portal .dte-badge,
.table-portal .deadline-ok,
.table-portal .deadline-warn,
.table-portal .deadline-exp { font-size: 1em; }

.table-portal .col-id {
    width: 1%;
    white-space: nowrap;
    font-size: 0.7rem;
    color: #adb5bd;
    text-align: right;
    padding-right: 0.4rem;
}

/* ── Status badges ────────────────────────────────────── */
.dte-badge {
    display: inline-block;
    padding: 0.22em 0.6em;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 4px;
    white-space: nowrap;
    color: #fff;
}

.dte-badge-received        { background: #6c757d; }
.dte-badge-stored          { background: #0dcaf0; color: #000; }
.dte-badge-parsed          { background: #0d6efd; }
.dte-badge-duplicate       { background: #fd7e14; }
.dte-badge-conflicting     { background: #dc3545; }
.dte-badge-detected-sii   { background: #0d6efd; }
.dte-badge-pending-val     { background: #ffc107; color: #000; }
.dte-badge-pending-sii     { background: #6f42c1; }
.dte-badge-pending-app     { background: #0dcaf0; color: #000; }
.dte-badge-approved        { background: #198754; }
.dte-badge-rejected        { background: #dc3545; }
.dte-badge-claim-candidate { background: #fd7e14; }
.dte-badge-sent-sii        { background: #6f42c1; }
.dte-badge-accepted        { background: #198754; }
.dte-badge-receipt         { background: #198754; }
.dte-badge-claimed         { background: #dc3545; }
.dte-badge-sii-error       { background: #dc3545; }
.dte-badge-expired         { background: #dc3545; }
.dte-badge-closed          { background: #6c757d; }

/* ── Deadline indicator ───────────────────────────────── */
.deadline-ok   { color: #198754; font-size: 0.82rem; }
.deadline-warn { color: #fd7e14; font-size: 0.82rem; font-weight: 600; }
.deadline-exp  { color: #dc3545; font-size: 0.82rem; font-weight: 700; }

/* ── Event timeline ───────────────────────────────────── */
.event-timeline {
    position: relative;
    padding-left: 1.5rem;
}

.event-timeline::before {
    content: '';
    position: absolute;
    left: 7px; top: 0; bottom: 0;
    width: 2px;
    background: #dee2e6;
}

.event-item {
    position: relative;
    padding: 0.5rem 0 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
}

.event-item::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 0.85rem;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #6c757d;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px #dee2e6;
}

.event-item.ev-user::before    { background: #0d6efd; }
.event-item.ev-sii::before     { background: #198754; }
.event-item.ev-system::before  { background: #6c757d; }
.event-item.ev-worker::before  { background: #6f42c1; }

.event-item-date {
    font-size: 0.72rem;
    color: #6c757d;
}

.event-item-desc {
    font-size: 0.84rem;
    margin-top: 2px;
}

/* ── Detail grid ──────────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.detail-field label {
    display: block;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6c757d;
    margin-bottom: 2px;
}

.detail-field p {
    margin: 0;
    font-size: 0.88rem;
    font-weight: 500;
}

/* ── Forms ────────────────────────────────────────────── */
.form-card {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 1.5rem;
    max-width: 640px;
}

.form-label {
    font-size: 0.83rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.form-control, .form-select {
    font-size: 0.84rem;
}

/* ── Upload zone ──────────────────────────────────────── */
.upload-zone {
    border: 2px dashed #dee2e6;
    border-radius: 6px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover,
.upload-zone:focus-within {
    border-color: #0d6efd;
    background: #f0f6ff;
}

.upload-zone input[type="file"] {
    display: none;
}

/* ── Login page — split screen ────────────────────────── */
.ls-shell {
    min-height: 100vh;
    display: flex;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #F5F7F4;
}

/* Panel izquierdo — imagen de fondo responsiva */
.ls-panel-left {
    flex: 0 0 58%;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;       /* contenido desde arriba */
    padding: 13% 3.5rem 3rem;         /* 13% top da la posición ~12-18% desde el top */
    background-color: #0d2819;
    background-image: url('/img/login/login-bg-768.webp');
    background-size: cover;
    background-position: left center;
    background-repeat: no-repeat;
}
@media (min-width: 768px) {
    .ls-panel-left { background-image: url('/img/login/login-bg-1280.webp'); }
}
@media (min-width: 1280px) {
    .ls-panel-left { background-image: url('/img/login/login-bg-1920.webp'); }
}
/* Overlay: oscurece la foto y tapa la franja blanca del borde derecho */
.ls-panel-left::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to right,
            rgba(18, 51, 39, 0.62) 0%,
            rgba(18, 51, 39, 0.75) 55%,
            rgba(18, 51, 39, 0.97) 100%),
        linear-gradient(to top,
            rgba(10, 30, 20, 0.55) 0%,
            transparent 50%);
    z-index: 0;
}
.ls-content {
    position: relative;
    z-index: 1;
    color: #fff;
    max-width: 560px;
}
/* ── Logo SERFOCOL ── */
.ls-logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2.25rem;
}
.ls-logo-icon {
    width: 54px;
    height: 54px;
    background: rgba(201,154,46,0.14);
    border: 1.5px solid rgba(201,154,46,0.35);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #C99A2E;
    flex-shrink: 0;
}
.ls-logo-name {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.ls-logo-leaf {
    font-size: 1.1rem;
    color: #C99A2E;
    vertical-align: middle;
}
.ls-logo-sub {
    font-size: 0.74rem;
    color: rgba(255,255,255,0.58);
    letter-spacing: 0.04em;
    margin-top: 0.2rem;
}
/* ── Título principal ── */
.ls-headline {
    font-size: clamp(2.2rem, 3.8vw, 3.4rem);   /* 35–54px según viewport */
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 0.85rem;
    letter-spacing: -0.01em;
}
.ls-headline span { color: #C99A2E; }
/* ── Subtítulo ── */
.ls-tagline {
    font-size: clamp(1rem, 1.5vw, 1.35rem);    /* 16–22px */
    font-weight: 400;
    color: rgba(255,255,255,0.78);
    margin-bottom: 2.25rem;
    line-height: 1.5;
    max-width: 460px;
}
/* ── Bullets ── */
.ls-features {
    list-style: none;
    padding: 0;
    margin: 0 0 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.35rem;
}
.ls-features li {
    display: flex;
    align-items: center;
    gap: 1.1rem;
    font-size: clamp(1rem, 1.4vw, 1.25rem);  /* 16–20px */
    font-weight: 500;
    color: rgba(255,255,255,0.88);
    line-height: 1.35;
}
.ls-feat-icon {
    width: 52px;
    height: 52px;
    background: rgba(201,154,46,0.14);
    border: 1.5px solid rgba(201,154,46,0.35);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.45rem;
    color: #C99A2E;
    flex-shrink: 0;
}
/* ── Pie lema ── */
.ls-footer-motto {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.32);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 1.1rem;
    letter-spacing: 0.06em;
}

/* Panel derecho */
.ls-panel-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    background: #F5F7F4;
}
.ls-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 16px;
    padding: 2.5rem 2.25rem;
    border: 1px solid #D9DED8;
    box-shadow: 0 4px 28px rgba(31,78,61,0.08);
}
.ls-card-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.75rem;
}
.ls-card-logo-icon {
    width: 44px;
    height: 44px;
    background: rgba(31,78,61,0.08);
    border: 1.5px solid rgba(31,78,61,0.22);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1F4E3D;
    font-size: 1.3rem;
}
.ls-card-brand {
    font-size: 1.05rem;
    font-weight: 800;
    color: #123327;
    letter-spacing: 0.05em;
    line-height: 1;
}
.ls-card-brand-sub {
    font-size: 0.68rem;
    color: #6c757d;
    letter-spacing: 0.03em;
    margin-top: 0.15rem;
}
.ls-card h2 {
    font-size: 1.3rem;
    font-weight: 700;
    color: #1F2933;
    margin: 0 0 0.2rem;
}
.ls-card-desc {
    font-size: 0.81rem;
    color: #6c757d;
    margin-bottom: 1.75rem;
}
.ls-field { margin-bottom: 1rem; }
.ls-field label {
    font-size: 0.79rem;
    font-weight: 600;
    color: #1F2933;
    display: block;
    margin-bottom: 0.35rem;
}
.ls-input-wrap { position: relative; }
.ls-input-wrap input {
    width: 100%;
    padding: 0.62rem 0.9rem 0.62rem 2.5rem;
    border: 1.5px solid #D9DED8;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #1F2933;
    background: #fff;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.ls-input-wrap input:focus {
    border-color: #1F4E3D;
    box-shadow: 0 0 0 3px rgba(31,78,61,0.1);
}
.ls-input-icon {
    position: absolute;
    left: 0.78rem;
    top: 50%;
    transform: translateY(-50%);
    color: #adb5bd;
    font-size: 0.95rem;
    pointer-events: none;
}
.ls-btn-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: #1F4E3D;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: background .15s;
}
.ls-btn-submit:hover { background: #123327; }
.ls-divider {
    text-align: center;
    font-size: 0.74rem;
    color: #c0c8c3;
    margin: 1.25rem 0;
    position: relative;
}
.ls-divider::before, .ls-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 38%;
    height: 1px;
    background: #e0e4df;
}
.ls-divider::before { left: 0; }
.ls-divider::after  { right: 0; }
.ls-motto {
    text-align: center;
    font-size: 0.71rem;
    color: #adb5bd;
    margin-top: 1.25rem;
    letter-spacing: 0.04em;
}
.ls-powered {
    text-align: center;
    font-size: 0.69rem;
    color: #c8cfc9;
    margin-top: 0.4rem;
}
.ls-powered span { color: #1F4E3D; font-weight: 600; }

/* Responsive */
@media (max-width: 767.98px) {
    /* Mobile: ocultar panel izquierdo, no descarga imagen */
    .ls-panel-left  { display: none; background-image: none; }
    .ls-panel-right { padding: 2rem 1rem; align-items: flex-start; padding-top: 3.5rem; }
}
@media (min-width: 768px) and (max-width: 991.98px) {
    /* Tablet: panel más estrecho, tipografía reducida */
    .ls-panel-left  { flex: 0 0 46%; padding: 10% 2rem 2rem; }
    .ls-logo-name   { font-size: 1.7rem; }
    .ls-logo-icon   { width: 44px; height: 44px; font-size: 1.3rem; }
    .ls-feat-icon   { width: 40px; height: 40px; font-size: 1.1rem; }
}
@media (min-width: 992px) and (max-width: 1199.98px) {
    /* Desktop medio: ajuste suave */
    .ls-panel-left  { padding: 12% 3rem 3rem; }
}

/* ── Pagination ───────────────────────────────────────── */
.pagination { font-size: 0.83rem; }

/* ── Responsive sidebar + tables ─────────────────────── */

/* 992–1199 px: sidebar colapsado a solo íconos */
@media (max-width: 1199.98px) {
    :root { --sidebar-w: 52px; }

    .sidebar-brand { padding: 0.8rem 0; text-align: center; }
    .sidebar .nav-link { justify-content: center; padding: 0.65rem 0; gap: 0; }
    .sidebar-icon { width: 52px; font-size: 1.15rem; text-align: center; margin: 0; opacity: 0.9; }
    .sidebar .nav-link.active { border-left-color: transparent; border-right: 3px solid var(--sidebar-active-border); }

    .nav-text,
    .sidebar-section,
    .sidebar-footer { display: none; }
}

/* < 768 px: sidebar completamente oculto */
@media (max-width: 767.98px) {
    :root { --sidebar-w: 0px; }
    .sidebar { display: none; }
}

/* Tablas: reducir fuente en pantallas medianas/pequeñas */
@media (max-width: 991.98px) {
    .table-portal { font-size: 0.75rem; }
    .table-portal thead th { font-size: 0.68rem; }
}

/* ── Misc ─────────────────────────────────────────────── */
.text-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.rut-tag    { font-family: monospace; font-size: 0.82rem; white-space: nowrap; }
