/* =========================================================
   Intratecbol — Facturación en línea SIAT (DEMO)
   ========================================================= */
:root {
  --navy: #00033c;
  --navy-2: #0a1052;
  --blue: #2563eb;
  --blue-2: #38bdf8;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --bg: #060b1a;
  --card: rgba(17, 27, 53, 0.72);
  --card-2: rgba(20, 31, 60, 0.6);
  --border: rgba(96, 130, 210, 0.16);
  --border-soft: rgba(255, 255, 255, 0.08);
  --text: #eaf0fb;
  --muted: #8fa0c4;
  --muted-2: #5d6b8c;
  --radius: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 600px at 80% -10%, rgba(37, 99, 235, 0.16), transparent 60%),
    linear-gradient(160deg, #0a1430, #070d1f 60%, var(--bg));
  min-height: 100vh; -webkit-font-smoothing: antialiased;
}

.fa-top {
  display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  border-bottom: 1px solid var(--border); background: rgba(10, 17, 38, 0.7); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
}
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: .88rem; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; }
.back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.back:hover { color: var(--text); background: rgba(56, 189, 248, 0.08); }
.fa-logo { height: 28px; }
.fa-title { font-family: "Sora", sans-serif; font-weight: 700; font-size: 1.1rem; }
.fa-pill { margin-left: auto; color: var(--amber); font-size: .8rem; font-weight: 600; border: 1px solid rgba(245, 158, 11, 0.35); background: rgba(245, 158, 11, 0.1); padding: 6px 12px; border-radius: 20px; }

.fa-body { display: grid; grid-template-columns: 400px 1fr; gap: 22px; padding: 22px; align-items: start; }

/* Formulario */
.form-panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; backdrop-filter: blur(8px); }
.form-panel > h2 { font-family: "Sora", sans-serif; font-size: 1.2rem; margin-bottom: 16px; }
.fieldset { margin-bottom: 18px; }
.fieldset h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--blue-2); margin-bottom: 10px; }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; color: var(--muted); margin-bottom: 10px; }
input, select { padding: 10px 12px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--border); color: var(--text); font-size: .92rem; font-family: inherit; }
input:focus, select:focus { outline: none; border-color: var(--blue); }
select option { background: #0d1730; }

#rows { display: flex; flex-direction: column; gap: 8px; }
.rows-head { display: grid; grid-template-columns: 1fr 54px 80px 26px; gap: 8px; font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted-2); padding: 0 2px; }
.item-row { display: grid; grid-template-columns: 1fr 54px 80px 26px; gap: 8px; align-items: center; }
.item-row input { width: 100%; }
.item-row .x { width: 26px; height: 38px; border-radius: 9px; border: 1px solid var(--border); background: var(--card-2); color: var(--muted-2); cursor: pointer; }
.item-row .x:hover { color: var(--red); border-color: var(--red); }
.add-row { margin-top: 10px; width: 100%; padding: 10px; border-radius: 10px; border: 1px dashed var(--border); background: transparent; color: var(--blue-2); cursor: pointer; font-weight: 600; font-size: .85rem; }
.add-row:hover { background: rgba(56, 189, 248, 0.08); }

.emit-btn {
  width: 100%; margin-top: 6px; padding: 15px; border-radius: 13px; border: 0; cursor: pointer;
  font-family: "Sora", sans-serif; font-weight: 700; font-size: 1.02rem; color: #fff;
  background: linear-gradient(100deg, #38bdf8, #2563eb); box-shadow: 0 14px 30px -12px rgba(37, 99, 235, 0.9);
  transition: transform .15s, filter .2s;
}
.emit-btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.08); }
.emit-btn:disabled { opacity: .5; cursor: not-allowed; }
.form-note { color: var(--muted-2); font-size: .76rem; text-align: center; margin-top: 10px; }

/* Vista previa */
.preview { position: sticky; top: 90px; }
.invoice {
  position: relative; background: #fff; color: #1a2238; border-radius: 12px; overflow: hidden;
  padding: 0 0 16px; box-shadow: 0 30px 60px -25px rgba(0, 0, 0, 0.6); font-size: .82rem; max-width: 720px;
}
.inv-state {
  position: absolute; top: 14px; right: 50%; transform: translateX(50%) rotate(-8deg);
  font-family: "Sora", sans-serif; font-weight: 800; font-size: 2.2rem; letter-spacing: .1em;
  color: rgba(120, 134, 170, 0.18); pointer-events: none; z-index: 1; white-space: nowrap;
}
.invoice.emitida .inv-state { color: rgba(22, 163, 74, 0.16); }

