@font-face { font-family: "Cinzel"; src: url("/assets/fonts/Cinzel-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Cinzel"; src: url("/assets/fonts/Cinzel-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --navy: #0b1f4d;
  --navy-2: #13306f;
  --blue: #1e56c8;
  --gold: #b8862a;
  --gold-2: #e3b54f;
  --ink: #1d2733;
  --text: #2c3539;
  --muted: #5e6e82;
  --line: #dde3ec;
  --bg: #f3f5f9;
  --panel: #ffffff;
  --danger: #b42318;
  --ok: #1a7f4b;
  --radius: 10px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--ui); }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--navy); color: #fff;
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, var(--navy) 0%, var(--blue) 45%, var(--gold) 62%, var(--gold-2) 100%) 1;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { background: #fff; border-radius: 6px; padding: 3px 4px; height: 34px; width: auto; }
.brand-name { font-family: "Cinzel", serif; font-weight: 700; letter-spacing: .02em; font-size: 15px; }
.brand-sub { color: var(--gold-2); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.tabs { display: flex; gap: 4px; background: rgba(255,255,255,.08); padding: 4px; border-radius: 999px; }
.tab { border: 0; background: transparent; color: #cfd8ea; padding: 7px 16px; border-radius: 999px; font: 600 13px var(--ui); cursor: pointer; }
.tab.is-active { background: #fff; color: var(--navy); }

main { padding: 18px 20px 40px; max-width: 1500px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- Compose ---------- */
#tab-compose { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; gap: 18px; align-items: start; }
.form { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
legend { font: 700 12px var(--ui); letter-spacing: .08em; text-transform: uppercase; color: var(--gold); margin-bottom: 4px; padding: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: 14px/1.4 var(--ui); color: var(--ink); background: #fff;
  border: 1px solid #cdd5e1; border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--blue) 35%, transparent); border-color: var(--blue); }
input[readonly] { background: #f6f8fb; }
.hint { color: var(--muted); font-size: 12px; }
.hint code { background: #eef2f8; padding: 0 4px; border-radius: 4px; }

.ref-card {
  border-radius: var(--radius); padding: 14px; color: #fff;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 70%, #2a3f73 100%);
  position: relative; overflow: hidden;
}
.ref-card::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: linear-gradient(90deg, var(--blue), var(--gold) 60%, var(--gold-2));
}
.ref-card .field > span { color: #c9d3e8; }
.ref-row { display: flex; gap: 10px; }
.ref-row .field { flex: 1; }
.ref-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.meta-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--gold-2); }
.meta-value { font-family: "Cinzel", serif; font-weight: 700; font-size: 16px; }
.ref-value { font-size: 18px; }
.ref-card.is-assigned .meta-label#ref-label { color: #8fe0b3; }
.ref-note { margin: 10px 0 0; font-size: 12px; color: #c9d3e8; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; border-top: 1px solid var(--line); padding-top: 14px; }
.btn {
  border: 1px solid #c8d1df; background: #fff; color: var(--navy); border-radius: 8px;
  padding: 9px 14px; font: 600 13.5px var(--ui); cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--navy); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--navy-2); }
.btn.gold { background: linear-gradient(180deg, #d2a447, var(--gold)); border-color: #a77920; color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); border-color: #f0c7c2; }
.btn.danger:hover:not(:disabled) { background: #fdf1f0; border-color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.status { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

/* ---------- Preview ---------- */
.preview-panel { position: sticky; top: 12px; overflow: hidden; }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; color: var(--navy); }
.preview-head small { color: var(--muted); font-weight: 400; }
.preview-scroll { background: #e7ebf2; padding: 18px; max-height: calc(100vh - 140px); overflow: auto; }
.sheet-wrap { margin: 0 auto; }

/* Sheet is drawn at real A4 size in points, then scaled to fit. */
.sheet {
  --scale: 1;
  width: 595.4pt; min-height: 841.7pt;
  transform: scale(var(--scale)); transform-origin: top left;
  background: #fff; box-shadow: 0 2px 14px rgba(11,31,77,.18);
  position: relative; color: #2c3539;
  font-family: "Cinzel", serif; font-size: 11pt; line-height: 1.685; /* 1.25 x Cinzel line box */
  padding: 126pt 57.6pt 72pt; /* top 1.75in, sides 0.8in, bottom 1in */
  display: flex; flex-direction: column;
}
.sheet p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet .wm { position: absolute; left: 50%; top: 50%; width: 374.4pt; transform: translate(-50%, -50%); pointer-events: none; opacity: .06; }
.sheet .lh { position: absolute; left: 57.6pt; right: 57.6pt; top: 32.4pt; }
.sheet .lh-row { display: flex; align-items: center; }
.sheet .lh-logo { flex: none; display: block; }
.sheet .lh-info { flex: none; }
.sheet .lh-name { font-size: 22pt; font-weight: 700; color: #0b1f4d; line-height: 1.348; white-space: nowrap; }
.sheet .lh-cin { font-size: 9pt; font-weight: 700; color: #b8862a; }
.sheet .lh-contact { font-size: 9pt; white-space: nowrap; }
.sheet .lh-contact a { color: #1e56c8; text-decoration: none; }
.sheet .rule { display: block; width: 100%; height: 1pt; margin-top: 6pt; }
.sheet .ft { position: absolute; left: 57.6pt; right: 57.6pt; bottom: 25.2pt; text-align: center; }
.sheet .ft .rule { height: 0.5pt; margin: 0 0 3pt; }
.sheet .ft-office { font-size: 6pt; color: #5e6e82; white-space: nowrap; }
.sheet .ft-conf { font-size: 6pt; color: #0b1f4d; white-space: nowrap; }
.sheet .lbl { font-weight: 700; color: #0b1f4d; }
.sheet b { color: #0b1f4d; }
.sheet .refrow { display: flex; justify-content: space-between; gap: 12pt; }
.sheet .rcp { font-size: 10pt; }
.sheet .muted { color: #5e6e82; }
.sheet .sig { font-size: 9pt; margin-top: 24pt; }
.sheet .blank { height: 1.685em; }
.sheet .bul { display: flex; padding-left: 18pt; }
.sheet .bul::before { content: "•"; color: #b8862a; font-weight: 700; width: 18pt; flex: none; }
.sheet .placeholder { color: #a3adbb; }

/* ---------- Account / sign-in ---------- */
.account { display: flex; align-items: center; gap: 10px; color: #cfd8ea; font-size: 12.5px; }
.btn.signout { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn.signout:hover:not(:disabled) { border-color: #fff; }
.login-page { min-height: 100vh; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 55%, #2a3f73 100%); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; max-width: none; }
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 28px 26px 22px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.3);
  position: relative; overflow: hidden;
}
.login-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: linear-gradient(90deg, var(--navy), var(--blue) 45%, var(--gold) 62%, var(--gold-2));
}
.login-logo { align-self: center; width: 150px; height: auto; }
.login-card h1 { margin: 4px 0 0; text-align: center; font: 700 18px "Cinzel", serif; color: var(--navy); }
.login-sub { margin: 0 0 6px; text-align: center; color: var(--gold); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.login-btn { margin-top: 4px; padding: 11px; }

/* ---------- Checkbox rows ---------- */
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--ink); cursor: pointer; }
.check input { width: auto; margin-top: 3px; accent-color: var(--navy); }
.check small { display: block; color: var(--muted); font-size: 12px; }

/* ---------- Settings ---------- */
.settings { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 22px; }
.logo-box { border: 1px dashed #c8d1df; border-radius: 8px; height: 110px; display: grid; place-items: center; background: #fafbfd; }
.logo-box img { max-width: 80%; max-height: 90px; }
.logo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { display: inline-flex; align-items: center; }

/* ---------- Register ---------- */
.register { padding: 14px; }
.register-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.register-tools input { flex: 1 1 260px; width: auto; }
.register-tools select { width: auto; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.reg-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.reg-table th { text-align: left; background: #f6f8fb; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.reg-table td { padding: 9px 12px; border-bottom: 1px solid #edf0f5; vertical-align: top; }
.reg-table tr:last-child td { border-bottom: 0; }
.reg-table .ref { font-family: "Cinzel", serif; font-weight: 700; color: var(--navy); white-space: nowrap; }
.reg-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.reg-empty { text-align: center; color: var(--muted); padding: 28px !important; }

@media (max-width: 980px) {
  #tab-compose { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .preview-scroll { max-height: none; }
}
@media (max-width: 560px) {
  main { padding: 12px 12px 32px; }
  .topbar { padding: 10px 12px; }
  .ref-row { flex-direction: column; }
  .reg-table th:nth-child(4), .reg-table td:nth-child(4) { display: none; }
}
