/* JWT Decoder (/jwt-decoder): only what is the app's own (the coloured token box, the part labels, the JSON colours,
   the status row and the verdict). Panels, tiles, fields, buttons, tables and colours come from the app kit
   (css/app-kit, docs/app-kit.md). Loaded only on this app's page (StylePaths in its demo catalog entry). */

/* On a phone the site's photo-app rule sets align-items: start on every stage, which beats the kit's stretch. */
.jwt-decoder-landing-app > .ak-stage > *,
.jwt-decoder-landing-app .jd-view > * {
    align-self: stretch;
    min-width: 0;
}

/* The part colours, as jwt.io made them familiar: header pink, payload purple, signature cyan. */
.jwt-decoder-landing-app {
    --jd-header: var(--ak-series-5);
    --jd-payload: var(--ak-series-4);
    --jd-signature: var(--ak-series-6);
    --jd-string: var(--ak-success);
    --jd-number: var(--ak-series-1);
    --jd-boolean: var(--ak-series-2);
}

.jwt-decoder-landing-app [hidden] {
    display: none !important;
}

.jwt-decoder-landing-app .jd-tabs {
    align-self: flex-start;
}

.jwt-decoder-landing-app .jd-view {
    display: flex;
    flex-direction: column;
    gap: var(--ak-space-4);
    min-width: 0;
}

.jwt-decoder-landing-app .jd-token-panel,
.jwt-decoder-landing-app .jd-part {
    gap: var(--ak-space-3);
    min-width: 0;
}

/* --- The token box: a text area over a coloured copy of its text --------------------------------------------------- */
/* Both sit in one grid cell with the same font, padding and wrapping; the copy sets the height, the text area's own
   text is transparent, so the colours show through while the caret and selection stay the text area's. */

.jwt-decoder-landing-app .jd-token {
    position: relative;
    display: grid;
    max-height: 22rem;
    overflow: auto;
    border: 1px solid var(--ak-border);
    border-radius: var(--ak-radius-sm);
    background: var(--ak-field);
}

.jwt-decoder-landing-app .jd-token:focus-within {
    border-color: var(--ak-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ak-accent) 22%, transparent);
}

.jwt-decoder-landing-app .jd-token-hl,
.jwt-decoder-landing-app .jd-token-input {
    grid-area: 1 / 1;
    box-sizing: border-box;
    width: 100%;
    min-height: 6.5rem;
    margin: 0;
    padding: 0.7rem 2.6rem 0.7rem 0.8rem;
    border: 0;
    font-family: var(--ak-font-mono);
    font-size: var(--ak-fs-sm);
    font-weight: 400;
    line-height: 1.6;
    letter-spacing: 0;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-wrap: anywhere;
    tab-size: 4;
}

.jwt-decoder-landing-app .jd-token-hl {
    color: var(--ak-text);
    pointer-events: none;
}

.jwt-decoder-landing-app .jd-token-input {
    height: 100%;
    overflow: hidden;
    resize: none;
    outline: none;
    background: transparent;
    color: transparent;
    caret-color: var(--ak-text);
    -webkit-text-fill-color: transparent;
}

.jwt-decoder-landing-app .jd-token-input::placeholder {
    color: var(--ak-muted);
    -webkit-text-fill-color: var(--ak-muted);
}

.jwt-decoder-landing-app .jd-token-input::selection {
    background: color-mix(in srgb, var(--ak-accent) 30%, transparent);
}

.jwt-decoder-landing-app .jd-token-copy {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
}

.jwt-decoder-landing-app .jd-p1 { color: var(--jd-header); }
.jwt-decoder-landing-app .jd-p2 { color: var(--jd-payload); }
.jwt-decoder-landing-app .jd-p3 { color: var(--jd-signature); }
.jwt-decoder-landing-app .jd-p4 { color: var(--ak-muted); }

.jwt-decoder-landing-app .jd-dot {
    color: var(--ak-text);
    font-weight: 700;
}

