/* ============================================================================
   ERP Insumos y Máquinas — estilos base
   ============================================================================ */

:root {
    /* Paleta Insumos y Máquinas — coral + gris carbón */
    --color-bg:           #f5f3ef;
    --color-surface:      #ffffff;
    --color-text:         #242428;
    --color-text-strong:  #1c1c1f;
    --color-muted:        #6b6b70;
    --color-border:       #e6e3dd;
    --color-border-soft:  #efece6;

    /* Acentos coral */
    --color-primary:        #b5301c;
    --color-primary-hover:  #d93b23;
    --color-primary-light:  #e55a44;
    --color-primary-dark:   #8f2516;
    --color-primary-soft:   #fde4df;

    /* Acentos carbón (botones secundarios y elementos neutros oscuros) */
    --color-carbon:        #3c3c41;
    --color-carbon-hover:  #2f2f33;
    --color-carbon-dark:   #1c1c1f;

    --color-success:  #16a34a;
    --color-warning:  #d97706;
    --color-danger:   #b5301c;
    --color-gray:     #9ca3af;

    --radius:        8px;
    --radius-sm:     4px;
    --shadow-sm:     0 1px 2px rgba(28, 28, 31, .06);
    --shadow:        0 4px 12px rgba(28, 28, 31, .08);

    --space-1: .25rem;
    --space-2: .5rem;
    --space-3: .75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f3f4f6; padding: 0 .35em; border-radius: 3px; font-size: 90%; }

.muted { color: var(--color-muted); }

