/* Dense, spreadsheet-like UI -- the people using this came from Google Sheets,
   so rows stay tight and scannable rather than airy. */

:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1a1d21;
  --muted: #667085;
  --line: #d8dee5;
  --line-soft: #eaeef2;
  --accent: #1a5fb4;
  --accent-soft: #e8f0fb;
  --pending: #c01c28;
  --pending-bg: #fdeceb;
  --hire: #fff3bf;
  --ok: #1a7f37;
  --head: #eef2f6;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --panel: #1c2024;
    --ink: #e6e8ea;
    --muted: #98a2b3;
    --line: #333a42;
    --line-soft: #262b31;
    --accent: #78aeed;
    --accent-soft: #1e2a3a;
    --pending: #ff7b72;
    --pending-bg: #2d1b1b;
    --hire: #3a3520;
    --ok: #5dd47f;
    --head: #232830;
  }
}

* { box-sizing: border-box; }

/* Several containers below set `display`, which would otherwise beat the user
   agent's `[hidden] { display: none }` and leave hidden panels painted. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 13px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.error { color: var(--pending); }

/* ---------------------------------------------------------------- login -- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 19px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 5px; font-weight: 600; font-size: 12px; }
.login-card input {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-weight: 400;
}
.login-card button {
  padding: 10px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.login-card button:disabled { opacity: .6; cursor: progress; }

/* --------------------------------------------------------------- topbar -- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: -.01em; }
.quick-search { flex: 1; display: flex; gap: 6px; min-width: 260px; }
.quick-search input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.quick-search button {
  padding: 7px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
}
.session { display: flex; align-items: center; gap: 10px; }
button.link {
  background: none;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
  padding: 0;
}

/* ----------------------------------------------------------------- tabs -- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 12px;
  background: var(--panel);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.tabs button {
  border: 0;
  background: none;
  padding: 9px 13px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-weight: 600;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ----------------------------------------------------------------- main -- */
main { padding: 14px 16px 60px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 14px; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.filters label { display: flex; align-items: center; gap: 5px; color: var(--muted); }

button.primary {
  padding: 6px 12px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 600;
}
button.ghost {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--ink);
}
button.danger { color: var(--pending); border-color: var(--pending); }
button.icon { background: none; border: 0; font-size: 20px; line-height: 1; color: var(--muted); }

