/*
   JWT DECODER — EXPERT WEB TOOLS
*/

@font-face { font-family: 'Inter';       src: url('/fonts/inter-v20-latin-regular.woff2') format('woff2');       font-weight: 400; font-display: swap; }
@font-face { font-family: 'Orbitron';    src: url('/fonts/orbitron-v35-latin-700.woff2') format('woff2');        font-weight: 700; font-display: swap; }
@font-face { font-family: 'Roboto Mono'; src: url('/fonts/roboto-mono-v31-latin-regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }

:root {
    --bg-dark:          #0a0a0f;
    --primary-accent:   #3b82f6;
    --text-main:        #ffffff;
    --text-muted:       #94a3b8;
    --card-bg:          rgba(25, 25, 35, 0.6);
    --card-border:      rgba(255, 255, 255, 0.08);
    --editor-bg:        #0d0d12;
    --input-bg:         rgba(255, 255, 255, 0.05);
    --faq-bg:           rgba(255, 255, 255, 0.03);
    --faq-hover:        rgba(255, 255, 255, 0.06);
    
    --color-header:     #ef4444;
    --color-payload:    #8b5cf6;
    --color-signature:  #06b6d4;
    
    --font-heading:     'Orbitron', sans-serif;
    --font-body:        'Inter', sans-serif;
    --font-code:        'Roboto Mono', monospace;
    --tooltip-bg:       #1e293b;
    --tooltip-text:     #f8fafc;
}

/* Light Theme Variables (Synchronized Architecture) */
html.light-theme {
    --bg-dark: #f8fafc;
    --card-bg: rgba(255, 255, 255, 0.9);
    --card-border: #cbd5e1;
    --editor-bg: #ffffff;
    --input-bg: #f1f5f9;
    --faq-bg: #ffffff;
    --faq-hover: #f8fafc;
    --text-main: #0f172a;
    --text-muted: #475569;
    --color-payload: #7c3aed;
    --color-signature: #0284c7;
    --tooltip-bg: #e2e8f0;
    --tooltip-text: #0f172a;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { width: 100%; max-width: 100vw; overflow-x: hidden; }

/* STRICT CHROMIUM BUG FIX: transition background-color only */
html, body { 
    background-color: var(--bg-dark); 
    transition: background-color 0.2s ease; 
}

body {
    color: var(--text-main); font-family: var(--font-body);
    min-height: 100vh; display: flex; flex-direction: column;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}

.background-glow {
    position: fixed; top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle at center, rgba(139,92,246,0.08) 0%, rgba(10,10,15,0) 50%);
    z-index: -1; pointer-events: none;
}
html.light-theme .background-glow { 
    background: radial-gradient(circle at center, rgba(139,92,246,0.15) 0%, rgba(248,250,252,0) 50%); 
}

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}

/* ── Header ─────────────────────────────────────────────────────────── */
.tool-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.5rem 5%; max-width: 1400px; margin: 0 auto; width: 100%;
}
.back-btn { color: var(--text-muted); text-decoration: none; display: flex; align-items: center; gap: 8px; transition: color 0.3s; }
.back-btn:hover { color: var(--primary-accent); }
.back-btn:focus-visible { outline: 2px solid var(--primary-accent); border-radius: 4px; }
.logo { font-family: var(--font-heading); font-size: 1.2rem; }
.logo span { color: var(--color-payload); }

/* Sync'd Theme Toggle Button */
.theme-toggle-btn { 
    background: var(--input-bg); border: 1px solid var(--card-border); 
    color: var(--text-main); width: 36px; height: 36px; border-radius: 8px; 
    cursor: pointer; display: flex; align-items: center; justify-content: center; 
    transition: all 0.2s ease;
}
.theme-toggle-btn:hover { border-color: var(--primary-accent); color: var(--primary-accent); }

