/* charged-job-tracker — shared design tokens and components.
   Light theme by decision, not by default: this app is used outdoors in daylight
   more than it is used indoors. See PRODUCT.md. */

:root {
  /* Neutrals, very slightly cooled toward the brand's green so surfaces read as
     one family rather than as pure greys. */
  --bg:            oklch(0.982 0.003 140);
  --surface:       oklch(1 0 0);
  --surface-sunk:  oklch(0.962 0.004 140);
  --panel:         oklch(0.945 0.005 140);   /* second neutral layer: bars, toolbars */
  --border:        oklch(0.892 0.006 140);
  --border-strong: oklch(0.800 0.008 140);

  --ink:           oklch(0.235 0.006 140);   /* 13.9:1 on --surface */
  --ink-muted:     oklch(0.468 0.008 140);   /*  5.6:1 on --surface */
  --ink-faint:     oklch(0.590 0.008 140);   /*  3.6:1 — large/decorative text only */

  --dark:          oklch(0.220 0 0);         /* #1a1a1a, Charged header */
  --dark-ink:      oklch(0.985 0 0);
  --brand:         oklch(0.879 0.203 122);   /* #bee900 — accent only, never text on light */

  /* Semantic states. Deliberately not the brand green: these must survive
     daylight and colour-vision deficiency, and be legible as text. */
  --pass:          oklch(0.520 0.132 152);
  --pass-bg:       oklch(0.960 0.031 152);
  --fail:          oklch(0.505 0.183 27);
  --fail-bg:       oklch(0.960 0.032 27);
  --na:            oklch(0.510 0.010 140);
  --na-bg:         oklch(0.945 0.004 140);
  --todo:          oklch(0.545 0.128 75);
  --todo-bg:       oklch(0.965 0.043 85);
  --info:          oklch(0.505 0.130 250);
  --info-bg:       oklch(0.962 0.026 250);

  --radius:    10px;
  --radius-sm: 7px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px oklch(0.2 0.01 140 / 0.06);
  --shadow:    0 2px 8px oklch(0.2 0.01 140 / 0.09);
  --shadow-lg: 0 12px 32px oklch(0.2 0.01 140 / 0.16);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Fixed rem scale, ratio ~1.15. Product UI, not a landing page. */
  --t-xs:  0.75rem;
  --t-sm:  0.8125rem;
  --t-md:  0.9375rem;
  --t-lg:  1.0625rem;
  --t-xl:  1.25rem;
  --t-2xl: 1.5rem;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);   /* ease-out-quart */
  --fast: 140ms;
  --base: 200ms;

  /* Semantic stacking order — never arbitrary values. */
  --z-sticky:  100;
  --z-overlay: 200;
  --z-sheet:   300;
  --z-toast:   400;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--t-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.011em; text-wrap: balance; }
h1 { font-size: var(--t-xl); }
h2 { font-size: var(--t-lg); }
h3 { font-size: var(--t-md); }
p  { margin: 0 0 0.75rem; }

a { color: var(--info); text-decoration-thickness: 1px; text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- app frame */

.app-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: var(--dark);
  color: var(--dark-ink);
  border-bottom: 3px solid var(--brand);
}

/* The bar must survive a long customer name on a 375px phone: one line each,
   truncated, with the save pill and sign-out holding their width. */
.app-bar__text { min-width: 0; flex: 1; }
.app-bar__title,
.app-bar__sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-bar__title { font-size: var(--t-md); font-weight: 650; letter-spacing: -0.01em; }
.app-bar__sub   { font-size: var(--t-xs); color: oklch(0.78 0 0); }
.app-bar__spacer { display: none; }
.app-bar .btn, .app-bar .save-pill { flex: none; }

.app-bar__btn {
  min-height: 32px;
  padding: 0.25rem 0.6rem;
  background: transparent;
  border-color: oklch(1 0 0 / 0.28);
  color: var(--dark-ink);
}
.app-bar__btn:hover:not(:disabled) { background: oklch(1 0 0 / 0.14); }

/* The save pill keeps its words at every width, including "Offline - 3 queued".
   The job title truncates instead: an engineer already knows which job they
   opened, but must never be left guessing whether their work is safe. */

.back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: -0.35rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--dark-ink);
  font-size: 1.25rem;
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.back-btn:hover { background: oklch(1 0 0 / 0.12); }
.back-btn:active { background: oklch(1 0 0 / 0.2); }

main {
  padding: 1rem;
  padding-bottom: 6rem;
  max-width: 900px;
  margin-inline: auto;
}

/* ---------------------------------------------------------------- save pill */

