/* Sistema de Presupuestos y OC — Metal Diseño Chile SpA */

:root {
    --acero: #161616;
    --acero-2: #333333;
    --acento: #d40000;
    --fondo: #f2f4f7;
    --tarjeta: #ffffff;
    --borde: #d8dee5;
    --texto: #1d2329;
    --tenue: #66717d;
    --ok: #1e7e4a;
    --ok-fondo: #e3f4ea;
    --error: #b3261e;
    --error-fondo: #fbe7e6;
    --aviso: #8a5a00;
    --aviso-fondo: #fff4d6;
    --info-fondo: #e7eff8;
    --radio: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--texto);
    background: var(--fondo);
}

a { color: var(--acero-2); }
h1 { font-size: 1.5rem; margin: 0 0 .2rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; }
.tarjeta > h2:first-child { margin-top: 0; }
h3 { font-size: .95rem; margin: .4rem 0; }
p { margin: .3rem 0 .8rem; }

/* ---------- Barra superior ---------- */
.barra {
    display: flex; align-items: center; gap: 1.5rem;
    background: var(--acero); color: #fff;
    padding: 0 1.25rem; height: 56px;
    position: sticky; top: 0; z-index: 10;
}
.marca { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-weight: 700; }
.menu { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.menu a { color: #c9d3dd; text-decoration: none; padding: .45rem .75rem; border-radius: 6px; white-space: nowrap; }
.menu a:hover { color: #fff; background: rgba(255,255,255,.08); }
.menu a.activo { color: #fff; background: rgba(255,255,255,.14); }
.cuenta { display: flex; align-items: center; gap: .9rem; }
.cuenta a, .cuenta .btn-link { color: #c9d3dd; }
.cuenta form { margin: 0; }

.contenedor { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.encabezado {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
    margin-bottom: 1rem; flex-wrap: wrap;
}

.tarjeta {
    background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio);
    padding: 1.1rem 1.25rem; margin-bottom: 1rem;
}
.tarjeta.angosta { max-width: 520px; }

.tenue { color: var(--tenue); }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }

/* ---------- Formularios ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 600; color: #3a444e; margin-bottom: .9rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
input, select, textarea {
    font: inherit; font-weight: 400; color: var(--texto);
    padding: .5rem .6rem; border: 1px solid #c3ccd5; border-radius: 6px; background: #fff;
    width: 100%;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8fb3d9; outline-offset: 0; border-color: #6d97c4; }
textarea { resize: vertical; }
.error { color: var(--error); font-weight: 500; font-size: .82rem; }
.enlace-chico { font-size: .82rem; font-weight: 500; }
.enlace-bajo-campo { display: inline-block; margin: -.6rem 0 .9rem; }

.grilla-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.grilla-2 > .tarjeta { margin-bottom: 1rem; }
.grilla-cab { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); gap: 0 1rem; }
.grilla-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.grilla-3 .span-2 { grid-column: span 2; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    font: inherit; font-weight: 600; font-size: .9rem;
    padding: .5rem .95rem; border-radius: 6px; cursor: pointer;
    border: 1px solid #b9c3cd; background: #fff; color: var(--texto); text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: #f1f4f7; }
.btn-primario { background: var(--acero); border-color: var(--acero); color: #fff; }
.btn-primario:hover { background: var(--acero-2); }
.btn-peligro { background: #fff; border-color: var(--error); color: var(--error); }
.btn-peligro:hover { background: var(--error-fondo); }
.btn-bloque { width: 100%; }
.btn-grande { padding: .7rem 1.3rem; font-size: 1rem; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--acero-2); text-decoration: underline; cursor: pointer; }

.barra-acciones { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-start; margin-bottom: 1rem; }
.en-linea { display: flex; gap: .4rem; margin: 0; }
.en-linea select { width: auto; }
details.anular summary { list-style: none; }
details.anular summary::-webkit-details-marker { display: none; }
details.anular[open] .tarjeta { position: absolute; z-index: 5; margin-top: .4rem; width: min(420px, 90vw); box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.acciones-form { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- Alertas ---------- */
.alerta { padding: .7rem 1rem; border-radius: var(--radio); margin-bottom: 1rem; border: 1px solid transparent; }
.alerta-ok { background: var(--ok-fondo); color: var(--ok); border-color: #b9e2c9; }
.alerta-error { background: var(--error-fondo); color: var(--error); border-color: #f1c0bd; }
.alerta-aviso { background: var(--aviso-fondo); color: var(--aviso); border-color: #f0dc9e; }

.aviso-folio {
    display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    background: var(--info-fondo); border: 1px solid #c6d7ea; border-radius: var(--radio);
    padding: .65rem 1rem; margin-bottom: 1rem;
}
.aviso-folio [data-editando].hay { color: var(--aviso); font-weight: 600; }

/* ---------- Tablas ---------- */
.tabla-contenedor { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; background: #fff; }
.tabla-contenedor > .tabla { border: 1px solid var(--borde); border-radius: var(--radio); }
.tabla th, .tabla td { padding: .55rem .7rem; border-bottom: 1px solid #e6eaef; text-align: left; vertical-align: top; }
.tabla th { background: #f7f9fb; font-size: .82rem; text-transform: uppercase; letter-spacing: .02em; color: #4d5864; }
.tabla th a { color: inherit; text-decoration: none; }
.tabla tbody tr:hover { background: #fafbfc; }
.tabla .num { text-align: right; }
.tabla .acciones a { margin-left: .6rem; }
.tabla .vacio { text-align: center; color: var(--tenue); padding: 2rem; }
.tabla tr.anulado td { color: #99a2ab; }
.tabla tr.anulado td a strong { text-decoration: line-through; }
.tabla tr.inactivo td { color: #99a2ab; }

.etiqueta { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; vertical-align: middle; }
.etiqueta-vigente  { background: var(--info-fondo); color: #24527f; }
.etiqueta-aceptado { background: var(--ok-fondo); color: var(--ok); }
.etiqueta-rechazado { background: #eceff2; color: #59636d; }
.etiqueta-anulado, .etiqueta-anulada { background: var(--error-fondo); color: var(--error); }
.etiqueta-emitida  { background: var(--info-fondo); color: #24527f; }
.etiqueta-recibida { background: var(--ok-fondo); color: var(--ok); }
.etiqueta-dcto { background: var(--acento); color: #fff; }

/* Ítems del documento */
.tabla-items td { padding: .35rem .4rem; vertical-align: middle; }
.tabla-items input, .tabla-items textarea { padding: .4rem .45rem; }
.tabla-items textarea { min-height: 2.3rem; }
.col-n { width: 2.2rem; text-align: center; color: var(--tenue); }
.col-cant { width: 6.5rem; }
.col-un { width: 5.5rem; }
.col-precio { width: 8.5rem; }
.col-desc { width: 5.5rem; }
.col-sub { width: 8.5rem; }
.col-x { width: 2.4rem; text-align: center; }
.tabla-items td:nth-child(3) input, .tabla-items td:nth-child(5) input, .tabla-items td:nth-child(6) input { text-align: right; }
.btn-quitar { border: 0; background: none; font-size: 1.3rem; line-height: 1; color: #98a2ac; cursor: pointer; padding: .2rem .4rem; border-radius: 4px; }
.btn-quitar:hover { color: var(--error); background: var(--error-fondo); }
#agregar-item { margin-top: .6rem; }

.pie-documento { display: flex; gap: 2rem; justify-content: space-between; align-items: flex-start; margin-top: 1.2rem; flex-wrap: wrap; }
.pie-textos { flex: 1; min-width: 260px; }
.totales { border-collapse: collapse; min-width: 260px; }
.totales th, .totales td { padding: .35rem .6rem; text-align: right; }
.totales th { font-weight: 500; color: var(--tenue); }
.totales td { font-variant-numeric: tabular-nums; white-space: nowrap; }
.totales .total th, .totales .total td { border-top: 2px solid var(--acero); font-size: 1.15rem; font-weight: 700; color: var(--acero); }

/* ---------- Filtros ---------- */
.filtros { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 .9rem; align-items: end; }
.filtros label { margin-bottom: .7rem; }
.filtros .ancho { grid-column: span 2; }
.filtros-botones { display: flex; align-items: center; gap: .8rem; margin-bottom: .7rem; }
.filtros-simple { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; max-width: 640px; }

.paginacion { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .8rem; }
.paginacion a, .paginacion span { padding: .35rem .7rem; border: 1px solid var(--borde); border-radius: 6px; background: #fff; text-decoration: none; }
.paginacion .actual { background: var(--acero); color: #fff; border-color: var(--acero); }

.historial ul { margin: .6rem 0 0; padding-left: 1.2rem; }
.historial li { margin-bottom: .3rem; }

/* ---------- Login ---------- */
.fondo-login { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(160deg, #000, #2a2a2a); padding: 1rem; }
.logo-login { width: 100%; max-width: 300px; height: auto; background: #111; padding: .8rem 1rem; border-radius: 8px; }
.login { background: #fff; border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); text-align: center; }
.login h1 { justify-content: center; margin-top: .6rem; }
.login .sub { color: var(--tenue); margin-bottom: 1.4rem; }
.login form { text-align: left; }

.error-pagina { max-width: 560px; margin: 3rem auto; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .grilla-2, .grilla-cab, .grilla-3 { grid-template-columns: minmax(0, 1fr); }
    .grilla-3 .span-2 { grid-column: span 1; }
    .filtros .ancho { grid-column: span 1; }
    .barra { height: auto; flex-wrap: wrap; padding: .6rem 1rem; gap: .5rem 1rem; }
    .menu { order: 3; width: 100%; }
    .contenedor { padding: 1rem; }
}

/* ---------- Revisiones y descuentos ---------- */
.revision { display: inline-block; margin-left: .3rem; padding: 0 .4rem; border-radius: 4px; background: var(--acento); color: #fff; font-size: .75rem; font-weight: 700; vertical-align: middle; }
.dcto-chico { color: var(--acento); font-size: .78rem; font-weight: 700; }
.totales .fila-dcto th, .totales .fila-dcto td { color: var(--acento); font-weight: 700; background: #fff0f0; }
.dcto-general { flex-direction: row; align-items: center; justify-content: flex-end; gap: .35rem; margin: 0; font-weight: 500; color: var(--tenue); font-size: inherit; }
.dcto-general input { width: 4.2rem; text-align: right; padding: .3rem .4rem; }
.aviso-dcto { margin-top: .6rem; padding: .5rem .8rem; border: 2px solid var(--acento); border-radius: 6px; background: #fff0f0; color: var(--acento); text-align: right; }
.tabla-items tr.con-dcto td:nth-child(6) input { border-color: var(--acento); color: var(--acento); font-weight: 700; }
.marca img { display: block; height: 30px; width: auto; }

/* ---------- Eliminar e importar clientes/proveedores ---------- */
.col-check { width: 2.2rem; text-align: center; }
.col-check input { width: 1rem; height: 1rem; }
.en-linea-texto { display: inline; margin: 0 0 0 .6rem; }
.texto-peligro { color: var(--error); }
.pie-listado { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: .6rem; }
.pie-listado p { margin: 0; }
.resumen-importacion { display: flex; gap: .5rem; flex-wrap: wrap; margin: .6rem 0 1rem; }
.confirmar-importacion { border-top: 1px solid var(--borde); padding-top: 1rem; display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; }
.confirmar-importacion p { margin: 0 0 .4rem; }
.etiqueta-imp-nuevo { background: var(--ok-fondo); color: var(--ok); }
.etiqueta-imp-existe { background: var(--info-fondo); color: #24527f; }
.etiqueta-imp-repetido { background: #eceff2; color: #59636d; }
.etiqueta-imp-error { background: var(--error-fondo); color: var(--error); }
.tabla tr.imp-error td { background: #fff7f7; }
.columna-login { width: 100%; max-width: 460px; }
.login-ancho { max-width: 460px; }

/* ---------- Cliente sin registrar y facturación ---------- */
.estado-cp { font-size: .8rem; font-weight: 500; }
.estado-cp.registrado { color: var(--ok); }
.estado-cp.libre { color: var(--aviso); }
.facturacion-resumen { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.barra-avance { flex: 1; min-width: 200px; height: .7rem; background: #e9edf1; border-radius: 999px; overflow: hidden; }
.barra-avance span { display: block; height: 100%; background: var(--ok); }
.form-factura { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 0 .8rem; align-items: end; border-top: 1px solid var(--borde); padding-top: 1rem; margin-top: 1rem; }
.form-factura label { margin-bottom: .5rem; }
.form-factura .atajos { display: flex; gap: .3rem; margin-top: .25rem; }
.form-factura .atajos button { font-size: .75rem; padding: .15rem .45rem; }
.form-factura .btn-primario { margin-bottom: .5rem; }
.etiqueta-fact-parcial { background: var(--aviso-fondo); color: var(--aviso); }
.etiqueta-fact-completa { background: var(--ok-fondo); color: var(--ok); }
@media (max-width: 860px) { .form-factura { grid-template-columns: minmax(0, 1fr); } }
