/* Coosada 911 Credential Management — admin interface
   ------------------------------------------------------------------------- */

:root {
  --navy-900: #0b1f3a;
  --navy-800: #12304f;
  --navy-700: #1b4570;
  --navy-100: #e8eef6;
  --red-600:  #b3261e;
  --red-100:  #fdeceb;
  --green-700:#1c6b3f;
  --green-100:#e6f4ec;
  --amber-700:#8a5a00;
  --amber-100:#fdf3dd;

  --ink:      #16202b;
  --ink-mid:  #4a5763;
  --ink-soft: #6b7783;
  --line:     #d7dee6;
  --line-soft:#e8edf2;
  --bg:       #f4f6f9;
  --surface:  #ffffff;

  --radius:   8px;
  --radius-sm:5px;
  --shadow:   0 1px 2px rgba(11, 31, 58, .06), 0 2px 8px rgba(11, 31, 58, .05);

  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* The hidden attribute has to win over any author `display` rule below, or
   an element toggled with el.hidden stays on screen. */
[hidden] { display: none !important; }

body.app,
body.auth-page {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy-700); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }

.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: -9999px; top: 0; z-index: 100;
  background: var(--navy-900); color: #fff; padding: .6rem 1rem;
}
.skip-link:focus { left: 0; }

/* --------------------------------------------------------------- topbar --- */

