/* Shared styles. Colour tokens match the ChargeCore Funnel app (Funnel 2). */
:root {
  --green: #70AD47;
  --green-dark: #507b32;   /* green as text: passes WCAG AA on white */
  --green-tint: #f0f7ea;
  --ink: #222;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #a8afba;  /* form control borders: 3:1 on white */
  --bg: #f6f7f9;
  --danger: #b91c1c;
  --danger-tint: #fde2e1;
  --radius: 10px;
  --radius-lg: 14px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .05);
  --ring: 0 0 0 3px rgba(112, 173, 71, .28);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}
:focus-visible { outline: 2px solid var(--green-dark); outline-offset: 2px; border-radius: 4px; }
input:focus-visible { outline: none; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--s3); }
.muted { color: var(--muted); }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--s5);
}

label { display: block; font-weight: 600; font-size: 14px; margin-bottom: var(--s1); }
input {
  width: 100%;
  font: inherit;
  padding: 10px var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
}
input:focus { border-color: var(--green-dark); box-shadow: var(--ring); }
.field { margin-bottom: var(--s4); }

/* Buttons look pressable: raised at rest, lift on hover, pushed in while pressed.
   The colour says what a button does:
     .btn             green  — go ahead (approve, submit, save, assign)
     .btn.danger      red    — stop / destroy (reject, delete)
     .btn.warn        amber  — send back (return for rectification)
     .btn.ghost       white  — everything else (documents, edit, cancel)
     .btn.ghost.danger-text  red outline — mild undo (deactivate, remove)
   Solid fills keep white text at ≥ 4.5:1 (brand green #70AD47 is only 2.7:1). */
