/* Data-entry UI. Mobile first: this is used on site, on a phone, one-handed.
   Everything here builds on the Industry tokens in industry.css.

   Two rules drive the sizing:
   - Fields are 16px. Anything smaller makes iOS Safari zoom on focus.
   - Anything tappable is at least 44px tall.
   Desktop is the same markup widened at 900px, not a second UI. */

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { font-family: var(--font-heading); font-weight: 600; margin: 0; }
h1 { font-size: 24px; line-height: 1.15; }
h2 { font-size: 17px; }
a { color: var(--color-accent-700); }

.app { min-height: 100dvh; display: flex; flex-direction: column; }

/* — top bar — */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  padding-top: calc(var(--space-3) + env(safe-area-inset-top));
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-divider);
}
.topbar .brand {
  font-family: var(--font-heading); font-weight: 600; font-size: 16px;
  letter-spacing: .02em; color: var(--color-text); text-decoration: none;
}
.topbar .who { font-size: 12px; color: var(--color-neutral-600); }
.spacer { flex: 1; }
.back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; margin-left: -8px; flex: none;
  border-radius: var(--radius-md); color: var(--color-text); text-decoration: none;
}
.back:active { background: rgba(29, 31, 32, .08); }
/* Declared as button.linkish so it outweighs the button[type="submit"] rule
   further down -- the sign-out control is a submit button too. */
button.linkish, .linkish {
  width: auto; min-height: 34px; padding: 8px; margin: -8px;
  background: none; border: 0; cursor: pointer;
  color: var(--color-accent-700); font: inherit; font-size: 13px; font-weight: 400;
}
button.linkish:active { background: rgba(29, 31, 32, .08); }

.page-head { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.page-head h1 { flex: 1; min-width: 0; }
.section-head { margin-top: var(--space-8); margin-bottom: var(--space-3); }
.row-go { color: var(--color-neutral-500); font-size: 20px; line-height: 1; align-self: center; }
.btn-link.compact { width: auto; min-height: 38px; padding: 0 14px; font-size: 14px; flex: none; }
.empty p { margin: 0 0 var(--space-3); }

main { flex: 1; padding: var(--space-4); padding-bottom: 96px; }
.sub { color: var(--color-neutral-600); font-size: 13px; margin: 2px 0 var(--space-4); }
.small { color: var(--color-neutral-600); font-size: 12px; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }

/* — bottom tab bar: the thumb lives here — */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--color-bg);
  border-top: 1px solid var(--color-divider);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; min-height: 54px; padding: 7px 2px 5px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--color-neutral-600); text-decoration: none; font-size: 10.5px;
  letter-spacing: .01em;
}
.tabbar a[aria-current="page"] { color: var(--color-accent-700); font-weight: 500; }
.tabbar svg { width: 21px; height: 21px; stroke-width: 1.6; }

/* — cards — */
/* .card and .field deliberately override the Industry versions: the same
   tokens, retuned for touch (white ground, larger radius, 46px controls).
   Pages that want the original look load industry.css alone -- the admin and
   the Plan Builder both do. */