/* ----- Topbar ----- */
.topbar {
    background: var(--color-carbon-dark);
    border-bottom: 3px solid var(--color-primary);
    box-shadow: var(--shadow-sm);
}
.topbar a, .topbar .brand, .topbar .user-name { color: #f5f3ef; }
.topbar .brand-sub { color: #c8c5be; }
.topbar .topnav a.active { color: #fff; border-bottom: 2px solid var(--color-primary-light); padding-bottom: 1px; }
.topbar .topnav a:hover { color: var(--color-primary-light); text-decoration: none; }
.topbar .topnav a.muted { color: #6b6b70; cursor: not-allowed; }
.topbar .btn-link { color: #d4d0c8; border-color: #44444a; }
.topbar .btn-link:hover { color: #fff; border-color: var(--color-primary-light); }
.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: .65rem 1rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
.brand { font-size: 1.05rem; display: inline-flex; align-items: center; }
.brand-sub { font-weight: 400; margin-left: .25rem; }
.brand-logo {
    display: block;
    height: 38px;
    max-width: 180px;
    width: auto;
    object-fit: contain;
    background: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    box-sizing: content-box;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
@media (max-width: 700px) {
    .brand-logo { height: 28px; max-width: 130px; padding: 3px 7px; }
}
.topnav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; align-items: center; }
.topnav a { padding: .35rem .25rem; }

/* Grupo de las 3 acciones principales */
.nav-main {
    display: inline-flex;
    gap: .35rem;
    align-items: center;
    padding: .25rem;
    background: rgba(255,255,255,.06);
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,.08);
}
.nav-main a {
    padding: .45rem .9rem;
    font-weight: 600;
    font-size: .95rem;
    border-radius: 4px;
    letter-spacing: .01em;
    transition: background .12s;
}
.nav-main a:hover {
    background: var(--color-primary);
    color: #fff !important;
    text-decoration: none;
}
.topbar .nav-main a.active {
    background: var(--color-primary);
    color: #fff;
    border-bottom: none;
    padding-bottom: .45rem;
}

/* Links secundarios (menos prominentes) */
.nav-secundarios {
    display: inline-flex;
    gap: .75rem;
    margin-left: auto;
    align-items: center;
}
.topbar .nav-secundario {
    font-size: .85rem;
    color: #a8a5a0 !important;
    font-weight: 400;
}
.topbar .nav-secundario:hover {
    color: #f5f3ef !important;
    text-decoration: none;
}
.user-box { display: flex; align-items: center; gap: .65rem; }
.user-name { font-weight: 600; }
.user-role {
    background: var(--color-primary-soft); color: var(--color-primary-dark);
    padding: .1rem .5rem; border-radius: 999px; font-size: .78rem;
    text-transform: uppercase; letter-spacing: .03em;
}
.btn-link {
    color: var(--color-muted);
    border: 1px solid var(--color-border);
    padding: .25rem .65rem;
    border-radius: var(--radius-sm);
    font-size: .85rem;
}
.btn-link:hover { color: var(--color-text); text-decoration: none; }

/* ----- Contenido ----- */
.content {
    max-width: 1280px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-4);
}

.page-head { margin-bottom: var(--space-6); }
.page-head h1 { margin: 0 0 .2rem; font-size: 1.5rem; }

/* ----- Cards / grid ----- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-4);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-4);
}
.card h2 {
    margin: 0 0 var(--space-4);
    font-size: 1.35rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--color-primary-dark);
    padding-bottom: .5rem;
    border-bottom: 2px solid var(--color-primary);
}
.card h3 { margin: 0 0 .35rem; font-size: .9rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: .04em; }

.metric { font-size: 1.85rem; font-weight: 700; margin: .15rem 0; }

.grid { display: grid; gap: var(--space-4); margin-bottom: var(--space-6); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ----- Steps ----- */
.steps { padding-left: 1.25rem; margin: 0; }
.steps li { padding: .15rem 0; }
.steps li.done { color: var(--color-success); }
.steps li.done::marker { content: "✓ "; }

/* ----- Alerts ----- */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-4);
    border: 1px solid transparent;
    font-size: .92rem;
}
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* ----- Forms ----- */
label { display: block; margin-bottom: var(--space-3); }
label > span {
    display: block;
    font-size: .95rem;
    color: var(--color-text-strong);
    margin-bottom: .35rem;
    font-weight: 600;
    letter-spacing: .01em;
}
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    background: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(181, 48, 28, .15);
}

.btn {
    display: inline-block;
    padding: .55rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text);
    font: inherit;
    cursor: pointer;
    transition: background .12s, border-color .12s;
}
.btn:hover { background: #faf8f4; border-color: var(--color-carbon); }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.btn-dark { background: var(--color-carbon); border-color: var(--color-carbon); color: #fff; }
.btn-dark:hover { background: var(--color-carbon-hover); border-color: var(--color-carbon-hover); }
.btn-block { width: 100%; }

/* ----- Login ----- */
.login-wrap {
    min-height: calc(100vh - 4rem);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-6);
    box-shadow: var(--shadow);
}
.login-head { text-align: center; margin-bottom: var(--space-6); }
.login-head h1 { margin: 0 0 .25rem; font-size: 1.2rem; }

/* ----- Page-head flex (título + acción) ----- */
.page-head-flex {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}

/* ----- Card sin padding (cuando contiene tabla full-width) ----- */
.card.no-padding { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-3); gap: var(--space-3); }

/* ----- Filtros ----- */
.filters .filters-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr 1fr auto;
    gap: .75rem;
    align-items: end;
}
@media (max-width: 1100px) {
    .filters .filters-grid { grid-template-columns: 1fr 1fr 1fr 1fr; }
}
@media (max-width: 600px) {
    .filters .filters-grid { grid-template-columns: 1fr 1fr; }
}
.filters label { margin-bottom: 0; }
.filter-q input { width: 100%; }
.filter-actions { display: flex; align-items: end; }

