/* Admin dashboard. Reuses the shared .kpi-* tiles (components/cards.css) and
   --token palette; theme-agnostic (works in classic / jarvis / win2000 /
   ivory because every color resolves through a variable). */

.admin-page {
  padding: 32px 28px;
  width: 100%;
  flex-direction: column;
  gap: 18px;
}

/* CRITICAL: do NOT put `display: flex` on the bare `.admin-page` rule. It has the
   same specificity as layout.css's `.page { display: none }` but loads later, so
   it would win and force the admin page visible on EVERY page (its denied gate
   then renders underneath every active page). Gating the flex display to
   `.active` — at higher specificity than `.page.active { display:block }` — keeps
   the page hidden until it's the active page, like every other page. */
.page.admin-page.active { display: flex; }

/* ── Access denied ─────────────────────────────────────────────────────── */

.admin-denied {
  margin: 80px auto;
  max-width: 440px;
  text-align: center;
  color: var(--text-muted);
}
.admin-denied-icon { font-size: 44px; margin-bottom: 12px; }
.admin-denied h2 { margin: 0 0 8px; color: var(--text); }
.admin-denied p { margin: 0; font-size: 14px; line-height: 1.5; }

/* ── Header + tabs ─────────────────────────────────────────────────────── */

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.admin-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-body);
}
.admin-subtitle { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.admin-refresh { white-space: nowrap; }

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.admin-tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-body);
  transition: color .12s, border-color .12s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--gold); border-bottom-color: var(--gold); }
.admin-tab-icon { margin-right: 4px; }

.admin-content { display: flex; flex-direction: column; gap: 20px; }

.admin-loading, .admin-empty {
  padding: 28px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}
.admin-error {
  padding: 16px;
  background: var(--red-soft);
  border: 1px solid var(--red);
  border-radius: 8px;
  color: var(--red);
  font-size: 13px;
}

/* ── Sections ──────────────────────────────────────────────────────────── */

.admin-section { display: flex; flex-direction: column; gap: 10px; }
.admin-section-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.admin-count { font-weight: 600; }
.admin-note-inline { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-dim); font-size: 12px; }
.admin-kpis { margin-bottom: 4px; }
.admin-kpi-warn { border-color: var(--red); }

/* ── Charts layout ─────────────────────────────────────────────────────── */

.admin-chart-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.admin-charts-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .admin-charts-2 { grid-template-columns: 1fr; } }

/* Account-status segmented bar */
.admin-statusbar {
  display: flex;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
  gap: 2px;                 /* 2px surface gap between segments */
  background: var(--surface);
}
.admin-statusseg { height: 100%; min-width: 3px; }
.admin-statusseg-ok   { background: var(--green); }
.admin-statusseg-warn { background: var(--gold); }
.admin-statusseg-dim  { background: var(--text-dim); }

.admin-status-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.admin-status-chip { font-size: 12px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.admin-status-chip b { color: var(--text); }
.admin-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.admin-dot-ok   { background: var(--green); }
.admin-dot-warn { background: var(--gold); }
.admin-dot-dim  { background: var(--text-dim); }
.admin-dot-off  { background: var(--red); }

/* ── Tables ────────────────────────────────────────────────────────────── */

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.admin-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: var(--bg-warm);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  vertical-align: top;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12px; color: var(--text-muted); }
.admin-dim { color: var(--text-dim); }
.admin-rel { color: var(--text-dim); font-size: 11px; }
.admin-row-disabled { opacity: 0.55; }
.admin-actions-cell { white-space: nowrap; display: flex; gap: 6px; }
.admin-actions-cell .btn-ghost { padding: 4px 8px; font-size: 12px; }
.admin-danger { color: var(--red) !important; }

/* ── Badges ────────────────────────────────────────────────────────────── */

.admin-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}
.admin-badge-on   { background: var(--green-soft); color: var(--green); }
.admin-badge-off  { background: var(--red-soft);   color: var(--red); }
.admin-badge-warn { background: var(--gold-soft);  color: var(--gold-hover); }
.admin-op-badge   { background: var(--gold-soft);  color: var(--gold-hover); font-family: ui-monospace, monospace; }

/* ── Triage list (errors + feedback) ───────────────────────────────────── */

