/* Kerf. Paper sheets on a drywall-grey ground, one blue chalk line,
   hi-vis yellow for the single thing to do next. Built for thumbs and sunlight. */

:root {
  --ground: #e6eaed;
  --sheet: #ffffff;
  --ink: #14212b;
  --soft: #55636f;
  --rule: #d3d9de;
  --chalk: #1d5fd1;
  --hivis: #ffc61a;
  --hivis-press: #eab30a;
  --paid: #1b7f4f;
  --late: #c23b22;
  --display: 'Barlow Semi Condensed', 'Arial Narrow', system-ui, sans-serif;
  --body: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --navh: 68px;
  --safe: env(safe-area-inset-bottom, 0px);
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 17px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 16px calc(var(--navh) + var(--safe) + 32px);
}

h1, h2, p { margin: 0; }
h1 {
  font: 700 2.1rem/1.08 var(--display);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h2 { font: 600 1.25rem/1.2 var(--display); margin: 28px 0 8px; }
.sub, .hint { color: var(--soft); font-size: 0.9rem; }
.amt { font: 600 1.05rem/1.2 var(--display); font-variant-numeric: tabular-nums; white-space: nowrap; }

:focus-visible { outline: 3px solid var(--chalk); outline-offset: 2px; }

/* The chalk line */
.chalk { display: block; width: 100%; height: 8px; overflow: visible; }
.chalk line {
  stroke: var(--chalk);
  stroke-width: 2.6;
  stroke-linecap: round;
  filter: url(#chalk);
  vector-effect: non-scaling-stroke;
}
.chalk.snap {
  transform-origin: left center;
  animation: snap 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) 0.1s backwards;
}
@keyframes snap { from { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) {
  .chalk.snap { animation: none; }
}

/* Page top */
.top { padding: 28px 2px 0; }
.top .brand { font: 600 0.95rem/1 var(--display); color: var(--chalk); margin-bottom: 10px; }
.top .chalk { margin-top: 14px; }
.top .late { color: var(--late); }

/* Sheets */
.sheet {
  background: var(--sheet);
  border-radius: 4px;
  box-shadow: 0 1px 0 var(--rule), 0 8px 18px -14px rgb(20 33 43 / 0.45);
  padding: 18px 16px;
  margin-top: 18px;
}
.sheet > h2:first-child { margin-top: 0; }
.sheet .hint { margin-bottom: 6px; }

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 0 18px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--sheet);
  color: var(--ink);
  font: 600 1.1rem/1 var(--display);
  text-decoration: none;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--hivis); }
.btn.primary:active { background: var(--hivis-press); }
.btn.quiet { border-color: transparent; background: transparent; text-decoration: underline; text-underline-offset: 4px; }
.btn.danger { color: var(--late); }
.stack { display: grid; gap: 10px; margin-top: 18px; }
.stack.tight { margin-top: 12px; }

/* Forms: fields sit on the sheet like lines on a paper form */
label { display: block; margin-top: 14px; color: var(--soft); font-size: 0.9rem; }
input, textarea, select {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 9px 0 8px;
  border: 0;
  border-bottom: 1.5px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 500 1.06rem/1.35 var(--body);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-bottom-color: var(--chalk); box-shadow: 0 1.5px 0 var(--chalk); }
::placeholder { color: #8b97a1; opacity: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
details { margin-top: 12px; }
summary { color: var(--chalk); font-weight: 500; cursor: pointer; padding: 8px 0; }
.file { cursor: pointer; margin-top: 0; font-size: 1.1rem; color: var(--ink); }

/* Jobs list */
.empty { margin-top: 22px; display: grid; gap: 20px; }
.empty p { max-width: 34ch; }
.nudge { display: block; margin-top: 16px; color: var(--chalk); font-weight: 500; }
.filters { display: flex; gap: 8px; margin-top: 20px; overflow-x: auto; }
.filters button {
  min-height: 42px;
  padding: 0 14px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: 600 1rem/1 var(--display);
  cursor: pointer;
  white-space: nowrap;
}
.filters button[aria-pressed='true'] { background: var(--ink); color: #fff; }
.list { padding: 0 16px; margin-top: 12px; }
.list .none { padding: 22px 0; color: var(--soft); }
.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 0;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}
.row:last-child { border-bottom: 0; }
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-main strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-side { display: grid; gap: 4px; justify-items: end; align-content: start; }

.status { font: 600 0.92rem/1 var(--display); white-space: nowrap; }
.status::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: currentColor; }
.status.draft { color: var(--soft); }
.status.unpaid { color: var(--chalk); }
.status.overdue { color: var(--late); }
.status.paid { color: var(--paid); }

