:root {
  --olive: #86881f;
  --olive-dark: #6b6d18;
  --ink: #23241c;
  --muted: #6b6d66;
  --line: #dcdcd2;
  --bg: #f4f4ee;
  --panel: #ffffff;
  --warn: #b4531f;
  --ok: #2f7d44;
  --radius: 8px;
  --formfont: "Segoe UI", "Helvetica Neue", Arial, "Nirmala UI", "Noto Sans Bengali",
               "Vrinda", "SolaimanLipi", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

/* ───────────────────────── chrome ───────────────────────── */

#topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
#topbar .brand {
  display: flex; align-items: baseline; gap: 8px;
  font-weight: 700; letter-spacing: .02em;
}
#topbar .brand small { font-weight: 400; color: var(--muted); letter-spacing: 0; }
#topbar .spacer { flex: 1; }

.rolechip {
  font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px;
  background: #eceedb; color: var(--olive-dark);
}
.rolechip.client { background: #e4eef3; color: #2b5f7a; }

/* who this browser belongs to */
.repchip {
  font-size: 12.5px; font-weight: 600; max-width: 190px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: #fbfbf7; color: var(--muted);
}
.repchip::before { content: "◍ "; color: var(--olive); }
.repchip:hover { border-color: var(--olive); color: var(--ink); }

/* ── dialogs: identity, sent, failed ── */
.sheet {
  position: fixed; inset: 0; z-index: 99;
  background: rgba(20,20,15,.55);
  display: grid; place-items: center; padding: 20px;
}
.sheetcard {
  background: var(--panel); border-radius: 14px;
  padding: 26px 26px 22px; max-width: 430px; width: 100%;
  box-shadow: 0 18px 50px rgba(0,0,0,.28);
}
.sheetcard h3 { margin: 0 0 8px; font-size: 19px; }
.sheetlede { margin: 0 0 18px; font-size: 13.5px; line-height: 1.55; color: var(--muted); }
.sheetnote { margin: 14px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.sheetrow { display: flex; gap: 8px; margin-top: 18px; }
.sheetrow > * { flex: 1; }
.sheeterr {
  font-size: 12.5px; line-height: 1.45; color: #7a4020;
  background: #fdf3ec; border-left: 3px solid var(--warn);
  padding: 9px 11px; border-radius: 0 6px 6px 0; margin-top: -4px;
}
.sheetcard.done { text-align: center; }
.sheetcard.done .sheetrow { justify-content: center; }
.tick {
  width: 54px; height: 54px; margin: 0 auto 14px;
  border-radius: 50%; background: #eef2e0; color: var(--olive-dark);
  display: grid; place-items: center; font-size: 27px; font-weight: 700;
}
.refline {
  margin: 0; padding: 13px; border-radius: 8px;
  background: #f7f7f1; border: 1px dashed #c6c8ba;
  font-size: 12px; color: var(--muted); line-height: 1.7;
}
.refline b {
  display: inline-block; font-size: 19px; letter-spacing: .06em;
  color: var(--ink); font-family: ui-monospace, Consolas, monospace;
}

button, .btn {
  font: inherit; font-weight: 600;
  padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { border-color: #b9bbae; }
button.primary, .btn.primary {
  background: var(--olive); border-color: var(--olive); color: #fff;
}
button.primary:hover { background: var(--olive-dark); }
button.ghost { background: transparent; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ───────────────────────── layout ───────────────────────── */

#app { display: flex; align-items: flex-start; gap: 0; }

#panel {
  width: 460px; flex: 0 0 460px;
  height: calc(100vh - 57px);
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 4px 0 120px;
}
#stage {
  flex: 1; min-width: 0;
  height: calc(100vh - 57px);
  overflow: auto;
  padding: 24px;
  display: flex; flex-direction: column; align-items: center; gap: 24px;
  background: #e8e8e0;
}

/* ───────────────────────── panel content ───────────────────────── */

.section { border-bottom: 1px solid var(--line); }
.section > h2 {
  margin: 0; padding: 14px 18px;
  font-size: 14px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--olive-dark);
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  user-select: none;
}
.section > h2::before { content: "▾"; font-size: 11px; opacity: .6; }
.section.collapsed > h2::before { content: "▸"; }
.section.collapsed .sbody { display: none; }
.section > h2 .count {
  margin-left: auto; font-size: 11px; font-weight: 500;
  text-transform: none; letter-spacing: 0; color: var(--muted);
}
.sbody { padding: 2px 18px 18px; }

.f { margin-bottom: 14px; }
.f > label {
  display: block; font-size: 12.5px; color: var(--muted);
  margin-bottom: 4px; line-height: 1.3;
}
.f > label .req { color: var(--warn); }
.f input[type=text], .f input[type=date], .f input[type=number],
.f input[type=email], .f textarea {
  width: 100%; font: inherit; font-size: 14px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: #fcfcfa; color: var(--ink);
}
.f input:focus, .f textarea:focus {
  outline: none; border-color: var(--olive); background: #fff;
  box-shadow: 0 0 0 3px rgba(134,136,31,.13);
}
.f.locked input { background: #f0f0ea; color: var(--muted); }
.f .hint { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opts label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; cursor: pointer; background: #fcfcfa;
}
.opts label:has(input:checked) {
  border-color: var(--olive); background: #f2f3e4; color: var(--olive-dark); font-weight: 600;
}
.opts input { accent-color: var(--olive); }

/* upload tiles */
.uploader {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 1px dashed #c6c8ba; border-radius: var(--radius);
  background: #fbfbf7;
}
.uploader .thumb {
  width: 62px; height: 74px; flex: none;
  border: 1px solid var(--line); border-radius: 4px;
  background: #fff center/contain no-repeat;
  display: grid; place-items: center; color: #b9bbae; font-size: 11px; text-align: center;
}
.uploader .thumb.sig { width: 96px; height: 44px; }
.uploader .meta { flex: 1; min-width: 0; }
.uploader .meta strong { display: block; font-size: 13.5px; }
.uploader .meta span { font-size: 11.5px; color: var(--muted); }
.uploader input[type=file] { display: none; }

/* schedule editor */
.sched { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.sched th, .sched td { border: 1px solid var(--line); padding: 0; }
.sched th { background: #f4f4ee; padding: 6px 4px; font-size: 11px; color: var(--muted); }
.sched td:first-child { padding: 4px 6px; white-space: nowrap; color: var(--muted); }
.sched input { width: 100%; border: 0; background: transparent; font: inherit; padding: 5px 6px; }
.sched input:focus { outline: 2px solid var(--olive); outline-offset: -2px; background: #fff; }
.schedwrap { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }

.note {
  font-size: 12.5px; line-height: 1.5; color: var(--muted);
  background: #f7f7f1; border-left: 3px solid var(--olive);
  padding: 10px 12px; border-radius: 0 6px 6px 0; margin: 0 0 14px;
}
.note.warn { background: #fdf3ec; border-left-color: var(--warn); color: #7a4020; }

#actions {
  position: fixed; left: 0; bottom: 0; z-index: 30;
  width: 460px;
  background: var(--panel); border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 12px 18px; display: flex; flex-direction: column; gap: 8px;
}
#actions .btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
#actions .btnrow > * { flex: 1 1 auto; min-width: 108px; }
#actions .btnrow > button { padding-left: 12px; padding-right: 12px; }

/* which client's booking is currently open */
.note.working {
  display: flex; align-items: center; gap: 12px;
  border-left-color: var(--warn); background: #fdf6ee;
}
.note.working .workingwho { flex: 1; min-width: 0; line-height: 1.45; }
.note.working .workingwho b {
  color: var(--ink); font-size: 13.5px;
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.note.working button { flex: none; font-size: 12.5px; padding: 7px 12px; }
#progress { height: 4px; background: var(--line); border-radius: 999px; overflow: hidden; }
#progress > i { display: block; height: 100%; background: var(--olive); width: 0; transition: width .25s; }
#progresstext { font-size: 11.5px; color: var(--muted); }

/* ───────────────────────── A4 pages ───────────────────────── */

.page {
  position: relative;
  width: 595.28pt; height: 841.89pt;
  flex: none;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0,0,0,.13);
  overflow: hidden;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.page > img.plate {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
  user-select: none;
}
.page { transform-origin: top center; }
.page .pagenum {
  position: absolute; left: -34pt; top: 0;
  font-size: 10pt; color: #9a9c90;
}

/* an overlaid value */
.v {
  z-index: 2;
  position: absolute;
  font-family: var(--formfont);
  font-size: 9.5pt; line-height: 1.05;
  color: #14140f;
  white-space: nowrap; overflow: hidden;
  display: flex; align-items: flex-end;
  padding-bottom: 1pt;
}
.v.bn { font-size: 10pt; }
.v.num { justify-content: flex-start; }
.v.center { justify-content: center; }
.v.sched { font-size: 8.5pt; align-items: center; padding: 0 3pt; }
.v.sched.amt { justify-content: flex-end; }

.v.tick {
  align-items: center; justify-content: center;
  font-size: 11pt; font-weight: 700; color: #14140f; padding: 0;
}

.v img.photo { width: 100%; height: 100%; object-fit: cover; }
.v img.sig { max-width: 100%; max-height: 100%; object-fit: contain; object-position: left bottom; }

/* editing affordances — never printed */
.page .hit {
  z-index: 3;
  position: absolute; border-radius: 2px;
  background: rgba(134,136,31,.07);
  outline: 1px dashed rgba(134,136,31,.35);
  cursor: pointer;
}
.page .hit:hover { background: rgba(134,136,31,.16); }
.page .hit.active { background: rgba(134,136,31,.24); outline: 1.5px solid var(--olive); }
.page .hit.missing { outline-color: rgba(180,83,31,.55); background: rgba(180,83,31,.07); }
body.hidehints .page .hit { display: none; }

@media screen and (min-width: 901px) and (max-width: 1250px) {
  #panel { width: 380px; flex: 0 0 380px; }
  #actions { width: 380px; }
  #stage { padding: 16px; }
}

/* ───────────────────────── mobile ───────────────────────── */

#mobiletabs { display: none; }

/* `screen and` matters: A4 paper is ~794 CSS px wide, so a bare max-width
   query would also match while printing and hide the pages. */
@media screen and (max-width: 900px) {
  #app { flex-direction: column; }
  #mobiletabs {
    display: flex; position: sticky; top: 57px; z-index: 35;
    background: var(--panel); border-bottom: 1px solid var(--line);
  }
  #mobiletabs button {
    flex: 1; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
    padding: 12px; color: var(--muted); background: transparent;
  }
  #mobiletabs button.on { color: var(--olive-dark); border-bottom-color: var(--olive); }
  #panel, #stage {
    width: 100%; flex: none; height: auto; border-right: 0;
    max-height: none;
    /* the panel must not be its own scroll container here, or the sticky
       action bar would stick to a box that never scrolls and end up buried
       at the bottom of the form */
    overflow: visible;
  }
  #stage { padding: 16px 8px 130px; background: #e8e8e0; }
  #actions { width: 100%; border-right: 0; }
  body[data-tab="fill"] #stage { display: none; }
  body[data-tab="preview"] #panel { display: none; }
  #topbar .brand small { display: none; }
}

/* ───────────────────────── print ───────────────────────── */

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

@media print {
  html, body { background: #fff; }
  #topbar, #panel, #mobiletabs, #actions, .page .hit, .page .pagenum { display: none !important; }
  #app { display: block; }
  #stage {
    display: block; height: auto; overflow: visible; padding: 0; background: #fff;
  }
  .page {
    box-shadow: none;
    /* fitPages() scales the plates down on a phone; undo that for paper */
    transform: none !important;
    margin: 0 !important;
    width: 210mm; height: 297mm;
    page-break-after: always; break-after: page;
  }
  .page:last-child { page-break-after: auto; break-after: auto; }
}

/* ── allotment agreement: the client's reading screen ── */
.annex {
  position: fixed; inset: 0; z-index: 120;
  background: var(--panel);
  display: flex; flex-direction: column;
}
.annexhead {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.annextitle { flex: 1; min-width: 0; }
.annextitle strong { display: block; font-size: 14.5px; line-height: 1.35; }
.annextitle span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.annexclose {
  flex: none; width: 38px; height: 38px; padding: 0;
  border-radius: 50%; font-size: 15px; line-height: 1;
}
.annexbody {
  flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
  background: #e8e8e0; padding: 14px 10px 26px;
}
.annexpage { margin: 0 auto 16px; max-width: 900px; }
.annexpage img {
  display: block; width: 100%; height: auto;
  aspect-ratio: 612 / 1008;   /* hold the space before the page loads */
  background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.14);
}
.annexpage figcaption {
  text-align: center; font-size: 11px; color: var(--muted); padding: 6px 0 0;
}
.annexend { height: 8px; }
.annexfoot {
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
}
.annexstatus { font-size: 12px; color: var(--muted); text-align: center; }
.annexstatus.ok { color: var(--olive-dark); font-weight: 600; }
.annexfoot button { width: 100%; }

/* the sales-side picker */
.f select {
  width: 100%; font: inherit; font-size: 14px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: #fcfcfa; color: var(--ink);
}
.f select:focus {
  outline: none; border-color: var(--olive); background: #fff;
  box-shadow: 0 0 0 3px rgba(134,136,31,.13);
}
.f select:disabled { background: #f0f0ea; color: var(--muted); }
