/* ============================================================
   BJB Closing Report System — design tokens
   Palette: deep ink navy (authority/record-keeping) + an oxblood
   accent (the "official stamp" color of a certified/closed case),
   on a cool paper background rather than a warm cream.
   Type: a serif for headings (case-file/letterhead feel), a clean
   civic sans for body and controls, and a monospace reserved for
   case numbers and record IDs — genuine data labels, not decoration.
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,500;8..60,600;8..60,700&family=Public+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #16243D;
  --ink-2: #223A5A;
  --paper: #EDF0F3;
  --surface: #FFFFFF;
  --rule: #D7DCE2;
  --text: #1A222E;
  --text-muted: #5B6472;
  --accent: #7A3020;
  --accent-hover: #5E2418;
  --ok: #2E6B4F;
  --ok-bg: #E7F1EC;
  --danger: #B3392B;
  --danger-bg: #FBEAE7;

  --font-display: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-body: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

/* ---------- Masthead + toolbar ---------- */
h1 {
  margin: 0;
  padding: 1.15rem 1.5rem;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  letter-spacing: 0.01em;
  border-bottom: 3px solid var(--accent);
}

.topbar-actions,
.bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  padding: 0.75rem 1.5rem;
  margin: 0;
}
.bar { justify-content: space-between; }
.bar input[type="search"] {
  flex: 1;
  max-width: 420px;
  margin: 0;
}

/* ---------- Buttons + links ---------- */
button,
input[type="submit"] {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
button:hover,
input[type="submit"]:hover {
  background: var(--ink);
  color: #fff;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:disabled:hover { background: var(--surface); color: var(--ink); }

#submitBtn, #save, #newReportBtn, input[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
#submitBtn:hover, #save:hover, #newReportBtn:hover, input[type="submit"]:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Form controls ---------- */
input[type="text"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="search"],
select,
textarea {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  width: auto;
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
select:focus,
textarea:focus {
  border-color: var(--ink);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
  width: 1.05rem;
  height: 1.05rem;
  vertical-align: middle;
  margin-right: 0.35rem;
  cursor: pointer;
}

label { font-weight: 500; }

/* ---------- Report form panels ---------- */
#closingForm { counter-reset: section; padding: 1.75rem 1rem 1rem; }

.BF {
  counter-increment: section;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--ink);
  border-radius: 6px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto 1.5rem;
  padding: 1.75rem 2rem;
}

.BF h3 {
  margin: 0 0 1.15rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
}
#closingForm .BF > h3::before {
  content: counter(section, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.definfo { color: var(--text); font-size: 1rem; }
p.definfo { max-width: 68ch; color: var(--text-muted); }

.defname {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink);
}
input.defname {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text);
  min-width: 260px;
}

.arlocate, .yesA {
  width: 100%;
  max-width: 500px;
}
.yesA { min-height: 70px; }

#status {
  color: var(--text-muted);
  font-size: 0.92rem;
  min-height: 1.3em;
}

/* ---------- Report photos ---------- */
input[type="file"] {
  display: block;
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  margin: 0.3rem 0 0.9rem;
}
.photo-preview {
  display: block;
  max-width: 100%;
  max-height: 240px;
  margin: 0 0 1.25rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
}

/* ---------- Confirmation page detail list ---------- */
.row { margin: 0.5rem 0; font-size: 1rem; }
.row .label { font-weight: 600; color: var(--text-muted); }

/* ---------- Signature ---------- */
.BF.sig-page { max-width: 700px; }
.pad {
  display: block;
  width: 100%;
  max-width: 600px;
  height: auto;
  margin: 0.75rem 0;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
}
#signatureBox img {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  max-width: 300px;
  width: 100%;
}

/* ---------- Login page ---------- */
body.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
}
body.login-page h1 { width: 100%; }
body.login-page br { display: none; }

.login {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 4px solid var(--ink);
  border-radius: 6px;
  padding: 2rem 2.25rem;
  max-width: 380px;
  width: calc(100% - 2rem);
  margin: 1.25rem 0 0;
}
.login h3 {
  margin: 0 0 1.25rem;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
}
.login label { display: block; margin: 0.9rem 0 0.3rem; font-size: 0.92rem; }
.login input[type="text"],
.login input[type="password"] { width: 100%; }
.login input[type="submit"] { margin-top: 1.4rem; width: 100%; }
.login .msg { color: var(--danger); font-size: 0.88rem; min-height: 1.3em; margin: 0.75rem 0 0; }

.admin-login {
  margin-top: 1.25rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.admin-login summary {
  cursor: pointer;
  text-align: center;
  padding: 0.4rem;
}
.admin-login .login { margin-top: 0.75rem; }

/* ---------- Index / landing buttons ---------- */
body:has(.Mng) {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.BH, .Mng {
  display: block;
  width: calc(100% - 3rem);
  max-width: 320px;
  margin: 1.5rem auto 0;
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
}
.Mng { background: var(--ink); color: #fff; border-color: var(--ink); }
.Mng:hover { background: var(--ink-2); border-color: var(--ink-2); }

/* ---------- Manager: saved reports table ---------- */
.wrap { max-width: 1100px; margin: 1.5rem auto; padding: 0 1rem; }
.table-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 6px; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.94rem;
}
th, td {
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
th {
  background: var(--ink);
  color: #fff;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.86rem;
}
tbody tr:hover { background: var(--paper); }
td.mono, .mono { font-family: var(--font-mono); font-size: 0.9rem; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }

.status-sent { color: var(--ok); font-weight: 600; }
.status-failed { color: var(--danger); font-weight: 600; }
.status-skipped, .status-not-recorded { color: var(--text-muted); }

/* ---------- Footer ---------- */
footer {
  text-align: center;
  padding: 1.75rem 1rem 2.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  h1 { font-size: 1.3rem; padding: 1rem; }
  .BF, .login { padding: 1.25rem 1.25rem; }
  .topbar-actions, .bar { flex-wrap: wrap; padding: 0.75rem 1rem; }
  .bar input[type="search"] { flex-basis: 100%; max-width: none; }

  /* Forms: every field stacks full-width under its label */
  #closingForm { padding: 1rem 0.5rem; }
  .BF { padding: 1.25rem 1rem; }
  .BF input[type="text"],
  .BF input[type="password"],
  .BF input[type="date"],
  .BF input[type="time"],
  .BF select,
  .BF textarea {
    display: block;
    width: 100%;
    max-width: none;
    min-width: 0;
    margin: 0.3rem 0 0.9rem;
  }

  /* Finger-sized tap targets */
  button, input[type="submit"] { min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 1.4rem; height: 1.4rem; }

  /* Tables become one card per row; labels come from table-labels.js */
  .table-scroll { overflow: visible; border: none; }
  table { background: none; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-left: 4px solid var(--ink);
    border-radius: 6px;
    margin-bottom: 0.9rem;
    padding: 0.35rem 0;
  }
  td {
    display: flex;
    gap: 0.75rem;
    white-space: normal;
    word-break: break-word;
    border-bottom: none;
    padding: 0.45rem 0.9rem;
  }
  td[data-label]::before {
    content: attr(data-label);
    flex-shrink: 0;
    min-width: 7rem;
    font-weight: 600;
    color: var(--text-muted);
  }
  td.empty { display: block; }
}