/*
  Fix Desk stylesheet
  -------------------
  1. Design tokens (colours, spacing). Every text colour pair here was
     checked for WCAG 2.1 AA contrast: 4.5:1 for text, 3:1 for borders of
     controls and focus outlines. See the evaluation report for the numbers.
  2. Base elements and accessibility helpers (skip link, focus, sr-only)
  3. Layout: header, main, footer, grids
  4. Components: panels, forms, buttons, tags, tables, cards, dialog
  5. Page-specific pieces
  6. Responsive rules (mobile first; wider screens add columns)

  Units: rem for sizes and spacing so the layout scales with the user's
  font size and with browser zoom (tested at 200%).
  No inline styles anywhere: the Content-Security-Policy blocks them.
*/

/* 1. Tokens ---------------------------------------------------------- */
:root {
  --ink: #111827;          /* main text: 17.7:1 on white */
  --ink-muted: #4b5563;    /* secondary text: 7.6:1 on white, 7.0:1 on --bg */
  --bg: #f3f4f6;
  --panel: #ffffff;
  --line: #d1d5db;         /* decorative dividers only */
  --control-line: #6b7280; /* input borders: 4.8:1 on white (needs 3:1) */
  --brand: #1d4ed8;        /* buttons and links: 6.7:1 on white */
  --brand-dark: #1e3a8a;
  --header: #16181d;
  --header-ink: #f9fafb;
  --header-muted: #d1d5db; /* 12.6:1 on --header */
  --focus: #1d4ed8;
  --focus-on-dark: #93c5fd;
  --danger: #b91c1c;       /* 6.5:1 on white */
  --danger-bg: #fef2f2;
  --ok: #166534;           /* 7.1:1 on white */
  --ok-bg: #f0fdf4;
  --warn-ink: #78350f;
  --warn-bg: #fffbeb;
  --radius: 0.5rem;
  --space: 1rem;
  --max: 75rem;
  font-size: 100%;
}

/* 2. Base ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.75rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; }

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

/* Visible focus for every interactive element, never removed. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.site-header :focus-visible { outline-color: var(--focus-on-dark); }

/* Headings and messages that receive focus from script should not show a ring
   on mouse use, but keyboard users still see where they are via the outline above. */
[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -10rem;
  z-index: 100;
  padding: 0.75rem 1rem;
  background: var(--panel);
  color: var(--brand);
  font-weight: 700;
  border-radius: var(--radius);
}
.skip-link:focus { top: 0.5rem; }

[hidden] { display: none !important; }

/* 3. Layout ---------------------------------------------------------- */
.site-header {
  background: var(--header);
  color: var(--header-ink);
}
.site-header .inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.75rem var(--space);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.brand { display: flex; flex-direction: column; }
.brand-name {
  color: var(--header-ink);
  font-weight: 800;
  font-size: 1.25rem;
  text-decoration: none;
}
.brand-name:hover { color: var(--header-ink); text-decoration: underline; }
.brand-sub { color: var(--header-muted); font-size: 0.875rem; }

.nav {
  list-style: none;
  margin: 0;
  padding: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  background: #2a2e37;
  border-radius: 0.625rem;
}
.nav a, .nav button {
  display: inline-block;
  padding: 0.5rem 0.875rem;
  border-radius: 0.4rem;
  color: var(--header-ink);
  text-decoration: none;
  font: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.nav a:hover, .nav button:hover { background: #3a3f4a; }
/* Current page: shown by shape and weight as well as colour. */
.nav a[aria-current="page"] {
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.account-name { color: var(--header-muted); font-size: 0.875rem; }
.account-name strong { color: var(--header-ink); display: block; font-size: 1rem; }

main {
  flex: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.5rem var(--space) 3rem;
}
main:focus { outline: none; }

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-muted);
  font-size: 0.875rem;
}
.site-footer .inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem var(--space);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
}
.site-footer p { margin: 0; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}
.page-head p { color: var(--ink-muted); margin: 0; }

.grid { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }

/* 4. Components ------------------------------------------------------ */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 1.25rem;
  min-width: 0;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}
.muted { color: var(--ink-muted); }
.small { font-size: 0.875rem; }

/* Forms */
.field { margin-bottom: 1rem; }
.field > label, .field-label, legend {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
}
.hint { display: block; color: var(--ink-muted); font-size: 0.875rem; margin: -0.1rem 0 0.4rem; }
.optional { font-weight: 400; color: var(--ink-muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
input[type="search"], select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--control-line);
  border-radius: 0.4rem;
  padding: 0.6rem 0.75rem;
  min-height: 2.75rem; /* comfortable touch target */
}
textarea { min-height: 7rem; resize: vertical; }
select { padding-right: 2rem; }

/* Invalid fields get a thicker red border AND an error message, never colour alone. */
[aria-invalid="true"] { border: 2px solid var(--danger); }
.field-error {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0.35rem 0 0;
}
.field-error:empty { display: none; }
.field-error:not(:empty)::before { content: "Error: "; }

