/* =============================================================================
 *  NAG27 — DESIGN MODE
 *  A live colour-token editor for the site. Toggle it from the button in the
 *  top-right corner, change any token, and watch the real page repaint.
 *
 *  IMPORTANT: this panel deliberately uses its OWN hardcoded --dm-* colours and
 *  never the site's tokens. If it themed itself along with the site, editing a
 *  colour to something unreadable would make the editor unreadable too.
 *
 *  Loaded only when NAG_CONFIG.designMode is true, or ?design is in the URL.
 * ========================================================================== */

.dm-root {
  /* instrument palette — cool slate, so the warm site colours read true beside it */
  --dm-bg:      #14181f;
  --dm-surface: #1c222b;
  --dm-raised:  #262e39;
  --dm-line:    #333d4b;
  --dm-text:    #e7ecf3;
  --dm-dim:     #98a4b5;
  --dm-accent:  #6ea8d8;
  --dm-pass:    #4a9c78;
  --dm-fail:    #d0625c;
  --dm-warn:    #c9944a;

  font-family: ui-sans-serif, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--dm-text);
}

.dm-mono {
  font-family: ui-monospace, "Cascadia Mono", "Consolas", "SF Mono", monospace;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ toggle */
.dm-toggle {
  position: fixed; top: 14px; right: 14px; z-index: 9001;
  display: inline-flex; align-items: center; gap: .5em;
  padding: .5em .9em;
  background: var(--dm-bg); color: var(--dm-text);
  border: 1px solid var(--dm-line); border-radius: 999px;
  font: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.28);
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.dm-toggle:hover { background: var(--dm-raised); border-color: var(--dm-accent); }
.dm-toggle:active { transform: translateY(1px); }
.dm-toggle:focus-visible { outline: 3px solid var(--dm-accent); outline-offset: 2px; }
.dm-toggle .dm-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: linear-gradient(135deg, #6db6dd 0 50%, #ff8c00 50% 100%);
  box-shadow: 0 0 0 1px rgba(255,255,255,.25);
}
.dm-root[data-open="true"] .dm-toggle { right: 386px; }

/* ------------------------------------------------------------------- panel */
.dm-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 9000;
  width: 370px; max-width: 100vw;
  display: flex; flex-direction: column;
  background: var(--dm-bg);
  border-left: 1px solid var(--dm-line);
  box-shadow: -8px 0 32px rgba(0,0,0,.3);
  transform: translateX(100%);
  transition: transform .22s ease;
}
.dm-root[data-open="true"] .dm-panel { transform: translateX(0); }
.dm-panel[hidden] { display: flex !important; }   /* we animate, we don't hide */

.dm-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1em;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--dm-line);
}
.dm-head h2 { margin: 0; font-size: 15px; font-weight: 600; font-family: inherit; color: var(--dm-text); letter-spacing: .01em; }
.dm-head p { margin: 3px 0 0; font-size: 11.5px; color: var(--dm-dim); }
.dm-close {
  background: none; border: 0; color: var(--dm-dim); cursor: pointer;
  font-size: 20px; line-height: 1; padding: 2px 6px; border-radius: 6px;
}
.dm-close:hover { color: var(--dm-text); background: var(--dm-raised); }
.dm-close:focus-visible { outline: 2px solid var(--dm-accent); outline-offset: 1px; }

.dm-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 0 20px; }