.save-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: var(--t-xs);
  font-weight: 600;
  background: oklch(1 0 0 / 0.14);
  color: var(--dark-ink);
  white-space: nowrap;
}
.save-pill__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--brand);
  flex: none;
}
.save-pill[data-state="saving"] .save-pill__dot { animation: pulse 1s ease-in-out infinite; }
.save-pill[data-state="offline"] { background: oklch(0.62 0.17 40 / 0.35); }
.save-pill[data-state="offline"] .save-pill__dot { background: oklch(0.82 0.16 60); }
.save-pill[data-state="error"] { background: oklch(0.6 0.2 27 / 0.4); }
.save-pill[data-state="error"] .save-pill__dot { background: oklch(0.75 0.18 27); }

@keyframes pulse { 50% { opacity: 0.25; } }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--t-md);
  font-weight: 600;
  text-decoration: none;        /* anchors styled as buttons must not keep the underline */
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              transform var(--fast) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-sunk); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: var(--dark);
  border-color: var(--dark);
  color: var(--dark-ink);
}
.btn--primary:hover:not(:disabled) { background: oklch(0.3 0 0); }

.btn--danger { color: var(--fail); border-color: color-mix(in oklch, var(--fail) 35%, var(--border)); }
.btn--danger:hover:not(:disabled) { background: var(--fail-bg); }

.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover:not(:disabled) { background: var(--surface-sunk); }

.btn--sm { min-height: 34px; padding: 0.3rem 0.65rem; font-size: var(--t-sm); }
.btn--block { width: 100%; }

.btn[data-loading="true"] { pointer-events: none; opacity: 0.7; }
.btn[data-loading="true"]::after {
  content: "";
  width: 13px; height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- forms */

label { display: block; font-size: var(--t-sm); font-weight: 600; margin-bottom: 0.3rem; }

input[type="text"], input[type="number"], input[type="date"], input[type="search"],
input[type="email"], input[type="tel"], input[type="password"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px;              /* stops iOS Safari zooming on focus */
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
textarea { min-height: 76px; resize: vertical; line-height: 1.45; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--info) 18%, transparent);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-sunk);
  color: var(--ink-muted);
  cursor: not-allowed;
}
::placeholder { color: var(--ink-muted); opacity: 1; }

.field { margin-bottom: 0.9rem; }
.field__hint { font-size: var(--t-xs); color: var(--ink-muted); margin-top: 0.25rem; }
.field__error { font-size: var(--t-xs); color: var(--fail); margin-top: 0.25rem; font-weight: 600; }
.field--invalid input, .field--invalid textarea, .field--invalid select { border-color: var(--fail); }

.req { color: var(--fail); margin-left: 0.15rem; }

/* ---------------------------------------------------------------- sections */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 0.85rem;
}

.panel__head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.85rem 1rem;
  background: var(--panel);
  border: 0;
  border-bottom: 1px solid var(--border);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.panel__head:hover { background: color-mix(in oklch, var(--panel) 88%, var(--ink)); }
.panel__title { font-weight: 650; font-size: var(--t-md); flex: 1; letter-spacing: -0.01em; }
.panel__body { padding: 1rem; }
.panel[data-open="false"] .panel__body { display: none; }
.panel[data-open="false"] .panel__head { border-bottom-color: transparent; }

.chevron {
  flex: none;
  color: var(--ink-muted);
  transition: transform var(--base) var(--ease);
}
.panel[data-open="true"] .chevron { transform: rotate(90deg); }

