      :root {
        color-scheme: light;
        --ink: #20243a;
        --muted: #747b91;
        --line: #e7eaf1;
        --brand: #454d87;
        --brand-dark: #353d73;
        --surface: #ffffff;
        --canvas: #f4f6fb;
        --green: #16835d;
        --shadow: 0 14px 40px rgba(35, 43, 78, 0.07);
      }

      * {
        box-sizing: border-box;
      }

      body {
        min-width: 320px;
        margin: 0;
        padding: 42px 24px 64px;
        background: var(--canvas);
        color: var(--ink);
        font-family: Inter, "Segoe UI", Arial, sans-serif;
      }

      button,
      input,
      textarea {
        font: inherit;
      }

      .app-shell {
        width: min(1180px, 100%);
        margin: 0 auto;
      }

      .page-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 24px;
        margin-bottom: 28px;
      }

      .header-content {
        display: flex;
        min-width: 0;
        flex-direction: column;
        gap: 18px;
      }

      .brand-lockup {
        display: flex;
        align-items: center;
        gap: 20px;
      }

      .brand-logo {
        display: block;
        flex: 0 0 auto;
        width: 205px;
        height: 52px;
        object-fit: contain;
        object-position: left center;
      }

      .company-details {
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding-left: 16px;
        border-left: 1px solid #d9deea;
        color: #626a80;
        font-size: 0.78rem;
        line-height: 1.35;
      }

      .company-details span:first-child {
        color: var(--ink);
        font-weight: 700;
      }

      .page-header h1 {
        margin: 0;
        font-size: clamp(1.8rem, 4vw, 2.35rem);
        letter-spacing: -0.045em;
      }

      .page-description,
      .section-heading p {
        margin: 8px 0 0;
        color: var(--muted);
        font-size: 0.95rem;
      }

      .invoice-card,
      .summary-card {
        border: 1px solid rgba(224, 228, 238, 0.9);
        border-radius: 16px;
        background: var(--surface);
        box-shadow: var(--shadow);
      }

      .invoice-card {
        padding: 26px 28px 20px;
      }

      .section-heading,
      .summary-heading {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 20px;
      }

      .section-heading {
        margin-bottom: 22px;
      }

      .section-heading h2,
      .summary-heading h2 {
        margin: 0;
        font-size: 1.12rem;
        letter-spacing: -0.02em;
      }

      .section-badge {
        flex: 0 0 auto;
        padding: 8px 11px;
        border-radius: 999px;
        background: #f0f2fa;
        color: var(--brand);
        font-size: 0.68rem;
        font-weight: 800;
        letter-spacing: 0.07em;
      }

      .table-wrap {
        overflow-x: auto;
        border: 1px solid var(--line);
        border-radius: 10px;
      }

      table {
        width: 100%;
        min-width: 700px;
        border-collapse: collapse;
        background: var(--surface);
        table-layout: fixed;
      }

      th,
      td {
        padding: 13px 14px;
        border-bottom: 1px solid var(--line);
        text-align: left;
        vertical-align: middle;
      }

      th {
        background: #f7f8fc;
        color: #626a80;
        font-size: 0.72rem;
        font-weight: 800;
        letter-spacing: 0.045em;
        text-transform: uppercase;
      }

      th:first-child {
        width: 43%;
      }

      th:nth-child(2) {
        width: 13%;
      }

      th:nth-child(3) {
        width: 18%;
      }

      th:nth-child(4) {
        width: 17%;
      }

      th:last-child {
        width: 9%;
        text-align: center;
      }

      tbody tr:last-child td {
        border-bottom: 0;
      }

      td textarea,
      td input[type="number"] {
        width: 100%;
        border: 1px solid #dfe3ed;
        border-radius: 7px;
        background: #fff;
        color: var(--ink);
        outline: none;
        transition: border-color 0.15s ease, box-shadow 0.15s ease;
      }

      td textarea {
        display: block;
        min-height: 58px;
        max-height: 180px;
        padding: 9px 10px;
        resize: vertical;
        line-height: 1.45;
      }

      td input[type="number"] {
        min-height: 38px;
        padding: 7px 8px;
      }

      td textarea:focus,
      td input[type="number"]:focus,
      .summary-row input:focus {
        border-color: #7882c1;
        box-shadow: 0 0 0 3px rgba(69, 77, 135, 0.12);
      }

      .total {
        color: var(--ink);
        font-weight: 700;
        white-space: nowrap;
      }

      button {
        border: 0;
        border-radius: 8px;
        cursor: pointer;
        font-weight: 700;
        transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
      }

      button:active {
        transform: translateY(1px);
      }

      button.agregar,
      button.pdf {
        min-height: 44px;
        padding: 0 17px;
        color: #fff;
      }

      button.agregar {
        background: var(--green);
      }

      button.agregar:hover {
        background: #116f4f;
      }

      button.pdf {
        flex: 0 0 auto;
        background: var(--brand);
        box-shadow: 0 5px 12px rgba(69, 77, 135, 0.18);
      }

      button.pdf:hover {
        background: var(--brand-dark);
      }

      button.eliminar {
        width: 36px;
        height: 36px;
        padding: 0;
        background: #fff1f0;
        color: #ce4540;
        font-size: 1rem;
      }

      button.eliminar:hover {
        background: #ffe2df;
      }

      td:last-child {
        text-align: center;
      }

      .table-footer {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        padding-top: 17px;
      }

      .summary-card {
        width: min(480px, 100%);
        margin: 22px 0 0 auto;
        padding: 23px 26px 20px;
      }

      .summary-heading {
        margin-bottom: 15px;
      }

      .summary-heading .eyebrow {
        margin-bottom: 6px;
      }

      .summary-icon {
        display: grid;
        width: 42px;
        height: 42px;
        place-items: center;
        border-radius: 12px;
        background: #f0f2fa;
        color: var(--brand);
        font-size: 1.35rem;
        font-weight: 800;
      }

      .summary-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        min-height: 42px;
        border-bottom: 1px solid #eef0f5;
        color: #555d72;
        font-size: 0.9rem;
      }

      .summary-row strong {
        color: var(--ink);
        font-variant-numeric: tabular-nums;
        font-weight: 700;
      }

      .adjustment-row input {
        width: 100px;
        min-height: 34px;
        padding: 5px 8px;
        border: 1px solid #dfe3ed;
        border-radius: 7px;
        color: var(--ink);
        text-align: right;
      }

      .detail-row {
        min-height: 35px;
        color: #858b9d;
        font-size: 0.82rem;
      }

      .detail-row strong {
        color: #747b91;
        font-weight: 600;
      }

      .summary-total {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        margin-top: 15px;
        padding: 15px 16px;
        border-radius: 10px;
        background: #f0f2fa;
        color: var(--brand-dark);
        font-weight: 750;
      }

      .summary-total strong {
        font-size: 1.2rem;
        font-variant-numeric: tabular-nums;
      }

      .calculation-note {
        margin: 12px 0 0;
        color: var(--muted);
        font-size: 0.75rem;
        text-align: right;
      }

      @media (max-width: 680px) {
        body {
          padding: 26px 14px 40px;
        }

        .page-header {
          align-items: flex-start;
          flex-direction: column;
          gap: 17px;
        }

        .brand-lockup {
          align-items: flex-start;
          gap: 12px;
        }

        .brand-logo {
          width: min(46vw, 185px);
          height: 48px;
        }

        .company-details {
          padding-left: 11px;
          font-size: 0.68rem;
        }

        .invoice-card {
          padding: 20px 16px 16px;
        }

        .section-heading {
          align-items: flex-start;
          flex-direction: column;
          gap: 12px;
        }

        .table-footer {
          align-items: stretch;
          flex-direction: column;
        }

        .summary-card {
          padding: 20px 17px;
        }
      }

      @media (max-width: 390px) {
        .adjustment-row input {
          width: 82px;
        }

        .summary-row,
        .detail-row {
          font-size: 0.78rem;
        }
      }


