:root {
  --bg: #f5f5f4;
  --card: #fff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --top: #1c2430;
  --accent: #ea580c;
  --accent-dark: #c2410c;
  --primary: #1d4ed8;
  --ok: #15803d;
  --danger: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; line-height: 1.2; }
h2 { font-size: 1.08rem; margin: 0 0 .6rem; }
section { margin: 0 0 1.6rem; }
code { background: #f0efed; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 18px; padding-bottom: 60px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.red { color: var(--danger); }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); font-weight: 600; }

/* ---- header ---- */
.top { background: var(--top); color: #fff; position: sticky; top: 0; z-index: 10; }
.top-in { display: flex; align-items: center; gap: 18px; min-height: 54px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; text-decoration: none; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { color: #cbd5e1; text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; font-size: .95rem; }
.nav a:hover { color: #fff; }
.nav a.on { color: #fff; background: rgb(255 255 255 / .12); }
.top-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.linklike { background: none; border: 0; color: #cbd5e1; cursor: pointer; font: inherit; font-size: .9rem; padding: 0; }
.linklike:hover { color: #fff; }
@media (max-width: 640px) {
  .top-in { gap: 6px 12px; padding-top: 8px; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -10px; padding-bottom: 4px; }
}

/* ---- buttons & forms ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 8px; border: 1px solid #d6d3d1; background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 44px;
}
.btn:hover { background: #fafaf9; }
.btn-sm { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn-lg { min-height: 52px; font-size: 1.05rem; }
.btn-xl { display: flex; width: 100%; min-height: 64px; font-size: 1.15rem; margin-bottom: 1.6rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1e40af; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #166534; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-danger-outline { color: var(--danger); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row form { margin: 0; }
.btn-row .btn-ok, .btn-row .btn-danger { flex: 1; }
form.busy button { opacity: .6; pointer-events: none; }

.stack { display: flex; flex-direction: column; gap: 14px; }
label, .label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .92rem; }
label .muted { font-weight: 400; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
label.check input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid #d6d3d1; border-radius: 8px;
  background: #fff; color: var(--ink); width: 100%; min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; outline-offset: 0; border-color: var(--primary); }
.inline-fields { display: flex; gap: 12px; }
.inline-fields > * { flex: 1; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-family: ui-monospace, monospace; font-size: .8rem !important; }

.field { display: flex; flex-direction: column; gap: 6px; }
.photo-pick {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-height: 64px; border: 2px dashed #d6d3d1; border-radius: var(--radius); background: #fafaf9;
  color: var(--muted); font-weight: 600; cursor: pointer; text-align: center; padding: 8px;
}
.photo-pick:hover { border-color: var(--accent); color: var(--accent-dark); }
.photo-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.previews { display: flex; gap: 6px; flex-wrap: wrap; }
.previews:empty { display: none; }
.previews img { width: 76px; height: 76px; object-fit: cover; border-radius: 6px; }

fieldset.seg { border: 0; padding: 0; margin: 0; display: flex; gap: 8px; flex-wrap: wrap; }
fieldset.seg legend { font-weight: 600; font-size: .92rem; margin-bottom: 6px; padding: 0; }
fieldset.seg label { flex: 1; min-width: 150px; flex-direction: row; align-items: center; gap: 8px; border: 1px solid #d6d3d1; border-radius: 8px; padding: 10px 12px; cursor: pointer; font-weight: 600; }
fieldset.seg label:has(input:checked) { border-color: var(--primary); background: #eff6ff; }

/* ---- cards, flash, tables ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card > h2:first-child { margin-top: 0; }
.card.flat { border: 0; box-shadow: none; padding: 12px 0 0; margin: 0; }
.primary-card { border-color: #93c5fd; box-shadow: 0 0 0 3px #dbeafe; }
.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.narrow-form { max-width: 560px; }
.flash { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 600; transition: opacity .6s; }
.flash.fade { opacity: 0; }
.empty { color: var(--muted); padding: 10px 0; margin: 0; }
.empty-state { text-align: center; padding: 28px 16px; }
.hint { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; font-size: .95rem; }
.callout { background: #fff7ed; border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 0 6px 6px 0; margin: 10px 0; font-size: .95rem; }
.count { display: inline-block; min-width: 22px; padding: 0 7px; border-radius: 99px; background: #e7e5e4; font-size: .8rem; text-align: center; vertical-align: 2px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.table-wrap { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
.num-col { text-align: right; }
tr.inactive td { color: var(--muted); }
details.more summary { cursor: pointer; font-weight: 600; }
.two-col { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .two-col { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; } }

/* ---- status pills & tags ---- */
.pill, .tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; white-space: nowrap; vertical-align: 1px; }
.tag { background: #f4f4f5; color: #52525b; }
.tag-red { background: #fee2e2; color: #991b1b; }
.tone-blue { --t-bg: #dbeafe; --t-fg: #1e40af; }
.tone-amber { --t-bg: #fef3c7; --t-fg: #92400e; }
.tone-purple { --t-bg: #ede9fe; --t-fg: #5b21b6; }
.tone-teal { --t-bg: #ccfbf1; --t-fg: #115e59; }
.tone-red { --t-bg: #fee2e2; --t-fg: #991b1b; }
.tone-green { --t-bg: #dcfce7; --t-fg: #166534; }
.tone-gray { --t-bg: #f4f4f5; --t-fg: #52525b; }
.pill { background: var(--t-bg); color: var(--t-fg); }

/* ---- dashboard stats ---- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 1.6rem; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(5, 1fr); } }
.stat { display: flex; flex-direction: column; padding: 14px 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--t-fg); text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.stat:hover { border-color: var(--t-fg); }
.stat-n { font-size: 2rem; font-weight: 800; line-height: 1.1; color: var(--t-fg); }

/* ---- item rows ---- */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; color: inherit; text-decoration: none; box-shadow: var(--shadow); }
a.row:hover { border-color: #a8a29e; }
.row.static { padding: 10px 14px; }
.thumb { width: 72px; height: 72px; flex: none; object-fit: cover; border-radius: 7px; background: #e7e5e4; }
.thumb-empty { display: flex; align-items: center; justify-content: center; font-size: .7rem; color: var(--muted); text-align: center; }
.row-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.num { font-weight: 800; }
.loc { color: var(--muted); font-weight: 600; font-size: .92rem; }
h1 .loc, h2 .loc { font-size: .75em; }
.row-top .pill { margin-left: auto; }
.row-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-meta { font-size: .82rem; color: var(--muted); }

/* ---- filters ---- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.filters > * { flex: 1 1 160px; width: auto !important; }

/* ---- item detail ---- */
.item-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.item-head h1 { margin-bottom: .4rem; }
.item-layout { display: grid; gap: 0 18px; grid-template-columns: 1fr; grid-template-areas: "details" "actions" "history"; }
@media (min-width: 860px) {
  .item-layout { grid-template-columns: minmax(0, 1fr) 380px; grid-template-areas: "details actions" "history actions"; grid-template-rows: auto 1fr; align-items: start; }
}
.item-details { grid-area: details; }
.item-actions { grid-area: actions; }
.item-history { grid-area: history; }
.desc { font-size: 1.08rem; margin: 12px 0; white-space: pre-wrap; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: .92rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; }
.gallery a { flex: none; scroll-snap-align: start; }
.gallery img { display: block; border-radius: 8px; object-fit: cover; background: #e7e5e4; }
.gallery-lg img { height: 260px; max-width: 86vw; }
.gallery-lg a:only-child { flex: 1; }
.gallery-lg a:only-child img { width: 100%; height: auto; min-height: 180px; max-height: 420px; max-width: none; object-fit: contain; background: #1c1917; }
.gallery-sm { margin-top: 6px; }
.gallery-sm img { width: 84px; height: 84px; }

/* ---- timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.ev { position: relative; padding: 0 0 16px 10px; }
.ev:last-child { padding-bottom: 0; }
.ev::before { content: ''; position: absolute; left: -25px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: #a8a29e; border: 2px solid var(--card); }
.ev-submit::before { background: #3b82f6; }
.ev-assign::before { background: #f59e0b; }
.ev-contractor_done::before, .ev-contractor_issue::before { background: #8b5cf6; }
.ev-send_inspection::before { background: #14b8a6; }
.ev-close::before { background: #16a34a; }
.ev-reopen::before, .ev-void::before { background: #dc2626; }
.ev-head { font-size: .95rem; }
.ev-time { font-size: .8rem; color: var(--muted); margin-top: 1px; }
.ev-note { margin: 6px 0 0; padding: 8px 10px; background: #f5f5f4; border-radius: 6px; white-space: pre-wrap; font-size: .95rem; }
.ev-item { display: block; font-size: .82rem; font-weight: 600; text-decoration: none; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- contractor portal ---- */
.portal-head { margin-bottom: 1rem; }
.item-card { max-width: 760px; }
.item-card-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.item-card-head h2 { margin: 0; font-size: 1.25rem; }
.item-card details { margin: 10px 0; }
.item-card details summary { cursor: pointer; font-weight: 600; font-size: .92rem; margin-bottom: 8px; }
.respond { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }

.email-frame { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

/* ---- additions for the static app ---- */
.pad { padding: 14px 16px; }
form.inline { display: inline-flex; gap: 0; }
form.inline .error { display: none; }
.error[hidden] { display: none; }
.error { margin: 0; }
.item-actions > form, .item-actions > details { margin-bottom: 14px; }
.respond.stack { gap: 12px; }
noscript { display: block; padding: 24px 0; }
.item-head .tag, .item-card-head .tag { margin-left: 6px; }
.code { background: #1c1917; color: #f5f5f4; padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-size: .85rem; white-space: pre-wrap; word-break: break-all; }
