:root {
  --navy: #0b192c;
  --form-navy: #133e58;
  --teal: #189ab4;
  --dark-teal: #133e58;
  --gold: #d4af37;
  --ink: #1a1a1a;
  --grey: #5c656e;
  --line: #d5dde3;
  --desk: #d5dee4;
  --paper: #ffffff;
  --row: #f4f7f8;
  --danger: #c62828;
  --ok: #2e7d32;
  --amber: #8a5a00;
  --shadow: 0 16px 40px rgba(10, 22, 40, 0.14);
  color-scheme: light;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--desk); min-height: 100vh; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; background: var(--navy); color: white;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img { display: block; height: 28px; width: auto; }
.brand-name, .brand-legal { display: block; }
.brand-name { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.02em; }
.brand-legal { color: #c5d0d8; font-size: 0.78rem; letter-spacing: 0.04em; }

.primary, .quiet, .danger {
  border-radius: 6px; padding: 7px 14px; font-size: 0.92rem; font-weight: 500; border: 1px solid transparent;
}
.primary { background: var(--brand, var(--dark-teal)); color: white; }
.paper-logo { height: 52px; width: auto; }
.step-panel { margin: 16px 0; padding: 14px; border: 1px solid var(--line); border-left: 4px solid var(--brand-accent, var(--teal)); border-radius: 10px; background: #f7fbfc; }
#step-sign { display: block; margin: 8px 0; background: #fff; border: 1px dashed var(--line); border-radius: 8px; touch-action: none; }
.paper-head { border-bottom: 3px solid var(--brand-accent, var(--teal)); }
.primary:hover:not(:disabled) { background: #00675d; }
.quiet { background: white; border-color: #b9c5cd; }
.quiet:hover:not(:disabled) { border-color: var(--dark-teal); color: var(--dark-teal); }
.quiet.on-dark { background: transparent; color: white; border-color: #4d5d70; }
.quiet.on-dark:hover { color: var(--teal); border-color: var(--teal); }
.danger { background: white; color: var(--danger); border-color: #e4b4b4; }
.danger:hover:not(:disabled) { background: #fdf1f1; }
.wide { width: 100%; }

.workspace { display: grid; grid-template-columns: 300px 1fr; min-height: calc(100vh - 60px); }
.rail { background: #f4f7f8; border-right: 1px solid #c5d0d6; padding: 16px 12px; }
.search input {
  width: 100%; margin: 12px 0 8px; padding: 7px 10px; border: 1px solid #c5d0d6; border-radius: 6px; background: white;
}
.request-list { display: flex; flex-direction: column; gap: 2px; }
.request-item {
  display: grid; grid-template-columns: 1fr auto; gap: 1px 8px; width: 100%; text-align: left;
  background: transparent; border: 0; border-left: 3px solid transparent; padding: 8px 10px; border-radius: 0;
}
.request-item:hover { background: #e8eef1; }
.request-item[aria-current="true"] { background: white; border-left-color: var(--dark-teal); }
.request-item .r-ref { font-weight: 600; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.request-item .r-total { font-size: 0.88rem; font-variant-numeric: tabular-nums; text-align: right; }
.request-item .r-sub { grid-column: 1 / -1; color: var(--grey); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.request-item .pill { justify-self: start; }
.list-empty { color: var(--grey); font-size: 0.88rem; padding: 12px 10px; }

.pill {
  display: inline-block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 1px 8px; border-radius: 999px; background: #e3e8ec; color: var(--grey);
}
.pill.submitted { background: #e1effa; color: #1c5d8c; }
.pill.approved { background: #e5f4e6; color: var(--ok); }
.pill.rejected, .pill.cancelled { background: #fbe9e9; color: var(--danger); }

#desk { padding: 20px 28px 48px; min-width: 0; }
.empty { max-width: 520px; margin: 12vh auto; text-align: center; background: white; padding: 36px; border-radius: 10px; box-shadow: var(--shadow); }
.empty h1 { margin: 0 0 8px; font-size: 1.4rem; color: var(--navy); }
.empty p { color: var(--grey); margin: 0 0 20px; }

.actions {
  position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 0; background: var(--desk);
}
.status-actions { display: contents; }
.save-state { color: var(--grey); font-size: 0.86rem; margin-left: auto; }
.save-state.dirty { color: var(--amber); }
.banner { max-width: 900px; margin: 4px auto 10px; padding: 10px 14px; border-radius: 6px; font-size: 0.92rem; }
.banner.error { background: #fdecec; color: #8e1c1c; border: 1px solid #f0c2c2; }
.banner.ok { background: #e8f5e9; color: #1d5a21; border: 1px solid #bfe0c1; }

.paper {
  max-width: 900px; margin: 0 auto; background: var(--paper); box-shadow: var(--shadow);
  padding: 28px 36px 24px; border-top: 4px solid var(--form-navy);
}
.paper-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px; }
.eyebrow { margin: 0; color: var(--dark-teal); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.paper-head h1 { margin: 2px 0 0; font-size: 1.5rem; color: var(--navy); letter-spacing: -0.02em; }
.ref-block { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.ref { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--form-navy); font-size: 1.05rem; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled input, fieldset:disabled textarea { background: #f6f8f9; color: #39424a; }
h2 { font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--form-navy); margin: 22px 0 8px; }
h3 { font-size: 0.92rem; margin: 0 0 6px; color: var(--navy); }
.label { font-size: 0.74rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--grey); margin-right: 4px; }
.types { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 10px 0; font-size: 0.93rem; }
.types label { display: inline-flex; align-items: center; gap: 6px; }
.types input[type="checkbox"], .types input[type="radio"] { accent-color: var(--dark-teal); width: 16px; height: 16px; }
.other-input { width: 160px; padding: 4px 8px; border: 0; border-bottom: 1px solid #9aa7b0; }

.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; }
.field { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
.field > span { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--grey); }
.field b { color: var(--danger); font-weight: 600; }
.field input, .field textarea, .items input {
  width: 100%; padding: 7px 9px; border: 1px solid #c8d2d8; border-radius: 5px; background: white;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus, .items input:focus { border-color: var(--dark-teal); outline: none; box-shadow: 0 0 0 2px rgba(0, 191, 165, 0.25); }
.field input[readonly] { background: #f2f5f7; color: var(--form-navy); font-weight: 600; }
.missing input, .missing textarea, input.missing, .types.missing { box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.35); border-color: var(--danger); }

.items { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.items th { background: var(--form-navy); color: white; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; padding: 7px 8px; text-align: left; font-weight: 600; }
.items th.num, .items td.num { text-align: right; }
.items td { padding: 4px; border-bottom: 1px solid var(--line); }
.items tbody tr:nth-child(odd) td { background: var(--row); }
.items td.desc { width: 56%; }
.items td.qty { width: 10%; }
.items td.unit { width: 16%; }
.items td.total { width: 18%; font-variant-numeric: tabular-nums; padding-right: 10px; }
.items td input { border-color: transparent; background: transparent; }
.items td input:hover { border-color: #c8d2d8; background: white; }
.items .num input { text-align: right; font-variant-numeric: tabular-nums; }
.items tfoot th { background: none; color: var(--navy); font-size: 0.85rem; text-align: left; padding: 10px 8px; }
.items tfoot .grand { font-weight: 700; font-size: 1.05rem; color: var(--navy); padding: 10px; border-bottom: 2px solid var(--form-navy); font-variant-numeric: tabular-nums; }
.hint { color: var(--grey); font-size: 0.8rem; margin: 4px 0 0; }
.note { color: var(--grey); font-size: 0.84rem; font-style: italic; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 16px; }

.page-two { margin-top: 18px; border: 1px solid var(--line); border-radius: 8px; padding: 0 16px; }
.page-two[open] { padding-bottom: 14px; }
.page-two summary { cursor: pointer; padding: 12px 0; display: flex; flex-direction: column; gap: 2px; list-style: none; }
.page-two summary::before { content: "\25B8  "; color: var(--dark-teal); }
.page-two[open] summary::before { content: "\25BE  "; }
.page-two summary span { font-weight: 600; color: var(--navy); display: inline; }
.page-two summary small { color: var(--grey); font-size: 0.8rem; }
.approval { border-top: 1px solid var(--line); padding-top: 10px; }
.history { color: var(--grey); font-size: 0.8rem; margin: 16px 0 0; }
.finance-note { margin-top: 14px; }

.sig-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 8px 0 4px; align-items: end; }
.sig-label { grid-column: 1 / -1; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--grey); }
.sig-box {
  height: 64px; border: 1px dashed #b9c5cd; border-radius: 5px; background: #fbfcfc;
  display: flex; align-items: flex-end; padding: 4px 8px; border-bottom: 2px solid var(--form-navy);
}
.sig-box.signed { border-style: solid; background: white; }
.sig-image { max-height: 56px; max-width: 100%; object-fit: contain; }
.sig-empty { color: #9aa7b0; font-size: 0.85rem; font-style: italic; }
.sig-buttons { display: flex; flex-direction: column; gap: 4px; }

.sign-dialog { border: 0; border-radius: 10px; padding: 0; box-shadow: var(--shadow); width: min(680px, 94vw); }
.sign-dialog::backdrop { background: rgba(10, 22, 40, 0.45); }
.sign-form { padding: 20px 22px; }
.sign-form h2 { margin: 0 0 2px; font-size: 1rem; text-transform: none; letter-spacing: -0.01em; color: var(--navy); }
#sign-pad {
  display: block; width: 100%; aspect-ratio: 3 / 1; margin: 10px 0 4px; touch-action: none; cursor: crosshair;
  background: white; border: 1px solid #c8d2d8; border-radius: 6px;
  background-image: linear-gradient(to top, transparent 22%, var(--form-navy) 22%, var(--form-navy) calc(22% + 1px), transparent calc(22% + 1px));
}
.sign-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.file-button { cursor: pointer; display: inline-flex; align-items: center; }
.remember { display: flex; gap: 8px; align-items: center; font-size: 0.88rem; color: var(--ink); }
.remember input { accent-color: var(--dark-teal); width: 16px; height: 16px; }
.sign-error { color: var(--danger); font-size: 0.88rem; margin: 8px 0 0; }
.sign-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid #c5d0d6; }
  .grid.two { grid-template-columns: 1fr; }
  .paper { padding: 20px 16px; }
  #desk { padding: 12px; }
}
