/* ===== Orange SpA · ERP — estilos ===== */
:root {
  --naranjo: #ff7a00;
  --naranjo-osc: #e56e00;
  --naranjo-suave: #fff3e8;
  --tinta: #1d2433;
  --gris: #6b7280;
  --gris-claro: #9aa3b2;
  --linea: #ececef;
  --fondo: #fbfbfc;
  --panel: #ffffff;
  --verde: #128a4a;
  --verde-suave: #edf7f1;
  --rojo: #d23f3f;
  --rojo-suave: #fdeff0;
  --azul: #2563eb;
  --sidebar: #ffffff;
  --sidebar-item: #565f6e;
  --sombra: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--fondo);
  color: var(--tinta);
  line-height: 1.45;
}
#app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
#sidebar {
  width: 244px;
  background: var(--sidebar);
  color: var(--tinta);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  border-right: 1px solid var(--linea);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--naranjo); color: #fff;
  font-weight: 800; font-size: 1.2rem;
  display: grid; place-items: center;
}
.brand-logo.has-img { background: #fff; border: 1px solid var(--linea); }
.brand-logo.has-img img { width: 100%; height: 100%; object-fit: contain; display: block; border-radius: inherit; }
.brand-text strong { display: block; font-size: 1rem; }
.brand-text span { font-size: .75rem; color: var(--gris-claro); letter-spacing: .12em; }
#nav { flex: 1; padding: 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; margin: 2px 0;
  border-radius: 9px; cursor: pointer;
  color: var(--sidebar-item); font-size: .92rem; font-weight: 500;
  user-select: none;
}
.nav-item .ic { display: inline-flex; align-items: center; justify-content: center; width: 20px; color: var(--gris-claro); }
.nav-item:hover { background: #f6f7f8; color: var(--tinta); }
.nav-item:hover .ic { color: var(--gris); }
.nav-item.activo { background: var(--naranjo-suave); color: var(--naranjo-osc); font-weight: 600; }
.nav-item.activo .ic { color: var(--naranjo); }
.sidebar-foot { padding: 14px 18px; font-size: .72rem; color: var(--gris-claro); border-top: 1px solid var(--linea); }
.ic-svg { display: inline-block; }

/* ===== Main ===== */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  height: 64px; background: var(--panel);
  border-bottom: 1px solid var(--linea);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 5;
}
#topbar h1 { font-size: 1.25rem; margin: 0; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: .85rem; color: var(--gris); }
.user-chip { background: var(--naranjo-suave); color: var(--naranjo-osc); padding: 6px 12px; border-radius: 999px; font-weight: 600; }

