
:root {
  --bg: #efefec;
  --surface: #ffffff;
  --surface-2: #f7f7f4;
  --ink: #171716;
  --muted: #6f716d;
  --line: #deded9;
  --accent: #171716;
  --danger: #b52d2d;
  --shadow: 0 18px 60px rgba(20, 20, 18, 0.10);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(255,255,255,.95), transparent 32%),
    var(--bg);
  font-family: "Montserrat", Arial, sans-serif;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 74px;
  padding: 12px clamp(18px, 4vw, 52px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
  background: rgba(23, 23, 22, .96);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.25);
  font-weight: 800;
  font-size: 22px;
}
.brand strong { display: block; letter-spacing: .13em; font-size: 14px; }
.brand span { display: block; margin-top: 3px; color: #bdbdb8; font-size: 11px; }

.app-shell {
  width: min(1540px, calc(100% - 36px));
  margin: 26px auto 48px;
  display: grid;
  grid-template-columns: minmax(540px, .95fr) minmax(500px, 1.05fr);
  gap: 22px;
  align-items: start;
}

.form-panel, .preview-panel {
  background: var(--surface);
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.form-panel { padding: clamp(22px, 3vw, 34px); }
.preview-panel {
  position: sticky;
  top: 98px;
  min-height: calc(100vh - 124px);
  padding: 20px;
  overflow: hidden;
}

.panel-heading, .preview-heading, .preview-heading > div:first-child {
  display: flex;
  align-items: center;
  gap: 13px;
}
.panel-heading { margin-bottom: 28px; align-items: flex-start; }
.panel-heading h1, .preview-heading h2 { margin: 0; }
.panel-heading h1 { font-size: clamp(24px, 3vw, 34px); letter-spacing: -.035em; }
.panel-heading p { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.preview-heading { justify-content: space-between; margin-bottom: 18px; }
.preview-heading h2 { font-size: 17px; }

.step-chip {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  color: white; background: var(--ink);
  border-radius: 50%;
  font-weight: 700;
}

fieldset {
  min-width: 0;
  margin: 0 0 24px;
  padding: 0;
  border: 0;
}
legend {
  margin-bottom: 13px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .02em;
}
.legend-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.legend-row legend { margin: 0; }

.field-grid { display: grid; gap: 12px; }
.three-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }

label {
  display: grid;
  gap: 7px;
  color: #4f514d;
  font-size: 11px;
  font-weight: 600;
}

input, textarea {
  width: 100%;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
input { height: 43px; padding: 0 12px; }
textarea { min-height: 112px; padding: 12px; resize: vertical; line-height: 1.5; }
.item-description { min-height: 43px; height: 43px; padding: 11px 12px; resize: none; overflow: hidden; line-height: 1.45; background: white; }
input:focus, textarea:focus {
  background: white;
  border-color: #777870;
  box-shadow: 0 0 0 3px rgba(23,23,22,.08);
}

.items-header, .item-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 116px 76px 38px;
  gap: 9px;
  align-items: start;
}
.items-header {
  padding: 0 8px 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.items-container { display: grid; gap: 9px; }
.item-row {
  padding: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.item-row input { background: white; }
.remove-item {
  height: 43px;
  border: 0;
  border-radius: 9px;
  color: var(--danger);
  background: #fff0f0;
  font-size: 23px;
  line-height: 1;
}
.remove-item:hover { background: #ffe3e3; }

.field-note { margin: 8px 2px 0; color: var(--muted); font-size: 10px; }

.switch-field { align-content: end; }
.switch-field > span:first-child { display: block; }
.switch-wrap { position: relative; width: 56px; height: 31px; }
.switch-wrap input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui {
  position: absolute; inset: 0;
  background: #c9cac5;
  border-radius: 99px;
  transition: .2s;
}
.switch-ui::after {
  content: "";
  position: absolute;
  width: 23px; height: 23px;
  left: 4px; top: 4px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 7px rgba(0,0,0,.2);
  transition: .2s;
}
.switch-wrap input:checked + .switch-ui { background: var(--ink); }
.switch-wrap input:checked + .switch-ui::after { transform: translateX(25px); }

.totals-card {
  margin-top: 16px;
  padding: 15px 17px;
  display: grid;
  gap: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.totals-card > div { display: flex; justify-content: space-between; gap: 20px; font-size: 12px; }
.totals-card span { color: var(--muted); }
.grand-total { margin: 4px -6px -5px; padding: 12px 12px; color: white; background: var(--ink); border-radius: 10px; }
.grand-total span { color: #d8d8d4; }

 details {
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: 13px;
  overflow: hidden;
 }
summary {
  padding: 15px 17px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
}
.details-content { padding: 18px; }
.details-content fieldset:last-child { margin-bottom: 0; }

.actions { display: flex; align-items: center; gap: 14px; }
#statusMessage { color: var(--muted); font-size: 11px; }

.primary-button, .secondary-button, .ghost-button, .mini-button {
  border-radius: 10px;
  font-weight: 700;
  transition: transform .15s, opacity .15s, background .15s;
}
.primary-button, .secondary-button { min-height: 44px; padding: 0 18px; border: 1px solid var(--ink); }
.primary-button { color: white; background: var(--ink); }
.primary-button:hover, .secondary-button:hover, .mini-button:hover, .ghost-button:hover { transform: translateY(-1px); }
.primary-button.compact { min-height: 38px; padding-inline: 14px; }
.secondary-button { color: var(--ink); background: white; }
.ghost-button { min-height: 38px; padding: 0 14px; color: white; background: transparent; border: 1px solid rgba(255,255,255,.22); }
.mini-button { min-height: 32px; padding: 0 11px; color: var(--ink); background: white; border: 1px solid var(--line); font-size: 10px; }
button:disabled { cursor: not-allowed; opacity: .35; transform: none !important; }

.preview-actions { display: flex; gap: 8px; }

/* Evita que el estado vacío siga ocupando espacio después de generar el PDF.
   Algunos navegadores permiten que el display:grid de .empty-preview prevalezca
   visualmente sobre el atributo hidden. */
.empty-preview[hidden],
#pdfPreview[hidden] {
  display: none !important;
}
.empty-preview {
  min-height: calc(100vh - 220px);
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  background:
    linear-gradient(90deg, rgba(0,0,0,.025) 1px, transparent 1px),
    linear-gradient(rgba(0,0,0,.025) 1px, transparent 1px),
    var(--surface-2);
  background-size: 24px 24px;
  border: 1px dashed #cdcec7;
  border-radius: 15px;
}
.empty-preview h3 { margin: 18px 0 7px; color: var(--ink); font-size: 16px; }
.empty-preview p { margin: 0; font-size: 12px; }
.document-icon {
  width: 76px; height: 92px;
  margin: auto;
  display: grid; place-items: center;
  color: white; background: var(--ink);
  border-radius: 6px 18px 6px 6px;
  font-weight: 800;
  letter-spacing: .08em;
}
#pdfPreview {
  width: 100%;
  height: calc(100vh - 190px);
  min-height: 680px;
  padding: 18px;
  overflow: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #d5d5d0;
}
.pdf-preview-page-wrap {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}
.pdf-preview-page {
  display: block;
  max-width: 100%;
  height: auto;
  background: white;
  box-shadow: 0 8px 28px rgba(0,0,0,.16);
}
.pdf-fallback-frame {
  width: 100%;
  min-height: 640px;
  flex: 1 0 640px;
  border: 0;
  background: white;
}
.pdf-page-badge {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 5px 8px;
  color: white;
  background: rgba(23,23,22,.82);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}


.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; width: min(820px, calc(100% - 28px)); }
  .preview-panel { position: static; min-height: 720px; }
  #pdfPreview { height: 760px; }
}

@media (max-width: 680px) {
  .topbar { padding-inline: 14px; }
  .brand span { display: none; }
  .app-shell { width: min(100% - 18px, 680px); margin-top: 10px; }
  .form-panel, .preview-panel { border-radius: 16px; padding: 17px; }
  .three-cols, .two-cols { grid-template-columns: 1fr; }
  .items-header { display: none; }
  .item-row { grid-template-columns: 1fr 1fr 72px 38px; }
  .item-row label:first-child { grid-column: 1 / -1; }
  .preview-heading { align-items: flex-start; gap: 14px; }
  .preview-actions { flex-direction: column; }
  .preview-actions button { min-height: 36px; }
}

/* --- Acceso seguro --- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #f5f5f2;
  background:
    radial-gradient(circle at 18% 12%, rgba(255,255,255,.10), transparent 28%),
    radial-gradient(circle at 82% 86%, rgba(255,255,255,.055), transparent 30%),
    #111110;
}
.login-shell {
  width: min(1040px, 100%);
  min-height: 610px;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 28px;
  background: #1a1a19;
  box-shadow: 0 35px 100px rgba(0,0,0,.45);
}
.login-visual {
  position: relative;
  min-height: 610px;
  padding: clamp(34px, 6vw, 70px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255,255,255,.055), transparent 45%),
    #151514;
}
.login-visual::before,
.login-visual::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(255,255,255,.07);
  transform: rotate(45deg);
}
.login-visual::before { width: 430px; height: 430px; right: -170px; top: -110px; }
.login-visual::after { width: 310px; height: 310px; left: -170px; bottom: -130px; }
.login-brand { position: relative; z-index: 1; display: flex; align-items: center; gap: 14px; }
.login-brand-mark {
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.34);
  font-size: 27px; font-weight: 800;
}
.login-brand strong { display: block; letter-spacing: .17em; font-size: 15px; }
.login-brand span { display: block; margin-top: 5px; color: #aaa9a3; font-size: 11px; }
.login-copy { position: relative; z-index: 1; max-width: 470px; }
.login-eyebrow { margin: 0 0 16px; color: #aaa9a3; font-size: 11px; font-weight: 700; letter-spacing: .17em; text-transform: uppercase; }
.login-copy h1 { margin: 0; max-width: 430px; font-size: clamp(36px, 5vw, 62px); line-height: .98; letter-spacing: -.055em; }
.login-copy p { margin: 24px 0 0; max-width: 400px; color: #bdbdb8; font-size: 13px; line-height: 1.8; }
.security-strip { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 9px; }
.security-strip span { padding: 8px 11px; color: #c9c9c4; border: 1px solid rgba(255,255,255,.11); border-radius: 999px; font-size: 9px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.login-panel {
  padding: clamp(34px, 6vw, 72px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: var(--ink);
  background: #f7f7f4;
}
.login-panel h2 { margin: 0; font-size: 28px; letter-spacing: -.035em; }
.login-panel > p { margin: 10px 0 30px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.login-form { display: grid; gap: 17px; }
.login-form label { font-size: 11px; }
.login-form input { height: 50px; background: white; }
.login-submit { width: 100%; min-height: 50px; margin-top: 4px; }
.login-error {
  margin: 0 0 18px;
  padding: 12px 14px;
  color: #7c2020;
  background: #fff0f0;
  border: 1px solid #efc8c8;
  border-radius: 10px;
  font-size: 11px;
  line-height: 1.5;
}
.login-meta { margin: 21px 0 0; color: #878983; font-size: 9px; line-height: 1.6; text-align: center; }
.logout-form { margin: 0; }
.logout-button { white-space: nowrap; }
.user-chip {
  margin-left: auto;
  padding: 8px 11px;
  color: #d4d4cf;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }

@media (max-width: 820px) {
  .login-shell { grid-template-columns: 1fr; min-height: auto; }
  .login-visual { min-height: 330px; padding: 34px; }
  .login-copy h1 { font-size: 40px; }
  .login-copy p { margin-top: 16px; }
  .security-strip { display: none; }
  .login-panel { padding: 34px; }
}
@media (max-width: 560px) {
  .login-body { padding: 10px; }
  .login-shell { border-radius: 19px; }
  .login-visual { min-height: 260px; }
  .login-copy h1 { font-size: 34px; }
  .login-copy p { display: none; }
  .user-chip { display: none; }
  .topbar-actions { gap: 6px; }
  .ghost-button { padding-inline: 10px; font-size: 10px; }
}
