/* JWT Decoder — self-contained, no external dependencies.
   Light default + dark via prefers-color-scheme + toggle. */
:root {
  color-scheme: light;
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #f6f7fb;
  --ink: #1a1c25; --muted: #475063; --faint: #5b6472; --line: #e4e6ef;
  --accent: #4f46e5; --accent-ink: #ffffff; --accent-soft: rgba(79,70,229,.10);
  --good: #06744a; --good-soft: rgba(6,116,74,.14); --bad: #b91c1c; --bad-soft: rgba(185,28,28,.13);
  --warn: #b45309; --warn-soft: rgba(180,83,9,.13);
  --tok-h: #b91c1c; --tok-p: #6d28d9; --tok-s: #06744a;
  --shadow: 0 1px 2px rgba(20,24,40,.05), 0 10px 28px -14px rgba(20,24,40,.18);
  --mono: 'SF Mono','JetBrains Mono',ui-monospace,Menlo,Consolas,monospace;
  --sans: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,system-ui,sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0b0d13; --surface: #141822; --surface-2: #1a1f2b;
    --ink: #e8eaf2; --muted: #b7bccd; --faint: #99a1b3; --line: #262a38;
    --accent: #8d89f6; --accent-ink: #0b0d13; --accent-soft: rgba(141,137,246,.14);
    --good: #35c08a; --good-soft: rgba(51,192,140,.15); --bad: #f0666b; --bad-soft: rgba(240,102,107,.14);
    --warn: #f0b432; --warn-soft: rgba(240,180,50,.16);
    --tok-h: #f0808a; --tok-p: #b39bff; --tok-s: #45cfa0;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 14px 32px -16px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d13; --surface: #141822; --surface-2: #1a1f2b;
  --ink: #e8eaf2; --muted: #b7bccd; --faint: #99a1b3; --line: #262a38;
  --accent: #8d89f6; --accent-ink: #0b0d13; --accent-soft: rgba(141,137,246,.14);
  --good: #35c08a; --good-soft: rgba(51,192,140,.15); --bad: #f0666b; --bad-soft: rgba(240,102,107,.14);
  --warn: #f0b432; --warn-soft: rgba(240,180,50,.16);
  --tok-h: #f0808a; --tok-p: #b39bff; --tok-s: #45cfa0;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 14px 32px -16px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
/* the `hidden` attribute must win over author display rules (.jw-check, .jw-verdict, .jw-out) */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; overflow-x: hidden; max-width: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.pg-header {
  display: flex; align-items: center; gap: 16px; padding: 0 18px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.pg-brand { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; }
.pg-logo { color: var(--accent); display: inline-flex; }
.pg-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.pg-header-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.pg-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  cursor: pointer; text-decoration: none; transition: background .15s, color .15s;
}
.pg-icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-moon { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .icon-sun { display: none; } :root:not([data-theme]) .icon-moon { display: inline; } }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: inline; }
:root[data-theme="light"] .icon-sun { display: inline; }
:root[data-theme="light"] .icon-moon { display: none; }

/* JWT layout */
.jw-main { max-width: 940px; margin: 0 auto; padding: 24px 20px 56px; }
.jw-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.jw-panel-label {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 14px;
  font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--faint);
  border-bottom: 1px solid var(--line);
}
.jw-panel-actions { display: flex; gap: 6px; }
.jw-mini-btn { appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  font-family: var(--sans); font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 7px; cursor: pointer; text-transform: none; letter-spacing: 0; }
.jw-mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.jw-input {
  width: 100%; min-height: 140px; border: 0; background: transparent; color: var(--ink);
  font-family: var(--mono); font-size: 14px; line-height: 1.55; padding: 14px; resize: vertical;
  outline: none; white-space: pre-wrap; overflow-wrap: anywhere;
}
.jw-encoded { padding: 0 14px 12px; font-family: var(--mono); font-size: 13.5px; line-height: 1.55; word-break: break-all; }
.jw-encoded:empty { display: none; }
.jw-encoded .tok-h { color: var(--tok-h); font-weight: 600; }
.jw-encoded .tok-p { color: var(--tok-p); font-weight: 600; }
.jw-encoded .tok-s { color: var(--tok-s); font-weight: 600; }
.jw-encoded .tok-dot { color: var(--faint); }
.jw-privacy { margin: 0; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--faint); background: var(--surface-2); }

