:root {
  --ink: #1c1917;
  --muted: #57534e;
  --paper: #f4f1ea;
  --card: #ffffff;
  --line: #e6e0d6;
  --navy: #1e3a5f;
  --amber: #f0b429;
  --amber-ink: #1c1404;
  --green: #085c32;
  --green-bg: #e5f6ec;
  --red: #b42318;
  --draft: #6a4b00;
  --draft-bg: #fff4d6;
  color-scheme: light;
  font-size: 17px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: #d5dbe3;
  color: var(--ink);
  font-family: Roboto, "Segoe UI", "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.35;
  overscroll-behavior-y: contain;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--paper);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--navy);
  color: #fff;
}

.header-inner {
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
}

.app-header h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.25;
  font-weight: 700;
}

.app-header h1 span {
  flex: 1;
}

.brand-logo {
  flex: 0 0 auto;
  width: 118px;
  height: auto;
  background: #fff;
  border-radius: 8px;
}

.header-sub {
  margin: 4px 0 0;
  color: #d6e2f0;
  font-size: 0.85rem;
  font-weight: 600;
}

.header-sub.is-offline {
  color: #ffe08a;
}

.editor-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.back-btn {
  min-height: 48px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: #2a4d78;
  color: #fff;
  font-weight: 700;
}

.card-chip {
  flex: 1;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.save-state {
  margin: 0;
  color: #d6e2f0;
  font-size: 0.85rem;
  font-weight: 700;
}

.save-state.is-bad {
  color: #ffb4a8;
}

input,
textarea,
select {
  scroll-margin-top: 12px;
  scroll-margin-bottom: 20px;
}

.alert {
  margin: 0;
  padding: 12px 14px;
  background: #fdecea;
  color: #7a1c14;
  font-weight: 700;
}

main {
  padding: 14px 14px 128px;
}

.screen-title,
.panel h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
}

.finished-hint {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--green-bg);
  color: var(--green);
  font-weight: 700;
}

.fine-print {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.panel {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  font-weight: 600;
}

.field:last-child,
.panel .field:last-child {
  margin-bottom: 0;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  padding: 12px 14px;
  border: 1.5px solid #d6d0c6;
  border-radius: 12px;
  background: #fff;
}

textarea {
  display: block;
  min-height: 96px;
  resize: vertical;
  line-height: 1.4;
}

#work-done {
  min-height: 140px;
}

input:focus,
textarea:focus {
  border-color: var(--navy);
  outline: 3px solid var(--amber);
  outline-offset: 1px;
}

::placeholder {
  color: #8a847c;
}

.warn {
  margin: -4px 0 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--draft-bg);
  color: #8a3b00;
  font-size: 0.9rem;
  font-weight: 600;
}

.segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  border-radius: 12px;
  background: #efeae2;
}

.segment button {
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 700;
}

.segment button[aria-pressed="true"] {
  background: #fff;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.12);
}

.time-grid,
.qty-row,
.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.time-grid .field,
.qty-row .field {
  margin-bottom: 0;
}

.hours-total {
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 12px;
  background: #fff8e8;
  font-size: 1.05rem;
  font-weight: 700;
}

.mat {
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf7;
}

.photo-actions {
  margin-bottom: 10px;
}

#sig-clear {
  margin: 10px 0 12px;
}

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

.photo {
  margin: 0;
}

.photo img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: #ece7df;
}

.photo .btn {
  margin-top: 6px;
}

.sig-pad {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 1;
  touch-action: none;
  user-select: none;
  border: 1.5px solid #d6d0c6;
  border-radius: 12px;
  background: #fff;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-weight: 700;
}

.btn:disabled {
  opacity: 0.55;
}

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

.btn.amber {
  background: var(--amber);
  color: var(--amber-ink);
}

.btn.ghost,
.btn.quiet-danger {
  background: #fff;
  border-color: #d6d0c6;
  color: var(--navy);
}

.btn.quiet-danger,
.job-delete {
  color: var(--red);
}

.btn.danger {
  background: var(--red);
  color: #fff;
}

.btn:focus-visible,
.back-btn:focus-visible,
.segment button:focus-visible,
.job-open:focus-visible,
.job-delete:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

