:root {
  --charcoal: #2b2f33;
  --steel: #4a5560;
  --steel-light: #8a97a3;
  --rust: #b5562f;
  --bg: #f4f2ee;
  --bg-app: #586b3d; /* deep olive, behind the app card once signed in */
  --panel: #ffffff;
  --border: #dcd8d1;
  --text: #23262a;
  --text-muted: #6b7178;

  --status-amber: #d99a2b;
  --status-green: #5c8a5c;
  --status-gray: #9a9a94;
  --status-blue: #4f7cac;
  --status-purple: #a89bd1;
  --status-teal: #4a9490;
}

* { box-sizing: border-box; }

/* ------------------------------------------------------------------------
   A steady screen. These few settings are what keep the app from moving on
   its own under heavy hands on a phone or tablet. Each one stops one way the
   page used to slide, bounce, zoom or reload without being asked to.
   tests/security/test_119_steady_screen.py holds them in place.
   ------------------------------------------------------------------------ */
:root {
  /* The notch and home-bar clearances, named once so every screen subtracts the same amounts. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* The height of what can really be seen. On a phone "100vh" is the screen with the browser's bars
     hidden, which is taller than what shows, so a screen sized with it always slides a little. */
  --view-h: 100vh;
  /* One full screen of the app: what can be seen, less the clearances the body already adds. */
  --screen-h: calc(var(--view-h) - var(--safe-top) - var(--safe-bottom));
}
@supports (height: 100dvh) {
  :root { --view-h: 100dvh; }
}