.jw-status { min-height: 20px; margin: 14px 2px; font-family: var(--mono); font-size: 13px; }
.jw-status.err { color: var(--bad); }

.jw-out { display: flex; flex-direction: column; gap: 14px; }
.jw-part { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); min-width: 0; }
.jw-part-head { display: flex; align-items: center; gap: 8px; padding: 11px 14px; font-weight: 600; font-size: 14px; border-bottom: 1px solid var(--line); }
.jw-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.dot-header { background: var(--tok-h); }
.dot-payload { background: var(--tok-p); }
.dot-sig { background: var(--tok-s); }
.jw-copy { margin-left: auto; appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  font-family: var(--sans); font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 7px; cursor: pointer; }
.jw-copy:hover { border-color: var(--accent); color: var(--accent); }
.jw-json { margin: 0; padding: 14px; overflow-x: auto; font-family: var(--mono); font-size: 13px; line-height: 1.6; color: var(--ink); white-space: pre; }
.jw-json .k { color: var(--tok-p); }
.jw-json .s { color: var(--good); }
.jw-json .n { color: var(--accent); }
.jw-json .b { color: var(--tok-h); }
.jw-sig { color: var(--muted); word-break: break-all; white-space: pre-wrap; }
.jw-note { margin: 0; padding: 0 14px 14px; font-size: 12.5px; color: var(--faint); }
.jw-note strong { color: var(--ink); }

/* signature verification */
.jw-verdict { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
  padding: 4px 11px; border-radius: 999px; letter-spacing: .01em; }
.jw-verdict.ok { background: var(--good-soft); color: var(--good); }
.jw-verdict.bad { background: var(--bad-soft); color: var(--bad); }
.jw-verdict.warn { background: var(--warn-soft); color: var(--warn); }
.jw-copy + .jw-verdict, .jw-verdict + .jw-copy { margin-left: 8px; }

.jw-verify { padding: 14px; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 8px; }
.jw-verify-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.jw-verify-input {
  width: 100%; min-height: 46px; resize: vertical; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); color: var(--ink); font-family: var(--mono); font-size: 13px; line-height: 1.5;
  padding: 10px 12px; outline: none;
}
.jw-verify-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.jw-verify-input::placeholder { color: var(--faint); }
.jw-check { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; width: fit-content; }
.jw-check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.jw-verify-status {
  display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; min-height: 20px;
  padding: 8px 12px; border-radius: 9px; background: var(--surface-2); color: var(--faint);
}
.jw-verify-status .vs-icon { flex: 0 0 auto; font-weight: 700; }
.jw-verify-status.ok { background: var(--good-soft); color: var(--good); }
.jw-verify-status.bad { background: var(--bad-soft); color: var(--bad); }
.jw-verify-status.warn { background: var(--warn-soft); color: var(--warn); }
.jw-verify-status.pending { color: var(--muted); }

.jw-claims { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px 0; }
.jw-claim { display: flex; flex-direction: column; gap: 2px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 12px; font-size: 12px; min-width: 0; max-width: 100%; }
.jw-claim .cl-k { font-family: var(--mono); color: var(--faint); font-size: 11px; }
.jw-claim .cl-v { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.jw-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 5px 12px; border-radius: 999px; }
.jw-badge.valid { background: var(--good-soft); color: var(--good); }
.jw-badge.expired { background: var(--bad-soft); color: var(--bad); }

