:root {
  color-scheme: light;
  --ink: #ffffff;
  --navy: #102f2e;
  --muted: #e8eef2;
  --line: rgba(255, 255, 255, 0.2);
  --surface: #071413;
  --panel: #ffffff;
  --accent: #f0522d;
  --accent-dark: #8b134a;
  --teal: #124b49;
  --warn: #ffb4b4;
  --shadow: 0 26px 80px rgba(0, 0, 0, 0.36);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf4f1;
  --muted: #b5c4d9;
  --line: #193a66;
  --surface: #071426;
  --panel: #0c1b32;
  --accent: #5fb1ff;
  --accent-dark: #b8dcff;
  --warn: #ff9ab2;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(3, 12, 13, 0.78), rgba(3, 12, 13, 0.9)),
    radial-gradient(circle at 8% 18%, rgba(240, 82, 45, 0.24), transparent 26rem),
    radial-gradient(circle at 93% 16%, rgba(139, 19, 74, 0.28), transparent 28rem),
    radial-gradient(circle at 85% 86%, rgba(18, 75, 73, 0.42), transparent 30rem),
    linear-gradient(135deg, #071312 0%, #102927 46%, #050b0c 100%);
  font-family: Avenir Next, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before,
body::after {
  content: "";
  pointer-events: none;
  position: fixed;
  z-index: -1;
}

body::before {
  border: 30px solid rgba(219, 248, 80, 0.8);
  border-radius: 50%;
  height: 360px;
  left: -210px;
  top: 80px;
  width: 360px;
}

body::after {
  border: 28px solid rgba(255, 215, 81, 0.84);
  border-radius: 50%;
  height: 300px;
  right: -150px;
  top: 38px;
  width: 300px;
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at 16% 6%, rgba(95, 177, 255, 0.16), transparent 30rem),
    linear-gradient(135deg, #061225 0%, #0a1a30 58%, #06101f 100%);
}

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

.shell {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(420px, 1fr);
  gap: 24px;
  min-height: 100vh;
  padding: 0 30px 30px;
}

.output-pending .shell {
  grid-template-columns: minmax(420px, 760px);
  justify-content: center;
}

.workspace,
.output {
  min-width: 0;
}

.topbar {
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  align-items: stretch;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 26px;
  padding: 28px 4px 0;
}

.brand-banner {
  align-items: center;
  display: flex;
  justify-content: center;
  min-width: 0;
  width: 100%;
}

.brand-side-logo {
  background: #fff;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
  height: 66px;
  object-fit: contain;
  padding: 9px;
  width: 132px;
}

.brand-noyola {
  width: 162px;
}

.brand-afas {
  width: 156px;
}

.brand-center {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 980px;
  text-align: center;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: none;
  color: #ffffff;
  font-family: Avenir Next, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(46px, 7vw, 88px);
  font-weight: 900;
  line-height: 0.98;
}

.brand-subtitle {
  color: rgba(255, 255, 255, 0.86);
  font-size: 14px;
  font-weight: 600;
  margin: 8px 0 0;
}

h2 {
  font-size: 20px;
}

.status-pill,
.theme-toggle {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.56);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
}

:root[data-theme="dark"] .status-pill,
:root[data-theme="dark"] .theme-toggle {
  background: rgba(17, 29, 27, 0.84);
}

.theme-toggle {
  color: #ffffff;
  cursor: pointer;
}

.logout-link {
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.56);
  color: #ffffff;
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  min-height: 36px;
  padding: 8px 12px;
  text-decoration: none;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(7, 27, 29, 0.78);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

form.panel {
  display: grid;
  gap: 16px;
  padding: 26px;
}

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

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.client-block {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.08);
}

.mode-block[hidden] {
  display: none;
}

:root[data-theme="dark"] .client-block {
  border-color: var(--line);
  background: #0d1a18;
}