/* ----- Tablas ----- */
table.data {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
}
table.data th, table.data td {
    padding: .55rem .7rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    font-size: .92rem;
    vertical-align: middle;
}
table.data th { background: #f9fafb; font-weight: 600; color: var(--color-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
table.data tr:last-child td { border-bottom: none; }
table.data td.empty { text-align: center; color: var(--color-muted); padding: 2rem; }

.th-num   { text-align: right; }
.th-flag  { text-align: center; width: 3rem; }
.th-acc   { text-align: right; white-space: nowrap; }
td.canal  { text-align: center; font-size: 1.05rem; }

tr.row-pendiente   { background: #fffbeb; }                                /* ámbar */
tr.row-enviada     { background: #fdf6f4; }                                /* coral muy suave */
tr.row-facturada   { background: #ecfdf5; }                                /* verde */
tr.row-rechazada   { background: #f0ede7; color: var(--color-muted); }     /* gris cálido */
tr.row-convertida  { background: #ecfdf5; }                                /* alias legacy */

/* ----- Badges de estado ----- */
.badge {
    display: inline-block;
    padding: .12rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.badge-gray   { background: #e8e5df; color: var(--color-carbon); }
.badge-blue   { background: #e0dcd4; color: var(--color-carbon-dark); }
.badge-amber  { background: #fde68a; color: #92400e; }
.badge-slate  { background: #d4d0c8; color: var(--color-carbon-hover); }
.badge-green  { background: #bbf7d0; color: #166534; }
.badge-coral  { background: var(--color-primary-soft); color: var(--color-primary-dark); }

/* Badges por estado de cotización */
.badge-cotizado  { background: #fde68a; color: #92400e; }
.badge-aprobado  { background: #fecaca; color: #7f1d1d; }
.badge-pagado    { background: #bbf7d0; color: #166534; }
.badge-enviado   { background: #dbeafe; color: #1e3a8a; }
.badge-rechazado { background: #d4d0c8; color: var(--color-carbon-hover); }
/* Sub-tipos de PAGADO */
.badge-fact-a    { background: #bfdbfe; color: #1e3a8a; font-weight: 700; }
.badge-fact-b    { background: #bbf7d0; color: #166534; font-weight: 700; }
.badge-fact-p    { background: #e5e7eb; color: #374151; font-weight: 700; }

/* Row backgrounds tenues por estado */
.row-cotizado  td { background: #fefce8; }
.row-aprobado  td { background: #fff1f2; }
.row-pagado    td { background: #f0fdf4; }
.row-rechazado td { background: #f5f5f4; color: #6b7280; }

/* Columnas del listado de cotizaciones — ajuste de anchos */
.th-numero { width: 62px;  white-space: nowrap; }
.th-fecha  { width: 82px;  white-space: nowrap; }
.th-canal  { width: 78px;  white-space: nowrap; padding-left: .4rem !important; padding-right: .4rem !important; }
.th-estado { min-width: 200px; }
.th-envio  { width: 90px;  white-space: nowrap; }
.th-num.th-num { white-space: nowrap; }

/* Chips de canal de contacto (colores por canal) */
.canal-chip {
    display: inline-block;
    padding: .15rem .4rem;
    border-radius: 4px;
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .02em;
    white-space: nowrap;
}
.canal-whatsapp      { background: #dcfce7; color: #166534; }
.canal-mail          { background: #dbeafe; color: #1e3a8a; }
.canal-telefono      { background: #e0e7ff; color: #3730a3; }
.canal-recomendacion { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.canal-local         { background: #fef3c7; color: #92400e; }
.canal-otro          { background: #e8e5df; color: var(--color-carbon); }

/* Dots leyenda */
.dot-blue  { background: #dbeafe; }
.dot-coral { background: var(--color-primary-soft); }

/* Filas por estado (nuevos) */
tr.row-cotizado  { background: #fffbeb; }
tr.row-aprobado  { background: #fdf6f4; }
tr.row-facturado { background: #ecfdf5; }
tr.row-enviado   { background: #eff6ff; }
tr.row-rechazado { background: #f0ede7; color: var(--color-muted); }

/* ----- Botones mini en acciones ----- */
form.inline { display: inline; margin: 0; }
.btn-mini {
    display: inline-block;
    padding: .25rem .55rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text);
    font-size: .82rem;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
}
.btn-mini:hover { background: #faf8f4; text-decoration: none; }
.btn-mini-ok      { border-color: #86efac; color: #166534; }
.btn-mini-ok:hover{ background: #ecfdf5; }
.btn-mini-danger  { border-color: #fca5a5; color: var(--color-primary-dark); }
.btn-mini-danger:hover { background: #fef2f2; }
.btn-mini-primary { border-color: var(--color-primary); color: var(--color-primary); }
.btn-mini-primary:hover { background: var(--color-primary-soft); }

/* Botón "Editar" grande (acción principal en cada fila del listado) */
.btn-edit {
    display: inline-block;
    padding: .35rem .85rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-primary);
    background: var(--color-primary);
    color: #fff;
    font-size: .82rem;
    font-weight: 600;
    text-decoration: none;
    line-height: 1.2;
    transition: background .12s;
}
.btn-edit:hover { background: var(--color-primary-hover); color: #fff; text-decoration: none; }

/* Chip de venta asociada (al final del listado de cotizaciones) */
.chip-doc {
    display: inline-block;
    padding: .25rem .65rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    text-decoration: none;
    line-height: 1.3;
    white-space: nowrap;
}
.chip-doc:hover { text-decoration: none; }
.chip-doc-presupuesto { background: #e5e7eb; color: var(--color-carbon-dark); }
.chip-doc-presupuesto:hover { background: #d1d5db; }
.chip-doc-factura-a   { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.chip-doc-factura-a:hover { background: #fbcdc4; }
.chip-doc-factura-b   { background: #d1fae5; color: #065f46; }
.chip-doc-factura-b:hover { background: #a7f3d0; }

/* ----- Flags de pagado/enviado ----- */
.flag {
    width: 1.5rem; height: 1.5rem;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: #fff;
    cursor: pointer;
    font-weight: 700;
    line-height: 1;
}
.flag-on  { background: #16a34a; color: #fff; border-color: #16a34a; }
.flag-off { color: #d1d5db; }
.flag:hover { transform: scale(1.05); }

/* ----- Leyenda de colores ----- */
.legend {
    display: flex; gap: 1.25rem; flex-wrap: wrap;
    margin-top: var(--space-4);
    padding: 0 var(--space-2);
    font-size: .85rem; color: var(--color-muted);
}
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.dot { display: inline-block; width: .75rem; height: .75rem; border-radius: 50%; border: 1px solid rgba(0,0,0,.1); }
.dot-amber { background: #fde68a; }
.dot-green { background: #bbf7d0; }
.dot-gray  { background: #e5e7eb; }

/* ============================================================================
   FORMULARIO DE COTIZACIÓN
   ============================================================================ */

.span-2 { grid-column: span 2; }

/* Bloque unificado Cabecera + Cliente */
.card-generales {
    background: linear-gradient(180deg, #fdf8f6 0%, #fff 100%);
    border-left: 4px solid var(--color-primary);
    padding: 1.25rem 1.5rem;
}
.sub-titulo {
    font-size: 1.35rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--color-primary-dark);
    margin: 1.75rem 0 1rem;
    padding-bottom: .5rem;
    border-bottom: 2px solid var(--color-primary);
}
.card-generales .sub-titulo:first-of-type,
.card-condiciones .sub-titulo:first-of-type { margin-top: 1.25rem; }

/* Grid Pagos: Forma | Plazo | Métodos aceptados (en una línea) */
.grid-pago-plazo-metodos {
    display: grid;
    grid-template-columns: 1fr 1fr 1.5fr;
    gap: 1rem;
    align-items: end;
}
@media (max-width: 900px) {
    .grid-pago-plazo-metodos { grid-template-columns: 1fr 1fr; }
    .grid-pago-plazo-metodos .pagos-metodos { grid-column: 1 / -1; }
}
@media (max-width: 500px) {
    .grid-pago-plazo-metodos { grid-template-columns: 1fr; }
}

.pagos-metodos { margin-bottom: 0; }
.pagos-metodos-label {
    display: block;
    font-size: .95rem;
    color: var(--color-text-strong);
    margin-bottom: .35rem;
    font-weight: 600;
    letter-spacing: .01em;
}
.check-inline-row {
    display: flex; flex-wrap: wrap; gap: .75rem 1.1rem;
    padding: .6rem .8rem;
    background: #f9fafb;
    border-radius: var(--radius-sm);
}
.check-inline-row .check { margin: 0; font-size: .88rem; }

/* Grid especial: Fecha - Canal - Estado - Pagado (checkbox) */
.grid-fecha-canal-estado-pagado {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1.2fr 1.2fr auto;
    gap: 1rem;
    align-items: end;
}
@media (max-width: 700px) {
    .grid-fecha-canal-estado-pagado { grid-template-columns: 1fr 1fr; }
}

/* Checkbox PAGADO como caja destacada al final */
.check-pagado {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: .5rem 1.1rem;
    background: #fff;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    min-width: 100px;
    transition: all .15s;
    margin-bottom: 0;
}
.check-pagado:hover { border-color: var(--color-primary); }
.check-pagado span {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-muted);
    margin-bottom: .3rem;
}
.check-pagado input[type="checkbox"] {
    width: 22px; height: 22px; margin: 0;
    accent-color: var(--color-primary);
    cursor: pointer;
}
.check-pagado:has(input:checked) {
    background: var(--color-primary-soft);
    border-color: var(--color-primary);
}
.check-pagado:has(input:checked) span { color: var(--color-primary-dark); }

/* Checkboxes en línea (PAGADO / ENVIADO) */
.check-row { display: flex; gap: 1.5rem; margin-top: var(--space-3); }
.check { display: inline-flex; align-items: center; gap: .4rem; margin: 0; cursor: pointer; }
.check input { width: auto; margin: 0; }
.check span { font-size: .9rem; color: var(--color-text); font-weight: 500; }

/* Grupo de checkboxes (métodos de pago) */
.check-group {
    display: flex; flex-wrap: wrap; gap: 1rem;
    padding: .75rem;
    background: #f9fafb;
    border-radius: var(--radius-sm);
    margin: var(--space-3) 0;
}
.check-label { font-size: .85rem; color: var(--color-muted); width: 100%; }

/* Tabla de líneas */
.items-table input[type="text"],
.items-table input[type="number"],
.items-table select {
    padding: .4rem .55rem;
    font-size: .95rem;
}
.items-table td { vertical-align: top; }
.items-table .col-code    { width: 7rem; }
.items-table .col-qty     { width: 5rem; }
.items-table .col-price   { width: 8rem; }
.items-table .col-iva-pct { width: 6rem; }
.items-table .col-del     { width: 2.5rem; text-align: center; }
.items-table .col-qty input,
.items-table .col-price input { text-align: right; }
.items-table td.col-price-cIva,
.items-table td.col-subtotal { text-align: right; font-weight: 600; color: var(--color-text-strong); padding-right: .8rem; padding-top: .55rem; }
.items-table td.col-subtotal { color: var(--color-primary-dark); font-size: 1rem; }
.items-table select { width: 100%; }

/* Textarea de descripción — 2 renglones */
.items-table textarea.input-desc {
    width: 100%;
    padding: .4rem .55rem;
    font: inherit;
    font-size: .95rem;
    resize: vertical;
    min-height: 2.5rem;
    line-height: 1.35;
}

/* Totales */
.totales {
    margin-top: var(--space-4);
    margin-left: auto;
    max-width: 360px;
    background: #f9fafb;
    padding: var(--space-4);
    border-radius: var(--radius-sm);
}
.totales > div {
    display: flex; justify-content: space-between;
    padding: .25rem 0;
    font-size: .92rem;
}
.totales .total-row {
    border-top: 2px solid var(--color-border);
    margin-top: .5rem; padding-top: .65rem;
    font-size: 1.1rem;
}

/* Acciones finales del form */
.form-actions {
    display: flex; justify-content: flex-end; gap: var(--space-3);
    margin-top: var(--space-4);
}

/* ----- Tabla key-value (detalle simple) ----- */
table.kv { width: 100%; }
table.kv td { padding: .3rem .5rem; font-size: .95rem; }
table.kv td.label { color: var(--color-muted); width: 180px; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; }

/* ----- Selector de tipo de comprobante (P/A/B) ----- */
.tipo-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
    margin-top: var(--space-3);
}
@media (max-width: 600px) {
    .tipo-options { grid-template-columns: 1fr; }
}
.tipo-card {
    display: block;
    cursor: pointer;
    margin: 0;
    position: relative;
}
.tipo-card input[type="radio"] {
    position: absolute; opacity: 0; pointer-events: none;
}
.tipo-card-body {
    padding: 1.5rem 1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    text-align: center;
    background: #fff;
    transition: border-color .15s, background .15s, transform .1s;
}
.tipo-card:hover .tipo-card-body {
    border-color: var(--color-primary);
    background: #fdf8f6;
}
.tipo-card input[type="radio"]:checked + .tipo-card-body {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
    box-shadow: 0 0 0 3px rgba(181, 48, 28, .15);
}
.tipo-letra {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1;
    margin-bottom: .35rem;
}
.tipo-label {
    font-size: .92rem;
    color: var(--color-text);
}

/* Filtros — columnas por sección */
.filters-grid-cotizaciones { grid-template-columns: 3fr 1fr 1fr 1fr 1fr auto; }
.filters-grid-ventas       { grid-template-columns: 2fr 1fr 1fr 1fr auto; }
.filters-grid-productos    { grid-template-columns: 3fr 1fr 1fr auto; }
.filters-grid-clientes     { grid-template-columns: 3fr 1fr auto; }
.filters-grid-facturas     { grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto; }
@media (max-width: 1100px) {
    .filters-grid-ventas,
    .filters-grid-productos,
    .filters-grid-clientes { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 600px) {
    .filters-grid-ventas,
    .filters-grid-productos,
    .filters-grid-clientes { grid-template-columns: 1fr 1fr; }
}

/* Grupo de botones en headers de página (alineados a la derecha) */
.btn-group { display: inline-flex; gap: .5rem; flex-wrap: wrap; }

/* Texto descriptivo pequeño */
.small { font-size: .82rem; }

/* Título grande de página (destacado) */
.page-title-big {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--color-text-strong);
    margin: 0 0 .2rem;
    letter-spacing: -.01em;
}

/* ============================================================================
   Buscador destacado (hero search) — para listados principales
   ============================================================================ */
.buscador-hero-form {
    display: block;
    margin-bottom: 1rem;
}
.buscador-hero {
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid var(--color-border);
    border-radius: 10px;
    padding: .3rem 1rem;
    box-shadow: 0 2px 8px rgba(28,28,31,.05);
    transition: border-color .15s, box-shadow .15s;
}
.buscador-hero:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 2px 12px rgba(181,48,28,.15);
}
.buscador-hero-ico {
    width: 22px;
    height: 22px;
    color: var(--color-muted);
    flex-shrink: 0;
    margin-right: .65rem;
}
.buscador-hero:focus-within .buscador-hero-ico { color: var(--color-primary); }
.buscador-hero-input {
    flex: 1;
    border: none !important;
    padding: .75rem .25rem !important;
    font-size: 1.05rem;
    background: transparent;
    outline: none;
    box-shadow: none !important;
}
.buscador-hero-input::placeholder { color: #a3a09a; font-weight: 400; }

.filtros-secundarios {
    display: flex;
    gap: .75rem;
    align-items: end;
    margin-top: .75rem;
    flex-wrap: wrap;
}
.filtros-secundarios label {
    margin: 0;
    min-width: 130px;
}
.filtros-secundarios .btn { align-self: end; margin-bottom: 0; }

/* Alert compacto (menos padding, más discreto) */
.alert-compacto {
    padding: .55rem .9rem;
    font-size: .87rem;
    margin-bottom: 1rem;
}

/* Cliente ancho en tabla */
.col-cliente-ancho {
    min-width: 180px;
    max-width: 260px;
    font-weight: 600;
    color: var(--color-text-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Totales de Proforma (sumatoria automática) */
.totales-proforma {
    margin-top: 1.25rem;
    margin-left: auto;
    max-width: 380px;
    background: linear-gradient(135deg, #faf8f4 0%, #fff 100%);
    border: 2px solid var(--color-primary);
    padding: 1.1rem 1.35rem;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(181,48,28,.06);
}
.totales-proforma > div {
    display: flex;
    justify-content: space-between;
    padding: .35rem 0;
    font-size: 1rem;
    color: var(--color-text);
}
.totales-proforma .total-final {
    border-top: 2px solid var(--color-primary);
    margin-top: .5rem;
    padding-top: .75rem;
    font-size: 1.35rem;
    color: var(--color-primary-dark);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}

/* ============================================================================
   DASHBOARD DE ESTADÍSTICAS
   ============================================================================ */

/* Tabs de período */
.periodo-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.periodo-tabs { display: inline-flex; gap: .25rem; background: var(--color-border-soft); padding: .2rem; border-radius: var(--radius); }
.periodo-tab {
    display: inline-block;
    padding: .4rem .85rem;
    border-radius: var(--radius-sm);
    color: var(--color-muted);
    font-size: .85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .12s, color .12s;
}
.periodo-tab:hover { color: var(--color-text); background: rgba(255,255,255,.5); text-decoration: none; }
.periodo-tab.active { background: var(--color-primary); color: #fff; }
.periodo-tab.active:hover { color: #fff; background: var(--color-primary-hover); }

.periodo-custom { display: flex; gap: .75rem; }
.periodo-custom label { margin-bottom: 0; }
.periodo-custom label span { font-size: .75rem; }
.periodo-custom input { padding: .35rem .5rem; font-size: .85rem; }

/* KPI cards destacadas */
.kpi-grid .kpi-card { padding: 1.1rem 1.25rem; }
.kpi-card .metric { font-size: 1.65rem; margin: .25rem 0; color: var(--color-text-strong); }
.kpi-card-accent { background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%); border-color: var(--color-primary-dark); }
.kpi-card-accent h3 { color: rgba(255,255,255,.85); }
.kpi-card-accent .metric { color: #fff; }
.kpi-card-accent .muted { color: rgba(255,255,255,.75) !important; }

/* Contenedores de gráficos (altura fija para evitar saltos) */
.chart-wrap { position: relative; height: 320px; width: 100%; }
.chart-wrap-sm { height: 240px; }

/* Header de card con acción a la derecha */
.card-head h2 { margin: 0; }

/* ============================================================================
   DASHBOARD HOME
   ============================================================================ */

/* Atajos */
.quick-access {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .75rem;
    margin-top: var(--space-2);
}
.quick-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    padding: 1.1rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--color-text);
    text-decoration: none;
    transition: border-color .12s, background .12s, transform .1s;
}
.quick-card:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
    text-decoration: none;
    transform: translateY(-1px);
}
.quick-icon { font-size: 1.6rem; line-height: 1; color: var(--color-primary); font-weight: 700; }
.quick-label { font-size: .88rem; font-weight: 500; }

/* ----- Autocomplete dropdown ----- */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
    position: absolute;
    top: 100%; left: 0; right: 0;
    z-index: 50;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    max-height: 280px;
    overflow-y: auto;
    margin-top: 2px;
}
.autocomplete-item {
    padding: .5rem .75rem;
    cursor: pointer;
    display: flex; justify-content: space-between; gap: .75rem;
    font-size: .9rem;
    border-bottom: 1px solid var(--color-border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--color-primary-soft); }
.autocomplete-create {
    padding: .55rem .75rem;
    cursor: pointer;
    background: #f0fdf4;
    color: #166534;
    font-size: .9rem;
    border-top: 1px solid #bbf7d0;
}
.autocomplete-create:hover { background: #dcfce7; }

/* ============ Fase 4: Adjuntos + pivot ventas ============ */
.adjunto-uploader {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 1rem;
    background: #f8f7f3;
    border: 1px dashed #d6d1c4;
    border-radius: 6px;
}
.adjunto-file { flex: 1 1 320px; min-width: 240px; }
.adjunto-file input[type="file"] {
    display: block;
    margin-top: .25rem;
    padding: .4rem;
    background: #fff;
    border: 1px solid #d6d1c4;
    border-radius: 4px;
    width: 100%;
}
.asociar-venta-form {
    padding: 1rem;
    background: #fff8f4;
    border: 1px solid #f2d4c1;
    border-radius: 6px;
    margin-bottom: 1rem;
}
.asociar-venta-form .autocomplete-wrap { margin-bottom: .75rem; }

/* ============================================================================
   Cambios v14 — Listado y form de cotizaciones
   ============================================================================ */

/* Row backgrounds (con Facturado nuevo) */
.row-facturado td { background: #FFF7ED; }
.row-pagado td    { background: #F0FDF4; }
.row-aprobado td  { background: #FFF1F2; }
.row-cotizado td  { background: #FEFCE8; }
.row-rechazado td { background: #F5F5F4; color: #6B7280; }

/* Badge Facturado nuevo */
.badge-facturado { background: #FED7AA; color: #9A3412; }

/* Columnas del listado — anchos ajustados */
.th-numero { width: 62px; white-space: nowrap; }
.th-fecha  { width: 82px; white-space: nowrap; }
.th-canal  { width: 44px; text-align: center; padding-left: 2px !important; padding-right: 2px !important; }
.th-estado { width: 130px; }
.th-fact   { width: 130px; white-space: nowrap; }
.th-envio  { width: 92px; text-align: center; padding-left: 6px !important; padding-right: 6px !important; }

/* Íconos de canal — monocromáticos con tooltip */
.canal-icon {
    display: inline-grid;
    place-items: center;
    color: var(--color-muted);
    cursor: help;
    padding: 4px;
    border-radius: 4px;
    position: relative;
    transition: background .15s, color .15s;
}
.canal-icon svg { width: 14px; height: 14px; }
.canal-icon:hover { background: #efece6; color: var(--color-carbon); }
.canal-icon[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-carbon);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    z-index: 10;
}
.canal-icon:hover[data-tip]::after { opacity: 1; }

/* Factura code corto (A-01234 / B-00082 / Presupuesto) */
.no-fact { color: var(--color-muted); font-style: italic; font-size: 12px; }
.fact-code {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: .02em;
}
.fact-a-code { background: #DBEAFE; color: #1E3A8A; }
.fact-b-code { background: #DCFCE7; color: #14532D; }
.fact-p-code {
    background: #F3F4F6;
    color: #4B5563;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* Enviado — pills compactas en una línea */
.env-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}
.env-si     { background: #DBEAFE; color: #1E3A8A; }
.env-no     { background: #FEE2E2; color: #991B1B; }
.env-prepar { background: #FEF3C7; color: #92400E; }

/* Dots leyenda: nuevos */
.dot-orange { background: #F97316; }
.dot-red    { background: #DC2626; }

/* Fila de Costo (bajo cada ítem de cotización) */
.costo-row td {
    padding-top: 2px !important;
    padding-bottom: 6px !important;
    background: #FBFAF7;
    border-bottom: 1px solid var(--color-border);
}
.costo-cell {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding-left: 4px;
}
.costo-label {
    color: var(--color-muted);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.costo-row input {
    max-width: 130px;
    padding: 3px 6px;
    font-size: 12px;
    border: 1px solid var(--color-border);
    background: white;
    color: var(--color-text);
    border-radius: 3px;
}

/* Totales del form de cotización (nuevo bloque automático) */
.totales-final {
    margin-top: 1.25rem;
    padding: 1rem 1.25rem;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: .35rem;
}
.totales-linea {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    color: #7F1D1D;
    font-weight: 600;
}
.totales-linea .val { font-variant-numeric: tabular-nums; font-weight: 700; }
.totales-linea.total-final {
    border-top: 2px dashed #FECACA;
    padding-top: .5rem;
    margin-top: .3rem;
    font-size: 1.05rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.totales-linea.total-final .val { font-size: 1.25rem; }
.totales-override {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .82rem;
    color: var(--color-muted);
    margin-top: .5rem;
    padding-top: .5rem;
    border-top: 1px dashed #FECACA;
}
.totales-override input[type="text"] {
    max-width: 130px;
    padding: 3px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.totales-override input[type="text"]:disabled { background: #f5f3ef; opacity: .5; }