.job {
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-left: 5px solid var(--amber);
  border-radius: 14px;
  background: #fff;
}

.job.finished {
  border-left-color: #0e7a45;
}

.job-open {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-height: 88px;
  padding: 12px 12px 8px;
  border: 0;
  background: transparent;
  text-align: left;
}

.job-open:active {
  background: #f7f4ee;
}

.job-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.job-open strong {
  font-size: 1.08rem;
  overflow-wrap: anywhere;
}

.job-open .site,
.job-open .tech {
  color: var(--muted);
  font-weight: 400;
}

.job-open .site {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge.draft {
  background: var(--draft-bg);
  color: var(--draft);
}

.badge.finished {
  background: var(--green-bg);
  color: var(--green);
}

.job-delete {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  z-index: 8;
  display: flex;
  justify-content: flex-start;
  width: min(480px, 100%);
  /* The free Netlify badge sits bottom-right and cannot be turned off.
     Leave that corner empty so it never covers Finish / New job card. */
  padding: 10px 170px calc(10px + env(safe-area-inset-bottom)) 14px;
  transform: translateX(-50%);
  border-top: 1px solid var(--line);
  background: var(--paper);
}

body.keyboard-open .app-header {
  position: static;
}

body.keyboard-open .app-header h1,
body.keyboard-open .header-sub,
body.keyboard-open .app-nav {
  display: none;
}

body.keyboard-open .header-inner {
  padding: calc(4px + env(safe-area-inset-top)) 10px 6px;
}

body.keyboard-open .editor-bar {
  margin-top: 0;
}

body.keyboard-open .bottom-bar {
  display: none !important;
}

body.keyboard-open main {
  padding-bottom: 28px;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(23, 32, 48, 0.48);
}

.sheet-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  width: min(480px, 100%);
  padding: 18px 170px calc(16px + env(safe-area-inset-bottom)) 16px;
  border-radius: 18px 18px 0 0;
  background: #fff;
}

.sheet-card .btn {
  width: 100%;
}

.sheet-card h2 {
  width: 100%;
  margin: 0;
  font-size: 1.2rem;
}

.sheet-card p {
  width: 100%;
  margin: 0;
  color: #3f3a36;
  overflow-wrap: anywhere;
}

#install-btn {
  margin-bottom: 12px;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.app-nav {
  display: flex;
  gap: 6px;
  padding: 8px 14px 0;
}

.nav-btn {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: #2a4d78;
  color: #fff;
  font-weight: 700;
}

.nav-btn[aria-current="page"] {
  background: var(--amber);
  color: var(--amber-ink);
}

.suggest {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 12px;
}

.suggest-btn {
  min-height: 52px;
  padding: 8px 12px;
  border: 1.5px solid #d6d0c6;
  border-radius: 12px;
  background: #fff;
  text-align: left;
  font: inherit;
}

.suggest-btn strong,
.suggest-btn span {
  display: block;
}

.suggest-btn span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

.travel-leg {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  align-items: end;
  margin-bottom: 10px;
}

.leg-name {
  grid-column: 1 / -1;
  font-weight: 700;
}

.now-btn {
  min-height: 52px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-weight: 650;
}

.keypad {
  margin: 8px 0 12px;
  padding: 10px;
  border-radius: 12px;
  background: #efeae2;
}

.keypad-display {
  margin: 0 0 8px;
  padding: 8px;
  border-radius: 12px;
  background: #fff;
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
}

.keypad-nums,
.keypad-actions {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.keypad-nums {
  grid-template-columns: repeat(6, 1fr);
}

.keypad-actions {
  grid-template-columns: 1fr 1fr 1fr;
}

.keypad-nums button,
.keypad-actions button {
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  background: #fff;
  font-weight: 700;
}

.key-add { background: #0e7a45; color: #fff; }
.key-sub { background: #b42318; color: #fff; }
.key-clear { background: #e7e0d6; }

.name-list {
  max-height: 220px;
  margin-top: 10px;
  overflow: auto;
  font-size: 0.95rem;
}

.job-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.job-actions button {
  min-height: 48px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--navy);
  font-weight: 700;
}

.stock-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.stock-line button {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: #fdecea;
  color: var(--red);
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
