/* Sistema visual das ferramentas — mesmo conjunto de tokens do portfólio. */

:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --accent: #2563eb;
    --accent-ink: #ffffff;
    --accent-rgb: 37, 99, 235;
    --danger: #dc2626;
    --font-sans: 'Inter', system-ui, sans-serif;
    --font-display: 'Space Grotesk', 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
    --radius: 16px;
}

[data-theme="dark"] {
    --bg: #081428;
    --surface: #0f203c;
    --surface-2: #0b1a33;
    --ink: #e2e8f8;
    --muted: #8b97b6;
    --line: #203458;
    --accent: #64ffda;
    --accent-ink: #061828;
    --accent-rgb: 100, 255, 218;
    --danger: #f87171;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color .3s ease, color .3s ease;
}

/* Fundo: brilho + grade sutil */
body::before, body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
}

body::before {
    background:
        radial-gradient(50rem 34rem at 85% -10%, rgba(var(--accent-rgb), .16), transparent 60%),
        radial-gradient(40rem 30rem at -10% 80%, rgba(99, 102, 241, .12), transparent 60%);
}

body::after {
    background-image:
        linear-gradient(var(--line) 1px, transparent 1px),
        linear-gradient(90deg, var(--line) 1px, transparent 1px);
    background-size: 56px 56px;
    opacity: .5;
    -webkit-mask-image: radial-gradient(ellipse 70% 50% at 50% 0%, #000 20%, transparent 75%);
    mask-image: radial-gradient(ellipse 70% 50% at 50% 0%, #000 20%, transparent 75%);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 10px; }
::selection { background: rgba(var(--accent-rgb), .3); }

/* ---------- Estrutura ---------- */
.topbar {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar .links { display: flex; align-items: center; gap: 18px; }

.back {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    transition: color .2s ease;
}
.back:hover { color: var(--accent); }

.back .logo {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: var(--accent);
    color: var(--accent-ink);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: .85rem;
}

.theme-btn {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 60%, transparent);
    color: var(--muted);
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: color .2s ease, border-color .2s ease;
}
.theme-btn:hover { color: var(--accent); border-color: rgba(var(--accent-rgb), .6); }
[data-theme="dark"] .icon-sun, [data-theme="light"] .icon-moon { display: none; }

.wrap {
    flex: 1;
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 8px 24px 56px;
}

.tool-head { padding: 36px 0 32px; max-width: 720px; }

.eyebrow {
    font-family: var(--font-mono);
    font-size: .75rem;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--accent);
}

h1 {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 3.25rem);
    line-height: 1.08;
    letter-spacing: -.02em;
    margin: 12px 0 0;
    text-wrap: balance;
}

.lead { margin: 14px 0 0; color: var(--muted); font-size: 1.05rem; max-width: 600px; }

h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    margin: 0 0 4px;
}