.section-label {
  margin: 0 0 12px;
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

label {
  color: #d7e3ee;
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

input::placeholder,
textarea::placeholder {
  color: rgba(255, 255, 255, 0.58);
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] select {
  background: #0b1715;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

small {
  color: #b7c6d6;
  font-size: 12px;
  line-height: 1.35;
}

input[type="file"] {
  padding: 9px;
}

input:focus,
textarea:focus,
select:focus,
button:focus {
  outline: 3px solid rgba(11, 92, 173, 0.18);
  outline-offset: 2px;
}

.advanced {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.advanced summary {
  cursor: pointer;
  color: #ffffff;
  font-weight: 800;
}

.advanced .grid {
  margin-top: 14px;
}

.primary,
.actions button,
.tab {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  min-height: 42px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

:root[data-theme="dark"] .primary,
:root[data-theme="dark"] .actions button,
:root[data-theme="dark"] .tab {
  background: #101d1b;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  min-height: 52px;
  box-shadow: 0 16px 28px rgba(240, 82, 45, 0.26);
  text-transform: none;
}

.mode-block:nth-of-type(3) {
  border-left: 5px solid var(--accent);
}

.mode-block:nth-of-type(4) {
  border-left: 5px solid var(--accent-dark);
}

.mode-block:nth-of-type(5) {
  border-left: 5px solid var(--teal);
}

.primary:disabled,
.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.login-page {
  min-height: 100vh;
}

.login-shell {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.login-card {
  background: rgba(7, 27, 29, 0.82);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  max-width: 720px;
  padding: 36px;
  width: 100%;
}

:root[data-theme="dark"] .login-card {
  background: rgba(17, 29, 27, 0.94);
}

.login-brand-banner {
  align-items: center;
  display: flex;
  gap: 0;
  justify-content: center;
  background: transparent;
  border-radius: 0;
  margin-bottom: 24px;
  padding: 14px;
  width: 100%;
}

.login-side-logo {
  background: #fff;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
  display: block;
  height: 62px;
  object-fit: contain;
  padding: 9px;
  width: 156px;
}

.login-brand-center {
  min-width: 0;
  text-align: center;
  width: 100%;
}

.login-card h1 {
  color: #ffffff;
  font-size: clamp(42px, 8vw, 76px);
  line-height: 0.95;
  margin-bottom: 10px;
}

.login-copy {
  color: #d7e3ee;
  line-height: 1.5;
  margin: 0 0 22px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-error {
  color: #ffb4b4;
  display: none;
  font-weight: 800;
  margin: 0;
}

.show-login-error .login-error {
  display: block;
}

.progress {
  margin-top: 18px;
  padding: 18px;
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  margin-top: 16px;
  background: #dfe7e2;
}

#barFill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

.error {
  margin: 12px 0 0;
  color: var(--warn);
  font-weight: 700;
  white-space: pre-wrap;
}

.output {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  min-height: calc(100vh - 48px);
}

.output[hidden] {
  display: none;
}

.tabs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tab.active {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.document {
  display: none;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  line-height: 1.6;
}

.document.active {
  display: block;
}

.letter-body:empty::before,
#transcript:empty::before {
  content: "Aquí aparecerá el documento cuando termine el procesamiento.";
  color: var(--muted);
}

.document-letter {
  max-width: 816px;
  min-height: 1056px;
  margin: 0 auto;
  padding: 38px 50px 62px;
  background: #fff;
  color: #1f2933;
  border: 1px solid #edf0f2;
  position: relative;
}

.print-page-header,
.print-page-footer,
.print-layout {
  display: none;
}

.letter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  border-bottom: 3px solid var(--navy);
  padding-bottom: 16px;
  margin-bottom: 24px;
}

.letter-head img {
  width: min(360px, 58%);
  height: auto;
  object-fit: contain;
}

.document-letter.no-logo .letter-head {
  justify-content: flex-end;
}

.document-letter.no-logo .letter-head div {
  text-align: left;
  width: 100%;
}

.letter-head div {
  text-align: right;
  color: var(--navy);
}

.letter-head p {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
}

.letter-head strong {
  font-size: 18px;
}

.letter-head small {
  color: #52615a;
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-style: italic;
  line-height: 1.35;
  margin-top: 6px;
}

.letter-body {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13.7px;
  line-height: 1.5;
  text-align: justify;
}

.letter-body h1,
.letter-body h2,
.letter-body h3 {
  color: var(--navy);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.2;
  text-align: left;
  break-after: avoid;
  page-break-after: avoid;
}

.letter-body h1 {
  margin: 0 0 16px;
  font-size: 22px;
  text-transform: uppercase;
}

.letter-body h2 {
  margin: 16px 0 6px;
  border-bottom: 1px solid #d9e0dc;
  padding-bottom: 4px;
  font-size: 15px;
}

.letter-body h3 {
  margin: 14px 0 6px;
  font-size: 14px;
}

.letter-body p {
  margin: 0 0 7px;
  orphans: 2;
  widows: 2;
}

.letter-body ul,
.letter-body ol {
  margin: 6px 0 12px 18px;
  padding: 0;
  text-align: left;
}

.letter-body li {
  margin-bottom: 3px;
  orphans: 2;
  widows: 2;
}

.letter-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  text-align: left;
}

.letter-body th,
.letter-body td {
  border: 1px solid #d9e0dc;
  padding: 8px 10px;
  vertical-align: top;
}

.letter-body th {
  background: #f1f5f4;
  color: var(--navy);
}

.signature-block {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-top: 10px;
}

#transcript {
  white-space: pre-wrap;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .brand-banner {
    justify-content: center;
  }

  .output {
    min-height: 680px;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 14px;
  }

  .topbar,
  .progress-head,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-banner,
  .login-brand-banner {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-side-logo,
  .login-side-logo {
    height: auto;
    width: min(100%, 260px);
  }

  .brand-center,
  .login-brand-center {
    min-width: 0;
    text-align: left;
  }

  .header-actions {
    align-items: stretch;
    justify-content: flex-start;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 36px;
  }

  .document {
    padding: 12px;
  }

  .document-letter {
    padding: 28px 24px 42px;
  }

  .letter-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .letter-head img {
    width: 100%;
  }

  .letter-head div {
    text-align: left;
  }
}

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

  .workspace,
  .tabs,
  .actions,
  #transcript {
    display: none !important;
  }

  .shell,
  .output {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .document {
    display: block !important;
    overflow: visible;
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .document-letter {
    max-width: none;
    min-height: auto;
    border: 0;
    padding: 0;
  }

  .letter-head,
  .print-page-header,
  .print-page-footer,
  #resultBody {
    display: none;
  }

  .print-layout {
    border-collapse: collapse;
    display: table;
    width: 100%;
  }

  .print-layout thead {
    display: table-header-group;
  }

  .print-layout tfoot {
    display: table-footer-group;
  }

  .print-layout td {
    border: 0;
    padding: 0;
  }

  .print-table-header {
    align-items: center;
    border-bottom: 2px solid var(--navy);
    color: var(--navy);
    display: flex;
    justify-content: space-between;
    margin-bottom: 5mm;
    padding-bottom: 3mm;
  }

  .document-letter.no-logo .print-table-header {
    justify-content: flex-start;
  }

  .print-table-header img {
    height: 16mm;
    width: auto;
  }

  .print-table-header div {
    text-align: right;
  }

  .document-letter.no-logo .print-table-header div {
    text-align: left;
  }

  .print-table-header strong {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 11.5pt;
    text-transform: uppercase;
  }

  .print-table-header span,
  .print-page-header span {
    color: #52615a;
    display: block;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 9pt;
    font-style: italic;
    line-height: 1.35;
    margin-top: 3mm;
    text-transform: none;
  }

  .print-table-footer {
    align-items: center;
    border-top: 1px solid #cfd8d3;
    color: #39443f;
    display: flex;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 7.5pt;
    justify-content: space-between;
    line-height: 1.3;
    margin-top: 5mm;
    padding-top: 2mm;
  }

  .letter-body {
    font-size: 9.8pt;
    line-height: 1.26;
    text-align: justify;
  }

  .letter-body h1 {
    font-size: 14pt;
    margin-bottom: 6pt;
  }

  .letter-body h2 {
    font-size: 10.8pt;
    margin: 8pt 0 3pt;
    padding-bottom: 3pt;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .letter-body h3 {
    font-size: 10.2pt;
    margin: 7pt 0 2pt;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .letter-body p {
    margin-bottom: 4pt;
    text-align: justify;
  }

  .letter-body ul,
  .letter-body ol {
    margin: 3pt 0 6pt 14pt;
  }

  .letter-body li {
    margin-bottom: 1.5pt;
    text-align: justify;
  }

  .letter-body h1,
  .letter-body h2,
  .letter-body h3 {
    break-after: avoid-page;
    page-break-after: avoid;
  }

  .letter-body p,
  .letter-body li {
    orphans: 2;
    widows: 2;
  }

  .signature-block {
    break-inside: avoid-page;
    page-break-inside: avoid;
    margin-top: 5pt;
  }

  @page {
    size: letter;
    margin: 11mm 14mm 10mm;
  }
}