.pg-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 600; padding: 10px 18px;
  border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; box-shadow: var(--shadow);
}
.pg-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* About section — self-contained WCAG-AA palette */
.tool-about {
  --ab-bg: #ffffff; --ab-surface: #f6f7fb; --ab-text: #1a1c25;
  --ab-muted: #475063; --ab-faint: #5b6472; --ab-border: #e4e6ef; --ab-accent: #4f46e5;
  background: var(--ab-bg); color: var(--ab-text); border-top: 1px solid var(--ab-border);
  padding: 64px 24px 80px; font-size: 15px;
}
:root[data-theme="dark"] .tool-about {
  --ab-bg: #0f131a; --ab-surface: #1a1f2b; --ab-text: #e8eaf2;
  --ab-muted: #b7bccd; --ab-faint: #99a1b3; --ab-border: #262a38; --ab-accent: #8d89f6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .tool-about { --ab-bg: #0f131a; --ab-surface: #1a1f2b; --ab-text: #e8eaf2;
    --ab-muted: #b7bccd; --ab-faint: #99a1b3; --ab-border: #262a38; --ab-accent: #8d89f6; }
}
.tool-about-inner { max-width: 860px; margin: 0 auto; line-height: 1.65; }
.tool-about h1 { font-size: clamp(1.6rem, 3.5vw, 2.2rem); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; color: var(--ab-text); }
.tool-about code { font-family: var(--mono); font-size: 0.88em; background: var(--ab-surface); padding: 1px 6px; border-radius: 5px; color: var(--ab-text); }
.about-lede { font-size: 1.05rem; color: var(--ab-muted); margin-top: 14px; max-width: 68ch; }
.about-cta-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.about-btn { display: inline-flex; align-items: center; padding: 10px 18px; border-radius: 10px; background: var(--ab-accent); color: #fff; text-decoration: none; font-weight: 600; font-size: 0.95rem; transition: transform .15s ease, box-shadow .15s ease; }
.about-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px -6px var(--ab-accent); }
.about-btn.ghost { background: transparent; color: var(--ab-accent); border: 1px solid var(--ab-border); }
.about-btn:focus-visible, .about-links a:focus-visible, .about-faq summary:focus-visible { outline: 2px solid var(--ab-accent); outline-offset: 2px; border-radius: 6px; }
.about-highlight { margin: 40px 0; padding: 22px 24px; background: var(--ab-surface); border: 1px solid var(--ab-border); border-left: 4px solid var(--ab-accent); border-radius: 12px; }
.about-highlight h2 { font-size: 1.15rem; margin: 0 0 8px; color: var(--ab-text); }
.about-highlight p { color: var(--ab-muted); margin: 0; }
.about-highlight strong { color: var(--ab-text); }
.about-h2 { font-size: 1.3rem; font-weight: 700; margin: 40px 0 16px; color: var(--ab-text); }
.about-features { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2,1fr); gap: 12px 28px; }
.about-features li { position: relative; padding-left: 26px; color: var(--ab-muted); font-size: 0.95rem; }
.about-features li::before { content: "\2713"; position: absolute; left: 0; top: 0; color: #15803d; font-weight: 700; }
:root[data-theme="dark"] .about-features li::before { color: #35c08a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .about-features li::before { color: #35c08a; } }
.about-features strong { color: var(--ab-text); }
.about-faq { display: flex; flex-direction: column; gap: 10px; }
.about-faq details { border: 1px solid var(--ab-border); border-radius: 10px; background: var(--ab-surface); overflow: hidden; }
.about-faq summary { cursor: pointer; padding: 14px 18px; font-weight: 600; color: var(--ab-text); list-style: none; position: relative; }
.about-faq summary::-webkit-details-marker { display: none; }
.about-faq summary::after { content: "+"; position: absolute; right: 18px; color: var(--ab-accent); font-weight: 700; }
.about-faq details[open] summary::after { content: "\2013"; }
.about-faq details p { padding: 0 18px 16px; margin: 0; color: var(--ab-muted); }
.about-links ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.about-links li { color: var(--ab-muted); }
.about-links a { color: var(--ab-accent); font-weight: 600; text-decoration: none; }
.about-links a:hover { text-decoration: underline; }
.about-foot { margin-top: 44px; padding-top: 20px; border-top: 1px solid var(--ab-border); font-size: 0.9rem; color: var(--ab-faint); }
.about-foot a { color: var(--ab-accent); text-decoration: none; }
@media (max-width: 640px) { .about-features { grid-template-columns: 1fr; } .tool-about { padding: 48px 18px 64px; } }