html {
  /* Nothing can slide the page sideways. */
  overflow-x: hidden;
  /* No pull-down-to-reload, no bounce that carries past the end of the page, no sideways "go back". */
  overscroll-behavior: none;
  /* A finger scrolls. Two fingers (or a palm and a finger) and a double tap no longer blow the whole page up,
     which is what left it sliding in every direction. Photos, PDFs and the Drawing Board zoom on their own. */
  touch-action: pan-x pan-y;
  /* Turning the phone sideways doesn't re-size the words. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The page a customer opens from a private link (a change order to sign, the welcome form) keeps its pinch-zoom:
   a homeowner reading a document on a phone may need the words bigger. */
html.customer-page {
  touch-action: auto;
}

body {
  overscroll-behavior: none;
}
@supports (overflow-x: clip) {
  body { overflow-x: clip; }
}

/* A press that lingers on a button is still a press: no text-selection handles, no pop-up menu. */
button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* While a pop-up or a full-screen viewer is up (anything marked data-wp-layer), the page behind it stays
   exactly where it is. Phones and tablets only: a laptop keeps its scroll bar, so nothing shifts sideways. */
@media (hover: none) and (pointer: coarse) {
  html:has([data-wp-layer]),
  html:has([data-wp-layer]) body {
    overflow: hidden;
  }
}

/* Reaching the end of a list inside a pop-up stops there instead of dragging the page along. */
[data-wp-layer],
[data-wp-layer] * {
  overscroll-behavior: contain;
}

/* A pop-up taller than the screen (a small phone, the keyboard up, the phone on its side) can always be
   scrolled to its top and its bottom. "sheet" sits at the bottom on a phone and in the middle on a wider
   screen; "bottom" always sits at the bottom; "center" always sits in the middle. The automatic margins put
   it in the same place as before, but never start it above the top of the screen where it can't be reached. */
[data-wp-layer="sheet"],
[data-wp-layer="bottom"],
[data-wp-layer="center"] {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
[data-wp-layer="sheet"] > *,
[data-wp-layer="bottom"] > * {
  margin-top: auto;
}
[data-wp-layer="center"] > * {
  margin-top: auto;
  margin-bottom: auto;
}
@media (min-width: 700px) {
  [data-wp-layer="sheet"] > * { margin-bottom: auto; }
}

/* The app's one font: Atkinson Hyperlegible Next, self-hosted (see css/FONT-LICENSES.txt), 400 and 600 only. The
   system fonts behind it are only what shows for a moment on the very first visit, or if the file cannot be read. */
@font-face { font-family: "Atkinson Hyperlegible Next"; font-weight: 400; font-style: normal; font-display: swap; src: url("/css/atkinson-hyperlegible-next-400.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible Next"; font-weight: 600; font-style: normal; font-display: swap; src: url("/css/atkinson-hyperlegible-next-600.woff2") format("woff2"); }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Atkinson Hyperlegible Next", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Buttons and fields never fall back to the browser's own font (Arial): every one speaks in the app's font. */
button, input, select, textarea {
  font-family: inherit;
}

/* Signed-in app: a light olive behind the tan app card (set by LoginGate). */
html.signed-in,
html.signed-in body {
  background: var(--bg-app);
}

body {
  /* Clears the notch/Dynamic Island and the home-indicator bar on iPhone —
     without viewport-fit=cover + this, fixed panels can sit underneath
     them and look like they're overlapping the phone's own UI. */
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Exactly one screen tall, clearances included. It used to be a full screen PLUS the clearances, so on a
   phone with a notch every screen could be dragged up and down even when everything fit. */
#root {
  min-height: var(--screen-h);
  display: flex;
  flex-direction: column;
}

.markup-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.25rem;
  gap: 1rem;
}

.pdf-pick {
  width: 100%;
  max-width: 640px;
  border: 2px dashed var(--steel-light);
  border-radius: 16px;
  background: var(--panel);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.pdf-pick:hover,
.pdf-pick.dragover {
  border-color: var(--rust);
  background: #fbf3ee;
}

.pdf-pick input { display: none; }

.pdf-pick .primary {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.toolbar {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.65rem 0.9rem;
}

.toolbar .group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.toolbar .spacer { flex: 1; }

/* A screen of its own (the Calendar) or a pop-up is never wider than the phone: an element that scrolls up and down
   would otherwise also be allowed to slide sideways, and anything too wide for it sat cut off beyond the edge. */
[data-wp-layer="sheet"], [data-wp-layer="bottom"], [data-wp-layer="center"], [data-wp-layer="screen"] {
  overflow-x: hidden;
}

/* On a phone the markup tools wrap onto more lines. Nothing in the app scrolls sideways: every screen fits the width. */
@media (max-width: 640px) {
  .toolbar {
    gap: 0.5rem;
    padding: 0.45rem 0.6rem;
  }
  .toolbar .spacer { display: none; }
}

/* ---- Editing a PDF: the bars above the page.
   The first bar never scrolls: Back, Undo, Clear and Save, and the three choices for what a finger does
   (Move, Draw, Erase). It used to be one long row that slid sideways on a phone, with Undo, Clear and Save
   off the right-hand edge. The second bar is pages, signature and zoom; the pen's colours show only while
   drawing. */
.markup-bars {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.markup-bars .toolbar { max-width: none; }
.markup-main .btn { min-height: 44px; }
.mode-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.mode-switch .btn {
  border: none;
  border-radius: 0;
  min-width: 4rem;
}
.mode-switch .btn + .btn { border-left: 1px solid var(--border); }
.markup-hint { text-align: center; }
/* The page being edited scrolls inside its own frame; reaching its end stops there. */
.markup-screen .canvas-scroll { overscroll-behavior: contain; }

@media (max-width: 640px) {
  .toolbar.markup-main {
    flex-wrap: wrap;
    overflow-x: visible;
    row-gap: 0.5rem;
  }
  .markup-main .markup-save { margin-left: auto; }
  /* The three choices take a full row of their own: big, and impossible to miss. */
  .markup-main .mode-switch { order: 5; flex: 1 0 100%; }
  .markup-main .mode-switch .btn { flex: 1 1 0; }
  /* Everything fits on the screen at once, so the page behind never has to move. */
  .markup-screen { padding: 0.75rem; gap: 0.6rem; }
  .markup-screen .canvas-scroll { max-height: max(260px, calc(var(--view-h) - 480px)); }
}
/* A tablet: the same idea. The bars and the page fit on the screen together, so the only thing that slides
   under a finger is the PDF itself. (A laptop keeps the taller frame; a mouse wheel has no such trouble.) */
@media (min-width: 641px) and (hover: none) and (pointer: coarse) {
  .markup-screen .canvas-scroll { max-height: max(300px, calc(var(--view-h) - 450px)); }
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover { border-color: var(--steel-light); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary {
  background: var(--rust);
  border-color: var(--rust);
  color: #fff;
}

.btn.primary:hover { background: #9c4a27; }

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--steel);
}

.swatch-row {
  display: flex;
  gap: 0.35rem;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.swatch.active {
  border-color: var(--charcoal);
}

.thickness-row {
  display: flex;
  gap: 0.3rem;
}

.thickness-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.thickness-btn.active {
  border-color: var(--rust);
  background: rgba(181, 86, 47, 0.08);
}

.thickness-btn span {
  display: block;
  pointer-events: none;
}

.page-indicator {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 5.5rem;
  text-align: center;
}

.canvas-scroll {
  width: 100%;
  max-width: 900px;
  max-height: 70vh;
  overflow: auto;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  background: #fff;
}

.canvas-stage {
  position: relative;
  display: inline-block;
}

/* No max-width/height:auto here on purpose — the canvas's own pixel
   dimensions (computed from the zoom level in PdfMarkup.js) ARE the zoom.
   Letting CSS scale it back down to fit the container would silently
   cancel out any zoom level greater than 1. */
.canvas-stage canvas {
  display: block;
}

.canvas-stage canvas.draw-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.status-line {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-line.error {
  color: var(--rust);
}

/* The sign-in page (signed-out view at workphasefx.com). It is built from the same calm look as the other sign-in and
   set-up screens (see AUTH_* in src/app.jsx); this keeps it as tall as the screen. */
.landing {
  min-height: var(--screen-h);
  overflow-x: clip; /* nothing on the page may ever add sideways scrolling */
}

/* Pinch-to-zoom is allowed (people who need bigger text can zoom). iPhones
   zoom the whole page when a field smaller than 16px is tapped, so fields
   are 16px on those devices to keep that from happening. */
@supports (-webkit-touch-callout: none) {
  input, select, textarea { font-size: 16px !important; }
}

/* Every back arrow gets a full thumb-sized target (44pt, Apple's minimum) without
   changing how it looks. The arrow stays where it was; only the tappable area grows. */
button:has(> svg.wp-back:only-child) {
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  margin-left: -12px;
}
button:has(> svg.wp-back) {
  min-height: 44px;
  align-items: center;
}

/* ---- The job page's Permit / Inspection / 811 boxes.
   iPhone and iPad Safari draw a date or time field at a built-in width, centred, with their own height, and ignore the
   box it sits in: the fields came out uneven and ran past the box's edge. Plain fields here are drawn by the app instead,
   so each is exactly the box's width, 36px high, its value on the left, the same as every other field. Tapping still
   opens the phone's own date or time picker. */
[data-status-box] input[type="date"],
[data-status-box] input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 36px;
  min-height: 36px;
  line-height: 22px;
  text-align: left;
  background-color: #FFFFFF;
}
[data-status-box] input[type="date"]::-webkit-date-and-time-value,
[data-status-box] input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
  margin: 0;
  min-height: 22px;
}
[data-status-box] input[type="date"]::-webkit-datetime-edit,
[data-status-box] input[type="time"]::-webkit-datetime-edit {
  padding: 0;
}
[data-status-box] input[type="date"]::-webkit-calendar-picker-indicator,
[data-status-box] input[type="time"]::-webkit-calendar-picker-indicator {
  margin: 0 0 0 2px;
  padding: 0;
}
/* On a phone three boxes across leave each about a third of the screen, too narrow for a date. An opened box takes the
   full width under the closed ones, and its fields sit two side by side (Date | Time, Scheduled | Ticket number). */
@media (max-width: 640px) {
  [data-status-row] [data-status-box][data-open="1"] {
    flex: 1 1 100% !important;
    order: 1;
  }
  [data-status-row] [data-status-box][data-open="1"] [data-inspection-at],
  [data-status-row] [data-status-box][data-open="1"] [data-c811-fields] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  [data-status-row] [data-status-box][data-open="1"] [data-c811-fields] > label:last-child {
    grid-column: 1 / -1;
  }
  [data-status-box] input[type="date"],
  [data-status-box] input[type="time"],
  [data-c811-fields] input:not([type="checkbox"]) {
    font-size: 16px !important;
  }
}