.topbar {
  background: var(--navy-900);
  color: #fff;
  border-bottom: 3px solid var(--red-600);
}
.topbar-inner {
  max-width: 1400px; margin: 0 auto; padding: .7rem 1.25rem;
  display: flex; align-items: center; gap: 1.5rem;
}
.brand { display: flex; align-items: center; gap: .65rem; color: #fff; text-decoration: none; }
/* The agency seal. Its own outer ring is navy, which would merge into the
   navy chrome, so it sits on a white disc — the way it is worn on a uniform. */
/* The seal artwork is trimmed to its own edge, so it needs no plate behind
   it: its red outer ring is what separates it from the navy chrome. */
.brand-seal {
  display: block; width: 76px; height: 76px; flex: 0 0 auto;
}
@media (max-width: 700px) { .brand-seal { width: 58px; height: 58px; } }
.brand-seal-lg {
  width: 168px; height: 168px; margin: 0 auto 1.1rem;
}
@media (max-width: 420px) { .brand-seal-lg { width: 132px; height: 132px; } }
.brand-text strong { display: block; font-size: 1.3rem; letter-spacing: .01em; line-height: 1.2; }
.brand-text small { display: block; font-size: .85rem; color: #b8c6d8; }

.mainnav { display: flex; gap: .25rem; margin-left: auto; }
.mainnav a {
  color: rgba(255,255,255,.82); text-decoration: none;
  padding: .45rem .8rem; border-radius: var(--radius-sm); font-size: .9rem;
}
.mainnav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.mainnav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }

.usermenu { display: flex; align-items: center; gap: .75rem; }
.user-id { text-align: right; font-size: .8rem; line-height: 1.3; }
.user-id strong { display: block; }
.role {
  display: inline-block; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .04em; opacity: .8;
}

/* ---------------------------------------------------------------- layout -- */

.main { min-height: calc(100vh - 130px); }
.wrap { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.wrap-narrow { max-width: 620px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.subhead { margin: .15rem 0 0; color: var(--ink-soft); font-size: .9rem; }
.count {
  font-size: .8rem; font-weight: 500; color: var(--ink-soft);
  background: var(--line-soft); padding: .1rem .5rem; border-radius: 99px;
  vertical-align: middle;
}
.lede { color: var(--ink-mid); max-width: 70ch; margin: 0 0 1.25rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.25rem; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- panels -- */

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-pad { padding: 1.15rem 1.25rem; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.25rem; border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { margin: 0; }
.center { text-align: center; }
.rule { border: 0; border-top: 1px solid var(--line-soft); margin: 1.25rem 0; }
.subsection {
  margin: 1.25rem 1.25rem .5rem; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .05em; font-size: .72rem;
}
.panel-pad .subsection { margin-left: 0; margin-right: 0; }

fieldset.panel { border: 1px solid var(--line); margin: 0 0 1rem; }
legend {
  font-weight: 600; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-soft); padding: 0 .4rem;
}

/* ----------------------------------------------------------------- stats -- */

.stat-row {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: .75rem; margin-bottom: 1.5rem;
}
@media (max-width: 900px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--navy-700);
  border-radius: var(--radius); padding: .9rem 1rem;
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.stat:hover { border-color: var(--navy-700); }
.stat-num { display: block; font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-label { display: block; font-size: .78rem; color: var(--ink-soft); }
.stat-ok    { border-left-color: var(--green-700); }
.stat-warn  { border-left-color: var(--amber-700); }
.stat-bad   { border-left-color: var(--red-600); }
.stat-muted { border-left-color: var(--ink-soft); }

/* --------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-size: .88rem; font-weight: 500;
  padding: .45rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--navy-100); border-color: var(--navy-700); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); border-color: var(--line); }
.btn-primary { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.btn-primary:hover { background: var(--navy-900); border-color: var(--navy-900); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--navy-700); }
.btn-ghost:hover { background: var(--navy-100); border-color: transparent; }
.btn-danger { background: var(--red-600); border-color: var(--red-600); color: #fff; }
.btn-danger:hover { background: #8f1e18; border-color: #8f1e18; color: #fff; }
.btn-danger-text { color: var(--red-600); }
.btn-sm { font-size: .8rem; padding: .3rem .6rem; }
.btn-lg { font-size: .95rem; padding: .6rem 1.4rem; }
.btn-block { width: 100%; }
.btn-file { position: relative; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }
.inline { display: inline; }
.link { font-size: .85rem; }

/* ----------------------------------------------------------------- forms -- */

label {
  display: block; font-size: .8rem; font-weight: 600;
  color: var(--ink-mid); margin-bottom: .25rem;
}
input[type="text"], input[type="search"], input[type="password"], input[type="email"],
input[type="date"], input[type="number"], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-size: .9rem;
  padding: .45rem .6rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--navy-700); outline-offset: -1px; border-color: var(--navy-700);
}
input[readonly], textarea[readonly] { background: var(--bg); color: var(--ink-mid); }

.field { margin-bottom: .9rem; flex: 1 1 180px; }
.field-sm { flex: 0 1 110px; }
.field-xs { flex: 0 1 90px; }
.field-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.field-inline { display: flex; gap: .4rem; align-items: center; }
.field-inline.compact input { font-size: .8rem; padding: .25rem .4rem; }
.stack .field, .stack label { margin-bottom: .35rem; }
.stack input { margin-bottom: .8rem; }

.hint { font-size: .78rem; color: var(--ink-soft); margin: .25rem 0 0; }
.hint-error { color: var(--red-600); font-weight: 500; }

.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-form input { flex: 1 1 160px; width: auto; }
.inline-form select { flex: 0 1 150px; width: auto; }

.filters {
  display: flex; gap: .5rem; flex-wrap: wrap;
  margin-bottom: 1rem; align-items: center;
}
.filters input[type="search"] { flex: 1 1 320px; width: auto; }
.filters select { flex: 0 1 170px; width: auto; }

.form-grid { display: grid; grid-template-columns: minmax(0,1.6fr) minmax(0,1fr); gap: 1.25rem; }
@media (max-width: 1100px) { .form-grid { grid-template-columns: 1fr; } }
.form-footer {
  display: flex; gap: .75rem; align-items: center;
  margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line);
}

.template-choice { display: grid; gap: .6rem; }
.template-option {
  display: flex; gap: .7rem; align-items: flex-start;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: .75rem .9rem; cursor: pointer; font-weight: 400; margin: 0;
}
.template-option:hover { border-color: var(--navy-700); background: var(--navy-100); }
.template-option:has(input:checked) {
  border-color: var(--navy-800); background: var(--navy-100);
  box-shadow: inset 0 0 0 1px var(--navy-800);
}
.template-option input { width: auto; margin-top: .2rem; }
.template-body strong { display: block; font-size: .92rem; }
.template-body small { color: var(--ink-soft); font-size: .8rem; }

.code-editor {
  font-family: var(--mono); font-size: .8rem; line-height: 1.55;
  tab-size: 2; white-space: pre; overflow-wrap: normal; overflow-x: auto;
}

/* ----------------------------------------------------------------- photo -- */

.photo-stage {
  position: relative; width: 300px; max-width: 100%; margin: 0 auto .75rem;
  /* height is set from the template's photo aperture by card-form.js */
  border: 1px dashed var(--line); border-radius: var(--radius);
  background: var(--bg); overflow: hidden;
}
/* The canvas carries its own intrinsic size, set from the template's photo
   aperture by card-form.js, so the stage needs no aspect-ratio of its own. */
#crop-canvas { display: block; width: 100%; height: auto; cursor: grab; }
#crop-canvas.dragging { cursor: grabbing; }
.photo-placeholder {
  position: absolute; inset: 0; display: grid; place-items: center;
  margin: 0; color: var(--ink-soft); font-size: .85rem; text-align: center; padding: 1rem;
}
#existing-photo { display: none; }
.photo-controls { margin-bottom: .5rem; }
.photo-controls input[type="range"] { width: 100%; }
.photo-actions { display: flex; gap: .5rem; justify-content: center; }

/* -------------------------------------------------------------- previews -- */

.preview-faces { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
/* Cards are CR-80 portrait (2.125in x 3.375in), so previews are taller than
   they are wide; reserving the ratio stops the page reflowing as they render. */
.card-canvas { aspect-ratio: 638 / 1013; }
.preview-faces-stacked { grid-template-columns: 1fr; }
.preview-faces figure { margin: 0; }
.preview-faces figcaption {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-soft); margin-bottom: .3rem;
}
.card-canvas {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------- tables -- */

.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th {
  text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-soft); font-weight: 600;
  padding: .6rem .9rem; border-bottom: 1px solid var(--line);
  background: #fbfcfd; position: sticky; top: 0;
}
.table td { padding: .6rem .9rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:hover { background: #fafbfd; }
.table-sm { font-size: .82rem; }
.table-sm td, .table-sm th { padding: .4rem .9rem; }
.table td small { display: block; color: var(--ink-soft); font-size: .75rem; }
.col-check { width: 34px; }
.col-actions { text-align: right; }
.col-actions .btn { margin-left: .25rem; }
.detail-cell { max-width: 380px; overflow: hidden; text-overflow: ellipsis; }

.mono { font-family: var(--mono); font-size: .85em; }
.small { font-size: .8rem; }
.muted { color: var(--ink-soft); }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.dot { color: var(--line); margin: 0 .35rem; }
.empty { color: var(--ink-soft); padding: 1.25rem; text-align: center; margin: 0; }

.facts { margin: 1rem 0 0; }
.facts div { display: flex; gap: .75rem; padding: .35rem 0; border-bottom: 1px solid var(--line-soft); }
.facts dt { flex: 0 0 120px; color: var(--ink-soft); font-size: .8rem; margin: 0; }
.facts dd { margin: 0; font-size: .88rem; }
.facts-inline div { border: 0; padding: .15rem 0; }

/* --------------------------------------------------------------- badges --- */

.badge {
  display: inline-block; font-size: .7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  padding: .12rem .45rem; border-radius: 3px;
  background: var(--line-soft); color: var(--ink-mid);
}
.badge-active    { background: var(--green-100); color: var(--green-700); }
.badge-expired   { background: var(--line-soft); color: var(--ink-soft); }
.badge-suspended { background: var(--amber-100); color: var(--amber-700); }
.badge-revoked,
.badge-lost,
.badge-stolen    { background: var(--red-100); color: var(--red-600); }

/* --------------------------------------------------------------- alerts --- */

.alert {
  padding: .7rem 1rem; border-radius: var(--radius);
  border: 1px solid; margin: 0 0 1.25rem; font-size: .9rem;
}
.alert ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.alert-ok    { background: var(--green-100); border-color: #b7dcc6; color: var(--green-700); }
.alert-warn  { background: var(--amber-100); border-color: #e6cd91; color: var(--amber-700); }
.alert-error { background: var(--red-100);   border-color: #eebab6; color: var(--red-600); }

.credential-reveal .credential {
  font-size: 1.3rem; letter-spacing: .05em; font-weight: 700;
  background: #fff; border: 1px solid #b7dcc6; border-radius: var(--radius);
  padding: .6rem .9rem; margin: .5rem 0; user-select: all;
}

/* -------------------------------------------------------- print console --- */

.print-layout { display: grid; grid-template-columns: minmax(0,340px) minmax(0,1fr); gap: 1.25rem; }
@media (max-width: 1000px) { .print-layout { grid-template-columns: 1fr; } }
.print-controls { position: sticky; top: 1rem; align-self: start; }
.preview-stack { display: grid; gap: 1rem; margin-bottom: 1.25rem; }
.card-preview {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.card-preview-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .75rem; font-size: .9rem;
}
.card-faces { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; max-width: 420px; }
.card-faces figure { margin: 0; }
.card-faces figcaption {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-soft); margin-bottom: .3rem;
}

.job-list { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.job-list li {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem 0; border-bottom: 1px solid var(--line-soft);
}
.job-list li .mono { margin-left: auto; }

.log {
  font-family: var(--mono); font-size: .78rem; line-height: 1.6;
  max-height: 300px; overflow-y: auto;
  background: #0f1b26; color: #d4dde6;
  border-radius: var(--radius-sm); padding: .6rem .8rem;
}
.log:empty::before { content: "Waiting…"; color: #6b7783; }
.log-line { display: flex; gap: .6rem; }
.log-time { color: #6b7783; flex: 0 0 auto; }
.log-ok    .log-msg { color: #7fd1a0; }
.log-warn  .log-msg { color: #f0c674; }
.log-error .log-msg { color: #f28b82; }
.progress { font-size: .85rem; color: var(--ink-soft); margin: .5rem 0 0; }

.help { margin-top: 1.25rem; font-size: .85rem; }
.help summary { cursor: pointer; color: var(--navy-700); font-weight: 500; }
.help-list, .token-list { margin: .6rem 0 0; padding-left: 1.2rem; color: var(--ink-mid); }
.help-list li, .token-list li { margin-bottom: .35rem; }
.token-list { list-style: none; padding: 0; columns: 2; }
code {
  font-family: var(--mono); font-size: .85em;
  background: var(--line-soft); padding: .05rem .3rem; border-radius: 3px;
}

.tpl-status { font-size: .85rem; margin: .6rem 0 0; min-height: 1.2em; }
.tpl-ok    { color: var(--green-700); }
.tpl-error { color: var(--red-600); }

.verify-url { font-size: .85rem; word-break: break-all; margin: .25rem 0 1rem; }
.qr-large { display: block; border: 1px solid var(--line); border-radius: var(--radius); }

.template-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.25rem; }
.template-card header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.template-card h2 { font-size: 1rem; }

/* ------------------------------------------------------------- downloads -- */

.download {
  display: flex; align-items: center; gap: 1rem;
  padding: .9rem 0; border-top: 1px solid var(--line-soft);
}
.download-main { flex: 1 1 auto; min-width: 0; }
.download-main strong { display: block; }
.download-main small { display: block; margin-top: .15rem; }
.checksum { word-break: break-all; background: var(--line-soft); padding: .4rem .6rem; border-radius: 4px; }

.steps { margin: .5rem 0 0; padding-left: 1.3rem; color: var(--ink-mid); }
.steps li { margin-bottom: .5rem; }
.subsection-h { margin-top: 1.5rem; }

/* ---------------------------------------------------------------- pager --- */

.pager { display: flex; gap: .25rem; margin-top: 1rem; justify-content: center; flex-wrap: wrap; }
.pager a {
  padding: .3rem .65rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); text-decoration: none; font-size: .85rem;
  background: var(--surface);
}
.pager a.current { background: var(--navy-800); border-color: var(--navy-800); color: #fff; font-weight: 600; }

/* ------------------------------------------------------------------ auth -- */

/* Matches the specificity of the shared `body.auth-page` rule above, which
   would otherwise win and leave white brand text on a light background. */
body.auth-page { display: grid; place-items: center; min-height: 100vh; background: var(--navy-900); }
.auth-shell { width: 100%; max-width: 420px; padding: 2rem 1.5rem; }
.auth-brand { text-align: center; color: #fff; margin-bottom: 1.75rem; }
.auth-brand h1 {
  font-size: 1.9rem; margin: 0; color: #fff;
  font-weight: 700; letter-spacing: .01em;
}
/* Was .7 opacity on navy, which is below AA for body text. */
.auth-brand p { margin: .3rem 0 0; color: #c6d2e2; font-size: .95rem; }
.auth-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
.auth-card h2 { margin-bottom: 1rem; }
.auth-card label { margin-top: .75rem; }
.auth-card .btn { margin-top: 1.25rem; }
.auth-fine { font-size: .75rem; color: var(--ink-soft); text-align: center; margin: 1rem 0 0; }

.error-code { font-size: 3rem; font-weight: 700; color: var(--line); margin: 0; line-height: 1; }

/* ---------------------------------------------------------------- footer -- */

.sitefoot {
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 1rem 1.25rem; text-align: center;
}
.sitefoot p { margin: 0; font-size: .78rem; color: var(--ink-soft); }

@media print {
  .topbar, .sitefoot, .page-actions, .print-controls, .filters, .pager { display: none !important; }
}