/* The signed token on the Encode tab. */
.jwt-decoder-landing-app .jd-token-out {
    margin: 0;
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--ak-border);
    border-radius: var(--ak-radius-sm);
    background: var(--ak-field);
    font-family: var(--ak-font-mono);
    font-size: var(--ak-fs-sm);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-wrap: anywhere;
    text-align: left;
}

/* --- Status row: alg, expiry (live), verdict ------------------------------------------------------------------------ */

.jwt-decoder-landing-app .jd-status {
    gap: 0.4rem 0.9rem;
}

.jwt-decoder-landing-app .jd-status .ak-tag {
    font-size: var(--ak-fs-sm);
}

.jwt-decoder-landing-app .jd-alg,
.jwt-decoder-landing-app .jd-typ {
    font-family: var(--ak-font-mono);
}

.jwt-decoder-landing-app .jd-time {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    color: var(--ak-text);
}

/* --- Part labels and JSON -------------------------------------------------------------------------------------------- */

.jwt-decoder-landing-app .jd-part-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ak-space-2);
    min-width: 0;
}

.jwt-decoder-landing-app .jd-part-name {
    --jd-c: var(--ak-accent);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--jd-c);
    font-size: var(--ak-fs-sm);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.jwt-decoder-landing-app .jd-part-name::before {
    content: "";
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    background: currentColor;
}

.jwt-decoder-landing-app .jd-part--header { border-top: 3px solid var(--jd-header); }
.jwt-decoder-landing-app .jd-part--payload { border-top: 3px solid var(--jd-payload); }
.jwt-decoder-landing-app .jd-part--signature { border-top: 3px solid var(--jd-signature); }
.jwt-decoder-landing-app .jd-part--header .jd-part-name { --jd-c: var(--jd-header); }
.jwt-decoder-landing-app .jd-part--payload .jd-part-name { --jd-c: var(--jd-payload); }
.jwt-decoder-landing-app .jd-part--signature .jd-part-name { --jd-c: var(--jd-signature); }

.jwt-decoder-landing-app .jd-json {
    max-height: 22rem;
    text-align: left;
}

.jwt-decoder-landing-app .jd-jk { color: var(--ak-text); font-weight: 600; }
.jwt-decoder-landing-app .jd-js { color: var(--jd-string); }
.jwt-decoder-landing-app .jd-jn { color: var(--jd-number); }
.jwt-decoder-landing-app .jd-jb { color: var(--jd-boolean); }
.jwt-decoder-landing-app .jd-jz { color: var(--ak-muted); font-style: italic; }

.jwt-decoder-landing-app .jd-alg-name {
    color: var(--ak-muted);
    font-family: var(--ak-font-mono);
    font-size: var(--ak-fs-sm);
}

/* --- Claims ------------------------------------------------------------------------------------------------------------ */

.jwt-decoder-landing-app .jd-claims th,
.jwt-decoder-landing-app .jd-claims td {
    vertical-align: top;
}

.jwt-decoder-landing-app .jd-claim-name {
    font-family: var(--ak-font-mono);
    color: var(--jd-payload);
    font-weight: 700;
}

.jwt-decoder-landing-app .jd-claim-value {
    min-width: 11rem;
}

.jwt-decoder-landing-app .jd-claim-value > span,
.jwt-decoder-landing-app .jd-claim-value > code {
    display: block;
}

.jwt-decoder-landing-app .jd-claim-date {
    font-weight: 600;
}

.jwt-decoder-landing-app .jd-claim-rel {
    font-size: var(--ak-fs-xs);
}

.jwt-decoder-landing-app .jd-claim-raw,
.jwt-decoder-landing-app .jd-claim-text {
    font-family: var(--ak-font-mono);
    font-size: var(--ak-fs-xs);
    overflow-wrap: anywhere;
}

.jwt-decoder-landing-app .jd-claim-raw {
    color: var(--ak-muted);
}

.jwt-decoder-landing-app .jd-claim-text {
    font-size: var(--ak-fs-sm);
}

