:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef2f7; --ink: #1b2430; --muted: #5b6675; --faint: #8a94a3;
  --rule: #d5dce5; --brand: #1f5bc4; --brand-ink: #ffffff; --brand-soft: #e3ecfb; --alert: #b42318; --alert-soft: #fdecea;
  --ok: #18794e; --ok-soft: #e3f5ec; --warn: #9a6700; --warn-soft: #fff4d6; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --surface: #171e27; --surface-2: #1f2833; --ink: #e6ebf2; --muted: #a3aebd; --faint: #77828f;
    --rule: #2c3743; --brand: #5b93f0; --brand-ink: #0b1220; --brand-soft: #1b2b45; --alert: #f2726a; --alert-soft: #3a1d1c;
    --ok: #4cc38a; --ok-soft: #15301f; --warn: #e5b450; --warn-soft: #3a2e12; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: .5rem 1rem; display: flex; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); font-weight: 700; white-space: nowrap; }
.brand img { height: 34px; width: auto; border-radius: 4px; background: #fff; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .25rem; align-items: center; flex: 1; }
.nav a, .nav button { white-space: nowrap; color: var(--muted); padding: .45rem .65rem; border-radius: 8px; font-size: .95rem; background: none; border: 0; font: inherit; cursor: pointer; }
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.nav .spacer { flex: 1; }
.nav form { margin: 0; }
.menu-toggle { display: none; }
@media (max-width: 1020px) {
  .topbar-inner { flex-wrap: wrap; }
  .menu-toggle { display: block; margin-left: auto; }
  .menu-toggle summary { list-style: none; cursor: pointer; padding: .4rem .7rem; border: 1px solid var(--rule); border-radius: 8px; }
  .menu-toggle summary::-webkit-details-marker { display: none; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: .5rem; }
  .menu-toggle[open] ~ .nav { display: flex; }
  .nav .spacer { display: none; }
}

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.25rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.crumbs { font-size: .875rem; color: var(--muted); margin-bottom: .25rem; }

.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 42px; padding: .5rem 1rem; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-danger { color: var(--alert); border-color: var(--alert); }
.btn-danger:hover { background: var(--alert-soft); }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .875rem; }
.btn-link { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: .25rem; }
.btn-link.danger { color: var(--alert); }

/* Forms */
form.stack > * + * { margin-top: 1rem; }
fieldset { border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.1rem 1.1rem; margin: 0 0 1rem; background: var(--surface); }
legend { font-weight: 700; padding: 0 .4rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field > span, .label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field .hint { font-size: .8rem; color: var(--faint); font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], input[type=tel], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: .55rem .7rem; min-height: 44px; }
textarea { min-height: 7rem; resize: vertical; }
textarea.tall { min-height: 12rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.row { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.row + .row, .row + .field, .field + .row, .field + .field { margin-top: .9rem; }
.row > .field { margin-top: 0; }
.choice { display: inline-flex; align-items: center; gap: .45rem; margin-right: 1.1rem; min-height: 36px; cursor: pointer; }
.choice input { width: 1.2rem; height: 1.2rem; accent-color: var(--brand); }
.choices { display: flex; flex-wrap: wrap; align-items: center; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .1rem .75rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; border-top: 1px solid var(--rule); z-index: 5; }
.form-actions .spacer { flex: 1; }

.alert { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert-error { background: var(--alert-soft); color: var(--alert); border-color: var(--alert); }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.alert-info { background: var(--brand-soft); color: var(--ink); border-color: var(--brand); }

/* Crew editor: table on wide screens, stacked cards on phones */
.crew { width: 100%; border-collapse: collapse; }
.crew th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 600; padding: 0 .3rem .3rem; white-space: nowrap; }
.crew td { padding: .25rem .3rem; vertical-align: middle; }
.crew td.rm { width: 1%; }
.crew input[type=time] { min-width: 7.2rem; }
.crew .equip-group th { color: var(--brand); }
@media (max-width: 860px) {
  .crew thead { display: none; }
  .crew, .crew tbody, .crew tr, .crew td { display: block; width: 100%; }
  .crew tr { border: 1px solid var(--rule); border-radius: var(--radius); padding: .6rem; margin-bottom: .7rem; display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .6rem; }
  .crew td { padding: 0; }
  .crew td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); font-weight: 600; margin-bottom: .15rem; }
  .crew td.wide { grid-column: 1 / -1; }
  .crew td.rm { grid-column: 1 / -1; width: auto; text-align: right; }
}

