/* inspectorjay admin UI. */

/* Colors. Text tokens are at least 4.5:1 on --bg and --panel, and
   --field-line is at least 3:1 (WCAG 1.4.3, 1.4.11), in both themes. Dark
   values apply on screen only, so printing is always dark on white. */
:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --muted: #5f6368;
  --line: #d9dce0;
  --bg: #ffffff;
  --panel: #f6f7f9;
  --accent: #0b5394;
  --accent-fg: #ffffff;
  --danger: #b3261e;
  --ok: #1e7b34;
  --warn: #7a5200;
  --field: #ffffff;
  --field-line: #767b82;
  --flash-bg: #e6f4ea;
  --flash-fg: #0d4a1f;
  --error-bg: #fce8e6;
  --error-fg: #7a1d16;
  --tag-bg: #fff4d6;
  --highlight: #eef4fa;
  --nav-hover: #e9ecef;
  --nav-current: #dde8f4;
  --badge-bg: #b3261e;
  --badge-fg: #ffffff;
  --focus: #0b5394;
  --radius: 6px;
  --sidebar: 15rem;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fg: #e6e8eb;
    --muted: #a9afb7;
    --line: #3b4148;
    --bg: #141619;
    --panel: #1c1f23;
    --accent: #8ab4f8;
    --accent-fg: #0d1b2e;
    --danger: #f28b82;
    --ok: #7fcf96;
    --warn: #f3c969;
    --field: #1c1f23;
    --field-line: #8a9199;
    --flash-bg: #15301f;
    --flash-fg: #b4e2c0;
    --error-bg: #3b1816;
    --error-fg: #f8b9b3;
    --tag-bg: #3a2f0b;
    --highlight: #1a2736;
    --nav-hover: #252a30;
    --nav-current: #1f3247;
    --badge-bg: #f28b82;
    --badge-fg: #2b0b08;
    --focus: #8ab4f8;
  }
}
/* The same values as above, for an explicit choice of dark. */
@media screen {
  :root[data-theme="dark"] {
    --fg: #e6e8eb;
    --muted: #a9afb7;
    --line: #3b4148;
    --bg: #141619;
    --panel: #1c1f23;
    --accent: #8ab4f8;
    --accent-fg: #0d1b2e;
    --danger: #f28b82;
    --ok: #7fcf96;
    --warn: #f3c969;
    --field: #1c1f23;
    --field-line: #8a9199;
    --flash-bg: #15301f;
    --flash-fg: #b4e2c0;
    --error-bg: #3b1816;
    --error-fg: #f8b9b3;
    --tag-bg: #3a2f0b;
    --highlight: #1a2736;
    --nav-hover: #252a30;
    --nav-current: #1f3247;
    --badge-bg: #f28b82;
    --badge-fg: #2b0b08;
    --focus: #8ab4f8;
  }
}

