/* InspectLog — tablet-first, plain and legible. Brand colours are per-firm
   config later; this neutral green is the product default, easily themed. */
:root {
  /* Inspection Records — Steel and Safety (see docs/BRAND.md) */
  --brand: #1E3A5F;          /* steel navy: structure, headers, emphasis */
  --brand-soft: #E3EAF3;
  --accent: #E8650D;         /* safety orange: primary actions only */
  --accent-ink: #ffffff;
  --ink: #1B2430;
  --muted: #5d6673;
  --line: #D4DAE2;
  --bg: #F3F5F8;
  --danger: #b4231f;
  --warn: #9a6700;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .5rem; }
label { display: block; margin: .9rem 0 .25rem; font-weight: 600; font-size: .95rem; }
input, textarea, select {
  width: 100%; padding: .65rem .75rem; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
/* iPhones draw drop-downs in system blue with their own arrow; draw ours
   so they match the other boxes everywhere */
select {
  -webkit-appearance: none; appearance: none; padding-right: 2.5rem;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235d6673' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right .8rem center / 18px;
}
/* iOS Safari paints date and drop-down values in its own link blue and
   ignores plain `color`; the fill colour below is what it obeys */
select, input[type="date"] { -webkit-text-fill-color: var(--ink); opacity: 1; }
input[type="date"] { -webkit-appearance: none; appearance: none; min-height: 2.9rem; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; color: var(--ink); }
select:required:invalid { color: var(--muted); -webkit-text-fill-color: var(--muted); }
select option { color: var(--ink); }
input:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
button { font: inherit; border: none; border-radius: var(--radius); padding: .7rem 1.2rem; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
button.small { padding: .4rem .8rem; font-size: .9rem; }
button.wide { width: 100%; margin-top: 1.2rem; }
.row { display: flex; gap: .75rem; align-items: center; margin-top: .5rem; }
.row.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.error { color: var(--danger); font-weight: 600; }

.view { min-height: 100vh; }

/* auth */
.auth-card {
  max-width: 420px; margin: 8vh auto; background: #fff; padding: 2rem;
  border-radius: 16px; border: 1px solid var(--line);
}
.brand { color: var(--brand); font-size: 1.6rem; }

/* layout */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: .75rem;
  padding: calc(.9rem + env(safe-area-inset-top)) 1.2rem .9rem; background: var(--brand); color: #fff;
}
.topbar h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar button { flex: none; }
.topbar h1 { color: #fff; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .ghost { color: #fff; border-color: rgba(255,255,255,.4); }
.content { max-width: 860px; margin: 0 auto; padding: 1rem 1rem calc(6.2rem + env(safe-area-inset-bottom)); }
.content.narrow { max-width: 560px; }

/* cards */
.cards { display: grid; gap: .6rem; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; display: flex; justify-content: space-between; gap: .75rem; align-items: center;
}
.card .title { font-weight: 600; }
.badge { padding: .15rem .6rem; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--brand-soft); color: var(--brand); }
.badge.due { background: #fff3d6; color: var(--warn); }
.badge.overdue { background: #fde3e2; color: var(--danger); }

/* signature pad */
#sig-pad {
  width: 100%; height: auto; background: #fff;
  border: 1px dashed var(--line); border-radius: var(--radius); touch-action: none;
}

/* tab bar: icons over labels, safe-area aware on iPhone */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  flex: 1; min-width: 0; background: none; border-radius: 0;
  display: flex; flex-direction: column; align-items: center; gap: .2rem;
  padding: .55rem .1rem .5rem; color: var(--muted);
}
.tab svg { width: 23px; height: 23px; flex: none; }
.tab .tablabel {
  font-size: .68rem; font-weight: 600; letter-spacing: .1px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tab.active { color: var(--brand); background: var(--brand-soft); border-radius: 10px; box-shadow: none; }
@media (min-width: 700px) {
  .tabbar { position: static; max-width: 1040px; margin: 0 auto; border: none; background: none; justify-content: flex-start; gap: .4rem; padding: .2rem 1.2rem; }
  .tab { flex: none; flex-direction: row; gap: .45rem; font-size: .95rem; padding: .55rem .9rem; }
  .tab .tablabel { font-size: .95rem; }
  .tab.active { background: none; border-radius: 0; box-shadow: inset 0 -3px 0 var(--accent); }
  .content { padding-bottom: 2rem; }
}

/* dialogs */
dialog {
  border: none; border-radius: 16px; padding: 1.5rem; width: min(480px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; }
.check input { width: auto; margin-top: .3rem; }

dialog { max-height: 86vh; overflow-y: auto; }
.content { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0)); }

@media (max-width: 480px) {
  .content { padding-left: .9rem; padding-right: .9rem; }
  h1 { font-size: 1.2rem; }
  .card { flex-wrap: wrap; }
  .card .actions { width: 100%; justify-content: flex-end; flex-wrap: wrap; row-gap: .4rem; }
  .segment { flex-wrap: wrap; }
  .segment .pill span { padding: .55rem .9rem; }
  .form-head .firm-logo { float: none; display: block; margin: 0 0 .5rem; }
}

@media (min-width: 700px) {
  .tabbar { position: static; max-width: 860px; margin: 0 auto; border: none; background: none; justify-content: flex-start; gap: .5rem; padding: 0 1.2rem; }
  .tab { flex: none; flex-direction: row; gap: .45rem; padding: .8rem .6rem; }
  .tab svg { width: 19px; height: 19px; }
  .tab .tablabel { font-size: .95rem; }
  .content { padding-bottom: 2rem; }
}

/* form sections (GA1 and future templates) */
.form-head h2 { margin-bottom: .1rem; }
fieldset.form-section {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; margin: 1rem 0; padding: .9rem 1rem 1rem;
  min-width: 0;
}
fieldset.form-section legend {
  /* floated so it sits INSIDE the card as a header, never on the border */
  float: left; width: 100%; padding: 0; margin: 0 0 .35rem;
  font-weight: 700; font-size: 1.02rem; color: var(--brand); line-height: 1.3;
}
fieldset.form-section > *:not(legend) { clear: both; }
fieldset.form-section.invalid { border-color: var(--danger); }
.req { color: var(--danger); }
.repeat-row { border-bottom: 1px dashed var(--line); padding-bottom: .8rem; margin-bottom: .4rem; }
.repeat-row:last-child { border-bottom: none; }

/* spacing rules: air between fields and the buttons that follow them */
input, textarea, select { margin-bottom: .35rem; }
button.primary, button.ghost { margin-top: .6rem; }
.topbar button, .tabbar button, .card button { margin-top: 0; }
.row { margin-top: 1rem; }
dialog .row.spread { margin-top: 1.3rem; }

/* switches */
.switchrow { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .9rem 0 .25rem; font-weight: 600; }
.switch { position: relative; flex: none; width: 52px; height: 30px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch .knob { display: block; width: 52px; height: 30px; border-radius: 999px; background: #cfcfcb; transition: background .15s; }
.switch .knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .knob { background: var(--brand); }
.switch input:checked + .knob::after { left: 25px; }

/* segmented pills */
.segment { display: flex; gap: .5rem; }
.segment .pill { position: relative; display: inline-block; }
.segment .pill input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segment .pill span { display: inline-block; padding: .6rem 1.1rem; border: 1.5px solid var(--line); border-radius: 999px; font-weight: 600; cursor: pointer; }
.segment .pill input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }

/* password + files + logo */
.pwrow { display: flex; gap: .5rem; align-items: center; }
.pwrow input { flex: 1; }
.pwrow .showpw { margin-top: 0; flex: none; }
.filebtn { display: inline-block; padding: .55rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; color: var(--brand); }
.firm-logo { max-height: 56px; max-width: 180px; object-fit: contain; }
.form-head .firm-logo { float: right; margin-left: 1rem; }
.hint { margin-top: .15rem; }

/* search, chips, desktop density */
.searchbox { margin: .4rem 0 .8rem; font-size: 1.05rem; padding: .75rem .9rem; }
.chips { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.chips.wrap .chip { cursor: default; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: .45rem 1rem; font-weight: 600; color: var(--muted); margin-top: 0; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .x { margin-left: .5rem; color: inherit; opacity: .7; cursor: pointer; }
.card .actions { display: flex; gap: .5rem; align-items: center; flex: none; }
.card .actions button, .card .actions .switch { margin-top: 0; }
.card.stack { flex-direction: column; align-items: stretch; gap: .4rem; }
.cardline { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }

@media (min-width: 900px) {
  .content { max-width: 1040px; }
  .tabbar { max-width: 1040px; }
  .cards.table .card { border-radius: 0; border-bottom: none; padding: .6rem 1rem; }
  .cards.table .card:first-child { border-radius: var(--radius) var(--radius) 0 0; }
  .cards.table .card:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: 1px solid var(--line); }
  .cards.table .title { min-width: 220px; }
}

/* mobile comfort */
button { min-height: 44px; }
.tab { min-height: 52px; }
.showpw, .chip, button.small { min-height: 40px; }
.card { flex-wrap: wrap; }
.card > div:first-child { min-width: 0; flex: 1 1 60%; }
.card .title, .card .muted { overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .card .actions { width: 100%; justify-content: flex-end; }
  .segment { flex-wrap: wrap; }
  .topbar h1 { font-size: 1.15rem; }
}

.badge.void { background: #e8e8e6; color: #555; }
.badge.draft { background: transparent; color: var(--muted, #5d6673); border: 1px dashed currentColor; }

/* photo grid */
.photo-grid { display: flex; flex-wrap: wrap; gap: .6rem; margin: .4rem 0 .6rem; }
.photo-thumb { position: relative; width: 96px; height: 96px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb.pending { opacity: .5; }
.photo-x {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; min-height: 26px;
  border-radius: 50%; background: rgba(27,36,48,.75); color: #fff; padding: 0;
  line-height: 1; font-size: 1rem; margin-top: 0;
}

/* Combo: native pick list plus an "Other" text box */
.combo-other { margin-top: .5rem; }
.wrapbtns { flex-wrap: wrap; }
.card.defect.red { border-left: 4px solid var(--danger); }
.card.defect.amber { border-left: 4px solid #e0a100; }
.defecttext { margin-top: .35rem; color: var(--ink); }

/* Your account */
#acc-sig-pad { width: 100%; height: auto; background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); touch-action: none; }
.sig-preview { max-width: 220px; max-height: 80px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .25rem; }
.acc-pw { margin: 1rem 0 .5rem; }
.acc-pw summary { cursor: pointer; color: var(--brand); font-weight: 600; padding: .5rem 0; min-height: 44px; display: flex; align-items: center; }
#acc-name { flex: 1; margin-bottom: 0; }
