:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --surface: #ffffff;
  --page: #f4f7fb;
  --brand: #075a91;
  --brand-strong: #03446f;
  --accent: #2f855a;
  --warn: #b65b15;
  --shadow: 0 20px 50px rgba(27, 39, 58, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

[hidden],
.is-hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 420px);
  display: grid;
  gap: 18px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-logo {
  width: 160px;
  height: auto;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.login-card h1 {
  font-size: 1.65rem;
  line-height: 1.15;
}

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 0.88rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 11px 12px;
  font-weight: 500;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(7, 90, 145, 0.14);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: #b42318;
  font-size: 0.88rem;
  font-weight: 700;
}

.primary-action,
.toolbar-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 15px;
  font-weight: 800;
}

.primary-action {
  color: #fff;
  background: var(--brand);
}

.primary-action:hover,
.toolbar-button:hover {
  filter: brightness(0.97);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand img {
  width: 96px;
  height: auto;
  flex: 0 0 auto;
}

.brand p,
.brand strong {
  display: block;
  margin: 0;
}

.brand p {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.brand strong {
  font-size: 1rem;
}

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

.toolbar-button {
  color: #fff;
  background: var(--brand);
}

.toolbar-button.subtle {
  color: #243142;
  border-color: #cbd5e1;
  background: #fff;
}

.workspace {
  width: min(100%, 1680px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 22px;
  padding: 22px;
}

.form-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(27, 39, 58, 0.07);
}

.form-panel {
  align-self: start;
}

.panel-title,
.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-title h2,
.preview-heading h2 {
  font-size: 1.15rem;
}

.status-pill {
  white-space: nowrap;
  border: 1px solid #bfdbca;
  border-radius: 999px;
  color: #19633b;
  background: #eff8f2;
  padding: 6px 10px;
  font-size: 0.76rem;
  font-weight: 800;
}

.term-form {
  display: grid;
  gap: 18px;
  padding: 18px;
}

fieldset {
  display: grid;
  gap: 14px;
  min-width: 0;
  margin: 0;
  padding: 0 0 18px;
  border: 0;
  border-bottom: 1px solid #e7ebf2;
}

fieldset:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

legend {
  margin-bottom: 2px;
  color: var(--warn);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

.preview-panel {
  min-width: 0;
}

.preview-frame {
  overflow: auto;
  padding: 24px;
  background: #e8edf5;
}

.print-sheet {
  width: min(100%, 210mm);
  min-height: auto;
  aspect-ratio: 210 / 297;
  display: flex;
  flex-direction: column;
  gap: 22px;
  margin: 0 auto;
  padding: 20mm 18mm 14mm;
  border: 1px solid #d2d9e4;
  background: #fff;
  box-shadow: 0 16px 36px rgba(30, 41, 59, 0.18);
  color: #111827;
}

.doc-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-bottom: 14px;
  border-bottom: 2px solid #1f4f7b;
}

.doc-header img {
  width: 132px;
  height: auto;
  flex: 0 0 auto;
}

.doc-header div {
  display: grid;
  gap: 4px;
  font-size: 0.88rem;
  line-height: 1.32;
}

.doc-header strong {
  font-size: 1rem;
}

.doc-body {
  display: grid;
  gap: 18px;
}

.doc-body h1 {
  margin-top: 14px;
  text-align: center;
  color: #111827;
  font-size: 1.1rem;
  line-height: 1.3;
  text-decoration: underline;
  text-transform: uppercase;
}

.control-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.control-grid th,
.control-grid td {
  border: 1px solid #cbd5e1;
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
}

.control-grid th {
  width: 30%;
  background: #eef4f8;
  color: #244761;
  font-size: 0.76rem;
  text-transform: uppercase;
}

.term-copy {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.72;
  text-align: justify;
}

.notes-copy {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: #243142;
}

.doc-date {
  margin: 8px 0 4px;
  text-align: right;
  font-size: 0.96rem;
}

.signature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 32px;
  margin-top: 42px;
}

.signature-block {
  display: grid;
  gap: 5px;
  text-align: center;
  font-size: 0.86rem;
  min-width: 0;
}

.signature-line {
  display: block;
  border-top: 1.5px solid #111827;
  min-height: 1px;
  margin-bottom: 8px;
}

.signature-block strong {
  text-transform: uppercase;
  font-size: 0.75rem;
}

.signature-block small {
  color: #4b5563;
}

.doc-footer {
  margin-top: auto;
  display: grid;
  gap: 4px;
  padding-top: 12px;
  border-top: 1px solid #cbd5e1;
  text-align: center;
  color: #344054;
  font-size: 0.73rem;
  line-height: 1.35;
}

.doc-footer strong {
  color: #1f4f7b;
}

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

  .form-panel {
    order: 1;
  }

  .preview-panel {
    order: 2;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
  }

  .toolbar-button {
    flex: 1 1 120px;
  }

  .workspace,
  .preview-frame {
    padding: 14px;
  }

  .two-column,
  .signature-grid {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 24px;
  }
}

@page {
  size: A4;
  margin: 14mm;
}

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

  .auth-screen,
  .topbar,
  .form-panel,
  .preview-heading {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .preview-panel,
  .preview-frame {
    display: block !important;
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    background: #fff;
    box-shadow: none;
    overflow: visible;
  }

  .print-sheet {
    width: auto;
    min-height: calc(297mm - 28mm);
    aspect-ratio: auto;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .doc-header,
  .control-grid,
  .signature-grid,
  .doc-footer {
    break-inside: avoid;
  }
}