.main-content { flex-grow: 1; padding: 2rem clamp(1rem, 5%, 5%); max-width: 1400px; margin: 0 auto; width: 100%; }
.tool-container {
    background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 16px; padding: 2rem; backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3); width: 100%; min-width: 0;
}
.tool-intro { text-align: center; margin-bottom: 2rem; }
.tool-intro h1 { font-family: var(--font-heading); margin-bottom: 0.5rem; font-size: clamp(1.4rem, 4vw, 2rem); }
.tool-intro p  { color: var(--text-muted); }

.jwt-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2rem; align-items: start; }
.input-section { display: flex; flex-direction: column; position: relative; min-width: 0; }
.input-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 6px; }
.input-header label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

.header-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
    background: transparent; border: none; color: var(--text-muted); cursor: pointer;
    display: flex; align-items: center; gap: 6px; font-size: 0.85rem;
    transition: color 0.2s, background 0.2s; padding: 6px 10px; border-radius: 6px;
}
.icon-btn:hover { color: var(--primary-accent); background: rgba(59,130,246,0.1); }
.icon-btn:focus-visible { outline: 2px solid var(--primary-accent); }
.icon-btn.small { padding: 4px 6px; font-size: 0.8rem; }

/* ── History Dropdown ────────────────────────────────────────────────── */
.history-dropdown-wrapper { position: relative; }
.history-menu {
    position: absolute; top: 100%; right: 0; margin-top: 8px; width: 260px;
    background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,0.5); z-index: 100;
    backdrop-filter: blur(10px);
}
.history-menu-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 12px; border-bottom: 1px solid var(--card-border);
    font-size: 0.8rem; font-weight: bold; color: var(--text-main);
}
.history-menu-header button {
    background: none; border: none; color: var(--text-muted); font-size: 0.75rem; cursor: pointer;
}
.history-menu-header button:hover { color: #ef4444; }
.history-list { list-style: none; max-height: 200px; overflow-y: auto; }
.history-list li {
    padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.05);
    font-family: var(--font-code); font-size: 0.75rem; cursor: pointer;
    color: var(--text-muted); word-break: break-all;
    transition: background 0.2s, color 0.2s;
}
.history-list li:last-child { border-bottom: none; }
.history-list li:hover:not(.history-empty) { background: var(--input-bg); color: var(--text-main); }
.history-empty { text-align: center; font-family: var(--font-body); color: var(--text-muted); cursor: default; }

#jwt-input {
    width: 100%; min-height: 200px; max-height: 550px; height: 550px;
    background: var(--editor-bg); border: 1px solid var(--card-border);
    color: var(--text-main); padding: 1.5rem; border-radius: 8px;
    font-family: var(--font-code); font-size: 16px;
    resize: vertical; outline: none; line-height: 1.5; word-break: break-all;
}
#jwt-input:focus { border-color: var(--primary-accent); }
#jwt-input:focus-visible { outline: 2px solid var(--primary-accent); }

.input-editor-wrapper { position: relative; }
.jwt-visualizer {
    position: absolute; inset: 0; background: var(--editor-bg); border: 1px solid var(--card-border);
    padding: 1.5rem; border-radius: 8px; font-family: var(--font-code); font-size: 16px;
    line-height: 1.5; word-break: break-all; cursor: text; overflow-y: auto; min-height: 200px;
}
.vis-header { color: var(--color-header); }
.vis-dot { color: var(--text-muted); }
.vis-payload { color: var(--color-payload); }
.vis-signature { color: var(--color-signature); }

.status-box {
    margin-top: 1rem; font-size: 0.85rem; color: var(--text-muted);
    background: var(--input-bg); padding: 10px; border-radius: 6px;
    display: flex; align-items: flex-start; gap: 8px; line-height: 1.4;
}
.status-box i { flex-shrink: 0; margin-top: 2px; }

