/* Poppins (SIL Open Font License 1.1) autoalojada: no depende de Google Fonts. */
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Regular.woff') format('woff'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Italic.woff') format('woff'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Medium.woff') format('woff'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Bold.woff') format('woff'); font-weight: 600 700; font-style: normal; font-display: swap; }
/* Interfaz de la plataforma · Alpha Wolf Group */
:root {
  --navy: #1B4699; --navy-d: #12306B; --ink: #1E2430; --txt: #2B2F36; --mut: #6B7280; --line: #E1E5EC; --bg: #F3F5F9; --card: #fff;
  --ok: #2E7D4F; --warn: #D98E04; --bad: #C0392B; --r: 10px;
  font-family: 'Poppins', Arial, Helvetica, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--txt); font-size: 14px; line-height: 1.45; }
a { color: var(--navy); }
h1, h2, h3 { color: var(--ink); margin: 0; }
code { background: #EEF1F6; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--mut); }
.hidden { display: none !important; }

/* ---------- Botones y campos ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #C5CCD8; background: #F8F9FB; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-d); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--mut); padding: 4px 6px; border-radius: 6px; font-size: 15px; line-height: 1; }
.icon-btn:hover { background: #EEF1F6; color: var(--ink); }
.icon-btn.del:hover { color: var(--bad); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 500; color: var(--mut); }
input, select, textarea { font: inherit; font-size: 14px; color: var(--txt); border: 1px solid #D3D9E3; border-radius: 7px; padding: 7px 9px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(27, 70, 153, .25); border-color: var(--navy); }
textarea { resize: vertical; min-height: 64px; }
input[type=checkbox], input[type=radio] { width: auto; }
label.radio, label.chk { flex-direction: row; align-items: center; gap: 8px; color: var(--txt); font-size: 14px; font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px 14px; margin: 0 0 14px; }
legend { font-weight: 600; color: var(--ink); padding: 0 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 12px; }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .span4 { grid-column: 1 / -1; }
.note { padding: 10px 12px; border-radius: 8px; background: #EEF3FB; border: 1px solid #D5E0F3; margin: 10px 0; }
.note.err { background: #FBEDEC; border-color: #F1CBC7; color: #8E2A20; }
.note.ok { background: #EAF5EE; border-color: #C6E3D1; color: #1F5A38; }
.note.warn { background: #FDF5E6; border-color: #F2DDB1; color: #7A5205; }

/* ---------- Acceso ---------- */
body.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px;
  background: radial-gradient(circle at 20% 10%, #E4EAF6, transparent 50%), var(--bg); }
.auth-card { background: #fff; border-radius: 16px; padding: 30px 30px 22px; width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(20, 40, 80, .12); display: flex; flex-direction: column; gap: 12px; }
.auth-card.wide { max-width: 620px; }
.auth-card h1 { font-size: 20px; text-align: center; }
.auth-card > .muted { text-align: center; margin: -6px 0 6px; font-style: italic; }
.auth-logo { height: 96px; align-self: center; }
.auth-card .strip { text-align: center; margin: 8px 0 0; } .auth-card .strip img { max-width: 100%; height: 22px; opacity: .85; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-logo { padding: 20px 18px 14px; display: block; }
.side-logo img { width: 100%; max-width: 170px; }
.side nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
.side nav a { color: var(--txt); text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 500; }
.side nav a:hover { background: #F1F4F9; }
.side nav a.on { background: #E8EDF7; color: var(--navy); }
.side-user { border-top: 1px solid var(--line); padding: 14px 18px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.side-user span { color: var(--mut); margin-bottom: 4px; }
.view { min-width: 0; padding: 26px 30px 60px; }
.view.full { padding: 0; }
.loading { color: var(--mut); padding: 40px; text-align: center; }
.page-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-h h1 { font-size: 22px; }
.page-h .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }

/* ---------- Panel ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat small { color: var(--mut); font-weight: 500; display: block; }
.stat b { font-size: 24px; color: var(--ink); display: block; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--mut); }
.divtiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.divtile { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 12px 10px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; font: inherit; color: var(--txt); }
.divtile:hover { border-color: var(--c, var(--navy)); box-shadow: 0 4px 16px rgba(20, 40, 80, .10); transform: translateY(-1px); }
.divtile img { height: 38px; max-width: 100%; object-fit: contain; }
.divtile small { color: var(--mut); font-size: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.two > .card { margin-top: 0; }

/* ---------- Tablas de listado ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; align-items: end; }
.filters label { min-width: 150px; }
.filters .grow { flex: 1; min-width: 220px; }
.list { width: 100%; border-collapse: collapse; background: #fff; }
.list-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--r); overflow: auto; }
.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--mut); text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #FAFBFD; position: sticky; top: 0; white-space: nowrap; }
.list td { padding: 10px 12px; border-bottom: 1px solid #EEF1F5; vertical-align: middle; white-space: nowrap; }
.list tr.click { cursor: pointer; }
.list tr.click:hover td { background: #F7F9FC; }
.list td.r, .list th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .code { font-weight: 600; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.list .t { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .empty { text-align: center; color: var(--mut); padding: 30px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip.div { background: #F1F3F7; color: var(--ink); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: #EEF1F6; color: var(--mut); text-transform: capitalize; }
.badge.emitido, .badge.enviado { background: #E6EEFB; color: var(--navy); }
.badge.aceptado { background: #E6F4EC; color: var(--ok); }
.badge.rechazado, .badge.anulado { background: #FBEBEA; color: var(--bad); }
.badge.borrador { background: #FDF3E1; color: #9A6200; }

/* ---------- Editor ---------- */
.ed { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.ed-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.ed-bar .ttl { display: flex; flex-direction: column; margin-right: auto; min-width: 0; flex: 1; }
.ed-bar .ttl b { font-size: 16px; color: var(--ink); white-space: nowrap; }
.ed-bar .ttl span { font-size: 12.5px; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-bar select { width: auto; }
#ed-toggle { display: none; }
.ed-bar .dirty { font-size: 12px; color: var(--warn); font-weight: 600; }
.ed-bar .saved { font-size: 12px; color: var(--ok); }
.ed-main { display: grid; grid-template-columns: minmax(420px, 44%) minmax(0, 1fr); min-height: 0; }
.ed-main > * { min-width: 0; }
.ed-form { overflow: auto; padding: 16px 18px 80px; border-right: 1px solid var(--line); }
.ed-prev { overflow: auto; background: #D9DEE6; position: relative; }
.ed-prev .zoomer { transform-origin: top left; }
.measure-stage { position: absolute; left: -10000px; top: 0; visibility: hidden; pointer-events: none; }
.ed-prev .doc-stack { padding: 18px 0; gap: 18px; }
.ed-prev-tools { position: sticky; top: 0; z-index: 2; display: flex; justify-content: flex-end; gap: 6px; padding: 6px 10px; background: rgba(217, 222, 230, .9); backdrop-filter: blur(4px); font-size: 12.5px; color: var(--mut); align-items: center; }
.ed-prev-tools .grow { flex: 1; }
details.sec-ed { background: #fff; border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 10px; }
details.sec-ed > summary { cursor: pointer; padding: 11px 14px; font-weight: 600; color: var(--ink); list-style: none; display: flex; align-items: center; gap: 10px; }
details.sec-ed > summary::-webkit-details-marker { display: none; }
details.sec-ed > summary::before { content: '▸'; color: var(--mut); transition: transform .15s; }
details.sec-ed[open] > summary::before { transform: rotate(90deg); }
details.sec-ed > summary .n { background: var(--navy); color: #fff; border-radius: 5px; font-size: 12px; min-width: 22px; text-align: center; padding: 1px 5px; }
details.sec-ed > summary .cnt { margin-left: auto; font-size: 12px; color: var(--mut); font-weight: 500; }
details.sec-ed > .bd { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.bd h4 { margin: 6px 0 -2px; font-size: 13px; color: var(--navy); }
.hint { font-size: 12.5px; color: var(--mut); margin: 0; }
.rows { overflow-x: auto; }
.rows table { width: 100%; border-collapse: collapse; }
.rows th { font-size: 11.5px; color: var(--mut); font-weight: 600; text-align: left; padding: 3px 4px; white-space: nowrap; }
.rows td { padding: 2px 3px; vertical-align: top; }
.rows td input, .rows td select, .rows td textarea { padding: 5px 7px; font-size: 13px; }
.rows td textarea { min-height: 34px; height: 34px; }
.rows td.act { white-space: nowrap; width: 1%; }
.rows td.idx { color: var(--mut); font-size: 12px; padding-top: 8px; text-align: center; width: 1%; }
.rows td.calc { font-size: 13px; padding-top: 8px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rows tr.titulo td input, .rows tr.titulo td textarea { font-weight: 600; background: #F1F4FA; }
.rows .add { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ph-card { border: 1px solid var(--line); border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 5px; background: #FAFBFD; }
.ph-card .th { aspect-ratio: 1; background: #EEF1F6 center / contain no-repeat; border-radius: 5px; position: relative; }
.ph-card .th b { position: absolute; left: 4px; top: 4px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.ph-card select, .ph-card input { font-size: 12.5px; padding: 4px 6px; }
.ph-card .act { display: flex; justify-content: space-between; }
.drop { border: 2px dashed #C8D0DC; border-radius: 10px; padding: 18px; text-align: center; color: var(--mut); cursor: pointer; }
.drop.over { border-color: var(--navy); background: #EEF3FB; color: var(--navy); }
.mod { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.mod.on { border-color: #C7D3EA; background: #FAFCFF; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; max-width: 320px; margin-left: auto; font-variant-numeric: tabular-nums; }
.totals span:nth-child(odd) { color: var(--mut); text-align: right; }
.totals span:nth-child(even) { text-align: right; font-weight: 500; }
.totals .tt { font-weight: 700 !important; color: var(--ink) !important; font-size: 16px; }

/* ---------- Modal y avisos ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 820px; }
.modal h3 { padding: 16px 20px 0; font-size: 17px; }
.modal .mb { padding: 14px 20px; display: flex; flex-direction: column; gap: 10px; max-height: 64vh; overflow: auto; }
.modal .mf { padding: 12px 20px 16px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 30px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- Vista de impresión ---------- */
body.print-view { background: #D9DEE6; }
.print-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 10px 18px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.print-bar .muted { flex: 1; font-size: 12.5px; }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
  .ed-bar { flex-wrap: wrap; }
  #ed-toggle { display: inline-flex; }
  .ed-main { grid-template-columns: minmax(0, 1fr); }
  .ed-prev { display: none; }
  .ed-main.show-prev .ed-form { display: none; }
  .ed-main.show-prev .ed-prev { display: block; }
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .ed-bar .ttl span { display: none; }
  .ed-bar img { display: none; }
  .ed-form { padding: 12px 10px 80px; }
  .ed-prev { min-height: 70vh; }
  .side { position: static; height: auto; }
  .side nav { flex-direction: row; overflow-x: auto; }
  .side-user { display: none; }
  .view { padding: 16px; }
  .two, .grid3, .grid4 { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
  .ed { height: auto; min-height: 100vh; }
}
@media print { .shell > .side { display: none; } }
