/* PELCRA account & admin dashboard, shared by every app that talks to the
   model gateway. Uses the host app's PELCRA tokens (--accent, --surface,
   --text …) with fallbacks; chart colours are the validated categorical
   palette (dataviz skill), stepped separately for light and dark. */

.pd {
  --pd-surface: var(--surface, #fff);
  --pd-alt: var(--surface-alt, #f1f9ff);
  --pd-muted-bg: var(--surface-muted, #f2f2f2);
  --pd-text: var(--text, #202020);
  --pd-body: var(--text-body, #454444);
  --pd-muted: var(--text-muted, #6c6c6c);
  --pd-line: var(--line, #d9d9d9);
  --pd-line-strong: var(--line-strong, #a8a8a8);
  --pd-accent: var(--accent, #0244b0);
  --pd-accent-ink: var(--accent-ink, #fff);
  --pd-brand: var(--font-brand, "Helvetica Neue", Arial, sans-serif);
  --pd-font: var(--font-body, Roboto, "Helvetica Neue", Arial, sans-serif);
  --pd-good: #20861e;
  --pd-warn: #a86400;
  --pd-bad: #a63429;
  /* charts */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s-other: #a8a8a8;
  --grid: #e8e8e8; --axis: #c8c8c8;
  --heat-0: #f2f2f2; --heat-lo: #cde2fb; --heat-hi: #0d366b;
  color: var(--pd-body);
  font: 400 15px/22px var(--pd-font);
}
:root[data-theme="dark"] .pd {
  --pd-good: #4cc24a; --pd-warn: #fab219; --pd-bad: #ff8a7f;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s-other: #6c7593;
  --grid: #24305c; --axis: #3b4a85;
  --heat-0: #1b2752; --heat-lo: #184f95; --heat-hi: #9ec5f4;
}

.pd *, .pd *::before, .pd *::after { box-sizing: border-box; }
.pd h2, .pd h3 { margin: 0; color: var(--pd-text); font-family: var(--pd-brand); font-weight: 600; }
.pd h2 { font-size: 22px; line-height: 28px; }
.pd h3 { font-size: 16px; line-height: 22px; }
.pd p { margin: 0; }
.pd a { color: var(--pd-accent); }
.pd code, .pd pre { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; }
.pd .muted { color: var(--pd-muted); }
.pd .small { font-size: 13px; line-height: 20px; }
.pd .pd-num { font-variant-numeric: tabular-nums; }
.pd .stack { display: flex; flex-direction: column; gap: 24px; }
.pd .row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.pd .spacer { flex: 1; }

/* ---- tabs ---- */
.pd-tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--pd-line); margin-bottom: 24px; }
.pd-tab {
  appearance: none; border: 0; background: none; cursor: pointer; color: var(--pd-muted);
  font: 600 15px/20px var(--pd-brand); padding: 10px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.pd-tab:hover { color: var(--pd-text); }
.pd-tab[aria-selected="true"] { color: var(--pd-accent); border-bottom-color: var(--pd-accent); }
.pd-tab:focus-visible, .pd button:focus-visible, .pd input:focus-visible, .pd select:focus-visible, .pd textarea:focus-visible {
  outline: 2px solid var(--focus, #21b3f4); outline-offset: 2px;
}

/* ---- controls ---- */
.pd button.pd-btn, .pd a.pd-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 8px 16px; cursor: pointer;
  border: 1px solid var(--pd-line-strong); background: var(--pd-surface); color: var(--pd-text);
  font: 600 14px/20px var(--pd-brand); text-decoration: none; border-radius: 0;
}
.pd .pd-btn:hover:not(:disabled) { border-color: var(--pd-accent); color: var(--pd-accent); }
.pd .pd-btn.primary { background: var(--pd-accent); border-color: var(--pd-accent); color: var(--pd-accent-ink); }
.pd .pd-btn.primary:hover:not(:disabled) { background: transparent; color: var(--pd-accent); }
.pd .pd-btn.danger:hover:not(:disabled) { border-color: var(--pd-bad); color: var(--pd-bad); }
.pd .pd-btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.pd .pd-btn:disabled { opacity: .45; cursor: not-allowed; }
.pd .seg { display: inline-flex; flex-wrap: wrap; }
.pd .seg button {
  appearance: none; cursor: pointer; border: 1px solid var(--pd-line-strong); background: var(--pd-surface); color: var(--pd-text);
  font: 500 13px/18px var(--pd-font); padding: 7px 12px; margin-right: -1px;
}
.pd .seg button[aria-pressed="true"] { background: var(--pd-accent); border-color: var(--pd-accent); color: var(--pd-accent-ink); position: relative; }
.pd .seg button:disabled { opacity: .4; cursor: not-allowed; }
.pd label.field { display: flex; flex-direction: column; gap: 4px; font: 500 13px/18px var(--pd-font); color: var(--pd-muted); }
.pd input[type="text"], .pd input[type="password"], .pd input[type="number"], .pd input[type="date"], .pd input[type="email"], .pd select, .pd textarea {
  border: 1px solid var(--pd-line-strong); background: var(--pd-surface); color: var(--pd-text);
  font: 400 14px/20px var(--pd-font); padding: 8px 10px; min-height: 38px; border-radius: 0;
}
.pd textarea { resize: vertical; }
.pd label.check { display: inline-flex; align-items: center; gap: 8px; color: var(--pd-text); font-size: 14px; cursor: pointer; }
.pd label.check input { accent-color: var(--pd-accent); width: 16px; height: 16px; }

/* ---- surfaces ---- */
.pd .pd-card { border: 1px solid var(--pd-line); background: var(--pd-surface); padding: 20px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pd .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.pd .pd-card .pd-label { font: 600 13px/18px var(--pd-brand); color: var(--pd-muted); letter-spacing: .01em; }
.pd .pd-card .pd-value { font: 600 32px/38px var(--pd-brand); color: var(--pd-text); }
.pd .pd-card .pd-value small { font: 500 15px/20px var(--pd-font); color: var(--pd-muted); margin-left: 4px; }
.pd .pd-card .pd-sub { font-size: 13px; line-height: 20px; color: var(--pd-muted); }
.pd .pd-card.accent { border-color: var(--pd-accent); background: var(--pd-alt); }
.pd .pd-meter { height: 8px; background: var(--heat-lo); position: relative; overflow: hidden; }
.pd .pd-meter > i { position: absolute; inset: 0 auto 0 0; background: var(--pd-accent); }
.pd .pd-meter.warn > i { background: var(--pd-warn); }
.pd .pd-badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; font: 600 12px/20px var(--pd-brand); background: var(--pd-alt); color: var(--pd-accent); border: 1px solid currentColor; }
.pd .pd-badge.good { color: var(--pd-good); background: transparent; }
.pd .pd-badge.bad { color: var(--pd-bad); background: transparent; }
.pd .pd-badge.muted { color: var(--pd-muted); background: transparent; }
.pd .pd-notice { border-left: 3px solid var(--pd-accent); background: var(--pd-alt); padding: 12px 16px; color: var(--pd-text); }
.pd .pd-notice.error { border-left-color: var(--pd-bad); background: transparent; color: var(--pd-bad); }
.pd .pd-notice.secret { border-left-color: var(--pd-warn); }
.pd .secret-key { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.pd .secret-key code { padding: 8px 10px; background: var(--pd-surface); border: 1px solid var(--pd-line); word-break: break-all; color: var(--pd-text); }

/* ---- tables ---- */
.pd .table-wrap { overflow-x: auto; border: 1px solid var(--pd-line); background: var(--pd-surface); }
.pd table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.pd th { text-align: left; font: 600 12px/18px var(--pd-brand); color: var(--pd-muted); padding: 10px 12px; border-bottom: 1px solid var(--pd-line); white-space: nowrap; background: var(--pd-surface); }
.pd td { padding: 9px 12px; border-bottom: 1px solid var(--pd-line); color: var(--pd-text); vertical-align: top; }
.pd tr:last-child td { border-bottom: 0; }
.pd td.r, .pd th.r { text-align: right; font-variant-numeric: tabular-nums; }
.pd td.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.pd tr.revoked td { color: var(--pd-muted); text-decoration: line-through; }
.pd tr.revoked td:last-child { text-decoration: none; }
.pd .share { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.pd .share i { display: block; height: 8px; background: var(--pd-accent); min-width: 1px; }
.pd .share span { font-variant-numeric: tabular-nums; color: var(--pd-muted); font-size: 13px; }
.pd .pd-empty { padding: 32px; text-align: center; color: var(--pd-muted); }

/* ---- quick start ---- */
.pd .pipeline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pd .pipeline .step { padding: 6px 12px; border: 1px solid var(--pd-line-strong); background: var(--pd-surface); color: var(--pd-text); font: 600 13px/18px var(--pd-brand); }
.pd .pipeline .step.on { border-color: var(--pd-accent); background: var(--pd-alt); color: var(--pd-accent); }
.pd .pipeline .step.off { color: var(--pd-muted); border-style: dashed; font-weight: 500; }
.pd .pipeline .arrow { color: var(--pd-muted); }
.pd .builder { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 24px; align-items: start; }
.pd .builder .opts { display: flex; flex-direction: column; gap: 16px; }
.pd .builder .opt-title { font: 600 13px/18px var(--pd-brand); color: var(--pd-muted); margin-bottom: 6px; }
.pd .code { border: 1px solid var(--pd-line); background: var(--pd-surface); min-width: 0; }
.pd .code-tabs { display: flex; border-bottom: 1px solid var(--pd-line); align-items: center; }
.pd .code-tabs .pd-tab { font-size: 13px; padding: 8px 12px; }
.pd .code-tabs .copy { margin-left: auto; margin-right: 8px; }
.pd pre.snippet { margin: 0; padding: 14px 0; overflow-x: auto; line-height: 20px; color: var(--pd-text); }
.pd pre.snippet span.ln { display: block; padding: 0 16px; white-space: pre; }
.pd pre.snippet span.ln.added { background: var(--pd-alt); box-shadow: inset 3px 0 0 var(--pd-accent); }
.pd pre.output { margin: 0; padding: 14px 16px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--pd-surface); border: 1px solid var(--pd-line); max-height: 360px; color: var(--pd-text); }
.pd .two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.pd .two > * { min-width: 0; }

/* ---- usage ---- */
.pd .filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.pd .filters label.field select, .pd .filters label.field input { min-width: 120px; }
.pd .chart { border: 1px solid var(--pd-line); background: var(--pd-surface); padding: 16px 16px 8px; }
.pd .chart-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 8px; }
.pd .pd-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--pd-body); }
.pd .pd-legend span { display: inline-flex; align-items: center; gap: 6px; }
.pd .pd-legend i { width: 10px; height: 10px; display: inline-block; }
.pd svg text { font-family: var(--pd-font); font-size: 11px; fill: var(--pd-muted); }
.pd svg .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.pd svg .axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.pd svg .mark { cursor: default; transition: opacity .12s; }
.pd svg .mark:hover, .pd svg .mark:focus { opacity: .8; outline: none; }
.pd svg .cell { stroke: var(--pd-surface); stroke-width: 2; }
.pd svg .cell:hover, .pd svg .cell:focus { stroke: var(--pd-text); stroke-width: 1.5; outline: none; }
.pd details.tableview { margin-top: 8px; }
.pd details.tableview summary { cursor: pointer; font-size: 13px; color: var(--pd-muted); padding: 4px 0; }
.pd-tip {
  position: fixed; z-index: 1000; pointer-events: none; background: var(--pd-surface); color: var(--pd-text);
  border: 1px solid var(--pd-line-strong); box-shadow: 0 9px 32px rgba(0, 0, 0, .16); padding: 8px 10px;
  font: 400 13px/18px var(--pd-font); max-width: 280px;
}
.pd-tip b { font-weight: 600; }
.pd-tip .k { display: inline-block; width: 8px; height: 8px; margin-right: 6px; }

/* ---- admin ---- */
.pd .admin-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.pd .panel { border: 1px solid var(--pd-accent); background: var(--pd-surface); padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.pd .panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pd .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.pd tr.sel td { background: var(--pd-alt); }

@media (max-width: 900px) {
  .pd .builder, .pd .two { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .pd .pd-card .pd-value { font-size: 26px; line-height: 32px; }
  .pd .pd-card { padding: 16px; }
}

/* ---- (i) tooltips, dividers, compact option groups ---- */
.pd .pd-info {
  appearance: none; display: inline-grid; place-items: center; width: 18px; height: 18px; padding: 0; margin-left: 6px;
  border: 1px solid var(--pd-line-strong); border-radius: 50%; background: transparent; color: var(--pd-muted);
  font: 600 11px/1 var(--pd-font); cursor: help; vertical-align: 1px; letter-spacing: 0;
}
.pd .pd-info:hover, .pd .pd-info:focus-visible { border-color: var(--pd-accent); color: var(--pd-accent); }
.pd hr.pd-divider { border: 0; border-top: 1px solid var(--pd-line); margin: 16px 0 8px; }
.pd .checks { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; }
.pd .check-wrap { display: inline-flex; align-items: center; }
.pd label.check input:disabled + * , .pd label.check:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.pd .builder .opts { gap: 20px; }
.pd .builder .opt-title { display: flex; align-items: center; }
.pd .example { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.pd .example > * { min-width: 0; }
.pd pre.output.input { color: var(--pd-muted); max-height: 140px; }
.pd pre.output.tall { max-height: 520px; }
.pd details.reference { border-top: 1px solid var(--pd-line); padding-top: 12px; }
.pd details.reference summary { cursor: pointer; font: 600 14px/20px var(--pd-brand); color: var(--pd-text); }
.pd .pd-tag { display: inline-block; padding: 0 6px; margin: 1px 0; font: 500 12px/18px var(--pd-font); border: 1px solid var(--pd-line-strong); color: var(--pd-body); white-space: nowrap; }
.pd .pd-card .pd-label { display: flex; align-items: center; }
@media (max-width: 900px) { .pd .example { grid-template-columns: 1fr; } }
