/* ---------------------------------------------------------------------------
   app.css - the tool around the document: top bar, form panel, banners.
   The document itself is styled in document.css.
--------------------------------------------------------------------------- */

/* ---- Fonts, bundled locally so the tool works with no internet ---- */
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Libre Baskerville'; src: url('/assets/fonts/libre-baskerville-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Libre Baskerville'; src: url('/assets/fonts/libre-baskerville-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Libre Baskerville'; src: url('/assets/fonts/libre-baskerville-latin-400-italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --brand:        #2b3a8f;
  --brand-deep:   #1b2559;
  --brand-soft:   #eef0fa;
  --chart-indigo: #3d4db3;
  --gold:         #a8811f;
  --gold-deep:    #7d5f13;
  --gold-soft:    #f6efdc;
  --ink:          #1b1e2e;
  --ink-2:        #4a4f66;
  --ink-3:        #767c93;
  --line:         #e2e4ee;
  --line-2:       #eef0f5;
  --wash:         #f4f5f9;
  --paper:        #ffffff;
  --good:         #16714f;
  --warn-bg:      #fdf5e3;
  --warn-ink:     #7a5a06;
  --bad:          #b3261e;
  --bad-bg:       #fdeceb;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Libre Baskerville', Georgia, 'Times New Roman', serif;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(23,26,45,.06), 0 8px 24px rgba(23,26,45,.07);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--wash);
  -webkit-font-smoothing: antialiased;
}

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

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

/* Visible keyboard focus everywhere. */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ============================ TOP BAR ============================ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: var(--brand-deep);
  color: #fff;
  border-bottom: 3px solid var(--gold);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { display: grid; place-items: center; color: var(--gold-soft); flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-family: var(--serif); font-size: 15px; letter-spacing: .01em; }