/* Accesos rápidos en la barra superior */
#quick-access { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: center; margin: 0 16px; overflow-x: auto; }
#quick-access::-webkit-scrollbar { height: 0; }
.qa-btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border: 1px solid var(--linea); background: #fff; border-radius: 9px; font-size: .82rem; font-weight: 600; color: var(--tinta); cursor: pointer; white-space: nowrap; }
.qa-btn:hover { background: #f6f7f8; }
.qa-btn.activo { background: var(--naranjo-suave); border-color: var(--naranjo); color: var(--naranjo-osc); }
.qa-btn .ic-svg { flex: none; }
@media (max-width: 900px) { #quick-access .qa-btn span { display: none; } #topbar h1 { display: none; } }

#vista { padding: 28px; }

/* ===== Tarjetas / paneles ===== */
.card { background: var(--panel); border: 1px solid var(--linea); border-radius: 14px; box-shadow: var(--sombra); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--linea); }
.card-head h3 { margin: 0; font-size: 1.02rem; }

/* ===== Stats (dashboard) ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
@media (max-width: 1000px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--panel); border: 1px solid var(--linea); border-radius: 14px; padding: 18px; box-shadow: var(--sombra); }
.stat .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--naranjo); background: var(--naranjo-suave); margin-bottom: 12px; }
.stat .lbl { color: var(--gris); font-size: .82rem; }
.stat .val { font-size: 1.7rem; font-weight: 700; margin-top: 2px; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .cols-2 { grid-template-columns: 1fr; } }

/* ===== Tablas ===== */
.tabla-wrap { overflow-x: auto; }
table.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.tabla th { text-align: left; color: var(--gris); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 12px 16px; border-bottom: 1px solid var(--linea); white-space: nowrap; }
table.tabla td { padding: 12px 16px; border-bottom: 1px solid var(--linea); }
table.tabla tr:last-child td { border-bottom: none; }
table.tabla tbody tr:hover { background: #fafbfc; }
.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--gris); }
.vacio { text-align: center; color: var(--gris); padding: 36px 0; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.badge.ok { background: var(--verde-suave); color: var(--verde); }
.badge.warn { background: #fff4e0; color: #b26a00; }
.badge.bad { background: var(--rojo-suave); color: var(--rojo); }
.badge.info { background: #e8f0fe; color: var(--azul); }

/* ===== Botones ===== */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 10px 16px; font-size: .9rem; font-weight: 600; border: 1px solid var(--linea); border-radius: 9px; background: var(--panel); color: var(--tinta); cursor: pointer; }
.btn:hover { background: #f7f8fa; }
.btn.primary { background: var(--naranjo); border-color: var(--naranjo); color: #fff; }
.btn.primary:hover { background: var(--naranjo-osc); }
.btn.sm { padding: 6px 10px; font-size: .82rem; }
.btn.danger { color: var(--rojo); border-color: #f1c9c9; }
.btn.danger:hover { background: var(--rojo-suave); }
.btn.icon { padding: 6px 9px; }

/* ===== Formularios ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: .82rem; color: var(--gris); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; font-size: .95rem;
  border: 1px solid var(--linea); border-radius: 9px; background: #fff; color: var(--tinta);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--naranjo); border-color: var(--naranjo); }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border-radius: 16px; width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(16,24,40,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--linea); }
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--linea); }
.x-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--gris); line-height: 1; }

/* ===== Toast ===== */
#toast-root { position: fixed; bottom: 24px; right: 24px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--tinta); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: .9rem; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: toastIn .2s ease; }
.toast.ok { background: var(--verde); }
.toast.bad { background: var(--rojo); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Utilidades ===== */
.row-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.row-head h2 { margin: 0; font-size: 1.1rem; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { padding: 9px 12px; border: 1px solid var(--linea); border-radius: 9px; min-width: 220px; font-size: .9rem; }
.hint { font-size: .8rem; color: var(--gris); }
.mb-0 { margin-bottom: 0; }
.mt-16 { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid-2, .form-grid { grid-template-columns: 1fr; } }

/* ===== Documento de cotización (imprimible / PDF) ===== */
#cotiza-print { display: none; }
#cotiza-print.activo { display: block; position: fixed; inset: 0; background: #e9edf2; overflow: auto; z-index: 100; }
.print-bar { position: sticky; top: 0; display: flex; justify-content: space-between; gap: 14px; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--linea); z-index: 2; }
.doc {
  background: #fff; width: 210mm; max-width: 100%; min-height: 296mm;
  margin: 24px auto; padding: 20mm 18mm; box-shadow: 0 6px 30px rgba(16,24,40,.16);
  color: #1d2433; font-size: 12.5px; position: relative;
}
.doc-band { position: absolute; top: 0; left: 0; right: 0; height: 8px; background: linear-gradient(90deg, var(--naranjo), #ffb066); }
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding: 10px 0 18px; margin-bottom: 20px; border-bottom: 2px solid var(--linea); }
.doc-empresa { display: flex; gap: 16px; align-items: flex-start; }
.doc-logo { max-height: 112px; max-width: 280px; object-fit: contain; }
.doc-logo-txt { font-size: 1.5rem; font-weight: 800; color: var(--naranjo); }
.doc-empresa-datos { font-size: 11.5px; line-height: 1.55; color: #555; }
.doc-empresa-datos strong { font-size: 15px; color: #1d2433; display: block; margin-bottom: 3px; }
.doc-num { text-align: right; min-width: 200px; }
.doc-num-t { font-size: 11px; letter-spacing: .16em; color: var(--gris); font-weight: 600; }
.doc-num-n { font-size: 1.6rem; font-weight: 800; color: var(--naranjo-osc); margin: 2px 0 8px; }
.doc-meta { margin-left: auto; border-collapse: collapse; font-size: 11.5px; }
.doc-meta td { padding: 3px 0 3px 14px; text-align: right; }
.doc-meta td:first-child { color: var(--gris); }
.doc-box { border: 1px solid var(--linea); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; }
.doc-cliente { background: #fafbfc; }
.doc-box-t { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--naranjo-osc); font-weight: 700; margin-bottom: 8px; }
.doc-kv { font-size: 12px; line-height: 1.65; }
.doc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 24px; }
.doc-cols .full { grid-column: 1 / -1; }
table.doc-items { width: 100%; border-collapse: collapse; margin: 8px 0 18px; font-size: 12px; }
table.doc-items thead th { background: #33363d; color: #fff; text-align: left; padding: 10px 12px; font-weight: 600; }
table.doc-items thead th.n { text-align: right; }
table.doc-items thead th.c { text-align: center; width: 34px; }
table.doc-items td { padding: 9px 12px; border-bottom: 1px solid var(--linea); }
table.doc-items td.c { text-align: center; color: var(--gris); }
table.doc-items tbody tr:nth-child(even) { background: #f6f7f9; }
.doc-foot { display: flex; gap: 24px; align-items: flex-start; }
.doc-foot-left { flex: 1; }
.doc-foot-right { width: 290px; flex-shrink: 0; }
table.doc-tot { width: 100%; border-collapse: collapse; font-size: 12.5px; border: 1px solid var(--linea); border-radius: 10px; overflow: hidden; }
table.doc-tot td { padding: 8px 14px; border-bottom: 1px solid var(--linea); }
table.doc-tot td:first-child { color: #444; }
table.doc-tot tr.doc-total td { font-size: 1.2rem; font-weight: 800; color: #fff; background: #33363d; border-bottom: none; }
.doc-nota { font-size: 10.5px; color: var(--gris); margin-top: 8px; text-align: right; line-height: 1.4; }
.doc-terms { font-size: 10.5px; color: var(--gris); margin-top: 26px; padding-top: 12px; border-top: 1px solid var(--linea); line-height: 1.5; }
.doc-gracias { text-align: center; color: var(--naranjo-osc); font-weight: 600; font-size: 12px; margin-top: 14px; }
@media (max-width: 760px) { .doc { padding: 24px; width: 100%; min-height: 0; } .doc-header, .doc-foot { flex-direction: column; } .doc-foot-right { width: 100%; } .doc-cols { grid-template-columns: 1fr; } }

/* ===== Documento formato Orange SpA / Facto ===== */
.doc.facto { font-size: 12px; padding: 14mm; }
.fac-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.fac-emp { display: flex; gap: 12px; align-items: flex-start; }
.fac-logo { max-height: 74px; max-width: 130px; object-fit: contain; }
.doc.facto { --fac-primary: #2b82b8; --fac-text: #ffffff; --fac-rut: #c82828; }
.fac-nombre { font-size: 1.3rem; font-weight: 800; color: var(--fac-primary); }
.fac-giro { font-size: 10.5px; color: #333; }
.fac-line { font-size: 10.5px; color: #555; }
.fac-rut { border: 1.5px solid var(--fac-rut); color: var(--fac-rut); border-radius: 3px; padding: 8px 16px; text-align: center; min-width: 150px; line-height: 1.4; }
.fac-rut-t { font-weight: 800; font-size: 1rem; }
.fac-rut-n { font-weight: 800; font-size: 1rem; }
table.fac-cli { width: 100%; border-collapse: collapse; font-size: 11.5px; margin-bottom: 10px; }
table.fac-cli td { border: 1px solid var(--linea); padding: 5px 9px; }
table.fac-cli td.lb { font-weight: 700; background: #eef0f3; width: 108px; white-space: nowrap; }
table.fac-items { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.fac-items th { background: var(--fac-primary); color: var(--fac-text); padding: 7px 9px; text-align: left; font-weight: 600; }
table.fac-items th.c { text-align: center; }
table.fac-items th.n { text-align: right; }
table.fac-items td { border: 1px solid var(--linea); padding: 6px 9px; }
table.fac-items td.c { text-align: center; }
table.fac-items td.n { text-align: right; }
.fac-item-foto { height: 42px; width: 42px; object-fit: cover; border-radius: 5px; border: 1px solid var(--linea); vertical-align: middle; }
.fac-foot { display: flex; gap: 16px; align-items: stretch; margin-top: 14px; }
.fac-transf { flex: 1; border: 1px solid var(--linea); border-radius: 4px; padding: 8px 11px; font-size: 10px; color: #000; line-height: 1.32; }
.fac-transf b { color: #000; display: block; margin-bottom: 3px; font-size: 10.5px; }
.fac-tot { width: 250px; flex-shrink: 0; }
.fac-tot table { width: 100%; border-collapse: collapse; font-size: 12px; }
.fac-tot td { border: 1px solid var(--linea); padding: 7px 11px; }
.fac-tot td.n { text-align: right; }
.fac-tot tr.fac-total td { background: var(--fac-primary); color: var(--fac-text); font-weight: 800; font-size: 1.1rem; }
.fac-transf-body { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 16px; }
.fac-transf-body div { margin: 0; }
.fac-obs { flex: 1; border: 1px solid var(--linea); border-radius: 4px; padding: 10px 12px; font-size: 11px; color: #000; line-height: 1.5; }
.fac-obs b { color: #000; display: block; margin-bottom: 4px; }
.fac-foot2 { display: flex; gap: 16px; align-items: stretch; margin-top: 14px; }
.fac-foot2 .fac-transf { flex: 1; }
.fac-firma { width: 240px; flex-shrink: 0; text-align: center; align-self: flex-end; }
.fac-firma-img { max-height: 60px; max-width: 210px; object-fit: contain; display: block; margin: 0 auto 2px; }
.fac-firma-linea { border-top: 1px solid #999; margin-top: 6px; }
.fac-firma-nom { font-weight: 700; margin-top: 5px; font-size: 12px; }
.fac-firma-lbl { font-size: 10.5px; color: #000; }
@media (max-width: 760px) { .fac-head, .fac-foot, .fac-foot2 { flex-direction: column; } .fac-tot, .fac-firma { width: 100%; } }
@media print { table.fac-items th, .fac-tot tr.fac-total td { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

@page { size: A4; margin: 12mm; }
@media print {
  #app, #modal-root, #toast-root, .no-print { display: none !important; }
  #cotiza-print.activo { position: static; background: #fff; overflow: visible; }
  .doc { box-shadow: none; margin: 0; width: 100%; min-height: 0; padding: 0; }
  table.doc-items thead th, table.doc-tot tr.doc-total td, .doc-band {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  table.doc-items tr, .doc-box { page-break-inside: avoid; }
}

/* ===== Pantalla de login ===== */
#login-root:empty { display: none; }
.login-overlay { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: linear-gradient(160deg, #ffffff 0%, #fff4e9 100%); padding: 20px; }
.login-card { background: #fff; border: 1px solid var(--linea); border-radius: 16px; padding: 34px 30px; width: 100%; max-width: 380px;
  box-shadow: 0 10px 40px rgba(16,24,40,.08); text-align: center; }
.login-logo { width: 60px; height: 60px; border-radius: 15px; background: var(--naranjo); color: #fff;
  font-weight: 800; font-size: 1.9rem; display: grid; place-items: center; margin: 0 auto 14px; }
.login-logo.has-img { background: #fff; border: 1px solid var(--linea); }
.login-logo.has-img img { width: 100%; height: 100%; object-fit: contain; display: block; border-radius: inherit; }
.login-card h1 { font-size: 1.35rem; margin: 0; }
.login-sub { color: var(--gris); margin: 2px 0 22px; letter-spacing: .14em; text-transform: uppercase; font-size: .78rem; }
.login-card .field { text-align: left; margin-bottom: 14px; }
.login-card .field label { display: block; font-size: .82rem; color: var(--gris); margin-bottom: 5px; }
.login-card .field input { width: 100%; padding: 11px 12px; font-size: 1rem; border: 1px solid var(--linea); border-radius: 9px; }
.login-card .field input:focus { outline: 2px solid var(--naranjo); border-color: var(--naranjo); }
.login-error { color: var(--rojo); font-size: .85rem; min-height: 18px; margin-bottom: 8px; text-align: left; }
.login-hint { margin-top: 16px; font-size: .78rem; color: var(--gris); }
