* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* ---------- LOGIN GATE ---------- */
.login-gate {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
}
.login-card {
  background: #fff; padding: 32px 28px; border-radius: 12px;
  width: 320px; box-shadow: 0 12px 48px rgba(0,0,0,0.25);
  display: flex; flex-direction: column; gap: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.login-card h2 { margin: 0 0 6px; font-size: 20px; text-align: center; }
.login-card label { font-size: 12px; color: #444; display: flex; flex-direction: column; gap: 4px; }
.login-card input {
  padding: 8px 10px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 6px; background: #fff;
}
.login-card input:focus { outline: 2px solid #2563eb; outline-offset: -1px; border-color: transparent; }
.pass-wrap { position: relative; display: block; }
.pass-wrap input { padding-right: 36px; width: 100%; }
.pass-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; cursor: pointer; padding: 4px 8px;
  font-size: 16px; line-height: 1; opacity: 0.6;
}
.pass-toggle:hover { opacity: 1; }
.login-card button {
  margin-top: 8px; padding: 10px; font-size: 14px; cursor: pointer;
  border: 0; border-radius: 6px; background: #2563eb; color: #fff; font-weight: 600;
}
.login-card button:hover { background: #1d4ed8; }
/* ---------- TOAST ---------- */
.toast-host {
  position: fixed; top: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 240px; max-width: 360px;
  padding: 12px 16px; border-radius: 8px;
  background: #111; color: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  font-size: 13px; line-height: 1.4;
  animation: toast-in 180ms ease-out;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.toast.error { background: #dc2626; }
.toast.success { background: #16a34a; }
.toast.info { background: #2563eb; }
.toast.leaving { animation: toast-out 180ms ease-in forwards; }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toast-out { from { transform: translateX(0); opacity: 1; } to { transform: translateX(20px); opacity: 0; } }
@media print { .toast-host { display: none; } }

html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f3f4f6; color: #111; }
body { display: flex; min-height: 100vh; }

/* ---------- FORM PANEL ---------- */
.form-panel {
  width: 360px;
  flex: 0 0 360px;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  padding: 16px;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}
.form-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.form-header h1 { font-size: 18px; margin: 0; }
.form-header .row { display: flex; gap: 6px; }
.form-panel details { margin-bottom: 12px; border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px 12px; background: #fafafa; }
.form-panel summary { font-weight: 600; cursor: pointer; padding: 4px 0; }
.form-panel label { display: block; font-size: 12px; color: #444; margin: 8px 0; }
.form-panel input, .form-panel textarea {
  width: 100%; padding: 6px 8px; font-size: 13px;
  border: 1px solid #d1d5db; border-radius: 6px; background: #fff;
  margin-top: 4px; font-family: inherit;
}
.form-panel input:focus, .form-panel textarea:focus { outline: 2px solid #2563eb; outline-offset: -1px; border-color: transparent; }

.item-row { display: grid; grid-template-columns: 1fr 70px 90px 28px; gap: 6px; align-items: end; margin-top: 8px; padding: 8px; background: #fff; border: 1px solid #e5e7eb; border-radius: 6px; }
.item-row label { margin: 0; font-size: 11px; }
.item-row .x { background: #ef4444; color: #fff; border: 0; border-radius: 4px; height: 30px; cursor: pointer; padding: 0; }
.item-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.item-buttons button { font-size: 11px; padding: 6px 8px; }
.total-line { margin-top: 12px; padding-top: 8px; border-top: 1px dashed #d1d5db; text-align: right; font-size: 14px; }

.form-panel button {
  padding: 8px 12px; font-size: 13px; cursor: pointer; border-radius: 6px;
  border: 1px solid #d1d5db; background: #fff; color: #111;
}
.form-panel button.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.form-panel button.primary:hover { background: #1d4ed8; }
.form-panel button.ghost { background: transparent; }
.form-footer { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.form-footer button { flex: 1; min-width: 120px; }

.history { max-height: 240px; overflow-y: auto; }
.history .item { padding: 6px 8px; border-bottom: 1px solid #e5e7eb; font-size: 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 4px; }
.history .item:hover { background: #f3f4f6; }
.history .item .meta { color: #666; font-size: 11px; }
.history .item .del { color: #ef4444; cursor: pointer; padding: 0 6px; }

/* ---------- PREVIEW PANE ---------- */
.preview-pane {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  height: 100vh;
}

/* A4-ish page; print uses real A4 */
.doc {
  background: #fff;
  width: 210mm;
  min-height: 297mm;
  padding: 20mm 18mm;
  margin: 0 auto 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  font-family: "Times New Roman", "Liberation Serif", serif;
  font-size: 11pt;
  line-height: 1.35;
  color: #000;
}
.doc h1, .doc h2 { text-align: center; font-size: 13pt; margin: 0 0 8pt; }
.doc h2 { font-size: 12pt; }
.doc .center { text-align: center; }
.doc .right { text-align: right; }
.doc .between { display: flex; justify-content: space-between; }
.doc p { margin: 0 0 6pt; text-align: justify; }
.doc .small { font-size: 10pt; }
.doc table { width: 100%; border-collapse: collapse; margin: 6pt 0; }
.doc table.bordered th, .doc table.bordered td { border: 1px solid #000; padding: 4pt 6pt; vertical-align: top; }
.doc table.bordered th { text-align: center; font-weight: bold; }
.doc table.signatures { table-layout: fixed; margin-top: 10pt; }
.doc table.signatures td { width: 50%; vertical-align: top; padding: 4pt 6pt 4pt 0; font-size: 10.5pt; }
.doc table.signatures td + td { padding-left: 6pt; }
.doc table.signatures .label { font-weight: bold; padding-bottom: 4pt; }
.doc .sect-title { font-weight: bold; text-align: center; margin: 10pt 0 6pt; text-transform: uppercase; }
.doc ol { padding-left: 18pt; margin: 0; }
.doc ol li { margin-bottom: 4pt; text-align: justify; }
.doc .bold { font-weight: bold; }
.doc .underline { text-decoration: underline; }
.doc .nowrap { white-space: nowrap; }
.doc .total-row td { font-weight: bold; }

@media print {
  body { background: #fff; display: block; }
  .form-panel { display: none; }
  .preview-pane { padding: 0; height: auto; overflow: visible; }
  .doc {
    width: auto; min-height: 0; padding: 14mm 16mm; margin: 0;
    box-shadow: none; page-break-after: always;
  }
  .doc:last-child { page-break-after: auto; }
  @page { size: A4; margin: 0; }
}
