/* =====================================================================
   Facturación electrónica | Skin "Marina"
   Base: estructura Gentelella (top_nav horizontal, x_panel, tile_count)
   Acabado: superficies limpias, radios suaves (estilo Cloudbeds)
   ===================================================================== */
:root {
  --navy: #0F2C44;
  --navy-2: #173B58;
  --teal: #1A7F8E;
  --teal-hover: #156B78;
  --teal-soft: #E3F2F4;
  --bg: #EEF2F5;
  --surface: #FFFFFF;
  --line: #DCE3E9;
  --line-soft: #EBF0F4;
  --ink: #1D2B36;
  --ink-2: #3E5060;
  --muted: #6B7C8A;
  --ok: #2E8B6A;
  --ok-soft: #E3F3EC;
  --warn: #B7791F;
  --warn-soft: #FBF1DF;
  --void: #B23A48;
  --void-soft: #F8E6E8;
  --info-soft: #E8EEF6;
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 7px;
  --shadow: 0 1px 2px rgba(15, 44, 68, .06), 0 4px 14px rgba(15, 44, 68, .05);
  --font: "Figtree", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.num, .money, td.n { font-variant-numeric: tabular-nums; }
a { color: var(--teal); }
a:hover { color: var(--teal-hover); }
:focus-visible { outline: 3px solid rgba(26, 127, 142, .45); outline-offset: 2px; border-radius: 6px; }

/* ---------------------------------------------------------- top nav */
.top_nav {
  position: sticky; top: 0; z-index: 1030;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 2px 10px rgba(15, 44, 68, .25);
}
.top_nav .nav-inner {
  display: flex; align-items: center; gap: 22px;
  height: 60px; padding: 0 22px; max-width: 1680px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; text-decoration: none; color: #fff; }
.brand:hover { color: #fff; text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(150deg, #2BA3B3, var(--teal));
  display: grid; place-items: center; font-weight: 800; font-size: 15px; letter-spacing: -.02em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text b { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.brand-text small { font-size: 11.5px; color: #A9C2D3; }

.nav-tabs-h { display: flex; gap: 4px; height: 100%; margin: 0; padding: 0; list-style: none; }
.nav-tabs-h a {
  display: flex; align-items: center; gap: 8px; height: 100%; padding: 0 14px;
  color: #C9D9E4; text-decoration: none; font-weight: 600; font-size: 13.5px;
  border-bottom: 3px solid transparent; border-top: 3px solid transparent;
}
.nav-tabs-h a:hover { color: #fff; background: var(--navy-2); }
.nav-tabs-h a.active { color: #fff; border-bottom-color: #3FB6C6; background: var(--navy-2); }
.nav-tabs-h .badge-dot {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; line-height: 18px; text-align: center;
  background: var(--warn); color: #fff; font-weight: 700;
}
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.conn {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .08); color: #DCE8F0; white-space: nowrap; cursor: pointer; border: 0;
}
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: #8AA0B0; }
.conn.ok .dot { background: #46C79A; box-shadow: 0 0 0 3px rgba(70, 199, 154, .2); }
.conn.bad .dot { background: #F07B86; box-shadow: 0 0 0 3px rgba(240, 123, 134, .22); }
.conn.sim { background: rgba(244, 196, 86, .16); color: #F6D88E; }
.clock { color: #A9C2D3; font-variant-numeric: tabular-nums; }
.user { display: flex; align-items: center; gap: 8px; color: #DCE8F0; }
.user .avatar { width: 30px; height: 30px; border-radius: 50%; background: #2C5272; display: grid; place-items: center; font-weight: 700; font-size: 12px; }

.env-banner { display: none; background: var(--warn-soft); color: #7A5113; text-align: center; font-size: 13px; padding: 7px 12px; border-bottom: 1px solid #EED7A8; }
.env-banner.show { display: block; }

/* ------------------------------------------------------------ layout */
.right_col { max-width: 1680px; margin: 0 auto; padding: 22px; }
.vista { display: none; }
.vista.active { display: block; }
.page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 2px 0 18px; flex-wrap: wrap; }
.page-title h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.page-title p { margin: 2px 0 0; color: var(--muted); }

/* --------------------------------------------------------- tile_count */
.tile_count {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden;
}
.tile_stats_count { padding: 16px 20px; border-left: 1px solid var(--line-soft); min-width: 0; }
.tile_stats_count:first-child { border-left: 0; }
.tile_stats_count .count_top { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 7px; }
.tile_stats_count .count { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile_stats_count .count_bottom { color: var(--muted); font-size: 12px; }
.tile_stats_count.alert-tile .count { color: var(--warn); }

/* ------------------------------------------------------------ x_panel */
.x_panel {
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow);
  margin-bottom: 20px; border: 1px solid transparent;
}
.x_title {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line-soft);
}
.x_title h2 { margin: 0; font-size: 15.5px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 9px; }
.x_title h2 i { color: var(--teal); font-size: 14px; }
.x_title .hint { color: var(--muted); font-size: 12.5px; }
.x_content { padding: 18px 20px 20px; }
.sticky-col { position: sticky; top: 80px; }

/* -------------------------------------------------------------- forms */
.f-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 14px; }
.f-grid > .c3 { grid-column: span 3; } .f-grid > .c4 { grid-column: span 4; }
.f-grid > .c5 { grid-column: span 5; } .f-grid > .c6 { grid-column: span 6; }
.f-grid > .c8 { grid-column: span 8; } .f-grid > .c12 { grid-column: span 12; }
.f-grid > .c2 { grid-column: span 2; }
.fld label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.fld label .opt { font-weight: 400; color: var(--muted); }
.fld .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-control, .custom-select {
  height: 40px; border-radius: var(--r-md); border: 1px solid var(--line); background-color: #FBFCFD;
  color: var(--ink); font-size: 14px; padding: 8px 12px; transition: border-color .15s, box-shadow .15s, background-color .15s;
}
textarea.form-control { height: auto; }
.form-control:focus, .custom-select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26, 127, 142, .15); background: #fff; }
.form-control.is-invalid { border-color: var(--void); background-image: none; padding-right: 12px; }
.form-control[readonly] { background: var(--line-soft); }
.input-group-text { border-radius: var(--r-md); border-color: var(--line); background: var(--line-soft); color: var(--muted); }
.input-affix { position: relative; }
.input-affix .form-control { padding-right: 34px; }
.input-affix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.section-label { font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 18px 0 10px; display: flex; align-items: center; justify-content: space-between; }
.section-label:first-child { margin-top: 0; }

.precarga {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  padding: 12px 14px; border-radius: var(--r-md); background: var(--teal-soft); margin-bottom: 18px;
}
.precarga .fld { flex: 1 1 140px; }
.precarga .fld label { color: #135E69; }
.precarga-note { font-size: 12.5px; color: #135E69; flex-basis: 100%; margin-top: -2px; }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 36px; height: 20px; border-radius: 10px; background: #C7D2DB; position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--teal); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 3px solid rgba(26, 127, 142, .45); outline-offset: 2px; }

/* ---------------------------------------------------------- buttons */
.btn { border-radius: var(--r-md); font-weight: 600; font-size: 13.5px; padding: 8px 15px; display: inline-flex; align-items: center; gap: 7px; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn-primary { background: var(--teal); border-color: var(--teal); }
.btn-primary:hover, .btn-primary:focus { background: var(--teal-hover); border-color: var(--teal-hover); }
.btn-primary:disabled { background: #8DB9C0; border-color: #8DB9C0; }
.btn-light { background: #fff; border: 1px solid var(--line); color: var(--ink-2); }
.btn-light:hover { background: var(--line-soft); border-color: #C9D3DB; }
.btn-ghost { background: transparent; border: 0; color: var(--teal); padding-left: 6px; padding-right: 6px; }
.btn-ghost:hover { background: var(--teal-soft); color: var(--teal-hover); }
.btn-danger { background: var(--void); border-color: var(--void); }
.btn-danger:hover { background: #962F3B; border-color: #962F3B; }
.btn-void-ghost { background: transparent; border: 0; color: var(--void); }
.btn-void-ghost:hover { background: var(--void-soft); color: #962F3B; }
.btn-emit { width: 100%; height: 50px; font-size: 15.5px; border-radius: 12px; }
.btn .spin { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: none; }
.btn.busy .spin { display: inline-block; }
.btn.busy .ico { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------ items table */
.items-wrap { border: 1px solid var(--line); border-radius: var(--r-md); overflow-x: auto; }
.items { width: 100%; border-collapse: collapse; min-width: 720px; }
.items th { background: #F6F8FA; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.items td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.items tr:last-child td { border-bottom: 0; }
.items .form-control { height: 36px; background: #fff; }
.items td.n, .items th.n { text-align: right; white-space: nowrap; }
.items .w-cant { width: 80px; } .items .w-val { width: 150px; }
.items tr.locked td { color: var(--ok); background: var(--ok-soft); font-size: 13px; }
.items .ref { font-size: 11.5px; color: var(--muted); }
.items-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 10px; flex-wrap: wrap; }

/* --------------------------------------------------------- resumen */
.resumen .linea { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.resumen .linea span:first-child { color: var(--ink-2); }
.resumen .linea .money { font-weight: 600; }
.resumen .iva-edit { display: inline-flex; align-items: center; gap: 6px; }
.resumen .iva-edit input { width: 72px; height: 32px; text-align: right; padding: 4px 8px; }
.total-box { margin: 16px 0 14px; padding: 16px 18px; border-radius: 12px; background: var(--navy); color: #fff; }
.total-box small { color: #A9C2D3; font-size: 12.5px; display: block; }
.total-box .money { font-size: 32px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; display: block; }
.total-box .sub { color: #A9C2D3; font-size: 12px; margin-top: 4px; }
.total-box.flash { animation: flash .5s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 4px rgba(63, 182, 198, .55); } to { box-shadow: 0 0 0 0 rgba(63, 182, 198, 0); } }
.calc-src { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.calc-src .d { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.calc-src.pending .d { background: var(--warn); }
.next-num { font-size: 12.5px; color: var(--muted); text-align: center; margin-top: 10px; }
.next-num b { color: var(--ink); }

/* ------------------------------------------------- timeline afacturar */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 12px 24px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 16px; bottom: -2px; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline li .mk { position: absolute; left: 0; top: 4px; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--muted); }
.timeline li.ok .mk { border-color: var(--ok); background: var(--ok); }
.timeline li.warn .mk { border-color: var(--warn); background: var(--warn); }
.timeline li.error .mk { border-color: var(--void); background: var(--void); }
.timeline li.info .mk { border-color: var(--teal); }
.timeline li.live .mk { border-color: var(--teal); border-top-color: transparent; animation: spin .8s linear infinite; }
.timeline .t { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.timeline .ms { color: var(--muted); font-size: 11.5px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 8px; }
.empty i { display: block; font-size: 22px; margin-bottom: 6px; color: #B5C3CE; }

.result { border-radius: 12px; padding: 14px 16px; margin-top: 4px; }
.result h3 { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.result p { margin: 0 0 10px; font-size: 13px; }
.result.ok { background: var(--ok-soft); color: #1E5E47; }
.result.error { background: var(--void-soft); color: #7D2832; }
.result.warn { background: var(--warn-soft); color: #6E4A12; }
.result .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cufe { font-size: 11.5px; word-break: break-all; color: inherit; opacity: .8; margin-top: 8px; }

/* -------------------------------------------------------- data table */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .form-control, .toolbar .custom-select { height: 36px; }
.table-wrap { overflow-x: auto; }
.dt { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 860px; }
.dt th { font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; background: #fff; }
.dt td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; vertical-align: middle; }
.dt tbody tr:hover td { background: #F7FAFB; }
.dt td.n, .dt th.n { text-align: right; white-space: nowrap; }
.dt .fid { font-weight: 700; color: var(--ink); }
.dt .sub { font-size: 12px; color: var(--muted); }
.dt tr.new td { animation: rowin 1.6s ease-out; }
@keyframes rowin { from { background: #DDF1F3; } to { background: transparent; } }
.dt tr.st-ANULADA td:not(:last-child) { color: var(--muted); }
.dt tr.st-ANULADA .money { text-decoration: line-through; }
.acts { display: flex; gap: 2px; justify-content: flex-end; white-space: nowrap; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.EMITIDA { background: var(--ok-soft); color: var(--ok); }
.chip.ANULADA { background: #EEF0F2; color: #66727C; }
.chip.ANULANDO, .chip.PENDIENTE { background: var(--info-soft); color: #2F5D8A; }
.chip.ANULANDO::before, .chip.PENDIENTE::before { animation: pulse 1s ease-in-out infinite; }
.chip.INCIERTA { background: var(--warn-soft); color: var(--warn); }
.chip.RECHAZADA { background: var(--void-soft); color: var(--void); }
@keyframes pulse { 50% { opacity: .25; } }

/* ------------------------------------------------------------ feed */
.feed { list-style: none; margin: 0; padding: 0; max-height: 640px; overflow-y: auto; }
.feed li { display: grid; grid-template-columns: 92px 18px 1fr auto; gap: 10px; align-items: start; padding: 9px 4px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.feed li.fresh { animation: rowin 1.6s ease-out; }
.feed .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; padding-top: 1px; }
.feed .lv { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: var(--teal); }
.feed .lv.ok { background: var(--ok); } .feed .lv.warn { background: var(--warn); } .feed .lv.error { background: var(--void); }
.feed .tipo { font-size: 11.5px; color: var(--muted); }
.feed .who { font-size: 11.5px; color: var(--muted); text-align: right; white-space: nowrap; }
.feed a.fref { font-weight: 600; cursor: pointer; }
.feed-mini { max-height: 300px; }
.live-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ok); font-weight: 600; }
.live-tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
.live-tag.off { color: var(--muted); }
.live-tag.off::before { animation: none; }

/* ---------------------------------------------------------- config */
.cfg-group { padding-bottom: 6px; }
.cfg-group + .cfg-group { border-top: 1px solid var(--line-soft); padding-top: 18px; margin-top: 8px; }
.cfg-group h3 { font-size: 14px; font-weight: 700; margin: 0 0 4px; }
.cfg-group > p { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.token-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.token-state.ok { color: var(--ok); } .token-state.no { color: var(--void); }
.cfg-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 16px; border-top: 1px solid var(--line-soft); margin-top: 14px; }

/* ----------------------------------------------------------- modals */
.modal-content { border: 0; border-radius: 16px; box-shadow: 0 20px 60px rgba(15, 44, 68, .3); }
.modal-header { border-bottom: 1px solid var(--line-soft); padding: 16px 20px; }
.modal-header .modal-title { font-weight: 700; font-size: 16px; }
.modal-body { padding: 18px 20px; }
.modal-footer { border-top: 1px solid var(--line-soft); padding: 12px 20px; }
.modal-backdrop.show { opacity: .45; background: var(--navy); }
.void-summary { border-radius: 12px; background: var(--void-soft); padding: 12px 14px; margin-bottom: 14px; color: #7D2832; font-size: 13px; }
.void-summary b { color: #5E1E26; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; margin-bottom: 14px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; word-break: break-word; }
pre.raw { background: #0F2C44; color: #CFE3EE; border-radius: 10px; padding: 12px; font-size: 11.5px; max-height: 260px; overflow: auto; }
.custom-control-label { font-size: 13px; }

/* ----------------------------------------------------------- toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 36px)); }
.toast-x {
  background: var(--surface); border-radius: 12px; box-shadow: 0 10px 30px rgba(15, 44, 68, .2);
  padding: 12px 14px 12px 16px; display: grid; grid-template-columns: 22px 1fr 20px; gap: 10px; align-items: start;
  border-left: 4px solid var(--teal); animation: tin .25s ease-out; font-size: 13.5px;
}
.toast-x.ok { border-left-color: var(--ok); } .toast-x.error { border-left-color: var(--void); } .toast-x.warn { border-left-color: var(--warn); }
.toast-x i.lead { margin-top: 2px; }
.toast-x.ok i.lead { color: var(--ok); } .toast-x.error i.lead { color: var(--void); } .toast-x.warn i.lead { color: var(--warn); } .toast-x.info i.lead { color: var(--teal); }
.toast-x b { display: block; }
.toast-x button { border: 0; background: none; color: var(--muted); padding: 0; line-height: 1; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* -------------------------------------------------------- responsive */
@media (max-width: 1199px) {
  .sticky-col { position: static; }
}
@media (max-width: 991px) {
  .tile_count { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile_stats_count { border-left: 0; border-top: 1px solid var(--line-soft); }
  .tile_stats_count:nth-child(-n+2) { border-top: 0; }
  .top_nav .nav-inner { flex-wrap: wrap; height: auto; padding: 10px 14px 0; gap: 8px 14px; }
  .nav-right { order: 2; }
  .nav-tabs-h { order: 3; width: 100%; overflow-x: auto; height: 46px; }
  .clock, .user span { display: none; }
  .f-grid > [class^="c"] { grid-column: span 6; }
  .f-grid > .c12 { grid-column: span 12; }
}
@media (max-width: 575px) {
  .right_col { padding: 14px; }
  .f-grid > [class^="c"] { grid-column: span 12; }
  .tile_stats_count .count { font-size: 21px; }
  .brand-text small { display: none; }
  .kv { grid-template-columns: 1fr; }
  .feed li { grid-template-columns: 70px 14px 1fr; }
  .feed .who { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
