:root {
  color-scheme: light;
  --ink: #151515;
  --muted: #62676f;
  --line: #cfd4da;
  --soft: #f4f6f8;
  --accent: #146c63;
  --accent-strong: #0d4d47;
  --notice: #f4c542;
  --danger: #a83232;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #fff;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
.button,
input,
select,
textarea {
  font: inherit;
}

button,
.button {
  display: inline-flex;
  min-height: 2.45rem;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: 1px solid var(--ink);
  border-radius: 4px;
  padding: .48rem .8rem;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}

button.primary,
.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.danger {
  border-color: var(--danger);
  color: var(--danger);
}

button:disabled {
  cursor: default;
  opacity: .55;
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .48rem .56rem;
  background: #fff;
}

input[type="checkbox"] {
  width: 1.175rem;
  height: 1.175rem;
  min-height: 0;
  padding: 0;
  accent-color: var(--accent);
}

label {
  display: grid;
  gap: .28rem;
  font-weight: 700;
}

.site-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid var(--line);
}

.ad-safe-header {
  padding-right: clamp(8rem, 24vw, 22rem);
}

.ad-safe-header::after {
  content: "";
  flex: 1 1 auto;
  min-width: clamp(5rem, 16vw, 16rem);
}

.topbar.ad-safe-header .brand {
  margin-right: clamp(1rem, 5vw, 4rem);
}

.brand {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0;
  margin-right: auto;
}

.lang-links {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-left: 2rem;
}

.lang-links a::before {
  content: "[ ";
}

.lang-links a::after {
  content: " ]";
}

.lang-links .is-current > span {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.identity {
  color: var(--muted);
}

.main {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
  flex: 1;
}

.hero {
  display: grid;
  min-height: calc(100vh - 170px);
  align-content: center;
  gap: 1.1rem;
}

.hero h1 {
  max-width: 850px;
  margin: 0;
  font-size: clamp(2.4rem, 8vw, 5.8rem);
  line-height: .95;
  letter-spacing: 0;
}

.hero p {
  max-width: 650px;
  margin: 0;
  color: var(--muted);
  font-size: 1.12rem;
}

.notice {
  padding: .75rem 1rem;
  background: var(--notice);
  color: #1d1700;
  font-weight: 700;
}

.section {
  margin-top: 2rem;
}

.section h2 {
  margin: 0 0 1rem;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
  align-items: center;
}

.history-nav {
  display: flex;
  flex-wrap: nowrap;
  gap: .7rem;
  align-items: center;
  margin-bottom: 16px;
  white-space: nowrap;
}

.history-nav select {
  width: auto;
  min-width: 5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.logo-line {
  display: grid;
  grid-template-columns: 120px minmax(220px, 1fr);
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.logo-upload {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .28rem .7rem;
}

.logo-upload label {
  grid-column: 1 / -1;
}

.logo-upload input[type="file"] {
  min-width: 0;
}

.logo-preview {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: var(--soft);
}

.placeholder-logo {
  display: grid;
  place-items: center;
  width: 120px;
  height: 120px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  font-weight: 700;
}

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

table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
}

th,
td {
  padding: .65rem .75rem;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--soft);
  font-weight: 800;
}

tbody tr:nth-child(even) {
  background: #fafafa;
}

tbody tr {
  border-bottom: 1px solid var(--line);
}

.actions-cell {
  display: flex;
  gap: .4rem;
}

.checkbox-cell {
  text-align: center;
}

.checkbox-cell form {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mini-form {
  display: inline;
}

.totals {
  display: grid;
  gap: .55rem;
  padding-top: .5rem;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 4vw, 3rem);
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.invoice-items {
  display: grid;
  gap: .75rem;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.3fr) 110px 145px 90px 96px;
  gap: .6rem;
  align-items: end;
}

.date-row {
  display: grid;
  grid-template-columns: 110px 150px 90px;
  gap: .7rem;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  place-items: center;
  background: rgba(0, 0, 0, .35);
}

.modal[open] {
  display: grid;
}

.modal-panel {
  width: min(460px, calc(100% - 2rem));
  border-radius: 6px;
  background: #fff;
  padding: 1.2rem;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .2);
}