/* Inicio de sesión Optimiza2 */
[hidden] { display: none !important; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 15%, rgba(69, 77, 135, .13), transparent 32%),
    radial-gradient(circle at 85% 85%, rgba(22, 131, 93, .10), transparent 30%),
    var(--canvas);
}

.login-card {
  width: min(430px, 100%);
  padding: 42px 38px 30px;
  border: 1px solid rgba(224, 228, 238, .95);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 22px 65px rgba(35, 43, 78, .13);
}

.login-logo {
  display: block;
  width: 230px;
  max-width: 100%;
  height: 62px;
  object-fit: contain;
  object-position: center;
  margin: 0 auto 28px;
}

.login-eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-align: center;
}

.login-card h1 {
  margin: 0;
  color: var(--ink);
  font-size: 2rem;
  letter-spacing: -.045em;
  text-align: center;
}

.login-description {
  margin: 10px 0 28px;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.55;
  text-align: center;
}

.login-card form label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: .85rem;
  font-weight: 700;
}

.password-field {
  display: flex;
  align-items: center;
  overflow: hidden;
  min-height: 49px;
  border: 1px solid #dfe3ed;
  border-radius: 9px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.password-field:focus-within {
  border-color: #7882c1;
  box-shadow: 0 0 0 3px rgba(69, 77, 135, .12);
}

.password-field input {
  width: 100%;
  min-width: 0;
  height: 47px;
  padding: 0 13px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.toggle-password {
  flex: 0 0 auto;
  padding: 8px 12px;
  color: var(--brand);
  background: transparent;
  font-size: .78rem;
}

.toggle-password:hover { background: #f5f6fb; }

.login-error {
  min-height: 19px;
  margin: 8px 0 10px;
  color: #c43e3e;
  font-size: .8rem;
}

.login-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 49px;
  color: #fff;
  background: var(--brand);
  box-shadow: 0 6px 15px rgba(69, 77, 135, .2);
}

.login-submit:hover { background: var(--brand-dark); }
.login-submit span { font-size: 1.15rem; }

.login-footer {
  margin: 26px 0 0;
  color: #9298a8;
  font-size: .72rem;
  text-align: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

button.logout {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid #dfe3ed;
  color: #626a80;
  background: #fff;
  font-size: .82rem;
}

button.logout:hover { background: #f7f8fc; }

@media (max-width: 680px) {
  .login-card { padding: 34px 24px 26px; }
  .header-actions { width: 100%; flex-wrap: wrap; }
  .header-actions .pdf { flex: 1 1 auto; }
}


/* Navegación y módulos del sistema */
.main-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -8px 0 22px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(35, 43, 78, .035);
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 17px;
  color: #687087;
  background: transparent;
  border-radius: 8px;
  font-size: .88rem;
}
.nav-link:hover { background: #f6f7fb; color: var(--brand); }
.nav-link.active { color: #fff; background: var(--brand); box-shadow: 0 4px 10px rgba(69,77,135,.16); }
.nav-count {
  display: inline-grid;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  place-items: center;
  border-radius: 999px;
  color: var(--brand);
  background: #eef0fa;
  font-size: .7rem;
  font-weight: 800;
}
.nav-link.active .nav-count { color: var(--brand); background: #fff; }

.client-card {
  margin-bottom: 20px;
  padding: 23px 28px 25px;
  border: 1px solid rgba(224, 228, 238, .9);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.client-card .section-heading { margin-bottom: 17px; }
.client-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px 18px;
}
.client-grid label, .history-filters label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: #555d72;
  font-size: .8rem;
  font-weight: 700;
}
.client-grid input, .history-filters input {
  width: 100%;
  min-height: 41px;
  padding: 8px 11px;
  border: 1px solid #dfe3ed;
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: #fff;
  font-weight: 400;
}
.client-grid input:focus, .history-filters input:focus {
  border-color: #7882c1;
  box-shadow: 0 0 0 3px rgba(69,77,135,.11);
}
.history-view {
  padding: 27px 28px 22px;
  border: 1px solid rgba(224, 228, 238, .9);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}
.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 23px;
}
.history-heading h2 { margin: 0; font-size: 1.45rem; letter-spacing: -.035em; }
.history-heading p:last-child { margin: 7px 0 0; color: var(--muted); font-size: .88rem; }
.eyebrow { margin: 0 0 6px; color: var(--brand); font-size: .68rem; font-weight: 800; letter-spacing: .12em; }
.history-total {
  flex: 0 0 auto;
  padding: 9px 13px;
  border-radius: 999px;
  color: var(--brand);
  background: #f0f2fa;
  font-size: .78rem;
  font-weight: 800;
}
.history-filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(140px, .85fr) minmax(140px, .85fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fafbfe;
}
.clear-filters {
  min-height: 41px;
  padding: 0 13px;
  border: 1px solid #dfe3ed;
  color: #626a80;
  background: #fff;
  font-size: .78rem;
}
.clear-filters:hover { background: #f1f3f9; }
.history-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.history-table { min-width: 760px; }
.history-table th:first-child { width: 17%; }
.history-table th:nth-child(2) { width: 19%; }
.history-table th:nth-child(3) { width: 19%; }
.history-table th:nth-child(4) { width: 13%; }
.history-table th:nth-child(5) { width: 16%; }
.history-table th:last-child { width: 16%; text-align: center; }
.history-table td { font-size: .82rem; }
.history-invoice-number { color: var(--brand); font-weight: 800; }
.history-amount { white-space: nowrap; font-weight: 800; }
.history-actions { text-align: center !important; white-space: nowrap; }
.history-detail, .history-delete {
  min-height: 31px;
  margin: 2px;
  padding: 0 9px;
  font-size: .72rem;
}
.history-detail { color: var(--brand); background: #f0f2fa; }
.history-delete { color: #bd4541; background: #fff0ef; }
.history-detail:hover { background: #e5e8f7; }
.history-delete:hover { background: #ffe2df; }
.history-empty { padding: 32px 15px; color: var(--muted); text-align: center; font-size: .88rem; }
.storage-note { margin: 14px 0 0; color: #8a90a1; font-size: .74rem; line-height: 1.5; }
@media (max-width: 760px) {
  .history-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-filters .search-field { grid-column: 1 / -1; }
  .history-filters .clear-filters { width: 100%; }
}
@media (max-width: 560px) {
  .main-nav { margin-top: 0; }
  .client-card, .history-view { padding: 19px 16px; }
  .client-grid { grid-template-columns: 1fr; }
  .history-heading { align-items: flex-start; flex-direction: column; }
  .history-filters { grid-template-columns: 1fr; }
  .history-filters .search-field { grid-column: auto; }
}

/* El formulario de cliente conserva únicamente el nombre. */
.client-grid-single { grid-template-columns: minmax(260px, 1fr); }
.client-grid-single label { max-width: 560px; }

/* Diálogo visual de confirmación para eliminar facturas */
.confirm-modal[hidden] { display: none !important; }
.confirm-modal {
  position: fixed; inset: 0; z-index: 9999; display: grid; place-items: center;
  padding: 20px; background: rgba(18, 24, 42, .48); backdrop-filter: blur(4px);
  animation: modalFadeIn .16s ease-out;
}
.confirm-dialog {
  width: min(100%, 440px); padding: 27px; border: 1px solid #e8ebf3; border-radius: 18px;
  background: #fff; box-shadow: 0 24px 70px rgba(15, 23, 42, .24);
  animation: dialogRise .2s ease-out;
}
.confirm-icon {
  display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 17px;
  border-radius: 14px; color: #c34d4a; background: #fff0ef; font-size: 1.35rem;
}
.confirm-dialog h2 { margin: 0 0 9px; color: #20263a; font-size: 1.25rem; letter-spacing: -.025em; }
.confirm-dialog p { margin: 0; color: #687086; font-size: .91rem; line-height: 1.6; }
.confirm-invoice { display: inline-block; margin-top: 12px; padding: 7px 10px; border-radius: 8px; color: #414b83; background: #f0f2fa; font-size: .82rem; font-weight: 800; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }
.confirm-actions button { min-height: 42px; padding: 0 17px; border-radius: 9px; font-size: .83rem; font-weight: 750; cursor: pointer; transition: background .15s, transform .15s; }
.confirm-cancel { border: 1px solid #dfe3ed; color: #555e73; background: #fff; }
.confirm-cancel:hover { background: #f5f6fa; }
.confirm-delete { border: 1px solid #bd4541; color: #fff; background: #bd4541; }
.confirm-delete:hover { background: #a93b38; transform: translateY(-1px); }
.confirm-actions button:focus-visible { outline: 3px solid rgba(83, 96, 166, .25); outline-offset: 2px; }
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialogRise { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (max-width: 480px) { .confirm-dialog { padding: 22px; } .confirm-actions { flex-direction: column-reverse; } .confirm-actions button { width: 100%; } }

/* Acceso rápido para comenzar una factura nueva sin tocar el historial. */
.clear-invoice {
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid #dfe3ed;
  border-radius: 9px;
  color: #454d87;
  background: #fff;
  font-size: .82rem;
  font-weight: 750;
  cursor: pointer;
  transition: background .15s, transform .15s;
}
.clear-invoice:hover { background: #f0f2fa; transform: translateY(-1px); }
@media (max-width: 760px) {
  .header-actions { display:flex; flex-wrap:wrap; gap:9px; }
  .clear-invoice { flex:1 1 auto; }
}