.error-banner {
    background: rgba(239,68,68,0.1); color: #ef4444;
    border: 1px solid rgba(239,68,68,0.2); padding: 1rem; border-radius: 8px;
    margin-top: 1rem; font-size: 0.9rem; word-break: break-word; line-height: 1.5;
}
html.light-theme .error-banner { background: #fee2e2; color: #dc2626; border-color: #dc2626; }

.output-section { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.output-group {
    background: rgba(255,255,255,0.02); border: 1px solid var(--card-border);
    border-radius: 12px; padding: 1rem; transition: transform 0.2s, background 0.2s; min-width: 0;
}
html.light-theme .output-group { background: var(--input-bg); }
.output-group:hover { transform: translateX(5px); background: rgba(255,255,255,0.04); }
html.light-theme .output-group:hover { background: #e2e8f0; }

.header-group    { border-left: 4px solid var(--color-header); }
.payload-group   { border-left: 4px solid var(--color-payload); }
.signature-group { border-left: 4px solid var(--color-signature); }

.group-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem; gap: 6px; }
.header-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.group-header h3 { font-size: 1rem; font-weight: 600; font-family: var(--font-heading); color: var(--text-main); }

.badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 4px; font-weight: bold; text-transform: uppercase; white-space: nowrap; }
.badge.red    { background: rgba(239,68,68,0.2);  color: var(--color-header); }
.badge.violet { background: rgba(139,92,246,0.2); color: var(--color-payload); }
.badge.blue   { background: rgba(6,182,212,0.2);  color: var(--color-signature); }
.badge.gray   { background: rgba(148,163,184,0.2); color: var(--text-muted); }
.badge.green  { background: rgba(16,185,129,0.2); color: #10b981; }

.output-box {
    font-family: var(--font-code); font-size: 0.88rem; color: var(--text-muted);
    white-space: pre-wrap; word-break: break-all; margin: 0; line-height: 1.6; overflow-x: auto;
}

/* ── WebCrypto Signature Verification ────────────────────────────────── */
.verify-section { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--card-border); }
.verify-section label { display: block; font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.verify-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.verify-controls input {
    flex-grow: 1; min-width: 150px; background: var(--input-bg);
    border: 1px solid var(--card-border); color: var(--text-main); padding: 8px 12px;
    border-radius: 6px; font-family: var(--font-code); font-size: 0.85rem; outline: none;
    transition: border-color 0.2s;
}
.verify-controls input:focus { border-color: var(--color-signature); }

/* ── Syntax highlighting & Claims Tooltips ───────────────────────────── */
.json-key     { color: #60a5fa; }
.json-string  { color: #fb923c; }
.json-number  { color: #4ade80; }
.json-boolean { color: #c084fc; }
.json-null    { color: #f472b6; }

html.light-theme .json-key { color: #2563eb; }
html.light-theme .json-string { color: #ea580c; }
html.light-theme .json-number { color: #16a34a; }
html.light-theme .json-boolean { color: #9333ea; }
html.light-theme .json-null { color: #db2777; }

.claim-tooltip {
    text-decoration: underline dashed; text-underline-offset: 4px;
    cursor: help; position: relative; display: inline-block;
}
.claim-tooltip:hover::after {
    content: attr(data-desc); position: absolute; bottom: 120%; left: 50%; transform: translateX(-50%);
    background: var(--tooltip-bg); color: var(--tooltip-text); font-family: var(--font-body);
    padding: 6px 10px; border-radius: 6px; font-size: 0.75rem; white-space: nowrap;
    z-index: 10; box-shadow: 0 4px 6px rgba(0,0,0,0.3); font-weight: normal; letter-spacing: normal;
}
.claim-tooltip:hover::before {
    content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
    border: 5px solid transparent; border-top-color: var(--tooltip-bg); z-index: 10;
}

.ts-badge {
    display: inline-flex; align-items: center; gap: 4px;
    background: var(--input-bg); color: var(--text-muted);
    font-size: 0.72rem; padding: 1px 7px; border-radius: 4px; margin-left: 8px;
    font-family: var(--font-body); border: 1px solid var(--card-border);
    white-space: nowrap; vertical-align: middle; cursor: help;
}

.expiry-valid   { color: #10b981; font-weight: 600; }
.expiry-expired { color: #ef4444; font-weight: 600; }

.color-header    { color: var(--color-header); }
.color-payload   { color: var(--color-payload); }
.color-signature { color: var(--color-signature); }

.toast {
    display: block; position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: #1e1e24; border: 1px solid var(--primary-accent); color: #fff;
    padding: 10px 20px; border-radius: 8px; z-index: 2000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5); transition: opacity 0.3s;
    font-size: 0.9rem; pointer-events: none; max-width: calc(100vw - 2rem); text-align: center;
}
html.light-theme .toast { background: #ffffff; color: #0f172a; border-color: var(--primary-accent); }
.hidden { display: none !important; opacity: 0; pointer-events: none; }

/* ── Info & FAQ Sections ─────────────────────────────────────────────── */
.info-section { margin-top: 4rem; padding: 0 1rem; width: 100%; }
.info-section h2 { font-family: var(--font-heading); margin-bottom: 2rem; color: var(--text-main); font-size: 1.5rem; text-align: center; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 2rem; margin-bottom: 2rem; }
.info-grid h3 { color: var(--primary-accent); margin-bottom: 0.5rem; font-family: var(--font-heading); font-size: 1rem; }
.info-grid i { margin-right: 8px; }
.info-grid p { color: var(--text-muted); font-size: 0.9rem; line-height: 1.6; }
.info-grid strong { font-weight: 600; }

.faq-section { margin-top: 4rem; padding: 0 1rem; width: 100%; max-width: 800px; margin-left: auto; margin-right: auto; }
.faq-section h2 { font-family: var(--font-heading); margin-bottom: 2rem; color: var(--text-main); font-size: 1.5rem; text-align: center; }
.faq-item {
    background: var(--faq-bg); border: 1px solid var(--card-border); border-radius: 8px;
    margin-bottom: 1rem; overflow: hidden; transition: background 0.2s;
}
.faq-item:hover { background: var(--faq-hover); }
.faq-item summary {
    padding: 1.25rem; font-weight: 600; font-size: 1rem; color: var(--text-main);
    cursor: pointer; list-style: none; position: relative; user-select: none; outline: none;
    display: flex; justify-content: space-between; align-items: center;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
    content: '+'; color: var(--primary-accent); font-family: var(--font-code);
    font-size: 1.25rem; font-weight: normal; transition: transform 0.2s;
}
.faq-item[open] summary::after { content: '−'; transform: rotate(90deg); }
.faq-item summary:focus-visible { box-shadow: inset 0 0 0 2px var(--primary-accent); border-radius: 8px; }
.faq-content { padding: 0 1.25rem 1.25rem 1.25rem; color: var(--text-muted); font-size: 0.95rem; line-height: 1.6; border-top: 1px solid transparent; }
.faq-item[open] .faq-content { border-top-color: var(--card-border); padding-top: 1rem; }

footer { text-align: center; padding: 3rem 0; color: var(--text-muted); font-size: 0.9rem; border-top: 1px solid var(--card-border); margin-top: 3rem; }
footer a       { color: var(--text-main); text-decoration: none; }
footer a:hover { color: var(--primary-accent); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; } }
@media (max-width: 900px) { .jwt-layout { grid-template-columns: 1fr; gap: 1.5rem; } .input-editor-wrapper { min-height: 180px; } #jwt-input, .jwt-visualizer { height: 220px; min-height: 160px; max-height: 280px; } }
@media (max-width: 600px) { .tool-header, .main-content { padding: 1rem; } .tool-container { padding: 1rem; border-radius: 12px; } .info-section, .faq-section { padding: 0; } .output-box { font-size: 0.8rem; } }
@media (max-width: 380px) { .tool-intro h1 { font-size: 1.2rem; } .tool-container { padding: 0.75rem; } .group-header { flex-direction: column; align-items: flex-start; } .faq-item summary { font-size: 0.9rem; } }