.pin-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .45rem;
  margin-top: 1rem;
}

.pin-row input {
  text-align: center;
  font-weight: 800;
}

.message {
  min-height: 1.4rem;
  color: var(--accent-strong);
}

.cookie-consent-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .5);
}

.cookie-consent {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  width: min(500px, calc(100vw - 2rem));
  border: 1px solid #c4a84a;
  background: #2b2b2b;
  color: #f0f3ff;
  padding: 1rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .3);
}

.cookie-consent.is-modal {
  position: static;
  width: min(540px, calc(100vw - 2rem));
}

.cookie-consent p,
.cookie-consent form {
  margin: 0 0 .85rem;
}

.cookie-consent p:last-child {
  margin-bottom: 0;
}

.cookie-text-link {
  color: #a9e7ff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.cookie-action-line,
.cookie-consent form {
  text-align: center;
}

.cookie-action-link {
  display: inline;
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: #a9e7ff;
  background: transparent;
  font-family: "Courier New", monospace;
  font-weight: 800;
  line-height: inherit;
}

a.cookie-action-link::before {
  content: "[ ";
  color: #f0f3ff;
}

a.cookie-action-link::after {
  content: " ]";
  color: #f0f3ff;
}

a.cookie-action-link:hover::before,
a.cookie-action-link:focus-visible::before {
  content: "[>";
}

a.cookie-action-link:hover::after,
a.cookie-action-link:focus-visible::after {
  content: "<]";
}

.cookie-action-link {
  cursor: pointer;
  text-align: center;
  white-space: normal;
}

.viewer-header {
  display: flex;
  gap: .75rem;
  align-items: center;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid var(--line);
}

.viewer-header h1 {
  margin: 0 auto 0 0;
  font-size: 1.35rem;
}

.viewer-header.ad-safe-header h1 {
  margin: 0 clamp(1rem, 4vw, 3rem) 0 0;
}

.page-stage {
  padding: 2rem 0;
  background: #e9edf1;
}

@media (max-width: 760px) {
  .topbar,
  .viewer-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .ad-safe-header {
    padding-right: clamp(1rem, 4vw, 3rem);
  }

  .ad-safe-header::after {
    display: none;
  }

  .topbar.ad-safe-header .brand,
  .viewer-header.ad-safe-header h1 {
    margin-right: 0;
  }

  .lang-links {
    margin-left: 0;
  }

  .form-grid,
  .logo-line,
  .item-row,
  .date-row {
    grid-template-columns: 1fr;
  }

  .actions-cell {
    flex-wrap: wrap;
  }

  .page-stage {
    overflow-x: auto;
  }

  .cookie-consent {
    right: .75rem;
    bottom: .75rem;
    max-height: calc(100vh - 1.5rem);
    overflow: auto;
  }

}

@media print {
  body {
    background: #fff;
  }

  .viewer-header,
  .site-footer,
  .cookie-consent,
  .cookie-consent-backdrop {
    display: none !important;
  }

  .page-stage {
    padding: 0;
    background: #fff;
  }

}

/* El diálogo nativo contiene el foco y bloquea el resto de la página. */
dialog.modal { width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; }
dialog.modal::backdrop { background: rgba(0, 0, 0, .35); }

.invoice-preview { display: block; width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto; border: 0; }

.legal-page { max-width: 850px; line-height: 1.7; }
.legal-page h1 { font-size: clamp(1.8rem, 5vw, 2.7rem); line-height: 1.2; }
.legal-subtitle { color: var(--muted); }
.legal-page .section { padding-top: 1.5rem; border-top: 1px solid var(--line); }
.legal-page li + li { margin-top: .5rem; }
.legal-page article a { text-decoration: underline; overflow-wrap: anywhere; }