fieldset {
  border: 0;
  margin: 0 0 1rem;
  padding: 0;
  min-width: 0;
}
.choices { display: grid; gap: 0.4rem; grid-template-columns: minmax(0, 1fr); }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--control-line);
  border-radius: 0.4rem;
  background: var(--panel);
  cursor: pointer;
}
.choice input { width: 1.25rem; height: 1.25rem; margin: 0.1rem 0 0; flex: none; accent-color: var(--brand); }
.choice:has(input:checked) { border: 2px solid var(--brand); background: #eff6ff; }
.choice-inline { border: 0; padding: 0.25rem 0; background: transparent; align-items: center; }
.choice-inline:has(input:checked) { border: 0; background: transparent; }

.row { display: grid; gap: 0 1rem; grid-template-columns: minmax(0, 1fr); }

.pw { display: flex; gap: 0.5rem; }
.pw input { flex: 1; min-width: 0; }

.counter { color: var(--ink-muted); font-size: 0.875rem; margin-top: 0.25rem; text-align: right; }

.reveal {
  border-left: 4px solid var(--danger);
  background: var(--danger-bg);
  padding: 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 1rem;
}
.reveal-plain { border-left-color: var(--brand); background: #eff6ff; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--control-line);
  border-radius: 0.4rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-small { min-height: 2.25rem; padding: 0.35rem 0.75rem; font-size: 0.9rem; }
/* aria-disabled keeps the button focusable so screen reader users still hear it. */
.btn[aria-disabled="true"] { opacity: 0.65; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

/* Messages */
.notice {
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.notice:empty { display: none; }
.notice ul { margin: 0.4rem 0 0; padding-left: 1.25rem; }
.notice-error { color: var(--danger); background: var(--danger-bg); border-color: var(--danger); }
.notice-error a { color: var(--danger); font-weight: 600; }
.notice-ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok); }
.notice-warn { color: var(--warn-ink); background: var(--warn-bg); border-color: #b45309; }
.notice-title { font-weight: 700; margin: 0; }

.status-line { color: var(--ink-muted); font-size: 0.9rem; min-height: 1.5rem; margin: 0.5rem 0; }

.empty {
  text-align: center;
  color: var(--ink-muted);
  padding: 2rem 1rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
}

/* Tags: always contain the word (Urgent, Done...), colour is extra. */
.tag {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}
.tag-urgent { color: #991b1b; background: #fee2e2; }       /* 6.8:1 */
.tag-high { color: #7c2d12; background: #ffedd5; }         /* 8.0:1 */
.tag-normal { color: #374151; background: #e5e7eb; }       /* 8.6:1 */
.tag-new { color: #1e40af; background: #dbeafe; }          /* 7.2:1 */
.tag-assigned { color: #374151; background: #f3f4f6; border-color: #9ca3af; }
.tag-in-progress { color: #6b21a8; background: #f3e8ff; }  /* 7.4:1 */
.tag-done { color: #166534; background: #dcfce7; }         /* 6.5:1 */
.overdue { color: var(--danger); font-weight: 700; }

/* Tables */
.table-wrap { width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
caption { text-align: left; font-weight: 600; padding-bottom: 0.5rem; }
th, td { text-align: left; vertical-align: top; padding: 0.7rem 0.6rem; border-bottom: 1px solid var(--line); }
thead th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-muted); white-space: nowrap; }
tbody tr.is-urgent td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
.ref { font-family: ui-monospace, Consolas, monospace; font-weight: 600; white-space: nowrap; }
.sub { display: block; color: var(--ink-muted); font-size: 0.875rem; }

/* Sortable column headers are real buttons inside the th. */
.sort-btn {
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0.2rem 0.1rem;
  cursor: pointer;
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
}
.sort-btn:hover { color: var(--ink); text-decoration: underline; }
.sort-icon { font-size: 0.75rem; }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Filters */
.filters {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
  align-items: end;
  margin-bottom: 0.5rem;
}
.filters .field { margin: 0; }
.filters .search-field, .filters .check-field { grid-column: 1 / -1; }

/* Cards (technician jobs) */
.cards { display: grid; gap: 1rem; list-style: none; padding: 0; margin: 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
}
.card.is-urgent { border: 2px solid var(--danger); border-left-width: 6px; }
.card-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem; align-items: flex-start; }
.card h2 { font-size: 1.1rem; margin: 0 0 0.25rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.details { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.15rem 1rem; margin: 0.75rem 0; }
.details dt { font-weight: 600; color: var(--ink-muted); font-size: 0.875rem; }
.details dd { margin: 0 0 0.4rem; }

.notes { list-style: none; padding: 0; margin: 0.5rem 0; border-left: 3px solid var(--line); }
.notes li { padding: 0.35rem 0 0.35rem 0.75rem; }
.notes .sub { font-size: 0.8rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; margin-top: 0.75rem; }
.actions .field { flex: 1 1 14rem; margin: 0; }
.confirm {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid #b45309;
  background: var(--warn-bg);
  border-radius: var(--radius);
}

/* Stats and workload (admin) */
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); list-style: none; padding: 0; margin: 0 0 1.25rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 0.75rem; padding: 1rem 1.25rem; }
.stat-num { display: block; font-size: 2rem; font-weight: 800; line-height: 1.1; }
.stat-alert { border-color: var(--danger); }
.stat-alert .stat-num { color: var(--danger); }

.workload { list-style: none; padding: 0; margin: 0 0 1rem; }
.workload li { display: grid; grid-template-columns: minmax(0, 1fr) 2.5rem; gap: 0.25rem 0.75rem; align-items: center; padding: 0.4rem 0; }
.workload .bar { grid-column: 1 / -1; height: 0.6rem; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--brand); border-radius: 999px; width: 0; }
.w-10 { width: 10%; } .w-20 { width: 20%; } .w-30 { width: 30%; } .w-40 { width: 40%; } .w-50 { width: 50%; }
.w-60 { width: 60%; } .w-70 { width: 70%; } .w-80 { width: 80%; } .w-90 { width: 90%; } .w-100 { width: 100%; }
.workload b { text-align: right; }

.messages { list-style: none; padding: 0; margin: 0; }
.messages li { border-top: 1px solid var(--line); padding: 0.75rem 0; }

/* Dialog (admin edit, report details) */
dialog {
  width: min(42rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 0;
  border-radius: 0.75rem;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(17, 24, 39, 0.6); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 1.25rem 1.25rem 0; }
.dialog-body { padding: 1rem 1.25rem 1.25rem; }

/* 5. Page specific --------------------------------------------------- */
.auth {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: 62rem;
  margin: 0 auto;
  border-radius: 1rem;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
}
.auth-side {
  background: var(--header);
  color: var(--header-ink);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.eyebrow { color: #93c5fd; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.85rem; margin: 0; }
.tagline { font-size: 1.75rem; font-weight: 800; line-height: 1.2; margin: 0; }
.ticks { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; }
.ticks li { display: flex; gap: 0.75rem; }
.ticks li::before { content: ""; flex: none; width: 0.75rem; height: 0.75rem; margin-top: 0.4rem; background: #60a5fa; border-radius: 0.15rem; }
.auth-side .muted { color: var(--header-muted); margin: 0; }
.auth-form { padding: 2rem; }
.auth-foot { text-align: center; margin-top: 1rem; }

.emergency {
  border: 2px solid var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.emergency p { margin: 0; }
.emergency .big { font-size: 1.2rem; font-weight: 800; }

.info { margin: 0; }
.info div { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.1rem 1rem; padding: 0.75rem 0; border-top: 1px solid var(--line); }
.info dt { font-weight: 600; color: var(--ink-muted); }
.info dd { margin: 0; }

/* Long-form text pages (accessibility statement) */
.prose { max-width: 60rem; margin: 0 auto; }
.prose h2 { margin-top: 2rem; }
.prose ul { padding-left: 1.25rem; }
.prose li { margin-bottom: 0.4rem; }
.prose caption { font-size: 1rem; }

.footer-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }

/* 6. Responsive ------------------------------------------------------ */

/* Sort menu for small screens (hidden on wider screens where the column headers sort). */
.sort-bar { display: none; flex-wrap: wrap; gap: 0.5rem; align-items: end; margin-bottom: 0.75rem; }

/* Small screens: each table row becomes a stacked card with its own labels,
   so nothing scrolls sideways. The labels come from data-label attributes. */
@media (max-width: 47.99rem) {
  .stack-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: 100%; }
  .stack-table tr { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 0.75rem; padding: 0.5rem 0.75rem; }
  .stack-table tr.is-urgent { border: 2px solid var(--danger); border-left-width: 6px; }
  .stack-table tbody tr.is-urgent td:first-child { box-shadow: none; }
  .stack-table td { border: 0; padding: 0.35rem 0; display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: 0.5rem; }
  .stack-table td::before { content: attr(data-label); font-weight: 600; color: var(--ink-muted); font-size: 0.85rem; }
  .sort-bar { display: flex; }
}

@media (min-width: 36rem) {
  .row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choices.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .info div { grid-template-columns: 9rem minmax(0, 1fr); }
  .details { grid-template-columns: 9rem minmax(0, 1fr); }
}

@media (min-width: 48rem) {
  .auth { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .auth-side, .auth-form { padding: 2.5rem; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .choices.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 64rem) {
  .grid.split { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
  .grid.admin { grid-template-columns: minmax(0, 1fr) minmax(0, 3fr); }
  .grid.contact { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
}

/* Respect users who ask the system for less motion. */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* Windows High Contrast / forced colours: keep focus and selected states visible. */
@media (forced-colors: active) {
  .choice:has(input:checked), .nav a[aria-current="page"] { outline: 2px solid CanvasText; }
  .tag { border: 1px solid CanvasText; }
}