.btn {
  --btn-bg: var(--green-dark); --btn-hover: #3f6f25; --btn-active: #345c1e;
  --btn-ink: #fff; --btn-edge: rgba(0, 0, 0, .25);
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-weight: 600;
  min-height: 44px; padding: 0 var(--s5);
  border: 1px solid transparent; border-bottom-color: var(--btn-edge); border-radius: var(--radius);
  background: var(--btn-bg); color: var(--btn-ink); cursor: pointer;
  white-space: nowrap; text-decoration: none;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .16), inset 0 1px 0 rgba(255, 255, 255, .14);
  transition: background-color .12s ease, box-shadow .12s ease, transform .12s ease, border-color .12s ease;
}
.btn:hover:not(:disabled) {
  background: var(--btn-hover); transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(16, 24, 40, .18);
}
.btn:active:not(:disabled) {
  background: var(--btn-active); transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .25);
}
.btn:disabled { background: #e5e7eb; color: var(--muted); border-color: #e5e7eb; box-shadow: none; cursor: not-allowed; }
.btn.danger { --btn-bg: var(--danger); --btn-hover: #991b1b; --btn-active: #7f1d1d; }
.btn.warn { --btn-bg: #b45309; --btn-hover: #92400e; --btn-active: #78350f; }
.btn.ghost {
  --btn-bg: #fff; --btn-hover: #f3f4f6; --btn-active: #e5e7eb; --btn-ink: var(--ink); --btn-edge: #8b93a1;
  border-color: var(--line-strong); border-bottom-color: var(--btn-edge);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .08);
}
.btn.ghost:hover:not(:disabled) { border-color: #8b93a1; }
.btn.ghost:active:not(:disabled) { box-shadow: inset 0 2px 4px rgba(0, 0, 0, .12); }
.btn.ghost:disabled { background: #f9fafb; color: #9ca3af; border-color: var(--line); }
.btn.ghost.danger-text {
  --btn-ink: var(--danger); --btn-hover: var(--danger-tint); --btn-active: #fbcfcd;
  border-color: #e7a3a3; border-bottom-color: #d77c7c;
}
@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .btn:hover:not(:disabled), .btn:active:not(:disabled) { transform: none; }
}

.error {
  color: var(--danger); background: var(--danger-tint);
  border-radius: var(--radius); padding: var(--s2) var(--s3); margin-bottom: var(--s4);
}
[hidden] { display: none !important; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--s4); }
.login { width: 100%; max-width: 380px; }
.login img { height: 36px; width: auto; display: block; margin-bottom: var(--s4); }
.login-foot { margin: var(--s3) 0 0; text-align: center; }
.link-btn {
  background: none; border: 0; padding: var(--s1) var(--s2); font: inherit; font-size: 14px;
  color: var(--green-dark); text-decoration: underline; cursor: pointer; border-radius: 4px;
}
.link-btn:hover { color: #3f6f25; background: var(--green-tint); }
.login .captcha { margin-bottom: var(--s4); min-height: 65px; }
.login .notice, .login .success { margin-bottom: var(--s4); }
.wait {
  background: #fef3c7; color: #92400e; border-radius: var(--radius);
  padding: var(--s2) var(--s3); font-size: 14px; margin-bottom: var(--s4);
}
.wait-bar { height: 6px; margin-top: var(--s2); border-radius: 999px; background: rgba(146, 64, 14, .15); overflow: hidden; }
.wait-bar span { display: block; height: 100%; width: 100%; border-radius: inherit; background: #b45309; }

/* App shell */
.topbar {
  display: flex; align-items: center; gap: var(--s4);
  padding: var(--s3) var(--s5); background: #fff; border-bottom: 1px solid var(--line);
}
/* The logo keeps one size everywhere; it never shrinks with the window. */
.topbar img { height: 28px; width: auto; flex-shrink: 0; display: block; }
.topbar .title { font-weight: 700; }
.topbar .spacer { flex: 1; }
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.nav { padding: var(--s4); border-right: 1px solid var(--line); background: #fff; }
.nav a, .nav span {
  display: block; padding: var(--s2) var(--s3); border-radius: var(--radius);
  color: var(--ink); text-decoration: none;
}
.nav a.active { background: var(--green-tint); color: var(--green-dark); font-weight: 600; }
.nav a:not(.active):hover { background: #f3f4f6; }
.nav span.soon { color: var(--muted); }
.content { padding: var(--s6) var(--s5); max-width: 1100px; }

@media (max-width: 760px) {
  /* auto rows: without this the nav row soaks up the min-height and grows tall. */
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .nav { align-items: center; }
  .nav { border-right: 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: var(--s1); }
  .topbar { padding: var(--s3) var(--s4); }
  .content { padding: var(--s5) var(--s4); }
}

/* Forms, tables, badges — shared by the admin pages */
.stack > * + * { margin-top: var(--s5); }
select {
  width: 100%;
  font: inherit;
  padding: 9px var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
select:focus { border-color: var(--green-dark); box-shadow: var(--ring); outline: none; }
.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 var(--s4);
  align-items: end;
}
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s4); }
.btn.small { min-height: 36px; padding: 0 var(--s3); font-size: 14px; }
.success {
  color: var(--green-dark); background: var(--green-tint);
  border-radius: var(--radius); padding: var(--s2) var(--s3);
}

/* position: relative keeps the absolutely positioned .sr-only cells inside the scroll box. */
.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.actions .row-actions { display: flex; gap: var(--s2); }
#users-table th, #users-table td { padding: var(--s2); }
#users-table td:first-child { overflow-wrap: anywhere; min-width: 150px; }
#users-table select { min-width: 140px; }
tr.inactive td { color: var(--muted); }

.badge { display: inline-block; padding: 2px var(--s2); border-radius: 999px; font-size: 13px; font-weight: 600; }
.badge.ok { background: var(--green-tint); color: var(--green-dark); }
.badge.off { background: var(--line); color: var(--muted); }
.badge.warn { background: #fef3c7; color: #92400e; margin-left: var(--s1); }

.matrix th, .matrix td { padding: var(--s2) 6px; }
.matrix th[scope="col"] { white-space: normal; min-width: 64px; font-size: 12px; text-align: center; }
.matrix td { text-align: center; }
.matrix td.yes { color: var(--green-dark); font-weight: 700; }
.matrix tbody th { white-space: nowrap; }

.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;
}

dialog {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: var(--s5); width: min(420px, calc(100vw - 32px));
  box-shadow: 0 8px 28px rgba(0, 0, 0, .14);
}
dialog::backdrop { background: rgba(0, 0, 0, .3); }

/* ---- APT pages ----------------------------------------------------------- */
.who-link { color: var(--muted); text-decoration: none; }
.who-link:hover { color: var(--green-dark); text-decoration: underline; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--green-dark); }

/* Status badges: one colour per stage, text always ≥ 4.5:1 on its tint. */
.status { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.st-new { background: #eef2f7; color: #374151; }
.st-assigned { background: #e0ecf9; color: #1d4f86; }
.st-submitted { background: #fef3c7; color: #92400e; }
.st-rectification { background: #fde2e1; color: #b91c1c; }
.st-pending_vgreen { background: #ede9fe; color: #5b21b6; }
.st-completed { background: var(--green-tint); color: var(--green-dark); }
.st-rejected { background: #e5e7eb; color: #374151; }

.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--line); margin-bottom: var(--s4); }
.tabs button {
  font: inherit; font-weight: 600; background: none; border: 0; cursor: pointer;
  padding: var(--s2) var(--s3); color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px;
  min-height: 44px;
}
.tabs button[aria-selected="true"] { color: var(--green-dark); border-bottom-color: var(--green); }
.tabs button[aria-selected="false"]:hover { color: var(--ink); border-bottom-color: var(--line-strong); }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: var(--s3); margin-bottom: var(--s4); }
.filters input, .filters select { min-height: 44px; }

.apt-table tbody tr { cursor: pointer; }
.apt-table tbody tr:hover td { background: #fafbfc; }
.apt-table a { color: inherit; font-weight: 600; text-decoration: none; }
.apt-table .sub { display: block; color: var(--muted); font-size: 13px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: var(--s3); margin-top: var(--s3); }
.empty { text-align: center; color: var(--muted); padding: var(--s6) var(--s4); }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.draft-state { font-size: 14px; color: var(--muted); }
.draft-state.unsaved { color: #92400e; font-weight: 600; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s3) var(--s5); margin: 0; }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; white-space: pre-line; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.card-head h2 { margin: 0; flex: 1; font-size: 18px; }
.hint { font-size: 14px; color: var(--muted); }
.notice { background: #fef3c7; color: #92400e; border-radius: var(--radius); padding: var(--s2) var(--s3); font-size: 14px; }

/* Checklist */
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: var(--s5) 0 var(--s2); }
.item { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); background: #fff; }
.item + .item { margin-top: var(--s3); }
.item.ok { border-left: 4px solid var(--green); }
.item.nok { border-left: 4px solid var(--danger); }
.item-head { display: flex; align-items: flex-start; gap: var(--s3); flex-wrap: wrap; }
.item-no { font-weight: 700; color: var(--muted); min-width: 1.5em; }
.item-title { font-weight: 700; flex: 1; min-width: 160px; }
.item ul { margin: var(--s2) 0 var(--s3) 1.6em; padding: 0; color: #374151; font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { font: inherit; font-weight: 700; border: 0; background: #fff; padding: 0 var(--s4); min-height: 40px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button { transition: background-color .12s ease, box-shadow .12s ease, color .12s ease; }
.seg button.ok:hover:not(:disabled):not([aria-pressed="true"]) { background: var(--green-tint); color: var(--green-dark); }
.seg button.nok:hover:not(:disabled):not([aria-pressed="true"]) { background: var(--danger-tint); color: var(--danger); }
.seg button:active:not(:disabled) { box-shadow: inset 0 2px 5px rgba(0, 0, 0, .22); }
.seg button[aria-pressed="true"].ok { background: var(--green-dark); color: #fff; }
.seg button[aria-pressed="true"].nok { background: var(--danger); color: #fff; }
.seg button:disabled { cursor: not-allowed; color: #b6bcc6; background: #f9fafb; }
.result-read { font-weight: 700; }
.result-read.ok { color: var(--green-dark); }
.result-read.nok { color: var(--danger); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s2); margin: var(--s3) 0; }
.photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photo .tag { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.photo .remove {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
}
.photo-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.remark { margin-top: var(--s2); }
.remark input { min-height: 40px; }

/* Changelog */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: var(--s2) 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-size: 13px; margin-right: var(--s2); }
.timeline .who { font-weight: 600; }
.timeline .note { display: block; color: var(--muted); margin-top: 2px; }

.sig-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s3); }
.sig { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s3); }
.sig img { max-height: 70px; max-width: 100%; display: block; margin-top: var(--s2); }

.cr { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s3); }
.cr + .cr { margin-top: var(--s2); }

dialog form .field:last-of-type { margin-bottom: var(--s4); }
dialog h2 { margin-bottom: var(--s2); }
textarea {
  width: 100%; font: inherit; padding: 10px var(--s3); border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: #fff; min-height: 80px; resize: vertical;
}
textarea:focus { border-color: var(--green-dark); box-shadow: var(--ring); outline: none; }
.radio-row { display: flex; gap: var(--s4); flex-wrap: wrap; }
.radio-row label { display: flex; align-items: center; gap: var(--s2); font-weight: 400; min-height: 44px; }
.radio-row input { width: auto; }

.lightbox { padding: 0; max-width: 96vw; max-height: 92vh; width: auto; background: #111; border: 0; }
.lightbox img { display: block; max-width: 96vw; max-height: 86vh; }
.lightbox .btn { position: absolute; top: 8px; right: 8px; }

.sig-preview { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: var(--s3); min-height: 90px; display: flex; align-items: center; justify-content: center; background: #fff; }
.sig-preview img { max-height: 120px; max-width: 100%; }

@media (max-width: 760px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search { grid-column: 1 / -1; }
  /* APT list: one card per row on phones. */
  .apt-table thead { display: none; }
  .apt-table, .apt-table tbody, .apt-table tr, .apt-table td { display: block; width: 100%; }
  .apt-table tr { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s2) var(--s3); margin-bottom: var(--s2); background: #fff; }
  .apt-table td { border: 0; padding: 2px 0; }
  .apt-table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; }
}

/* Phones: logo, name and sign-out must fit one line. */
@media (max-width: 520px) {
  .topbar { gap: var(--s2); padding: var(--s2) var(--s3); }
  .topbar .title { display: none; }
  #who { min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .btn { min-height: 36px; padding: 0 var(--s3); font-size: 14px; }
  .content { padding: var(--s4) var(--s3); }
  .card { padding: var(--s4); }
}

/* APT detail: downloads sit at the right of the title row; the changelog folds away. */
.page-head .downloads { gap: var(--s2); }
.log-card summary {
  cursor: pointer; font-weight: 700; font-size: 18px; list-style-position: outside;
  min-height: 32px; display: list-item;
}
.log-card[open] summary { margin-bottom: var(--s3); }
@media (max-width: 760px) {
  .page-head .spacer { display: none; }
  .page-head .downloads { width: 100%; }
}
.toast {
  position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%); z-index: 20;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .14); max-width: calc(100vw - 32px);
}