/* Tables */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.list th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: .5rem .6rem; border-bottom: 1px solid var(--rule); white-space: nowrap; }
table.list td { padding: .6rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list tfoot td { font-weight: 700; background: var(--surface-2); }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-active { background: var(--ok-soft); color: var(--ok); }
.badge-on_hold, .badge-bidding { background: var(--warn-soft); color: var(--warn); }
.badge-alert { background: var(--alert-soft); color: var(--alert); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: .75rem .9rem; }
.stat .v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .k { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }




/* Job cards */
.job-card { display: block; color: inherit; }
.job-card:hover { text-decoration: none; border-color: var(--brand); }
.job-card .meta { display: flex; justify-content: space-between; gap: .5rem; font-size: .875rem; color: var(--muted); margin-top: .5rem; }

/* Timeline */
.timeline { position: relative; margin: 0; padding: 0 0 0 1.6rem; list-style: none; }
.timeline::before { content: ""; position: absolute; left: .45rem; top: .3rem; bottom: .3rem; width: 2px; background: var(--rule); }
.timeline > li { position: relative; margin-bottom: 1rem; }
.timeline > li::before { content: ""; position: absolute; left: -1.5rem; top: 1.15rem; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--bg); }
.timeline > li.incident::before { background: var(--alert); border-radius: 2px; transform: rotate(45deg); }
.timeline .month { list-style: none; font-weight: 700; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; margin: 1.25rem 0 .5rem; }
.timeline > li.month::before { display: none; }
.tl-card { margin-bottom: 0; }
.tl-card.incident { border-left: 3px solid var(--alert); }
.tl-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1rem; align-items: baseline; margin-bottom: .4rem; }
.tl-head h3 { margin: 0; }
.tl-meta { display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .875rem; color: var(--muted); margin-bottom: .5rem; }
.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

/* Photos */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .4rem; margin-top: .6rem; }
.thumbs a, .thumbs img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.photo { border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.photo > a img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--surface-2); }
.photo .body { padding: .6rem .7rem; }
.photo form { margin: 0; }
.photo .excluded { opacity: .55; }
.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .4rem; margin-top: .5rem; }
.previews img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.dropzone { border: 2px dashed var(--rule); border-radius: var(--radius); padding: 1rem; text-align: center; }
.dropzone input[type=file] { max-width: 100%; }
.upload-progress { display: none; margin-top: .5rem; }
.upload-progress.show { display: block; }

/* Signature pad */
.sig canvas { width: 100%; max-width: 520px; height: 150px; display: block; background: #fff; border: 1px solid var(--rule); border-radius: 8px; touch-action: none; cursor: crosshair; }
.sig .sig-actions { display: flex; justify-content: space-between; max-width: 520px; font-size: .85rem; color: var(--faint); margin-top: .25rem; }
.sig-img { max-width: 300px; max-height: 90px; background: #fff; border-radius: 6px; padding: .25rem; border: 1px solid var(--rule); }

/* Detail views */
dl.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem 1rem; margin: 0; }
dl.fields div { min-width: 0; }
dl.fields dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
dl.fields dd { margin: .1rem 0 0; overflow-wrap: anywhere; }
dl.fields .full { grid-column: 1 / -1; }

/* Chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--rule); stroke-width: 1; }
.chart .grid line.base { stroke: var(--faint); }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .series { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .mark { fill: var(--brand); stroke: var(--surface); stroke-width: 2; }
.chart .label { fill: var(--ink); font-size: 12px; font-weight: 600; }
.chart .crosshair { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 3 3; display: none; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); padding: .3rem .55rem; border-radius: 6px; font-size: .8rem; white-space: nowrap; display: none; transform: translate(-50%, -115%); }

.pdf-form { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.auth-wrap { max-width: 420px; margin: 3rem auto; }
.auth-wrap .logo { display: block; margin: 0 auto 1rem; max-width: 200px; background: #fff; border-radius: 8px; padding: .4rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: 1rem; }
.filters .field { flex: 1 1 150px; }
@media print { .topbar, .form-actions, .no-print { display: none !important; } body { background: #fff; } }

/* Utilities (no inline styles: the CSP forbids them) */
.m-0 { margin: 0; } .mt-half { margin-top: .5rem; } .mt-1 { margin-top: 1rem; } .mt-3 { margin-top: 3rem; } .mx-auto { margin-left: auto; margin-right: auto; }
.center { text-align: center; } .right { text-align: right; } .w-full { width: 100%; } .narrow { max-width: 520px; }
.between { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.inline { display: inline; margin: 0; }
progress.bar { appearance: none; -webkit-appearance: none; width: 100%; height: 8px; border: 0; border-radius: 4px; background: var(--surface-2); overflow: hidden; display: block; }
progress.bar::-webkit-progress-bar { background: var(--surface-2); border-radius: 4px; }
progress.bar::-webkit-progress-value { background: var(--brand); border-radius: 4px; }
progress.bar::-moz-progress-bar { background: var(--brand); border-radius: 4px; }
.review.is-pending { border-left: 3px solid var(--warn); }
.review.is-reviewed { border-left: 3px solid var(--ok); }
.job-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .1rem .75rem; max-height: 22rem; overflow: auto; border: 1px solid var(--rule); border-radius: 8px; padding: .5rem .75rem; }
.team-list { list-style: none; margin: 0; padding: 0; }
.team-list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--rule); }
.team-list li:last-child { border-bottom: 0; }
.team-list form { margin: 0; }
.ms-btn svg { flex: none; background: #fff; padding: 2px; border-radius: 2px; }
details summary { cursor: pointer; }
.danger-text { color: var(--alert); overflow-wrap: anywhere; }
.between > .filters { flex: 1; }