.inv-head { display: grid; grid-template-columns: 1fr 230px; gap: 14px; padding: 18px 20px 12px; }
.inv-emisor img { height: 26px; margin-bottom: 8px; filter: brightness(0) saturate(100%) invert(8%) sepia(60%) saturate(3500%) hue-rotate(230deg); }
.inv-razon { font-family: "Sora", sans-serif; font-weight: 800; font-size: 1rem; color: var(--navy); }
.inv-emisor p { font-size: .74rem; color: #4a5673; line-height: 1.5; }
.inv-box { border: 1.5px solid var(--navy); border-radius: 10px; padding: 10px 12px; text-align: center; }
.inv-nit { font-size: .66rem; color: #6b7896; }
.inv-nit-num { font-family: "Sora", sans-serif; font-weight: 800; font-size: 1rem; color: var(--navy); margin-bottom: 4px; }
.inv-fac { font-size: .66rem; color: #6b7896; }
.inv-fac-num { font-family: "Sora", sans-serif; font-weight: 800; font-size: .95rem; color: var(--navy); margin-bottom: 6px; }
.inv-cuf-l { font-size: .6rem; color: #6b7896; }
.inv-cuf { font-size: .58rem; word-break: break-all; color: #1a2238; line-height: 1.3; }

.inv-modal { background: var(--navy); color: #fff; text-align: center; font-weight: 700; font-size: .78rem; letter-spacing: .04em; padding: 7px; }

.inv-client { display: flex; flex-wrap: wrap; gap: 4px 22px; padding: 12px 20px; border-bottom: 1px dashed #c7d2e0; }
.inv-client div { font-size: .78rem; color: #4a5673; }
.inv-client .full { flex-basis: 100%; }
.inv-client b { color: #1a2238; }

.inv-items { width: 100%; border-collapse: collapse; }
.inv-items th { text-align: left; font-size: .66rem; text-transform: uppercase; color: #6b7896; padding: 8px 10px; border-bottom: 1px solid #e2e8f0; }
.inv-items td { padding: 7px 10px; font-size: .78rem; border-bottom: 1px solid #f1f4f9; vertical-align: top; }
.inv-items th:first-child, .inv-items td:first-child { padding-left: 20px; }
.inv-items th:last-child, .inv-items td:last-child { padding-right: 20px; }
.inv-items th:nth-child(1), .inv-items td:nth-child(1) { width: 42px; white-space: nowrap; }
.inv-items th:nth-child(2), .inv-items td:nth-child(2) { width: 46px; white-space: nowrap; color: #6b7896; }
.inv-items .r { text-align: right; white-space: nowrap; }

.inv-totals { padding: 10px 20px 4px; }
.inv-totals div { display: flex; justify-content: flex-end; gap: 16px; padding: 2px 0; color: #4a5673; font-size: .82rem; }
.inv-totals b { min-width: 90px; text-align: right; }
.inv-total { color: #1a2238; font-family: "Sora", sans-serif; font-size: 1.1rem; font-weight: 800; border-top: 1px solid #e2e8f0; margin-top: 4px; padding-top: 6px; }
.inv-total b { font-size: 1.2rem; }

.inv-literal { padding: 6px 20px 10px; font-size: .74rem; color: #1a2238; font-weight: 600; }

.inv-foot { display: grid; grid-template-columns: 110px 1fr; gap: 14px; padding: 12px 20px 0; border-top: 1px dashed #c7d2e0; align-items: start; }
.inv-qr { width: 100px; height: 100px; background: #fff; }
.inv-qr svg { width: 100%; height: 100%; }
.inv-qr.empty { border: 1px dashed #c7d2e0; border-radius: 8px; display: grid; place-items: center; color: #aab4c8; font-size: .66rem; text-align: center; }
.inv-foot-data p { font-size: .72rem; color: #4a5673; margin-bottom: 4px; }
.inv-foot-data b { color: #1a2238; }
.inv-leyenda { font-weight: 700; color: #1a2238 !important; font-size: .68rem !important; margin-top: 6px !important; }
.inv-rep { font-size: .66rem !important; color: #5b6680 !important; border-top: 1px dashed #e2e8f0; padding-top: 5px; margin-top: 5px !important; }
.inv-ley { font-style: italic; }

.preview-actions { display: flex; gap: 10px; margin-top: 14px; }
.sec-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 13px; border-radius: 12px; cursor: pointer; font-weight: 600; font-size: .92rem;
  background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.4); color: #cbeafe; transition: background .2s;
}
.sec-btn:hover:not(:disabled) { background: rgba(56, 189, 248, 0.22); }
.sec-btn:disabled { opacity: .4; cursor: not-allowed; }
.sec-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Overlay emisión */
.emit-overlay { position: fixed; inset: 0; background: rgba(4, 8, 20, 0.8); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; }
.emit-card { background: linear-gradient(160deg, #0d1730, #0a1228); border: 1px solid var(--border); border-radius: 20px; padding: 34px 40px; text-align: center; max-width: 340px; }
.emit-card h3 { font-family: "Sora", sans-serif; font-size: 1.2rem; margin-bottom: 6px; }
.emit-card p { color: var(--muted); font-size: .86rem; }
.emit-card.done .spinner { display: none; }
.spinner { width: 48px; height: 48px; border-radius: 50%; border: 4px solid rgba(56, 189, 248, 0.2); border-top-color: var(--blue-2); margin: 0 auto 18px; animation: spin .8s linear infinite; }
.ok-mark { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 16px; display: grid; place-items: center; background: radial-gradient(circle, rgba(34,197,94,.22), transparent 70%); color: var(--green); font-size: 2rem; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* Responsive */
@media (max-width: 920px) {
  .fa-body { grid-template-columns: 1fr; }
  .preview { position: static; }
}

/* Impresión: solo la factura */
@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  .invoice, .invoice * { visibility: visible; }
  .invoice { position: absolute; left: 0; top: 0; width: 100%; max-width: none; box-shadow: none; border-radius: 0; }
  .inv-state { display: none; }
  .inv-modal, .inv-box { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