/* New estimate */
.speak label { margin-top: 0; }
.speak textarea { font-size: 1.15rem; border: 1.5px solid var(--rule); border-radius: 4px; padding: 12px; margin-top: 8px; }
.speak textarea:focus { border-color: var(--chalk); box-shadow: none; }
.mic {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  margin-top: 12px;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font: 600 1.2rem/1 var(--display);
  cursor: pointer;
}
.mic .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--hivis); }
.mic[aria-pressed='true'] { background: var(--late); }
.mic[aria-pressed='true'] .dot { background: #fff; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.6); opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) { .mic .dot { animation: none !important; } }
#preview:not(:empty) { margin-top: 20px; }
.for { font-weight: 600; margin-bottom: 4px; }
.found { list-style: none; margin: 0; padding: 0; }
.found li, .found-total { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; }
.found li { border-bottom: 1px solid var(--rule); }
.found li:last-child { border-bottom: 0; }
.found .missing { color: var(--late); }
.found-total { font-weight: 600; }
.found-total .amt { font-size: 1.4rem; }

/* Editor */
.docbar { display: flex; justify-content: space-between; align-items: center; padding: 18px 2px 0; }
.back { color: var(--ink); font: 600 1.05rem/1 var(--display); text-decoration: none; padding: 10px 10px 10px 0; }
.back::before { content: '‹'; margin-right: 6px; font-size: 1.3em; line-height: 0; }
.doc { margin-top: 10px; }
.doc-title { display: flex; justify-content: space-between; align-items: baseline; }
.doc-title .num { color: var(--soft); font: 600 1rem/1 var(--display); }

.item {
  display: grid;
  grid-template-columns: 1fr 1.2fr auto;
  column-gap: 14px;
  align-items: end;
  padding: 12px 0 10px;
  border-bottom: 1px solid var(--rule);
}
.item > input[data-k='desc'] { grid-column: 1 / -1; font-weight: 600; border-bottom-color: transparent; padding-top: 0; }
.item > input[data-k='desc']:focus { border-bottom-color: var(--chalk); }
.item label { margin-top: 4px; }
.item .line-amt { padding-bottom: 10px; min-width: 5.5ch; text-align: right; }
.item .remove {
  grid-column: 1 / -1;
  justify-self: start;
  margin-top: 6px;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--soft);
  font: 500 0.9rem/1 var(--body);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.add { justify-content: flex-start; padding: 0; margin-top: 4px; }

.totals { margin-top: 18px; }
.totals p { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; }
.totals .inline { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 1rem; }
.totals .inline input { width: 4.2em; margin: 0; padding: 4px 0; text-align: right; }
.totals .chalk { margin: 8px 0 4px; }
.totals .grand { font: 700 1.3rem/1 var(--display); }
.totals .grand .amt { font-size: 1.9rem; font-weight: 700; }

.sendbar, #nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 8px max(16px, calc((100vw - 620px) / 2 + 16px)) calc(8px + var(--safe));
  background: var(--ink);
}
.sendbar { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }
.sendbar .btn { border-color: #fff; min-height: 52px; }
.sendbar .btn:not(.primary) { background: transparent; color: #fff; }
.sendbar .btn.primary { border-color: var(--hivis); }
body[data-view='doc'] #nav { display: none; }

/* Bottom navigation */
#nav { display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 10px; align-items: center; }
#nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border-radius: 6px;
  color: #c5cdd4;
  font: 600 1.05rem/1 var(--display);
  text-decoration: none;
}
#nav a[aria-current='page'] { color: #fff; box-shadow: inset 0 -3px 0 var(--chalk); border-radius: 0; }
#nav a.nav-new { background: var(--hivis); color: var(--ink); box-shadow: none; border-radius: 6px; }
#nav a:focus-visible, .sendbar .btn:focus-visible { outline-color: #fff; }

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--navh) + var(--safe) + 14px);
  z-index: 10;
  width: max-content;
  max-width: min(92vw, 560px);
  padding: 12px 16px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-weight: 500;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Photos, logo, signature, saved items */
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photos:empty { display: none; }
.photos figure { margin: 0; }
.photos img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 4px; }
.remove {
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--soft);
  font: 500 0.9rem/1 var(--body);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.logo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 8px; }
.logo-row img { max-height: 56px; max-width: 160px; }
.logo-row .file { min-height: 44px; }
.sig { display: block; width: 100%; max-width: 320px; border-bottom: 1.5px solid var(--ink); }
.sig polyline { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.signpad {
  width: min(94vw, 600px);
  padding: 18px 16px;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
}
.signpad::backdrop { background: rgb(20 33 43 / 0.7); }
.signpad h2 { margin-top: 0; }
.signpad canvas {
  display: block;
  width: 100%;
  margin: 12px 0;
  border: 1.5px dashed var(--soft);
  border-radius: 4px;
  background: #fff;
  touch-action: none;
}
.signpad .two { gap: 10px; }
.check { display: flex; align-items: center; gap: 12px; margin-top: 4px; color: var(--ink); font-size: 1.06rem; font-weight: 500; }
.check input { width: 24px; height: 24px; margin: 0; accent-color: var(--chalk); flex: none; }
.saved { list-style: none; margin: 8px 0 0; padding: 0; }
.saved li { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 10px 0 4px; border-top: 1px solid var(--rule); }
.saved .remove { grid-column: 1 / -1; justify-self: start; }
.sheet > .none { color: var(--soft); margin-top: 8px; }

@media (min-width: 700px) {
  h1 { font-size: 2.6rem; }
  .sheet { padding: 26px 28px; }
  .list { padding: 4px 28px; }
  .item { grid-template-columns: 110px 160px 1fr; }
  .item .line-amt { justify-self: end; }
}