.admin-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-filter {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  text-transform: capitalize;
  font-family: var(--font-body);
}
.admin-filter:hover { border-color: var(--gold); }
.admin-filter.active { background: var(--gold); color: #fff; border-color: var(--gold); }
.admin-filter-n { opacity: 0.7; margin-left: 2px; }

.admin-triage-list { display: flex; flex-direction: column; gap: 8px; }
.admin-triage-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.admin-triage-item.admin-status-new           { border-left-color: var(--gold); }
.admin-triage-item.admin-status-investigating  { border-left-color: var(--green); }
.admin-triage-item.admin-status-resolved       { border-left-color: var(--border); opacity: 0.72; }
.admin-triage-item.admin-status-ignored        { border-left-color: var(--border); opacity: 0.55; }

.admin-triage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.admin-triage-main { min-width: 0; flex: 1; }
.admin-triage-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-triage-item.expanded .admin-triage-title { white-space: normal; }
.admin-triage-meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.admin-triage-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.admin-status-badge-new           { background: var(--gold-soft);  color: var(--gold-hover); }
.admin-status-badge-investigating { background: var(--green-soft); color: var(--green); }
.admin-status-badge-resolved      { background: var(--green-soft); color: var(--green); }
.admin-status-badge-ignored       { background: var(--red-soft);   color: var(--text-muted); }

.admin-triage-actions { display: none; gap: 4px; }
.admin-triage-item:hover .admin-triage-actions,
.admin-triage-item.expanded .admin-triage-actions { display: flex; }
.admin-status-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-muted);
  white-space: nowrap;
}
.admin-status-btn:hover { border-color: var(--gold); color: var(--text); }

.admin-triage-body { display: none; padding: 0 14px 14px; border-top: 1px solid var(--border-light); }
.admin-triage-item.expanded .admin-triage-body { display: block; padding-top: 12px; }
.admin-pre {
  background: var(--bg-warm);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px;
  font-size: 11px;
  line-height: 1.45;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.admin-detail-ctx { font-size: 11px; color: var(--text-dim); word-break: break-word; line-height: 1.6; }
.admin-notes {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--gold-soft);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
}

/* ── Toast ─────────────────────────────────────────────────────────────── */

.admin-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--surface);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 9999;
}
.admin-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Contracts & Documents ──────────────────────────────────────────────────
   Button size modifiers are scoped to .admin-page on purpose: buttons.css is
   shared by every page, and .btn-sm / .btn-xs are used nowhere else yet. */

.admin-page .btn-sm { padding: 6px 12px; font-size: 12px; }
.admin-page .btn-xs { padding: 4px 9px;  font-size: 11px; }
.admin-page .btn-xs.danger,
.admin-page .btn-sm.danger { color: var(--red); }
.admin-page .btn-xs.danger:hover,
.admin-page .btn-sm.danger:hover { background: var(--red-soft); }

.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.admin-section-note {
  margin: -2px 0 4px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
  max-width: 68ch;
}
.admin-table-wrap { overflow-x: auto; }

/* Links out to the published legal pages */
.doc-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}
.doc-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.doc-link:hover { border-color: var(--gold); background: var(--bg-warm); }
.doc-link-label { font-size: 13px; font-weight: 600; color: var(--text); }
.doc-link-meta  { font-size: 11px; color: var(--text-dim); }

/* Agreements table */
.ag-name  { font-weight: 600; }
.ag-sub   { font-size: 11px; color: var(--text-dim); display: block; }
.ag-legal { font-style: italic; }
.ag-actions { white-space: nowrap; }

.ag-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: capitalize;
  background: var(--bg-warm);
  color: var(--text-muted);
}
.ag-status-signed     { background: var(--green-soft); color: var(--green); }
.ag-status-sent       { background: var(--gold-soft);  color: var(--gold-hover); }
.ag-status-terminated { background: var(--red-soft);   color: var(--red); }

.doc-chip {
  border: 1px solid var(--border);
  background: var(--bg-warm);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  margin: 0 3px 3px 0;
}
.doc-chip:hover { border-color: var(--gold); color: var(--text); }

/* Document library */
.doc-group { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.doc-group-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.doc-count {
  background: var(--bg-warm);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--text-dim);
}
.doc-list { display: flex; flex-direction: column; gap: 6px; }
.doc-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.doc-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.doc-open {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--border);
}
.doc-open:hover { color: var(--gold-hover); text-decoration-color: currentColor; }
.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11px;
  color: var(--text-dim);
}
.doc-desc { font-size: 12px; color: var(--text-muted); }

/* Shared inline form (agreements + upload) */
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.af-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.af-field { display: flex; flex-direction: column; gap: 4px; }
.af-field > span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.af-field input,
.af-field select,
.af-field textarea {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.af-field input:focus,
.af-field select:focus,
.af-field textarea:focus { outline: 2px solid var(--gold-soft); outline-offset: -1px; }
.af-wide { grid-column: 1 / -1; }
.af-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.af-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.af-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}
.af-check input { margin-top: 2px; }