/* ---------------------------------------------------------------- table -- */
.table-wrap { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td {
  border-bottom: 1px solid var(--line-soft);
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}
thead th {
  background: var(--head);
  position: sticky;
  top: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  z-index: 1;
}
tbody tr:hover { background: var(--accent-soft); }
td.wrap { white-space: normal; min-width: 200px; max-width: 340px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* The sheet used red text for "no plate assigned yet". Keep that cue. */
tr.pending td:not(.chk) { color: var(--pending); }
tr.pending { background: var(--pending-bg); }
tr.pending:hover { background: var(--pending-bg); filter: brightness(.97); }

.pill {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; border: 1px solid var(--line);
}
.pill.hire { background: var(--hire); border-color: #d9c86a; color: #533f00; }
.pill.pvt  { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pill.gov  { background: #ece3fb; border-color: #8a63d2; color: #4c2889; }
@media (prefers-color-scheme: dark) {
  .pill.hire { color: #f5e6a8; }
  .pill.gov  { background: #2a2140; color: #c3a8f0; }
}

td.chk { text-align: center; width: 34px; }
td.chk input { cursor: pointer; }

/* Two distinct controls, not one run of underlined text. */
td.row-actions { white-space: nowrap; }
.row-actions button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.7;
  color: var(--ink);
}
.row-actions button + button { margin-left: 8px; }
.row-actions button:hover { border-color: var(--accent); color: var(--accent); }
.row-actions .act-edit  { color: var(--accent); }
.row-actions .act-print { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.row-actions .act-print:hover {
  color: var(--ok);
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, var(--panel));
}

.pager {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-top: 1px solid var(--line); color: var(--muted);
}

.empty { padding: 34px; text-align: center; color: var(--muted); }

/* --------------------------------------------------------------- lookup -- */
.lookup-grid { display: grid; gap: 12px; }
.result-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px;
}
.result-card h3 { margin: 0 0 8px; font-size: 13px; }
.verdict {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 8px; margin-bottom: 12px;
  border: 1px solid var(--line); background: var(--panel);
}
.verdict.assigned { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--panel)); }
.verdict.none     { border-color: var(--pending); background: var(--pending-bg); }
.verdict strong { font-size: 16px; }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* --------------------------------------------------------------- report -- */
.report-week { margin-bottom: 20px; }
.report-week h3 { margin: 0 0 8px; font-size: 13px; text-align: center; }
.totals-strip { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 14px; min-width: 130px;
}
.stat .n { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
tfoot td { font-weight: 700; background: var(--head); }

/* ---------------------------------------------------------------- modal -- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--panel); border-radius: 10px;
  width: min(760px, 100%); max-height: 90vh; display: flex; flex-direction: column;
  border: 1px solid var(--line);
}
.modal-head, .modal-foot {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px;
}
.modal-head { border-bottom: 1px solid var(--line); }
.modal-foot { border-top: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 15px; }
.modal-body {
  padding: 16px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px;
}
.modal-body label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.modal-body input[type=text], .modal-body input[type=date],
.modal-body input[type=email], .modal-body select, .modal-body textarea {
  padding: 7px 9px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg); font-weight: 400;
}
.modal-body .full { grid-column: 1 / -1; }
.modal-body .checks { grid-column: 1 / -1; display: flex; gap: 18px; flex-wrap: wrap; }
.modal-body .checks label { flex-direction: row; align-items: center; gap: 6px; font-weight: 600; color: var(--ink); }

/* ---------------------------------------------------- certification doc -- */
/* The source template is legal / long bond: 8.5in x 14in with 1in margins. */
.cert-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 900px) { .cert-layout { grid-template-columns: 1fr; } }

.cert-controls { position: sticky; top: 96px; }
.cert-form { padding: 12px; display: grid; gap: 10px; }
.cert-form label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.cert-form input, .cert-form select {
  padding: 7px 9px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg); font-weight: 400;
}
.cert-search { display: flex; gap: 6px; }
.cert-search input { flex: 1; }
.cert-hits { display: grid; gap: 4px; }
.cert-hit { text-align: left; font-size: 12px; }

.cert-page {
  display: flex;
  justify-content: center;
  overflow-x: auto;
}
.cert-doc {
  width: 8.5in;
  flex: none;          /* a flex item would otherwise shrink below true page width */
  min-height: 14in;
  padding: 1in;
  background: #fff;
  color: #000;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .25);
  font-family: "Times New Roman", Times, serif;
  font-size: 12pt;
  line-height: 1.35;
}

.cert-head { display: flex; align-items: center; gap: 10px; }
.cert-seal { width: 0.9in; height: auto; flex: none; }
.cert-org { flex: 1; text-align: center; line-height: 1.15; }
.cert-org .l1 { font-size: 11pt; }
.cert-org .l2 { font-size: 11pt; }
.cert-org .l3 { font-size: 13pt; font-weight: 700; letter-spacing: .01em; }
.cert-org .l4 { font-size: 11.5pt; font-weight: 700; }
.cert-org .l5 { font-size: 10pt; font-style: italic; }
.cert-org .l6 { font-size: 9pt; }
.cert-rule { border: 0; border-top: 1.5px solid #000; margin: 8px 0 20px; }

.cert-title {
  text-align: center; font-size: 14pt; font-weight: 700;
  margin: 0 0 18px; letter-spacing: .02em;
}
.cert-to { margin: 0 0 14px; }
.cert-body { margin: 0 0 12px; text-align: justify; }
.cert-body.strong, .strong { font-weight: 700; }

.cert-details {
  display: grid;
  grid-template-columns: 2.4in 1fr;
  margin: 0 0 14px;
  padding-left: 0.3in;
}
.cert-details dt { font-weight: 400; }
.cert-details dd { margin: 0; font-weight: 700; }

.cert-sign { margin-top: 26px; line-height: 1.25; }
.cert-esig { display: block; height: 0.75in; width: auto; margin-bottom: -6px; }
.cert-signer { font-weight: 700; text-transform: uppercase; }

.cert-disclaimer { margin-top: 26px; font-size: 10.5pt; }
.cert-disclaimer p { margin: 0 0 8px; text-align: justify; }

/* -------------------------------------------------------------- settings -- */
.settings-list { display: grid; gap: 14px; margin-top: 14px; }
.settings-card { display: block; }
.settings-grid {
  padding: 14px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px;
}
.settings-grid label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.settings-grid .full { grid-column: 1 / -1; }
.settings-grid input, .settings-grid textarea {
  padding: 7px 9px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg); font-weight: 400;
  font-family: inherit;
}
.esig-box {
  border: 1px dashed var(--line); border-radius: 8px; padding: 12px;
  display: grid; gap: 10px; justify-items: start;
}
.esig-preview {
  max-height: 90px; max-width: 260px;
  background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 6px;
}
.esig-preview.empty-img { display: none; }
.esig-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- print -- */
@media print {
  @page { size: 8.5in 14in; margin: 0; }
  body { background: #fff; }
  .topbar, .tabs, .cert-controls, .modal-backdrop, .toast { display: none !important; }
  main { padding: 0 !important; }
  .cert-layout { display: block; }
  .cert-page { display: block; overflow: visible; }
  .cert-doc {
    width: auto; min-height: 0; box-shadow: none;
    margin: 0; padding: 1in;
  }
  .cert-disclaimer, .cert-sign { break-inside: avoid; }
}

/* ---------------------------------------------------------------- toast -- */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; z-index: 60; font-weight: 600;
}
.toast.bad { background: var(--pending); color: #fff; }

/* ----------------------------------------------------------- responsive -- */

/* Tablet: loosen the two-column certificate layout and the sticky sidebar. */
@media (max-width: 900px) {
  .cert-controls { position: static; }
}

/* Phones. The grid stops being a grid: each record becomes a card with the
   column name printed beside its value, because a 12-column table on a 380px
   screen is unreadable no matter how much you let it scroll sideways. */
@media (max-width: 760px) {
  body { font-size: 14px; }
  main { padding: 10px 10px 72px; }

  /* brand + sign-out share the first line; search gets its own full-width line */
  .topbar { gap: 8px; padding: 8px 10px; }
  .brand { flex: 1 1 auto; font-size: 14px; }
  .session { order: 0; flex: 0 0 auto; }
  .quick-search { order: 1; flex: 1 1 100%; min-width: 0; }
  #session-email { display: none; }
  .tabs { padding: 0 6px; }
  .tabs button { padding: 11px 12px; font-size: 13px; }

  .panel-head { padding: 10px; gap: 8px; }
  .panel-head h2 { width: 100%; }
  .filters { width: 100%; }
  .filters input, .filters select { flex: 1 1 130px; min-width: 0; padding: 9px 10px; }
  .filters label { flex: 1 1 130px; }
  .panel-head > button { flex: 1 1 auto; padding: 10px 12px; }

  .table-wrap { overflow-x: visible; }
  table { display: block; }
  thead { display: none; }
  tbody { display: block; }
  tbody tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 0 0 8px;
    padding: 6px 10px;
    background: var(--panel);
  }
  tbody tr:hover { background: var(--panel); }
  tbody td {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    white-space: normal;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
    padding: 5px 0;
    max-width: none;
    min-width: 0;
  }
  tbody td:last-child { border-bottom: 0; }
  /* Cells with no value collapse away rather than printing an empty label. */
  tbody td:empty { display: none; }
  tbody td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding-top: 2px;
  }
  tbody td[data-label=""]::before { display: none; }
  tbody td.num { text-align: left; }
  tbody td.chk { width: auto; text-align: left; }
  tbody td.chk input { width: 22px; height: 22px; }

  /* pending rows keep the red cue, but tint the whole card */
  tbody tr.pending { border-color: var(--pending); }

  td.row-actions { display: flex; gap: 8px; padding-top: 8px; }
  .row-actions button { flex: 1; padding: 9px 10px; font-size: 13px; }
  .row-actions button + button { margin-left: 0; }

  .pager { flex-wrap: wrap; padding: 10px; }
  .pager button { flex: 1 1 auto; padding: 10px; }
  .pager span { width: 100%; font-size: 12px; }

  .modal { max-height: 94vh; }
  .modal-body { grid-template-columns: 1fr; padding: 12px; }
  .modal-foot { padding: 10px 12px; }
  .modal-foot button { padding: 10px 14px; }

  .settings-grid { grid-template-columns: 1fr; padding: 10px; }
  .totals-strip .stat { flex: 1 1 44%; min-width: 0; }

  /* Report keeps a real table -- it is a numeric grid, so let it scroll. */
  .report-week .table-wrap { overflow-x: auto; }
  .report-week table { display: table; }
  .report-week thead { display: table-header-group; }
  .report-week tbody { display: table-row-group; }
  .report-week tbody tr { display: table-row; border: 0; border-radius: 0; margin: 0; padding: 0; }
  .report-week tbody td {
    display: table-cell; border-bottom: 1px solid var(--line-soft);
    padding: 5px 8px; white-space: nowrap;
  }
  .report-week tbody td::before { display: none; }
  .report-week tbody td.num { text-align: right; }

  /* Same for the lookup result tables. */
  .result-card .table-wrap { overflow-x: auto; }
  .result-card table { display: table; }
  .result-card thead { display: table-header-group; }
  .result-card tbody { display: table-row-group; }
  .result-card tbody tr { display: table-row; border: 0; border-radius: 0; margin: 0; padding: 0; }
  .result-card tbody td {
    display: table-cell; border-bottom: 1px solid var(--line-soft);
    padding: 5px 8px; white-space: nowrap;
  }
  .result-card tbody td::before { display: none; }
}

/* The certificate is a fixed 8.5in page. Instead of letting it run off the side
   of narrow screens, scale it to the available width. Applied at every width
   rather than behind a breakpoint, since the sidebar means the space left for
   the page can be under 8.5in even on a fairly wide window. cert.js measures
   --cert-scale and sets the host's height to the scaled page. Scale never
   exceeds 1, so wide screens are unaffected. */
.cert-page {
  --cert-scale: 1;
  justify-content: flex-start;
  overflow: hidden;   /* transform does not shrink the layout box */
}
.cert-doc {
  transform: scale(var(--cert-scale));
  transform-origin: top left;
}
@media print {
  .cert-doc { transform: none !important; }
  .cert-page { height: auto !important; overflow: visible !important; }
}