.jwt-decoder-landing-app .jd-claim-meaning {
    color: var(--ak-muted);
    font-size: var(--ak-fs-sm);
}

/* --- Signature: secret or key, and the verdict ------------------------------------------------------------------------ */

.jwt-decoder-landing-app .jd-verify-fields {
    display: flex;
    flex-direction: column;
    gap: var(--ak-space-2);
    min-width: 0;
}

.jwt-decoder-landing-app .jd-label {
    color: var(--ak-text);
    font-size: var(--ak-fs-sm);
    font-weight: 600;
}

.jwt-decoder-landing-app input.jd-secret.ak-field {
    font-family: var(--ak-font-mono);
}

.jwt-decoder-landing-app textarea.jd-key.ak-editor,
.jwt-decoder-landing-app textarea.jd-enc-json.ak-editor {
    min-height: 0;
    text-align: left;
}

.jwt-decoder-landing-app textarea.jd-enc-json.ak-editor {
    flex: 1 1 auto;
}

.jwt-decoder-landing-app .jd-verdict {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin: 0;
    padding: 0.6rem 0.8rem;
    border-radius: var(--ak-radius-sm);
    font-weight: 600;
    --jd-v: var(--ak-muted);
    border: 1px solid color-mix(in srgb, var(--jd-v) 40%, var(--ak-border));
    background: color-mix(in srgb, var(--jd-v) 10%, var(--ak-panel));
    color: color-mix(in srgb, var(--jd-v) 70%, var(--ak-text));
}

.jwt-decoder-landing-app .jd-verdict.is-ok { --jd-v: var(--ak-success); }
.jwt-decoder-landing-app .jd-verdict.is-bad { --jd-v: var(--ak-danger); }
.jwt-decoder-landing-app .jd-verdict.is-warn { --jd-v: var(--ak-warning); }
.jwt-decoder-landing-app .jd-verdict.is-idle { font-weight: 500; }

.jwt-decoder-landing-app .jd-vi {
    display: none;
    flex: none;
    color: var(--jd-v);
}

.jwt-decoder-landing-app .jd-verdict.is-ok .jd-vi--ok,
.jwt-decoder-landing-app .jd-verdict.is-bad .jd-vi--bad,
.jwt-decoder-landing-app .jd-verdict.is-idle .jd-vi--idle,
.jwt-decoder-landing-app .jd-verdict.is-warn .jd-vi--warn {
    display: inline-flex;
}

.jwt-decoder-landing-app .jd-verdict-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.jwt-decoder-landing-app .jd-weak {
    color: var(--ak-warning);
    font-size: var(--ak-fs-sm);
    font-weight: 500;
}

.jwt-decoder-landing-app .jd-sample-note {
    margin: 0;
}

.jwt-decoder-landing-app .jd-enc-tools {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

/* RTL: the token, JSON and keys stay left to right, so the copy button keeps its corner; in the claims table the
   left-to-right values still sit on the cell's start side. */
[dir="rtl"] .jwt-decoder-landing-app .jd-claim-raw,
[dir="rtl"] .jwt-decoder-landing-app .jd-claim-text {
    text-align: right;
}

[dir="rtl"] .jwt-decoder-landing-app .jd-token-hl,
[dir="rtl"] .jwt-decoder-landing-app .jd-token-input {
    direction: ltr;
}

/* On a phone the meaning moves under the value (a copy kept in the value cell), so the table has two columns. */
.jwt-decoder-landing-app .jd-claim-value > .jd-claim-meaning-sm {
    display: none;
    margin-top: 0.2rem;
    color: var(--ak-muted);
    font-size: var(--ak-fs-xs);
}

@media (max-width: 640px) {
    .jwt-decoder-landing-app .jd-claims thead th:nth-child(3),
    .jwt-decoder-landing-app .jd-claims td.jd-claim-meaning {
        display: none;
    }

    .jwt-decoder-landing-app .jd-claim-value > .jd-claim-meaning-sm {
        display: block;
    }

    .jwt-decoder-landing-app .jd-claim-value {
        min-width: 0;
    }
}