/* Template merge fields */
.doc-actions { display: flex; gap: 6px; align-items: flex-start; white-space: nowrap; }
.doc-tag {
  background: var(--gold-soft);
  color: var(--gold-hover);
  border-radius: 999px;
  padding: 1px 8px;
  font-weight: 600;
}
.fill-warn {
  font-size: 12px;
  color: var(--red);
  background: var(--red-soft);
  border-radius: 6px;
  padding: 8px 10px;
  line-height: 1.6;
}
.fill-warn code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 11px;
  background: var(--surface);
  border-radius: 4px;
  padding: 1px 5px;
}
/* Open-ticket count on a tab. Hidden entirely at zero — a badge showing "0"
   is noise, and one showing nothing before the count loads is honest. */
.admin-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}
.admin-tab-badge[hidden] { display: none; }
.admin-tab.active .admin-tab-badge { background: var(--red); }

.print-guide {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 10px 12px;
}
.print-guide ol { margin: 6px 0 6px 18px; padding: 0; }
.print-guide li { margin-bottom: 3px; }
.print-guide strong { color: var(--text); }
.print-guide-why { display: block; color: var(--text-dim); font-size: 11px; }
.print-guide code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 11px;
  background: var(--bg-warm);
  border-radius: 4px;
  padding: 1px 5px;
}

.fill-preview {
  max-height: 320px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--text-muted);
}

@media (max-width: 720px) {
  .admin-page { padding: 20px 16px; }
  .admin-actions-cell { flex-wrap: wrap; }
  .af-grid { grid-template-columns: 1fr; }
  .doc-row { flex-direction: column; }
}

/* ── Collapsible sections ─────────────────────────────────────────────────── */
/* The agreement records tracker and the odds-and-ends document groups. Present
   but folded away, so the two things you actually do — send a document, file a
   signed one — are what the tab opens on. */
.admin-details > summary {
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  list-style: none;
}
.admin-details > summary::-webkit-details-marker { display: none; }
.admin-details > summary::before {
  content: '▸';
  color: var(--text-dim);
  transition: transform 120ms ease;
}
.admin-details[open] > summary::before { transform: rotate(90deg); }
.admin-details > summary:hover .admin-section-title { color: var(--accent, inherit); }
.admin-details-body { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }

/* ── Fill workspace ───────────────────────────────────────────────────────── */
/* Template on the left, its fields on the right. The preview is a real render
   through contract-print.css, so what you see is the document, not an
   approximation of it. */
.fill-workspace { display: flex; flex-direction: column; gap: 12px; min-height: 0; }

.fw-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.fw-title { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fw-title strong { font-size: 15px; }
.fw-sub { font-size: 12px; color: var(--text-dim); }
/* The only signal that a field was missed — an empty merge field prints as
   nothing, so the document itself will not show the hole. */
.fw-sub.is-incomplete { color: var(--warn, #b45309); font-weight: 600; }

.fw-body {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: start;
}
.fw-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  height: calc(100vh - 240px);
  min-height: 420px;
}
.fw-preview iframe { width: 100%; height: 100%; border: 0; background: #fff; }

.fw-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 240px);
  overflow-y: auto;
  padding-right: 4px;
}
.fw-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
}
.fw-group legend {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.fw-count {
  font-weight: 600;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 6px;
}
.fw-group-note { margin: 0; font-size: 12px; color: var(--text-dim); }

/* Colour carries the grouping: what you supply vs what you still have to go
   and ask the agency for. */
.fw-group-theirs { border-color: color-mix(in srgb, var(--accent, #4f46e5) 40%, var(--border)); }
.fw-group-preset { opacity: 0.92; }

.fw-hint { display: block; margin-top: 4px; font-size: 12px; color: var(--text-dim); }
/* The rate card is not monotonic — 24 seats bills more than 25 does. */
.fw-hint.is-warn { color: var(--warn, #b45309); font-weight: 600; }

@media (max-width: 1100px) {
  .fw-body { grid-template-columns: 1fr; }
  .fw-preview { height: 60vh; }
  .fw-fields { max-height: none; overflow: visible; }
}

/* The clause number a field writes into. Clicking or typing in the field
   scrolls the preview to it. */
.fw-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: middle;
}

/* Who signs — a repeater rather than a markdown textarea. The table has a
   fixed shape, so asking anyone to hand-write pipe characters for it is a trap. */
.fw-signer {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr auto;
  gap: 6px;
  margin-bottom: 6px;
}
.fw-signer input { min-width: 0; }
.fw-signer button[disabled] { opacity: 0.35; cursor: default; }
#fw-add-signer { align-self: flex-start; margin-top: 2px; }