.brand-text small { font-size: 11px; color: #b9c0e4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  font-size: 11px; font-weight: 500; padding: 4px 10px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.25); white-space: nowrap;
}
.pill-muted { color: #b9c0e4; }
.pill-good  { color: #c9f0dd; border-color: rgba(160,235,205,.5); background: rgba(22,113,79,.35); }
.pill-warn  { color: #f7e3b5; border-color: rgba(247,227,181,.45); background: rgba(168,129,31,.3); }

.view-switch { display: flex; background: rgba(255,255,255,.12); border-radius: 999px; padding: 2px; }
.switch-btn {
  border: 0; background: transparent; color: #cfd5f2; padding: 5px 14px;
  border-radius: 999px; cursor: pointer; font-size: 12px; font-weight: 500;
}
.switch-btn.is-active { background: #fff; color: var(--brand-deep); }

.btn {
  border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.08);
  color: #fff; padding: 7px 14px; border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover:not(:disabled) { background: rgba(255,255,255,.18); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #241a00; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #c09627; border-color: #c09627; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-quiet { background: transparent; border-color: var(--line); color: var(--brand); }
.btn-quiet:hover:not(:disabled) { background: var(--brand-soft); }

/* "More" dropdown */
.menu { position: relative; }
.menu > summary { list-style: none; display: inline-block; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  background: #fff; color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); min-width: 250px; padding: 5px;
}
.menu-item {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 11px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.menu-item:hover { background: var(--brand-soft); }
.menu-item-danger { color: var(--bad); }
.menu-item-danger:hover { background: var(--bad-bg); }

/* ============================ BANNERS ============================ */
.banners { display: flex; flex-direction: column; gap: 1px; }
.banner {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 18px; font-size: 13px;
}
.banner-text { flex: 1; }
.banner-warn { background: var(--warn-bg); color: var(--warn-ink); border-bottom: 1px solid #eddfb6; }
.banner-bad  { background: var(--bad-bg);  color: var(--bad);      border-bottom: 1px solid #f3cfcc; }
.banner-good { background: #eaf6f0;        color: var(--good);     border-bottom: 1px solid #cae7da; }
.banner-x { border: 0; background: none; cursor: pointer; font-size: 18px; line-height: 1; opacity: .6; }
.banner-x:hover { opacity: 1; }

/* ============================ PROGRESS ============================ */
.progress {
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 12px 18px;
}
.progress-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; font-size: 13px; }
.progress-head strong { font-weight: 600; }
.progress-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 12.5px; }
.progress-list li { display: flex; align-items: center; gap: 8px; color: var(--ink-3); }
.progress-list em { font-style: normal; font-size: 11px; color: var(--ink-3); }
.progress-list .dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none;
}
.progress-list .is-running { color: var(--ink); font-weight: 500; }
.progress-list .is-running .dot { background: var(--gold); animation: pulse 1.1s ease-in-out infinite; }
.progress-list .is-done { color: var(--good); }
.progress-list .is-done .dot { background: var(--good); }
.progress-list .is-failed { color: var(--warn-ink); }
.progress-list .is-failed .dot { background: var(--warn-ink); }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.5); opacity: .55; } }

/* ============================ LAYOUT ============================ */
.layout {
  display: grid;
  grid-template-columns: 430px minmax(0, 1fr);
  align-items: start;
  min-height: 0;
}

.panel {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 18px 20px 60px;
  position: sticky; top: 58px;
  max-height: calc(100vh - 58px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.output {
  padding: 26px 20px 80px;
  min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}

/* ============================ FORM ============================ */
.fs { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 16px; margin: 0 0 16px; }
.fs > legend {
  font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--brand); padding: 0 7px;
}
.fs-note { margin: 0 0 10px; font-size: 12px; color: var(--ink-3); }

.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > .label { display: block; font-size: 12.5px; font-weight: 500; margin-bottom: 5px; color: var(--ink-2); }
.field > .label small { font-weight: 400; color: var(--ink-3); }
.field-req > .label b { color: var(--bad); }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover:not(:disabled), select:hover, textarea:hover { border-color: #c8cbdb; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(43,58,143,.12);
}
textarea { resize: vertical; }
input.is-bad { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(179,38,30,.12); }
input[type="file"] { padding: 6px; font-size: 12.5px; background: var(--wash); }

.hint { display: block; margin-top: 5px; font-size: 11.5px; color: var(--ink-3); line-height: 1.45; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.inline-row { display: flex; gap: 8px; align-items: center; }
.inline-row input { flex: 1; }

.thumb-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.thumb { max-height: 52px; max-width: 90px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.thumb-wide { max-width: 170px; }

/* ---- little tables in the form ---- */
.table-wrap { overflow-x: auto; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mini-table th, .mini-table td { border: 1px solid var(--line); padding: 5px 7px; text-align: left; }
.mini-table thead th { background: var(--wash); font-weight: 600; font-size: 11.5px; color: var(--ink-2); }
.mini-table tbody th { font-weight: 500; }
.mini-table tbody th small { display: block; font-weight: 400; font-size: 10.5px; color: var(--ink-3); line-height: 1.35; }
.mini-table input { padding: 4px 6px; border-radius: 4px; text-align: right; }
.mini-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.mini-table tfoot th, .mini-table tfoot td { background: var(--wash); font-weight: 600; }
.mini-table .grand { color: var(--brand); }
.mini-table tr.is-bad th, .mini-table tr.is-bad td { background: var(--bad-bg); }
.mini-table tr.is-bad input { border-color: var(--bad); }

.warn {
  margin: 10px 0 0; padding: 9px 11px; border-radius: 6px;
  background: var(--bad-bg); color: var(--bad); font-size: 12.5px; border: 1px solid #f3cfcc;
}

/* ---- resource person rows ---- */
.rp-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.rp-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 26px; gap: 4px; }
.rp-row input { padding: 6px 7px; font-size: 12px; }
.rp-del {
  border: 1px solid var(--line); background: #fff; border-radius: 5px;
  cursor: pointer; color: var(--ink-3); font-size: 15px; line-height: 1;
}
.rp-del:hover { background: var(--bad-bg); color: var(--bad); border-color: #f3cfcc; }

/* ---- NEP list ---- */
.nep-mode { margin: 0 0 9px; font-size: 12px; color: var(--ink-3); }
.linkish { border: 0; background: none; padding: 0; color: var(--brand); text-decoration: underline; cursor: pointer; font-size: 12px; }
.nep-list { display: flex; flex-direction: column; gap: 5px; }
.nep-item {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
  font-size: 12.5px; line-height: 1.4;
}
.nep-item:hover { background: var(--wash); }
.nep-item.is-on { border-color: #c2c9ec; background: var(--brand-soft); }
.nep-item input { margin-top: 2px; accent-color: var(--brand); flex: none; }
.nep-item strong { display: block; font-weight: 500; }
.nep-item em { display: block; font-style: normal; font-size: 11px; color: var(--ink-3); margin-top: 1px; }

/* ---- declarations ---- */
.decl-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.decl-item {
  display: flex; gap: 9px; align-items: flex-start; font-size: 12px; line-height: 1.45;
  padding: 8px 9px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; color: var(--ink-2);
}
.decl-item:hover { background: var(--wash); }
.decl-item input { margin-top: 2px; accent-color: var(--brand); flex: none; }

.save-note { font-size: 11.5px; color: var(--ink-3); text-align: center; margin: 6px 0 0; }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .panel {
    position: static;
    max-height: none;
    overflow: visible;
    overscroll-behavior: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .output { padding: 18px 10px 60px; }
}

@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-actions { margin-left: 0; width: 100%; }
  .brand-text small { display: none; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .rp-row { grid-template-columns: 1fr 1fr; }
  .rp-row .rp-del { grid-column: 1 / -1; height: 28px; }
}

@media (max-width: 560px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* The offscreen ruler used to measure blocks before paginating. */
.measure-ruler {
  position: absolute; left: -10000px; top: 0; visibility: hidden;
  pointer-events: none; width: 794px;
}

/* ---------------------------------------------------------------------------
   Mobile document fit - added 19 Aug 2026
   The A4 preview (.doc / .sheet) is ~794px wide, which made the whole page
   slide sideways on a phone. Lock the page to the viewport width and scale the
   preview to fit. Screen media only - printing is untouched.
   --------------------------------------------------------------------------- */
@media screen and (max-width: 900px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  .layout, .panel, .output { max-width: 100%; min-width: 0; }
  .output { overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  .doc { zoom: 0.78; }
}
@media screen and (max-width: 640px) {
  .doc { zoom: 0.56; }
}
@media screen and (max-width: 430px) {
  .doc { zoom: 0.44; }
}
@supports not (zoom: 1) {
  @media screen and (max-width: 900px) {
    .output { overflow-x: auto; }
    .doc { zoom: normal; }
  }
}
