/* CubbyKit app — screen + print. No external fonts, no external anything. */

:root {
  --paper: #fdf9f1;
  --card: #ffffff;
  --ink: #2d2a24;
  --muted: #7d7466;
  --line: #eadfcd;
  --brand: #22808c;
  --brand-dark: #175f68;
  --accent: #e8654f;
  --gold: #a3742a;
  --gold-bg: #f9eed3;
  --ok: #2f7d4f;
  --err: #b23a3a;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--sans); color: var(--ink); background: var(--paper); font-size: 15px; }

#app {
  display: grid;
  grid-template: "top top" auto "nav main" 1fr / 300px 1fr;
  height: 100vh;
}

/* ---- top bar ---- */
#topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 19px; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand-mark { margin-right: 2px; }
.saved { color: var(--muted); font-size: 12.5px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.pro-badge { color: var(--ok); font-weight: 600; font-size: 13.5px; border: 1px solid #cfe6d8; background: #eef7f1; border-radius: 999px; padding: 5px 12px; }

/* ---- buttons ---- */
.btn {
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  padding: 8px 14px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  text-decoration: none; display: inline-block;
}
.btn:hover { border-color: #d6c8ac; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-gold { background: var(--gold-bg); border-color: #e6d09a; color: var(--gold); }
.btn-lg { font-size: 16px; padding: 12px 18px; width: 100%; text-align: center; margin-top: 10px; }
.btn-add { color: var(--brand); border-style: dashed; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---- nav ---- */
#nav {
  grid-area: nav;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 12px 10px 40px;
  background: #f2efe6;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 11px;
  color: var(--ink); text-decoration: none;
}
.nav-item:hover { background: #eae5d6; }
.nav-item.active { background: var(--card); box-shadow: 0 1px 4px rgba(45, 42, 36, .07); }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }
.nav-text { display: flex; flex-direction: column; min-width: 0; }
.nav-title { font-weight: 600; font-size: 14px; }
.nav-tag { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-pct { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.nav-pct.complete { color: var(--ok); font-weight: 700; font-size: 14px; }

/* ---- main / form ---- */
#main { grid-area: main; overflow-y: auto; padding: 30px clamp(18px, 5vw, 64px) 80px; }
.section-head { display: flex; gap: 16px; align-items: flex-start; max-width: 760px; margin-bottom: 8px; }
.section-icon { font-size: 34px; margin-top: 4px; }
.section-head h1 { margin: 0 0 6px; font-size: 27px; font-weight: 800; letter-spacing: -0.015em; }
.section-intro { color: var(--muted); margin: 0; max-width: 640px; line-height: 1.5; }

.block { max-width: 760px; background: var(--card); border: 1px solid var(--line); border-radius: 15px; padding: 20px 22px; margin-top: 18px; }
.block h3 { margin: 0 0 4px; font-size: 17px; font-weight: 700; }

.field { margin-top: 14px; }
.field label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; font-family: var(--sans); font-size: 14.5px; color: var(--ink);
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fffdf8;
}
.field textarea { resize: vertical; line-height: 1.45; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid #b7d8dc; border-color: var(--brand); }
.field ::placeholder { color: #b6ab96; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.starter-link {
  display: inline-block; margin-top: 6px; padding: 0;
  border: none; background: none; cursor: pointer;
  color: var(--brand); font-size: 12.5px; font-weight: 600; text-decoration: underline;
}
.starter-link:hover { color: var(--brand-dark); }

.item-card { position: relative; border: 1px solid var(--line); border-radius: 11px; padding: 4px 16px 16px; margin-top: 14px; background: #fefcf6; }
.item-remove {
  position: absolute; top: 10px; right: 10px;
  font-size: 12px; color: var(--muted); background: none; border: none; cursor: pointer; text-decoration: underline;
}
.item-remove:hover { color: var(--err); }
.btn-add { margin-top: 14px; }

.section-footer { max-width: 760px; display: flex; justify-content: space-between; margin-top: 26px; }

/* ---- dialogs ---- */
dialog { border: none; border-radius: 16px; padding: 0; max-width: 480px; width: calc(100vw - 40px); box-shadow: 0 24px 70px rgba(30, 25, 15, .3); }
dialog::backdrop { background: rgba(35, 30, 22, .45); }
.dlg { padding: 26px 26px 22px; position: relative; }
.dlg h2 { margin: 0 0 10px; font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
.dlg p { line-height: 1.5; margin: 8px 0; }
.dlg-list { padding-left: 4px; list-style: none; margin: 12px 0; }
.dlg-list li { margin: 8px 0; line-height: 1.45; }
.dlg-note { color: var(--muted); font-size: 12.5px; }
.dlg-note a { color: var(--brand); }
.dlg-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; font-weight: 600; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.dlg-divider::before, .dlg-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.dlg-label { display: block; font-weight: 600; font-size: 13px; margin: 8px 0 5px; }
.dlg input[type="password"], .dlg input[type="text"], .dlg input:not([type]) {
  width: 100%; font-size: 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
}
.dlg input[type="file"] { font-size: 13px; }
.keyrow { display: flex; gap: 8px; }
.keyrow input { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.dlg-error { color: var(--err); font-size: 13px; }
.dlg-ok { color: var(--ok); font-size: 13px; }
.dlg-close { position: absolute; top: 10px; right: 14px; border: none; background: none; font-size: 22px; color: var(--muted); cursor: pointer; }
.pro-tag { background: var(--gold-bg); color: var(--gold); font-size: 10.5px; padding: 2px 8px; border-radius: 999px; letter-spacing: 0; text-transform: none; font-weight: 600; }

/* document picker */
.doc-picker { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 6px; }
.doc-choice {
  display: flex; gap: 12px; align-items: center; text-align: left; cursor: pointer;
  border: 1px solid var(--line); background: #fffdf8; border-radius: 12px; padding: 11px 14px;
  font-family: var(--sans); font-size: 14px; color: var(--ink);
}
.doc-choice:hover { border-color: var(--brand); background: #f4fafa; }
.doc-choice .doc-icon { font-size: 22px; }
.doc-choice b { display: block; font-size: 14.5px; }
.doc-choice small { color: var(--muted); font-size: 12px; line-height: 1.35; display: block; }
.doc-all { border-style: dashed; }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 14px; opacity: 0; transition: all .3s ease; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- narrow screens ---- */
@media (max-width: 860px) {
  #app { grid-template: "top" auto "nav" auto "main" 1fr / 1fr; height: auto; }
  #nav { display: flex; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 8px; }
  .nav-item { flex: 0 0 auto; }
  .nav-tag, .nav-pct { display: none; }
  .saved { display: none; }
}

/* ==========================================================================
   PRINT — the documents themselves. --doc-accent is set by print.js from the
   provider's chosen brand colour.
   ========================================================================== */

#printRoot { display: none; --doc-accent: #22808c; }

@media print {
  #app, dialog, .toast { display: none !important; }
  body { background: #fff; }
  #printRoot { display: block; font-family: var(--sans); color: #211e18; font-size: 12.5px; }

  @page { size: letter portrait; margin: 0.65in 0.7in; }

  .p-watermark {
    position: fixed; inset: 0; z-index: 10; pointer-events: none;
    display: flex; align-items: center; justify-content: center;
    transform: rotate(-28deg);
    font-size: 24px; font-weight: 800; letter-spacing: .06em;
    color: rgba(160, 60, 40, .16); text-align: center;
  }

  /* every document page */
  .d-page { page-break-before: always; }
  .d-page:first-child { page-break-before: auto; }

  /* letterhead */
  .d-head {
    display: flex; align-items: center; gap: 10px;
    border-bottom: 2.5px solid var(--doc-accent);
    padding-bottom: 8px; margin-bottom: 16px;
  }
  .d-head-logo { font-size: 24px; }
  .d-head-name { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }
  .d-head-sub { color: #6d675b; font-size: 9.5px; margin-top: 1px; }
  .d-head-doc { margin-left: auto; color: var(--doc-accent); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; }

  /* handbook cover */
  .d-cover { text-align: center; padding-top: 2.1in; }
  .d-cover-logo { font-size: 84px; }
  .d-cover h1 { font-size: 38px; margin: 18px 0 4px; font-weight: 800; letter-spacing: -0.02em; }
  .d-cover-doc { font-size: 17px; color: var(--doc-accent); font-weight: 700; text-transform: uppercase; letter-spacing: .18em; margin-top: 6px; }
  .d-cover-rule { width: 1.5in; height: 4px; border-radius: 2px; background: var(--doc-accent); margin: 26px auto; }
  .d-cover-facts { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-bottom: 30px; }
  .d-cover-facts span { border: 1px solid #d8d0bf; border-radius: 999px; padding: 5px 14px; font-size: 12px; }
  .d-cover-contact { font-size: 13px; line-height: 1.7; color: #4a453b; }
  .d-cover-updated { margin-top: 40px; font-size: 10.5px; color: #8b8375; text-transform: uppercase; letter-spacing: .12em; }

  /* handbook chapters */
  .d-chapter { margin: 4px 0 14px; }
  .d-chapter-num { font-size: 10px; font-weight: 700; color: var(--doc-accent); text-transform: uppercase; letter-spacing: .12em; }
  .d-chapter h2 { font-size: 25px; margin: 4px 0 0; font-weight: 800; letter-spacing: -0.015em; }
  .d-policy { margin: 14px 0; page-break-inside: avoid; }
  .d-policy h3 { font-size: 13.5px; margin: 0 0 4px; font-weight: 700; color: #37332b; }
  .d-policy p { margin: 5px 0; line-height: 1.6; font-size: 12px; color: #2c2922; }
  .d-letter p { line-height: 1.75; font-size: 12.5px; }
  .d-letter-sign { margin-top: 18px; font-size: 14px; font-weight: 600; }

  /* toc */
  .d-toc { margin-top: 8px; }
  .d-toc-row { display: flex; align-items: baseline; gap: 8px; font-size: 13.5px; padding: 8px 0; border-bottom: 1px solid #e7e0d0; }
  .d-toc-num { font-weight: 800; width: 22px; color: var(--doc-accent); }
  .d-toc-tag { margin-left: auto; color: #8b8375; font-size: 10.5px; text-align: right; }

  /* form typography */
  .d-formtitle { font-size: 20px; font-weight: 800; letter-spacing: -0.015em; margin: 2px 0 4px; }
  .d-formtitle.sm { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--doc-accent); margin: 16px 0 4px; }
  .d-formsub { color: #6d675b; font-size: 10.5px; line-height: 1.5; margin: 2px 0 10px; }

  .d-line { display: flex; align-items: flex-end; gap: 6px; margin: 13px 0; page-break-inside: avoid; }
  .d-line-label { font-size: 10px; font-weight: 700; color: #55503f; white-space: nowrap; }
  .d-line-rule { flex: 1; border-bottom: 1px solid #8f8775; height: 16px; }
  .d-cols { display: flex; gap: 22px; }
  .d-cols .d-line { flex: 1; }
  .d-cols3 .d-line { flex: 1; }
  .d-writein { margin: 13px 0; page-break-inside: avoid; }
  .d-writein .d-line-label { display: block; margin-bottom: 2px; }
  .d-rule { height: 21px; border-bottom: 1px solid #b5ac97; }
  .d-sig { margin-top: 20px; }
  .d-sig .d-line-rule { border-bottom-width: 1.3px; border-color: #55503f; }

  .d-check { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; margin-right: 14px; }
  .d-checkbox { display: inline-block; width: 11px; height: 11px; border: 1.3px solid #55503f; border-radius: 2px; }
  .d-checkrow { margin: 8px 0; }

  .d-agree { font-size: 10.5px; line-height: 1.55; color: #37332b; border: 1px solid #d8d0bf; border-left: 3px solid var(--doc-accent); border-radius: 6px; padding: 9px 12px; margin: 14px 0 4px; }

  /* tables */
  .d-table { width: 100%; border-collapse: collapse; margin: 8px 0; page-break-inside: avoid; }
  .d-table th {
    text-align: left; font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em;
    color: #fff; background: var(--doc-accent); padding: 5px 8px;
  }
  .d-table td { border: 1px solid #c9c1ac; padding: 0 8px; height: 26px; font-size: 11.5px; }
  .d-table.d-filled td { height: auto; padding: 6px 8px; }
  .d-signin td { height: 30px; }
  .d-summary .d-sum-label { font-weight: 700; width: 1.6in; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: #55503f; }

  /* consent rows */
  .d-consent { margin: 10px 0; }
  .d-consent-row { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid #e7e0d0; font-size: 11.5px; line-height: 1.5; }
  .d-consent-row .d-check { margin: 2px 0 0; }

  /* posters */
  .d-poster .d-poster-title { font-size: 30px; font-weight: 800; letter-spacing: -0.01em; margin: 6px 0 2px; }
  .d-poster-table td { height: 34px; }
  .d-em-address { border: 2.5px solid var(--doc-accent); border-radius: 10px; padding: 14px 18px; margin: 12px 0 18px; font-size: 14px; line-height: 1.7; }
  .d-em-num { font-size: 26px; font-weight: 800; color: #b23a3a; }

  /* meal rows on daily report */
  .d-meal .d-eat { font-size: 10px; color: #55503f; white-space: nowrap; }

  /* receipts */
  .d-receipt { border: 1.5px dashed #8f8775; border-radius: 10px; padding: 12px 18px 14px; margin: 16px 0; page-break-inside: avoid; }
  .d-receipt .d-line { margin: 10px 0; }
  .d-receipt .d-sig { margin-top: 10px; }
  .d-receipt-head { display: flex; gap: 8px; align-items: center; border-bottom: 2px solid var(--doc-accent); padding-bottom: 6px; margin-bottom: 4px; }
  .d-receipt-logo { font-size: 18px; }
  .d-receipt-name { font-weight: 800; font-size: 13px; }
  .d-receipt-sub { font-size: 8.5px; color: #6d675b; }
  .d-receipt-title { margin-left: auto; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--doc-accent); }
}