.card {
  background: #fff; border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg); padding: var(--space-4); gap: var(--space-3);
}
.row-card {
  display: flex; align-items: flex-start; gap: var(--space-3);
  background: #fff; border: 1px solid var(--color-divider);
  border-radius: var(--radius-md); padding: var(--space-3);
  text-decoration: none; color: inherit;
}
.row-card:active { background: var(--color-neutral-100); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-go { color: var(--color-neutral-500); font-size: 20px; line-height: 1; align-self: center; }
.row-title { font-weight: 500; font-size: 15px; }
.row-sub { font-size: 12px; color: var(--color-neutral-600); }
.row-amount {
  font-family: var(--font-heading); font-weight: 600; font-size: 17px;
  font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right;
}

/* — figures — */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
.tile {
  background: #fff; border: 1px solid var(--color-divider);
  border-radius: var(--radius-md); padding: var(--space-3);
}
.tile span { display: block; font-size: 10.5px; letter-spacing: .08em; color: var(--color-neutral-600); }
.tile strong {
  display: block; margin-top: 3px; font-family: var(--font-heading); font-weight: 600;
  font-size: 19px; font-variant-numeric: tabular-nums; line-height: 1.15;
}
.over { color: #8c2f2f; }
.under { color: #1d7a45; }
.dir-out { color: #8c2f2f; }
.dir-in { color: #1d7a45; }

/* — forms — */
.field { display: block; margin-bottom: var(--space-4); }
.field > span, .field > label {
  display: block; font-size: 12px; letter-spacing: .04em;
  color: var(--color-neutral-700); margin-bottom: 5px;
}
.field input, .field select, .field textarea,
input[type="text"], input[type="date"], input[type="number"],
input[type="password"], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  font: inherit; font-size: 16px; color: var(--color-text);
  background: #fff; border: 1px solid var(--color-divider);
  border-radius: var(--radius-md); appearance: none;
}
select { background-image: none; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 22%, transparent);
}
.field small { display: block; margin-top: 4px; font-size: 12px; color: var(--color-neutral-600); }
.amount input { font-family: var(--font-heading); font-size: 26px; font-weight: 600; min-height: 58px; }

/* Direction as a two-up switch: bigger targets than a dropdown. */
.switch { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.switch label {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 50px; padding: 0 10px; cursor: pointer; font-size: 15px; font-weight: 500;
  background: #fff; border: 1px solid var(--color-divider); border-radius: var(--radius-md);
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch label:has(input:checked) {
  background: var(--color-accent); border-color: var(--color-accent-800); color: var(--color-bg);
}
.switch label:has(input:focus-visible) { outline: 2px solid var(--color-accent); outline-offset: 2px; }

button:not(.linkish), .btn-link {
  font: inherit; font-family: var(--font-heading); font-weight: 600; font-size: 16px;
  min-height: 50px; padding: 0 18px; cursor: pointer;
  border-radius: var(--radius-md); border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
/* Sign-out is a submit button too, so it has to be excluded by name rather
   than out-specified. */
button[type="submit"]:not(.linkish), .primary {
  width: 100%; background: var(--color-accent); border-color: var(--color-accent-800);
  color: var(--color-bg);
}
button[type="submit"]:not(.linkish):active, .primary:active { background: var(--color-accent-700); }
.secondary {
  width: 100%; background: #fff; border-color: var(--color-divider); color: var(--color-text);
}
.ghost { min-height: 44px; background: none; border: 0; color: var(--color-accent-700); padding: 0; }

/* Deliberately not sticky. A sticky footer inside a long form floats over the
   fields that precede it, hiding the ones you have not filled in yet. */
.save-row, .sticky-save { margin-top: var(--space-6); }

.check { display: flex; align-items: center; gap: 10px; min-height: 46px; margin-bottom: var(--space-4); font-size: 15px; }
.check input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--color-accent); }

/* — feedback — */
.ok, .warn, .error-box {
  border-radius: var(--radius-md); padding: 10px 12px; font-size: 13.5px;
  margin-bottom: var(--space-3);
}
.ok { background: #e7f5ec; border: 1px solid #b9e0c8; color: #1d7a45; }
.warn { background: #fdf3e3; border: 1px solid #f0dcb4; }
.error-box, .error { color: #8c2f2f; }
.errorlist { list-style: none; padding: 0; margin: 5px 0 0; font-size: 13px; color: #8c2f2f; }
.messages { list-style: none; padding: 0; margin: 0 0 var(--space-3); }
.empty {
  text-align: center; color: var(--color-neutral-600); font-size: 14px;
  padding: var(--space-8) var(--space-4);
}

/* — filters — */
.picker { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.picker label { font-size: 12px; color: var(--color-neutral-600); flex: none; }
.picker select { min-height: 40px; font-size: 14px; }

/* — tables (reports) — wide data scrolls rather than squeezing — */
.scroller { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--space-4)); padding: 0 var(--space-4); }
.grid { width: 100%; min-width: 560px; border-collapse: collapse; background: #fff;
  border: 1px solid var(--color-divider); border-radius: var(--radius-md); font-size: 13.5px; }
.grid th, .grid td { padding: 9px 10px; border-bottom: 1px solid var(--color-divider); text-align: left; }
.grid th { font-size: 10.5px; letter-spacing: .06em; color: var(--color-neutral-600); font-weight: 600; white-space: nowrap; }
.grid tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.branch > td { font-weight: 600; background: #fbfcfd; }
.status-late, .status-unpaid, .status-behind { color: #8c2f2f; }
.status-on-time, .status-on_time, .status-on-track { color: #1d7a45; }
.status-partial, .status-not-started { color: #a8660d; }

/* — attachments — */
.shots { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.shot {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  padding: 6px 10px; background: var(--color-accent-100); color: var(--color-accent-800);
  border-radius: var(--radius-md); text-decoration: none;
}
.capture {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 58px; border: 1px dashed var(--color-divider); border-radius: var(--radius-md);
  background: #fff; color: var(--color-accent-700); font-size: 15px; cursor: pointer;
}
.capture input { position: absolute; opacity: 0; width: 0; height: 0; }

/* — wider screens: same markup, more room — */
@media (min-width: 900px) {
  main { max-width: 1100px; margin: 0 auto; width: 100%; padding: var(--space-8); padding-bottom: var(--space-8); }
  .tabbar {
    position: static; border-top: 0; border-bottom: 1px solid var(--color-divider);
    padding: 0 var(--space-8); gap: var(--space-2);
  }
  .tabbar a { flex: none; flex-direction: row; gap: 7px; font-size: 13.5px; padding: 0 12px; min-height: 46px; }
  .tabbar svg { width: 17px; height: 17px; }
  .topbar { padding: var(--space-3) var(--space-8); }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .grid { min-width: 0; }
  .scroller { margin: 0; padding: 0; }
  .sticky-save { position: static; background: none; padding-top: 0; }
  button[type="submit"]:not(.linkish), .primary, .secondary { width: auto; min-width: 200px; }
  /* Flex children stretch by default, so width:auto alone leaves them full width. */
  .actions { flex-direction: row; align-items: flex-start; }
  .fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
}