/* ------------------------------------------------------------------- bars */
.dm-bar { padding: 12px 18px; border-bottom: 1px solid var(--dm-line); display: grid; gap: 8px; }
.dm-bar-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--dm-dim); font-weight: 700;
}
.dm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dm-chip {
  padding: .38em .7em; font: inherit; font-size: 12px;
  background: var(--dm-surface); color: var(--dm-text);
  border: 1px solid var(--dm-line); border-radius: 7px; cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dm-chip:hover { border-color: var(--dm-accent); background: var(--dm-raised); }
.dm-chip:focus-visible { outline: 2px solid var(--dm-accent); outline-offset: 1px; }
.dm-chip[aria-pressed="true"] { background: var(--dm-accent); border-color: var(--dm-accent); color: #0d1218; font-weight: 600; }
.dm-chip .dm-swatches { display: inline-flex; gap: 2px; margin-right: .45em; vertical-align: -1px; }
.dm-chip .dm-swatches i { width: 8px; height: 8px; border-radius: 2px; display: block; }

/* ------------------------------------------------------------------ verdict */
.dm-verdict { padding: 12px 18px; border-bottom: 1px solid var(--dm-line); }
.dm-verdict-count { font-size: 22px; font-weight: 700; line-height: 1; }
.dm-verdict-count.is-pass { color: var(--dm-pass); }
.dm-verdict-count.is-fail { color: var(--dm-fail); }
.dm-verdict p { margin: 5px 0 0; font-size: 12px; color: var(--dm-dim); }
.dm-fails { margin: 9px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.dm-fails li {
  display: flex; align-items: baseline; gap: .5em;
  font-size: 11.5px; padding: 5px 7px;
  background: var(--dm-surface); border-left: 3px solid var(--dm-fail); border-radius: 0 5px 5px 0;
}
.dm-fails .dm-ratio { color: var(--dm-fail); font-weight: 700; }
.dm-fails .dm-role { color: var(--dm-dim); }

/* ------------------------------------------------------------------ groups */
.dm-group { border-bottom: 1px solid var(--dm-line); }
.dm-group > summary {
  padding: 11px 18px; cursor: pointer; list-style: none;
  display: flex; align-items: center; justify-content: space-between; gap: .6em;
  font-size: 12.5px; font-weight: 600; color: var(--dm-text);
}
.dm-group > summary::-webkit-details-marker { display: none; }
.dm-group > summary:hover { background: var(--dm-surface); }
.dm-group > summary:focus-visible { outline: 2px solid var(--dm-accent); outline-offset: -2px; }
.dm-group > summary::after { content: "+"; color: var(--dm-dim); font-size: 15px; }
.dm-group[open] > summary::after { content: "\2212"; }
.dm-group-preview { display: flex; gap: 3px; margin-left: auto; margin-right: .5em; }
.dm-group-preview i { width: 12px; height: 12px; border-radius: 3px; display: block; border: 1px solid rgba(255,255,255,.14); }
.dm-group-note { margin: 0; padding: 0 18px 10px; font-size: 11.5px; color: var(--dm-dim); }

/* ------------------------------------------------------------------ tokens */
.dm-token {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center;
  gap: 10px; padding: 7px 18px;
}
.dm-token:hover { background: var(--dm-surface); }
.dm-token input[type="color"] {
  width: 34px; height: 30px; padding: 0; cursor: pointer;
  background: none; border: 1px solid var(--dm-line); border-radius: 6px;
}
.dm-token input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.dm-token input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 4px; }
.dm-token input[type="color"]:focus-visible { outline: 2px solid var(--dm-accent); outline-offset: 1px; }

.dm-token-meta { min-width: 0; }
.dm-token-name { font-size: 11.5px; color: var(--dm-text); display: block; }
.dm-token-hint { font-size: 10.5px; color: var(--dm-dim); display: block; }

.dm-token-right { display: flex; align-items: center; gap: 6px; }
.dm-hex {
  width: 74px; padding: .3em .45em; font-size: 11.5px;
  background: var(--dm-surface); color: var(--dm-text);
  border: 1px solid var(--dm-line); border-radius: 5px;
}
.dm-hex:focus-visible { outline: 2px solid var(--dm-accent); outline-offset: 0; border-color: var(--dm-accent); }
.dm-hex[aria-invalid="true"] { border-color: var(--dm-fail); }

.dm-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  padding: .22em .42em; border-radius: 4px; white-space: nowrap;
  border: 1px solid transparent;
}
/* state is carried by the LABEL TEXT as well as the colour — WCAG 1.4.1, the
   rule this whole panel exists to demonstrate. Never colour-only. */
.dm-badge.is-pass { color: var(--dm-pass); border-color: color-mix(in srgb, var(--dm-pass) 45%, transparent); }
.dm-badge.is-warn { color: var(--dm-warn); border-color: color-mix(in srgb, var(--dm-warn) 45%, transparent); }
.dm-badge.is-fail { color: var(--dm-fail); border-color: color-mix(in srgb, var(--dm-fail) 45%, transparent); }

/* ------------------------------------------------------------------ footer */
.dm-foot {
  padding: 12px 18px; border-top: 1px solid var(--dm-line);
  display: flex; flex-wrap: wrap; gap: 6px; background: var(--dm-surface);
}
.dm-foot .dm-chip { flex: 1 1 auto; text-align: center; }
.dm-foot .dm-chip.dm-primary { background: var(--dm-accent); border-color: var(--dm-accent); color: #0d1218; font-weight: 600; }
.dm-foot .dm-chip.dm-primary:hover { filter: brightness(1.08); }

.dm-toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 9002;
  padding: .6em 1em; border-radius: 8px; font-size: 12.5px;
  background: var(--dm-bg); color: var(--dm-text); border: 1px solid var(--dm-accent);
  box-shadow: 0 4px 18px rgba(0,0,0,.35);
  opacity: 0; transform: translateY(6px); pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.dm-toast[data-show="true"] { opacity: 1; transform: translateY(0); }

/* ------------------------------------------------------- narrow viewports */
@media (max-width: 560px) {
  .dm-panel { width: 100vw; }
  .dm-root[data-open="true"] .dm-toggle { right: 14px; top: auto; bottom: 14px; z-index: 9003; }
}

@media (prefers-reduced-motion: reduce) {
  .dm-panel, .dm-toggle, .dm-toast, .dm-chip { transition: none; }
}