/* ---------- Painéis ---------- */
.panel {
    background: color-mix(in srgb, var(--surface) 72%, transparent);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 24px;
    backdrop-filter: blur(10px);
    box-shadow: 0 24px 48px -32px rgba(var(--accent-rgb), .18);
    transition: border-color .3s ease;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-aside { display: grid; grid-template-columns: 1.1fr .9fr; gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.mt { margin-top: 20px; }

/* ---------- Campos ---------- */
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.field > label, .label {
    font-family: var(--font-mono);
    font-size: .75rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

.control { position: relative; display: flex; }

textarea, input[type="text"], input[type="search"], select, .output {
    width: 100%;
    font: inherit;
    font-size: 1rem;
    color: var(--ink);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
    transition: border-color .2s ease, box-shadow .2s ease, background-color .3s ease;
}

textarea { min-height: 240px; resize: vertical; padding-right: 54px; }
textarea::placeholder, input::placeholder { color: var(--muted); opacity: .75; }

textarea:focus, input[type="text"]:focus, input[type="search"]:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(var(--accent-rgb), .15);
}

.output { min-height: 240px; white-space: pre-wrap; word-break: break-word; padding-right: 54px; }
.output .placeholder { color: var(--muted); opacity: .75; }

.mono { font-family: var(--font-mono); font-size: .9rem; }

input[type="color"] {
    appearance: none;
    -webkit-appearance: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-2);
    cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 4px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 8px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 8px; }

select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 40px;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

/* ---------- Botões ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 22px;
    font: inherit;
    font-size: .9rem;
    font-weight: 600;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 60%, transparent);
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
    transition: transform .25s ease, border-color .25s ease, color .25s ease, box-shadow .25s ease, opacity .25s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); border-color: rgba(var(--accent-rgb), .6); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 10px 24px -10px rgba(var(--accent-rgb), .55);
}
.btn-primary:hover:not(:disabled) { color: var(--accent-ink); box-shadow: 0 14px 28px -10px rgba(var(--accent-rgb), .7); }

.icon-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: color .2s ease, border-color .2s ease, opacity .2s ease;
}
.icon-btn:hover:not(:disabled) { color: var(--accent); border-color: rgba(var(--accent-rgb), .6); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn svg { width: 18px; height: 18px; display: block; }

/* ---------- Controle segmentado (rádios) ---------- */
.segmented {
    display: inline-flex;
    padding: 4px;
    gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
}
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span {
    display: block;
    padding: 8px 16px;
    border-radius: 9px;
    font-size: .875rem;
    font-weight: 500;
    color: var(--muted);
    transition: background-color .2s ease, color .2s ease;
}
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.segmented label:hover input:not(:checked) + span { color: var(--ink); }

/* ---------- Estatísticas ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.stat {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-2);
}
.stat .value {
    display: block;
    font-family: var(--font-display);
    font-size: 2.1rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}
.stat .name {
    display: block;
    margin-top: 6px;
    font-family: var(--font-mono);
    font-size: .72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

/* ---------- Tabela ---------- */
.table-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.table-head .field { flex: 1 1 260px; max-width: 380px; }

.table-wrapper {
    max-height: 420px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-2);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 18px; text-align: left; border-bottom: 1px solid var(--line); }
th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: .72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}
td { font-family: var(--font-mono); font-size: .9rem; }
td:first-child { font-family: var(--font-display); font-size: 1.15rem; color: var(--accent); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(var(--accent-rgb), .06); }

/* ---------- QR ---------- */
.qr-stage {
    display: grid;
    place-items: center;
    min-height: 320px;
    padding: 24px;
    border: 1px dashed var(--line);
    border-radius: 16px;
    background: var(--surface-2);
}
.qr-stage #qrcode { display: grid; place-items: center; max-width: 100%; border-radius: 14px; }
.qr-stage #qrcode[style*="padding"] { box-shadow: 0 16px 40px -20px rgba(0, 0, 0, .45); }
.qr-stage #qrcode img, .qr-stage #qrcode canvas { max-width: 100%; height: auto !important; }
.qr-empty { text-align: center; color: var(--muted); font-size: .95rem; }
.qr-empty svg { width: 72px; height: 72px; margin-bottom: 10px; opacity: .5; }

.color-field { flex-direction: row; align-items: center; gap: 12px; }
.color-field label { text-transform: none; letter-spacing: 0; font-family: var(--font-sans); font-size: .9rem; color: var(--ink); }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translate(-50%, 12px);
    max-width: calc(100vw - 32px);
    padding: 12px 20px;
    border-radius: 12px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    background: var(--surface);
    color: var(--ink);
    font-size: .9rem;
    box-shadow: 0 20px 40px -20px rgba(0, 0, 0, .5);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .3s ease, transform .3s ease, visibility .3s ease;
    z-index: 50;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* ---------- Rodapé ---------- */
.foot {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid var(--line);
    font-family: var(--font-mono);
    font-size: .8rem;
    color: var(--muted);
}
.foot a { color: var(--accent); text-decoration: none; }
.foot a:hover { text-decoration: underline; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Animação de entrada ---------- */
.reveal { opacity: 0; transform: translateY(16px); animation: rise .6s cubic-bezier(.2, .7, .2, 1) forwards; animation-delay: var(--d, 0ms); }
@keyframes rise { to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
    .reveal { animation: none; opacity: 1; transform: none; }
    html { scroll-behavior: auto; }
    .btn, .toast { transition: none; }
}

@media (max-width: 860px) {
    .grid-2, .grid-aside { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .topbar, .wrap, .foot { padding-left: 16px; padding-right: 16px; }
    .tool-head { padding: 24px 0 24px; }
    .panel { padding: 18px; }
    .topbar .back .label { display: none; }
    textarea, .output { min-height: 180px; }
    .segmented { width: 100%; }
    .segmented label { flex: 1; }
    .segmented span { text-align: center; padding: 8px 8px; }
}