* { box-sizing: border-box; }
html { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--fg); background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--fg); }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .25rem 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Page shell: navigation in a sidebar, or above the page on narrow screens. */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line);
}
.sidebar-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1rem .5rem; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--fg); text-decoration: none; }
.brand-workspace { display: block; font-weight: 400; font-size: .85rem; color: var(--muted); }
.menu-toggle { display: none; }
.site-nav { display: flex; flex-direction: column; flex: 1; gap: 1rem; padding: 0 .5rem 1rem; }
.site-nav nav { flex: 1; }
.nav-label { margin: 1rem .5rem .25rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  min-height: 2.25rem; padding: .35rem .5rem; border-radius: var(--radius);
  color: var(--fg); text-decoration: none;
}
.nav-list a:hover { background: var(--nav-hover); }
.nav-list a[aria-current="page"] { background: var(--nav-current); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.badge {
  flex: none; min-width: 1.5rem; padding: 0 .4rem; border-radius: 999px; text-align: center;
  font-size: .75rem; font-weight: 700; line-height: 1.5rem; background: var(--badge-bg); color: var(--badge-fg);
}
.account { border-top: 1px solid var(--line); padding: .75rem .5rem 0; font-size: .875rem; }
.account-who { margin: 0 0 .5rem; overflow-wrap: anywhere; }
.account-who .small { display: block; }
.account form { margin: 0 0 .5rem; }
.theme-picker label { margin: 0 0 .2rem; font-size: .8rem; }
.theme-picker select { width: 100%; }

.page { display: flex; flex-direction: column; min-width: 0; }
main { flex: 1; padding: 1.25rem 1.5rem 3rem; width: 100%; max-width: 1200px; }
.pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.foot { padding: 1rem 1.5rem 2rem; font-size: .85rem; border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar { position: static; height: auto; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-bar { padding: .6rem 1rem; }
  .menu-toggle { display: inline-block; }
  .site-nav { display: none; padding: 0 .5rem .75rem; }
  .sidebar.open .site-nav { display: flex; }
  main { padding: 1rem 1rem 3rem; }
  .foot { padding: 1rem; }
}

/* Breadcrumbs and in-page navigation */
.crumbs ol { display: flex; flex-wrap: wrap; gap: .25rem; list-style: none; margin: 0 0 .5rem; padding: 0; font-size: .875rem; }
.crumbs li + li::before { content: "›"; margin-right: .25rem; color: var(--muted); }
.crumbs [aria-current] { color: var(--muted); }
.subnav { margin: 0 0 1rem; border-bottom: 1px solid var(--line); }
.subnav ul { display: flex; flex-wrap: wrap; gap: .25rem 1rem; list-style: none; margin: 0; padding: 0 0 .5rem; font-size: .9rem; }
.subnav a { display: inline-block; padding: .2rem 0; }
.subnav .out { margin-left: auto; }
.filters { display: flex; flex-wrap: wrap; gap: .25rem; list-style: none; margin: .25rem 0 .75rem; padding: 0; }
.filters a { display: inline-block; padding: .15rem .65rem; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: .875rem; }
.filters a[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }

/* Accessibility helpers */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: .5rem; top: -3rem; z-index: 1000; padding: .5rem .9rem; background: var(--accent); color: var(--accent-fg); border-radius: var(--radius); }
.skip:focus { top: .5rem; }
main h1:focus, main:focus { outline: none; }
.map-note { margin-top: -.5rem; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }

/* Messages */
.flash, .error { padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash { background: var(--flash-bg); color: var(--flash-fg); }
.demo-banner { padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; background: var(--tag-bg); color: var(--warn); }
.flash a { color: inherit; font-weight: 600; }
.error { background: var(--error-bg); color: var(--error-fg); }

/* Tables */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr.section td { background: var(--panel); font-weight: 600; }
td.num, th.num { text-align: right; }
/* position: relative so visually hidden text in a wide table is clipped
   with it, instead of widening the page. */
.table-wrap { overflow-x: auto; position: relative; }

/* Forms */
form.inline { display: inline; }
label { display: block; font-weight: 600; margin: .75rem 0 .25rem; font-size: .9rem; }
label.check { display: flex; gap: .4rem; align-items: center; font-weight: 400; }
input[type=text], input[type=email], input[type=url], input[type=number], input[type=date], input[type=month], input[type=search], input:not([type]), select, textarea {
  font: inherit; padding: .4rem .55rem; border: 1px solid var(--field-line); border-radius: var(--radius); background: var(--field); color: var(--fg); max-width: 100%;
}
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
input.wide, textarea.wide { width: 100%; }
/* Checklist item text: a text box that grows to show the whole item. */
textarea.autogrow { width: 100%; min-width: 12rem; resize: none; overflow: hidden; field-sizing: content; line-height: 1.4; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.row { display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; }
/* Let fields shrink, so a dropdown with long option text doesn't push the
   page wider than the screen. */
.row > select, .row > input, .row > div { min-width: 0; max-width: 100%; }
.row label { margin-top: 0; }
/* min-inline-size: 0, since fieldsets otherwise grow to fit their widest
   content (a long dropdown) and widen the page. */
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 1rem 0; min-inline-size: 0; }
legend { font-weight: 600; padding: 0 .25rem; }
fieldset.plain { border: 0; padding: 0; margin: .75rem 0 0; }
fieldset.plain legend { padding: 0; font-weight: normal; }
.hint { color: var(--muted); font-size: .85rem; font-weight: 400; }

button, .button {
  font: inherit; display: inline-block; padding: .4rem .85rem; border-radius: var(--radius); border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-fg); cursor: pointer; text-decoration: none; line-height: 1.4;
}
button.secondary, .button.secondary { background: var(--bg); color: var(--accent); }
button.danger { background: var(--bg); color: var(--danger); border-color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); padding: 0; text-decoration: underline; }
button.small, .button.small { padding: .15rem .5rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: default; }

/* Status pills */
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid currentColor; white-space: nowrap; }
.st-open { color: var(--muted); }
.st-pass, .st-fixed, .st-active { color: var(--ok); }
.st-fail { color: var(--danger); }
.st-na, .st-closed, .st-inactive { color: var(--muted); }
.tag { display: inline-block; font-size: .75rem; padding: 0 .4rem; border-radius: 4px; background: var(--tag-bg); color: var(--warn); }
.tag.overdue { background: var(--error-bg); color: var(--error-fg); font-weight: 600; }
.overdue-text { color: var(--error-fg); font-weight: 600; }
tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

