/* HSM Service diagnostics console.

   The frame and the components are the shared PQCTrust "indigo / violet" theme, the same one the HSM Manager and the CA admin use
   (tokens --tsp-*; source of truth ssa/web/resources/design/thrivosign-purple.css, reference implementation hsm-manager
   design-system.css): a deep indigo header band with a floating white pill menu straddling its lower edge, a lavender canvas, white
   rounded cards, pill buttons, and the violet gradient only for the one action that matters. The menu groups are dropdowns; at 900 px
   and below the bar collapses into a Menu button. Status colour is never the only signal: every status pill carries a word.
   Sign-in uses the shared sign-in theme (thrivosign-login.css). */

:root {
  --tsp-bg: #f3f2fa;
  --tsp-panel: #ffffff;
  --tsp-ink: #17143a;
  --tsp-ink-2: #3a3763;
  --tsp-muted: #6b6a8a;
  --tsp-line: #e3e1f1;
  --tsp-line-2: #cfcce6;
  --tsp-accent: #5b4ce6;
  --tsp-accent-2: #7a3ff0;
  --tsp-accent-deep: #3b2fb5;
  --tsp-accent-soft: #edeafe;
  --tsp-chrome: radial-gradient(900px 260px at 12% -40%, rgba(122, 63, 240, 0.45), transparent 70%),
    radial-gradient(700px 240px at 92% 10%, rgba(18, 179, 166, 0.22), transparent 70%),
    linear-gradient(135deg, #0b2a55 0%, #1b2b86 55%, #3b2fb5 100%);
  --tsp-radius: 14px;
  --tsp-radius-sm: 10px;
  --tsp-shadow: 0 1px 2px rgba(23, 20, 58, 0.05), 0 8px 28px rgba(35, 28, 95, 0.07);
  --tsp-shadow-md: 0 2px 4px rgba(23, 20, 58, 0.06), 0 12px 32px rgba(35, 28, 95, 0.12);
  --tsp-gradient: linear-gradient(135deg, #5b4ce6, #7a3ff0);
  --ok-fg: #07684a;   --ok-bg: #e6f6ef;
  --warn-fg: #8a5200; --warn-bg: #fff4de;
  --bad-fg: #b3243f;  --bad-bg: #fdecef;
  --info-fg: #3b2fb5; --info-bg: #edeafe;
  --idle-fg: #3a3763; --idle-bg: #eceaf5;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--tsp-bg); color: var(--tsp-ink); font-family: var(--font-sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; color: var(--tsp-ink); letter-spacing: -0.01em; }
a { color: var(--tsp-accent); text-underline-offset: 2px; }
a:hover { color: var(--tsp-accent-deep); }
code { font-family: var(--font-mono); background: var(--tsp-accent-soft); color: var(--tsp-accent-deep); padding: 1px 6px; border-radius: 6px; font-size: .88em; }
:focus-visible { outline: 2px solid #7a63ff; outline-offset: 2px; }
.dg-login-help { margin: 14px 0 0; color: var(--tsp-muted); font-size: 13px; line-height: 1.45; }

/* ---- Frame: indigo header band, floating pill menu, full-width content -------------------------------------------------- */
.dg { max-width: none; margin: 0; padding: 0 0 60px; }
.dg-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 15px 32px 66px; background: var(--tsp-chrome); color: #fff; }
.dg-mark { width: 34px; height: 34px; flex-shrink: 0; }
.dg-title { flex: 1; min-width: 220px; }
.dg-title h1 { color: #fff; font-size: 1.25rem; letter-spacing: .01em; }
.dg-title p { margin: 2px 0 0; color: #dcd8f5; font-size: .85rem; }
.dg-user { color: #f1effc; font-size: .88rem; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dg-link { background: none; border: 0; color: #fff; cursor: pointer; text-decoration: underline; font: inherit; padding: 0; }
.dg-link:hover { color: #dcd8f5; }
.dg-head .dg-btn--ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .45); box-shadow: none; }
.dg-head .dg-btn--ghost:hover { background: rgba(255, 255, 255, .14); filter: none; }
.dg-head .dg-pill { background: rgba(255, 255, 255, .16); color: #fff; }
.dg-head .dg-menu-toggle { display: none; }

/* The main menu: one white pill bar that straddles the header's lower edge. Groups are dropdowns; a single page is a plain pill. */
.dg-tabs { position: relative; z-index: 30; display: flex; flex-wrap: wrap; gap: 3px; width: max-content; max-width: calc(100% - 64px);
  margin: -2.35rem auto 14px 32px; padding: 5px; background: var(--tsp-panel); border: 1px solid var(--tsp-line); border-radius: 999px;
  box-shadow: 0 10px 30px rgba(21, 16, 61, .18); }
.dg-nav-group { position: relative; }
.dg-nav-trigger, .dg-tab--solo { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border: 0; border-radius: 999px; background: transparent;
  color: var(--tsp-ink-2); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s; }
.dg-nav-trigger::after { content: ""; width: .4em; height: .4em; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-.12em) rotate(45deg); transition: transform .15s; }
.dg-nav-trigger[aria-expanded="true"]::after { transform: translateY(.1em) rotate(225deg); }
.dg-nav-trigger:hover, .dg-nav-trigger[aria-expanded="true"], .dg-tab--solo:hover { background: var(--tsp-accent-soft); color: var(--tsp-accent-deep); }
.dg-nav-trigger[data-active="true"], .dg-tab--solo.dg-tab--on { background: var(--tsp-gradient); color: #fff; box-shadow: 0 3px 10px rgba(91, 76, 230, .35); }
.dg-nav-menu { position: absolute; top: calc(100% + .5rem); left: 0; z-index: 40; min-width: 15rem; padding: 5px; display: none;
  background: var(--tsp-panel); border: 1px solid var(--tsp-line); border-radius: var(--tsp-radius); box-shadow: var(--tsp-shadow-md); }
.dg-nav-group[data-open="true"] .dg-nav-menu { display: block; }
.dg-nav-menu .dg-tab { display: flex; width: 100%; align-items: center; padding: 8px 12px; border: 0; border-radius: 999px; background: transparent; color: var(--tsp-ink-2);
  font: inherit; text-align: left; cursor: pointer; transition: background .15s, color .15s; }
.dg-nav-menu .dg-tab:hover { background: var(--tsp-accent-soft); color: var(--tsp-accent-deep); }
.dg-nav-menu .dg-tab.dg-tab--on { background: var(--tsp-gradient); color: #fff; font-weight: 600; box-shadow: 0 3px 10px rgba(91, 76, 230, .3); }

.dg-panel, #app-error, #restart-banner { margin-left: 32px; margin-right: 32px; }
#app-error:empty { display: none; }

/* ---- Content -------------------------------------------------------------------------------------------------------------- */
.dg-panel h2 { font-size: 1.15rem; margin: 26px 0 8px; }
.dg-panel h3 { font-size: 1rem; margin: 20px 0 8px; }
.dg-box h2 { margin-top: 0; font-size: 1.15rem; }
.dg-box h3 { margin: 18px 0 8px; }
.dg-note { color: var(--tsp-muted); font-size: .9rem; line-height: 1.5; }
.dg-box { background: var(--tsp-panel); border: 1px solid var(--tsp-line); border-radius: var(--tsp-radius); padding: 20px 22px; margin: 14px 0; box-shadow: var(--tsp-shadow); }
.dg-box fieldset { border: 0; padding: 0; margin: 0 0 8px; }
.dg-box legend { font-weight: 600; margin-bottom: 6px; }
.dg-box summary { cursor: pointer; font-weight: 600; color: var(--tsp-accent-deep); }
.dg-steps { margin: 10px 0; padding-left: 20px; line-height: 1.6; font-size: .92rem; }
.dg-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 10px; }
.dg-card { background: var(--tsp-panel); border: 1px solid var(--tsp-line); border-radius: var(--tsp-radius); padding: 14px 16px; box-shadow: var(--tsp-shadow); }
.dg-card b { display: block; font-size: 1.3rem; margin-top: 4px; color: var(--tsp-ink); }
.dg-card span { color: var(--tsp-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.dg-device { background: var(--tsp-panel); border: 1px solid var(--tsp-line); border-radius: var(--tsp-radius); padding: 16px 18px; margin: 12px 0; box-shadow: var(--tsp-shadow); }
.dg-device h3 { margin: 0 0 8px; font-size: 1.05rem; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Tables: lavender header, hairline rows, a row you can click shows it. */
.dg-scroll { overflow-x: auto; }
.dg-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--tsp-panel); border: 1px solid var(--tsp-line); border-radius: var(--tsp-radius-sm);
  overflow: hidden; font-size: .9rem; }
.dg-table th, .dg-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--tsp-line); vertical-align: top; overflow-wrap: anywhere; }
.dg-table tr:last-child > th, .dg-table tr:last-child > td { border-bottom: 0; }
.dg-table th { background: #f8f7fd; color: var(--tsp-ink-2); font-weight: 600; width: 30%; }
.dg-table thead th { width: auto; overflow-wrap: normal; color: var(--tsp-muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; }
.dg-table tbody tr:hover > td { background: #fbfaff; }
.dg-table tr.dg-row--on td { background: var(--tsp-accent-soft); }
.dg-table td.dg-problems { color: var(--bad-fg); font-size: .84rem; }
.dg-table caption { caption-side: top; text-align: left; padding: 10px 12px; color: var(--tsp-muted); }
.dg-table .dg-btn { white-space: nowrap; }

/* Status pills. */
.dg-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; letter-spacing: .02em; background: var(--idle-bg); color: var(--idle-fg); white-space: nowrap; }
.st-PASS, .st-READY, .st-HEALTHY, .st-UP, .st-OK, .st-SUCCESS, .st-SUCCEEDED, .st-JOINED, .st-INFO, .st-ACTIVE, .st-MATCH { background: var(--ok-bg); color: var(--ok-fg); }
.st-WARN, .st-DEGRADED, .st-STARTING, .st-COUNT_LOW, .st-UNKNOWN, .st-PENDING, .st-JOINING, .st-RETRYING, .st-SUSPENDED, .st-LEFTOVER_IN_HSM, .st-DESTROYING,
.st-ON_HOLD, .st-IN_PROGRESS { background: var(--warn-bg); color: var(--warn-fg); }
.st-FAIL, .st-NOT_READY, .st-UNHEALTHY, .st-DOWN, .st-LOCKED, .st-STOPPING, .st-FAILURE, .st-DENIED, .st-ERROR, .st-REFUSED, .st-INVALID, .st-REVOKED,
.st-FAILED, .st-MISSING_IN_HSM { background: var(--bad-bg); color: var(--bad-fg); }
.st-SKIPPED, .st-INACTIVE, .st-NOT_CONFIGURED, .st-DEBUG, .st-DESTROYED, .st-EXPIRED { background: var(--idle-bg); color: var(--idle-fg); }

/* ---- Forms and buttons ------------------------------------------------------------------------------------------------------ */
.dg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 18px; }
.dg-grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 18px; }
.dg-field { display: block; margin: 6px 0 10px; }
.dg-field > label { display: block; margin: 0 0 4px; font-size: .84rem; font-weight: 600; color: var(--tsp-ink-2); }
.dg-field--inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.dg-field--inline > label { margin: 0; }
.dg-input { width: 100%; padding: 9px 12px; font: inherit; font-size: .92rem; color: var(--tsp-ink); background: #fff; border: 1px solid var(--tsp-line-2); border-radius: var(--tsp-radius-sm); }
.dg-input::placeholder { color: #9a98b8; }
.dg-field--inline .dg-input { width: auto; min-width: 170px; }
.dg-input:focus, .dg-editor:focus { outline: 0; border-color: var(--tsp-accent); box-shadow: 0 0 0 3px rgba(91, 76, 230, .2); }
.dg-editor { width: 100%; min-height: 420px; padding: 12px 14px; font: 13px/1.5 var(--font-mono); color: var(--tsp-ink); background: #fbfaff;
  border: 1px solid var(--tsp-line-2); border-radius: var(--tsp-radius-sm); resize: vertical; white-space: pre; }
.dg-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 12px; }
.dg-check { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; margin: 6px 0; cursor: pointer; }
.dg-check input { margin-top: 3px; accent-color: var(--tsp-accent); }
.dg-actions { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; align-items: center; }
/* Controls in a button row keep their own size: a search box or a filter never stretches across the card. */
.dg-actions .dg-input { width: auto; flex: 1 1 260px; max-width: 420px; }
.dg-actions select.dg-input { flex: 0 1 190px; }
.dg-btn { white-space: nowrap; display: inline-block; padding: 9px 20px; font: inherit; font-size: .92rem; font-weight: 600; color: #fff; cursor: pointer;
  background: var(--tsp-gradient); border: 1px solid transparent; border-radius: 999px; box-shadow: 0 3px 10px rgba(91, 76, 230, .28); transition: filter .15s, background .15s; }
.dg-btn:hover { filter: brightness(1.07); }
.dg-btn[disabled] { opacity: .55; cursor: default; box-shadow: none; filter: none; }
.dg-btn--ghost { background: #fff; color: var(--tsp-accent-deep); border-color: var(--tsp-line-2); box-shadow: none; }
.dg-btn--ghost:hover { background: var(--tsp-accent-soft); filter: none; }
.dg-btn--warn { background: #b3243f; box-shadow: 0 3px 10px rgba(179, 36, 63, .25); }
.dg-btn--small { padding: 5px 13px; font-size: .84rem; }
.dg-msg { margin: 8px 0; padding: 10px 14px; font-size: .9rem; border-radius: var(--tsp-radius-sm); line-height: 1.5; }
.dg-msg:empty { display: none; }
.dg-msg--error { color: var(--bad-fg); background: var(--bad-bg); }
.dg-msg--info { color: var(--info-fg); background: var(--info-bg); }
.dg-msg--ok { color: var(--ok-fg); background: var(--ok-bg); }
.dg-msg--warn { color: var(--warn-fg); background: var(--warn-bg); }
.dg-secret { display: inline-block; margin-top: 6px; padding: 6px 12px; font: 600 1.05rem var(--font-mono); letter-spacing: .04em; background: #fff;
  border: 1px dashed var(--tsp-line-2); border-radius: 8px; user-select: all; }
.dg-banner { position: sticky; top: 0; z-index: 5; margin-top: 8px; margin-bottom: 8px; padding: 10px 14px; border-radius: var(--tsp-radius-sm); background: var(--warn-bg);
  color: var(--warn-fg); font-weight: 600; box-shadow: var(--tsp-shadow); }
.dg-report { background: var(--tsp-panel); border: 2px solid var(--tsp-line-2); border-radius: var(--tsp-radius); padding: 14px 16px; margin: 8px 0 16px; }
.dg-report__head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.dg-report__head b { flex: 1; }
.dg-log { background: var(--tsp-panel); border: 1px solid var(--tsp-line); border-radius: var(--tsp-radius-sm); font: 12.5px/1.45 var(--font-mono); }
.dg-log__entry { padding: 5px 12px; border-bottom: 1px solid var(--tsp-line); display: grid; grid-template-columns: 170px 70px 1fr; gap: 8px; }
.dg-log__entry:last-child { border-bottom: 0; }
.dg-log__time { color: var(--tsp-muted); }
.dg-log__msg { word-break: break-word; white-space: pre-wrap; }
.dg-log__src { color: #8d89a8; }
.dg-log__empty { padding: 12px; color: var(--tsp-muted); font-family: inherit; }
.dg-pre { background: #f8f7fd; border: 1px solid var(--tsp-line); border-radius: var(--tsp-radius-sm); padding: 12px 14px; overflow: auto; max-height: 320px; font: .85rem/1.45 var(--font-mono); white-space: pre; }

/* Lists: toolbar with search, rows you can click, long values wrap so the action column stays on screen. */
.dg-subtabs { display: flex; gap: 6px; margin: 4px 0 8px; flex-wrap: wrap; }
.dg-subtab { background: #fff; border: 1px solid var(--tsp-line-2); border-radius: 999px; padding: 6px 15px; cursor: pointer; font: inherit; font-size: .9rem; color: var(--tsp-ink-2); }
.dg-subtab:hover { background: var(--tsp-accent-soft); }
.dg-subtab--on { background: var(--tsp-accent-soft); border-color: var(--tsp-accent); color: var(--tsp-accent-deep); font-weight: 600; }
.dg-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.dg-toolbar h2 { margin: 0; flex: 1 1 auto; }
.dg-toolbar .dg-search { flex: 1 1 260px; width: auto; max-width: 420px; }
.dg-count { color: var(--tsp-muted); font-weight: 400; font-size: .95rem; }
.dg-name { font-weight: 600; }
.dg-sub { display: block; margin-top: 2px; color: var(--tsp-muted); font-size: .84rem; }
.dg-mono { font-family: var(--font-mono); font-size: .86em; }
.dg-row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dg-click { cursor: pointer; }
.dg-click:hover td, .dg-click:focus td { background: #f4f2fd; }
.dg-click.dg-selected td { background: var(--tsp-accent-soft); }
.dg-click:focus { outline: 2px solid var(--tsp-accent); outline-offset: -2px; }
#cl-clients td:nth-child(6), #cl-clients td:last-child, #tn-table td:nth-child(5), #tn-table td:last-child { white-space: nowrap; word-break: normal; }

/* ---- Narrow screens ---------------------------------------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .dg-head { padding: 12px 16px 14px; }
  .dg-head .dg-menu-toggle { display: inline-block; }
  .dg-tabs { display: none; flex-direction: column; flex-wrap: nowrap; gap: 0; width: auto; max-width: none; margin: 10px 12px 12px; padding: 8px; border-radius: var(--tsp-radius); }
  .dg-tabs[data-open="true"] { display: flex; }
  .dg-nav-trigger::after { display: none; }
  .dg-nav-trigger { cursor: default; font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--tsp-muted); padding: 10px 12px 2px; pointer-events: none; }
  .dg-nav-menu, .dg-nav-group[data-open="true"] .dg-nav-menu { display: block; position: static; min-width: 0; padding: 0; border: 0; box-shadow: none; background: transparent; }
  /* In the list layout a group is only a label: no pill, no hover. The page that is open is the lit entry. */
  .dg-nav-trigger[data-active="true"], .dg-nav-trigger:hover { background: transparent; color: var(--tsp-muted); box-shadow: none; }
  .dg-tab--solo { width: 100%; justify-content: flex-start; padding: 8px 12px; }
  .dg-panel, #app-error, #restart-banner { margin-left: 12px; margin-right: 12px; }
}
@media (max-width: 720px) {
  .dg-log__entry { grid-template-columns: 1fr; gap: 2px; }
  .dg-scroll { overflow: visible; }
  .dg-table, .dg-table tbody, .dg-table tr { display: block; width: auto; }
  .dg-table:has(thead) { border: 0; background: none; border-radius: 0; }
  .dg-table thead { display: none; }
  .dg-table:has(thead) tbody tr { background: var(--tsp-panel); border: 1px solid var(--tsp-line); border-radius: var(--tsp-radius); padding: 4px 12px; margin: 0 0 10px; }
  .dg-table th, .dg-table td { display: block; width: auto !important; }
  .dg-table:has(thead) th, .dg-table:has(thead) td { padding: 6px 0; }
  .dg-table tr > :last-child { border-bottom: 0; }
  .dg-table td[data-label]:not([data-label=""]) { display: grid; grid-template-columns: minmax(6rem, 34%) minmax(0, 1fr); column-gap: 10px; }
  .dg-table td[data-label]:not([data-label=""])::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 9; color: var(--tsp-muted);
    font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding-top: 2px; }
  .dg-table td[data-label]:not([data-label=""]) > * { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Show/hide eye on password, PIN and secret boxes (secret-reveal.js). */
.dg-pw { position: relative; display: block; }
.dg-pw > input { padding-right: 44px; }
.dg-pw > input::-ms-reveal, .dg-pw > input::-ms-clear { display: none; }
.dg-pw__toggle { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); width: 32px; height: 32px; padding: 6px;
  border: 0; border-radius: 8px; background: transparent; color: #6b6890; cursor: pointer; }
.dg-pw__toggle:hover { color: #1f1b4d; background: rgba(91, 76, 230, 0.08); }
.dg-pw__toggle:focus-visible { outline: 0; color: #1f1b4d; box-shadow: 0 0 0 3px rgba(91, 76, 230, 0.3); }
.dg-pw__toggle[aria-pressed="true"] { color: #1f1b4d; }
.dg-pw__toggle svg { display: block; width: 20px; height: 20px; }

/* Keys tab: the full key id under its short tag. */
.dg-small { font-size: .78rem; color: var(--tsp-ink-2); overflow-wrap: anywhere; }
