:root {
  --ink: #12213f;
  --text: #232833;
  --muted: #6b7280;
  --faint: #8a8f99;
  --line: #e2e4e9;
  --body: #3a3f4a;
  --panel: #0f172a;
  --panel-2: #1e293b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --bg: #e8eaef;
  --sheet: #ffffff;
  --radius: 12px;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.14);
  font-family: Inter, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: #0f172a;
}

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

.app {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  min-height: 100vh;
}

/* ── Form panel ─────────────────────────────────────────── */

.panel {
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #0b1220 0%, #111827 100%);
  color: #e5e7eb;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  max-height: 100vh;
  position: sticky;
  top: 0;
}

.panel-header {
  padding: 28px 24px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #93c5fd;
  font-weight: 600;
}

.panel-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.sub {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: #94a3b8;
}

.ttl-banner {
  margin: 12px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: #fde68a;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.28);
}

#offer-form {
  flex: 1;
  overflow: auto;
  padding: 8px 24px 24px;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

.field-group {
  margin-top: 22px;
  padding-top: 4px;
}

.field-group h2 {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #93c5fd;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

label > span {
  font-size: 12px;
  font-weight: 500;
  color: #cbd5e1;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="file"],
select,
textarea {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.55);
  color: #f8fafc;
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder,
textarea::placeholder {
  color: #64748b;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%94a3b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

textarea {
  resize: vertical;
  min-height: 64px;
  line-height: 1.45;
}

input[type="file"] {
  padding: 8px;
  font-size: 12px;
}

input[type="file"]::file-selector-button {
  margin-right: 10px;
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  background: #1e3a5f;
  color: #dbeafe;
  cursor: pointer;
}

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

.logo-row input[type="file"] {
  flex: 1;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.panel-actions {
  display: flex;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(2, 6, 23, 0.45);
}

.btn {
  border: 0;
  border-radius: 9px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  flex: 1;
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn.secondary {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.btn.secondary:hover {
  background: #334155;
}

.btn.ghost {
  background: transparent;
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.25);
  padding: 8px 12px;
}

.btn.ghost:hover {
  background: rgba(148, 163, 184, 0.12);
}

/* ── Preview ────────────────────────────────────────────── */

.preview-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  position: sticky;
  top: 0;
  z-index: 5;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #0f766e;
  background: #ccfbf1;
  border-radius: 999px;
  padding: 6px 12px;
}

.live-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #14b8a6;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.25);
}

.sheet-stage {
  flex: 1;
  padding: 28px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: auto;
}

/* ── Letter (print surface) ─────────────────────────────── */

.letter {
  width: 8.5in;
  min-height: 11in;
  background: var(--sheet);
  box-shadow: var(--shadow);
  color: var(--text);
  display: flex;
  flex-direction: column;
  position: relative;
}

.letter-accent {
  height: 6px;
  background: var(--ink);
  flex-shrink: 0;
}

.letter-inner {
  flex: 1;
  padding: 0.5in 0.85in 0.35in;
}

.letter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 22px;
  margin-bottom: 34px;
  border-bottom: 1px solid var(--ink);
}

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

.logo-box {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border: 1px dashed #c5cad3;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #f8fafc;
  color: #94a3b8;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.logo-box.has-image {
  border-style: solid;
  border-color: transparent;
  background: transparent;
}

.logo-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.company-name {
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 21px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.2px;
  line-height: 1.25;
}

.company-address {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
  letter-spacing: 0.2px;
}

.company-contact {
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
  line-height: 1.6;
  flex-shrink: 0;
}

.doc-label {
  margin: 0 0 6px;
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.offer-date {
  margin: 0 0 30px;
  font-size: 13.5px;
  color: var(--body);
}

.candidate-block {
  font-style: normal;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--body);
  margin: 0 0 30px;
}

.candidate-block p {
  margin: 0 0 3px;
}

.candidate-name {
  font-weight: 600;
  color: #1a1f29;
}

.body {
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--text);
}

.body p {
  margin: 0 0 22px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 32px 0 12px;
  font-family: Inter, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  white-space: nowrap;
}

.section-head .rule {
  flex: 1;
  height: 1px;
  background: var(--line);
}

.optional-note:empty {
  display: none;
}

.optional-note:not(:empty)::before {
  content: " ";
}

.closing-block {
  margin-top: 34px !important;
}

.sincerely {
  margin: 36px 0 2px !important;
}

.sig-space {
  height: 40px;
}

.sender-name {
  margin: 0 0 2px !important;
  font-weight: 700;
}

.sender-title {
  margin: 0 0 44px !important;
  color: var(--muted);
  font-family: Inter, system-ui, sans-serif;
  font-size: 13px;
}

.acceptance {
  border-top: 1px solid var(--ink);
  padding-top: 30px;
  font-family: Inter, system-ui, sans-serif;
}

.acceptance-label {
  margin: 0 0 22px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--ink);
}

.acceptance > p:nth-child(2) {
  margin: 0 0 30px;
  font-size: 13.5px;
  color: var(--body);
  line-height: 1.6;
}

.sig-rows {
  display: flex;
  gap: 64px;
  margin-top: 8px;
}

.sig-rows > div {
  flex: 1;
}

.sig-line {
  border-bottom: 1px solid var(--text);
  height: 38px;
}

.sig-rows p {
  margin: 8px 0 0;
  font-size: 10.5px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--faint);
}

.letter-footer {
  margin-top: auto;
  height: 0.5in;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.85in;
  font-family: Inter, system-ui, sans-serif;
  font-size: 9.5px;
  letter-spacing: 0.3px;
  color: var(--faint);
  border-top: 0.5px solid var(--line);
}

/* Empty / missing fill states in preview */
[data-bind].is-empty {
  background: color-mix(in srgb, #f59e0b 14%, transparent);
  border-radius: 2px;
  outline: 1px dashed color-mix(in srgb, #f59e0b 45%, transparent);
  outline-offset: 1px;
}

/* ── Responsive ─────────────────────────────────────────── */

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

  .panel {
    position: relative;
    max-height: none;
  }

  .sheet-stage {
    padding: 16px;
  }

  .letter {
    width: min(8.5in, 100%);
    transform-origin: top center;
  }
}

@media (max-width: 720px) {
  .letter {
    font-size: 90%;
  }

  .letter-inner {
    padding: 0.4in 0.55in 0.3in;
  }

  .company-name {
    font-size: 17px;
  }

  .body {
    font-size: 13px;
  }

  .sig-rows {
    flex-direction: column;
    gap: 24px;
  }
}

/* ── Print / PDF ────────────────────────────────────────── */

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

  .panel,
  .preview-toolbar {
    display: none !important;
  }

  .app,
  .preview-wrap,
  .sheet-stage {
    display: block;
    padding: 0;
    margin: 0;
    min-height: 0;
    overflow: visible;
  }

  .letter {
    width: 100%;
    min-height: auto;
    box-shadow: none;
    margin: 0;
  }

  @page {
    size: letter;
    margin: 0;
  }
}

/* html2pdf capture mode */
.letter.pdf-export .logo-box:not(.has-image) {
  border-color: transparent;
  background: transparent;
  color: transparent;
}

.letter.pdf-export [data-bind].is-empty {
  background: none;
  outline: none;
}