/* Maps */
.map { height: 360px; border: 1px solid var(--line); border-radius: var(--radius); margin: .5rem 0 1rem; }
.map.small { height: 260px; }

/* Photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.photo { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--panel); }
.photo .meta { padding: .5rem .65rem; font-size: .875rem; }
.photo .note { white-space: pre-wrap; margin: .25rem 0; }
.photo form { margin-top: .4rem; }

/* Two-column page body */
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 2rem; }
@media (max-width: 900px) { .cols, .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } .span2 { grid-column: auto; } }
.span2 { grid-column: span 2; }

/* Template library */
/* The library's state and search filter: the search box takes the room left. */
.library-filter .grow { flex: 1 1 14rem; }
.library-filter .grow input { width: 100%; }
details.pack { border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem 1rem; margin: .75rem 0; }
details.pack summary { cursor: pointer; padding: .25rem 0; }
details.pack-items summary { cursor: pointer; color: var(--accent); margin-top: .25rem; }
details.pack-items ol { margin: .4rem 0 .25rem; padding-left: 1.5rem; font-size: .9rem; }
details.pack-items li { margin: .15rem 0; }

/* Diary and quantities */
table.compact { width: auto; min-width: 50%; }
table.compact th, table.compact td { padding: .3rem .6rem; }
table.quantities { font-size: .85rem; }
table.quantities td, table.quantities th { white-space: nowrap; padding: .4rem .45rem; }
table.quantities th { white-space: normal; vertical-align: bottom; }
table.quantities td:nth-child(2) { white-space: normal; min-width: 10rem; }
tfoot th { border-top: 2px solid var(--fg); color: var(--fg); }
.sign-lines { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3rem; margin: 3.5rem 0 1rem; break-inside: avoid; }
.sign-lines div { display: flex; justify-content: space-between; border-top: 1px solid var(--fg); padding-top: .3rem; font-size: .85rem; color: var(--muted); }
.diary-list li { margin: .3rem 0; }

/* Schedule */
table.schedule td:first-child { width: 22%; }
table.schedule td:nth-child(2) { width: 25%; }
table.schedule tr.cancelled td { text-decoration: line-through; }
ul.visits { padding-left: 1.25rem; margin: 0 0 1rem; }

/* Today. The ring keeps dark inspector colors visible on a dark page. */
.dot { display: inline-block; width: .75rem; height: .75rem; border-radius: 50%; margin-right: .4rem; vertical-align: baseline; box-shadow: 0 0 0 1px var(--fg); }
table.today tr.idle td { color: var(--muted); }

.new-key { border-color: var(--accent); background: var(--highlight); }
.new-key input[readonly] { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }

pre.val { margin: 0; white-space: pre-wrap; font: inherit; font-size: .85rem; }

/* Inspection report (/app/report/ID): a document, on screen and on paper. */
body.report main { max-width: 60rem; margin: 0 auto; }
.report-tools { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: end; padding: .75rem 0 1rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.report-tools form { flex: 1; }
.report-tools label { margin: 0 0 .2rem; font-size: .8rem; }
.back-link { font-weight: 600; text-decoration: none; padding: .4rem 0; }
.report-head .kicker { text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; font-weight: 700; color: var(--muted); margin: 0; }
.report-head h1 { font-size: 1.75rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .5rem 1.5rem; margin: .75rem 0 0; }
.facts div { border-top: 1px solid var(--line); padding-top: .3rem; }
.facts dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; }
.report-map { height: 320px; }
.report-photos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.report-photos figure { margin: 0; break-inside: avoid; }
.report-photos img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }
.report-photos figcaption { font-size: .875rem; margin-top: .35rem; }
.report-photos .note { white-space: pre-wrap; }
.report-signatures { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem 2rem; }
.report-signatures figure { margin: 0; break-inside: avoid; }
/* Signatures are dark ink on a transparent image: keep paper behind them. */
.report-signatures img { display: block; width: 100%; max-width: 20rem; aspect-ratio: 3 / 1; object-fit: contain; border-bottom: 1px solid var(--fg); background: #ffffff; border-radius: 4px 4px 0 0; }
.report-signatures figcaption { font-size: .875rem; margin-top: .3rem; }
.signatures-section { break-inside: avoid; }
@media (max-width: 640px) {
  body.report main { padding: 1rem; }
  .report-photos { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .no-print, form, button, .actions, .crumbs, .subnav { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .map { display: none; }
  .table-wrap { overflow: visible; }
  body.report .map { display: block; break-inside: avoid; }
  body.report table, body.report tr { break-inside: avoid; }
  .page-break { break-before: page; }
  @page { margin: 1.5cm; }
  .photos { grid-template-columns: repeat(2, 1fr); }
  .photo { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
  h2 { break-after: avoid; }
}