/* Progress counter in a section head. */
.count {
  flex: none;
  font-size: var(--t-xs);
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.count[data-done="true"] {
  background: var(--pass-bg);
  border-color: color-mix(in oklch, var(--pass) 40%, transparent);
  color: var(--pass);
}
.count[data-fail="true"] {
  background: var(--fail-bg);
  border-color: color-mix(in oklch, var(--fail) 40%, transparent);
  color: var(--fail);
}

/* ---------------------------------------------------------------- check rows */

.check {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}
.check:last-child { border-bottom: 0; padding-bottom: 0; }
.check:first-child { padding-top: 0; }

.check__label { font-size: var(--t-md); line-height: 1.4; margin-bottom: 0.6rem; }

/* Three-state control. The most-tapped element in the app: full width, 46px tall. */
.pfn {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.pfn__opt {
  min-height: 46px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-muted);
  font: inherit;
  font-size: var(--t-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              color var(--fast) var(--ease);
}
.pfn__opt:hover { background: var(--surface-sunk); }
.pfn__opt[aria-pressed="true"][data-v="pass"] {
  background: var(--pass-bg); border-color: var(--pass); color: var(--pass);
}
.pfn__opt[aria-pressed="true"][data-v="fail"] {
  background: var(--fail-bg); border-color: var(--fail); color: var(--fail);
}
.pfn__opt[aria-pressed="true"][data-v="na"] {
  background: var(--na-bg); border-color: var(--border-strong); color: var(--ink);
}

.check[data-status=""] { border-left: 0; }
.check__notes { margin-top: 0.6rem; }

/* A failed check must look different from three feet away. */
.check[data-status="fail"] .check__label { font-weight: 600; }

.evidence {
  margin-top: 0.6rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--fail-bg);
  border: 1px solid color-mix(in oklch, var(--fail) 30%, transparent);
  font-size: var(--t-sm);
  color: var(--fail);
  font-weight: 600;
}

/* ---------------------------------------------------------------- photos */

.photos { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }

.photo {
  position: relative;
  width: 84px; height: 84px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--surface-sunk);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo[data-pending="true"] img { opacity: 0.4; }

.photo__del {
  position: absolute;
  top: 3px; right: 3px;
  width: 24px; height: 24px;
  border: 0;
  border-radius: 50%;
  background: oklch(0.2 0 0 / 0.72);
  color: #fff;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.photo__del:hover { background: oklch(0.2 0 0 / 0.9); }

.photo-add {
  width: 84px; height: 84px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-muted);
  font-size: var(--t-xs);
  font-weight: 600;
  cursor: pointer;
  display: grid;
  place-items: center;
  gap: 2px;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.photo-add:hover { border-color: var(--info); background: var(--info-bg); color: var(--info); }
.photo-add span { font-size: 1.2rem; line-height: 1; }

/* ---------------------------------------------------------------- job list */

.job {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.job:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }

.job__top { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.15rem; }
.job__ref { font-size: var(--t-xs); font-weight: 700; color: var(--ink-muted);
            font-variant-numeric: tabular-nums; }
.job__date { margin-left: auto; font-size: var(--t-xs); color: var(--ink-muted); }
.job__customer { font-weight: 650; font-size: var(--t-md); letter-spacing: -0.01em; }
.job__site { font-size: var(--t-sm); color: var(--ink-muted); }
.job__meta { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: var(--t-xs);
  font-weight: 650;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  color: var(--ink-muted);
}
.tag--scheduled  { background: var(--info-bg); border-color: color-mix(in oklch, var(--info) 30%, transparent); color: var(--info); }
.tag--in_progress{ background: var(--todo-bg); border-color: color-mix(in oklch, var(--todo) 32%, transparent); color: var(--todo); }
.tag--completed,
.tag--sent       { background: var(--pass-bg); border-color: color-mix(in oklch, var(--pass) 32%, transparent); color: var(--pass); }

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.tab {
  flex: 1;
  min-height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: var(--t-sm);
  font-weight: 650;
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------------- states */

.empty {
  padding: 2.5rem 1.25rem;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.empty__title { font-weight: 650; margin-bottom: 0.3rem; }
.empty__body { font-size: var(--t-sm); color: var(--ink-muted); max-width: 46ch; margin: 0 auto; }

.skeleton {
  height: 76px;
  margin-bottom: 0.6rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--surface-sunk) 25%, var(--panel) 50%, var(--surface-sunk) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.notice {
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius);
  font-size: var(--t-sm);
  margin-bottom: 0.85rem;
  border: 1px solid transparent;
}
.notice--info  { background: var(--info-bg); border-color: color-mix(in oklch, var(--info) 25%, transparent); color: var(--info); }
.notice--warn  { background: var(--todo-bg); border-color: color-mix(in oklch, var(--todo) 28%, transparent); color: var(--todo); }
.notice--error { background: var(--fail-bg); border-color: color-mix(in oklch, var(--fail) 28%, transparent); color: var(--fail); }
.notice--ok    { background: var(--pass-bg); border-color: color-mix(in oklch, var(--pass) 28%, transparent); color: var(--pass); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translate(-50%, 120%);
  z-index: var(--z-toast);
  max-width: min(92vw, 420px);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--dark);
  color: var(--dark-ink);
  font-size: var(--t-sm);
  box-shadow: var(--shadow-lg);
  transition: transform var(--base) var(--ease);
}
.toast[data-show="true"] { transform: translate(-50%, 0); }
.toast[data-tone="error"] { background: oklch(0.42 0.17 27); }

/* ---------------------------------------------------------------- sticky footer */

.action-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: var(--z-sticky);
  display: flex;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
  background: color-mix(in oklch, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.action-bar__inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 0.6rem;
  width: 100%;
}
.action-bar__inner > * { flex: 1; }

/* ---------------------------------------------------------------- signature */

.sig-pad {
  width: 100%;
  height: 190px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  touch-action: none;
  display: block;
}
.sig-pad[data-signed="true"] { border-style: solid; border-color: var(--pass); }

/* ---------------------------------------------------------------- carried forward */

.carried {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--info);
  background: var(--info-bg);
  border: 1px solid color-mix(in oklch, var(--info) 25%, transparent);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  margin-left: 0.35rem;
  vertical-align: middle;
}

/* ---------------------------------------------------------------- utility */

.muted { color: var(--ink-muted); }
.small { font-size: var(--t-sm); }
.xs    { font-size: var(--t-xs); }
.row   { display: flex; gap: 0.6rem; align-items: center; }
.row--wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 0.75rem; }
.grow  { flex: 1; }
.right { margin-left: auto; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
