/* ──────────────────────────────────────────────────────────────────────────
   Docum · Design System v2
   Vibe AI-first / futurista · tema claro e escuro premium
   ────────────────────────────────────────────────────────────────────────── */

:root {
    /* Paleta */
    --color-primary: #7c3aed;        /* violet-600 */
    --color-primary-dark: #6d28d9;
    --color-primary-soft: #ede9fe;
    --color-accent: #06b6d4;          /* cyan-500 */
    --color-accent-dark: #0891b2;
    --color-cta: #06b6d4;
    --color-cta-dark: #0891b2;
    --color-cta-soft: #cffafe;

    /* Surfaces */
    --color-bg: #fafaff;
    --color-bg-elev: #ffffff;
    --color-surface: #ffffff;
    --color-surface-2: #f5f5fb;
    --color-border: #e7e7f0;
    --color-border-strong: #d1d1e0;

    /* Texto */
    --color-text: #0a0a1e;
    --color-text-soft: #4a4a66;
    --color-muted: #6b6b85;

    /* Semânticos */
    --color-success: #10b981;
    --color-warn: #f59e0b;
    --color-danger: #ef4444;

    /* Toasts */
    --toast-success-bg: #ecfdf5;
    --toast-success-fg: #065f46;
    --toast-error-bg: #fef2f2;
    --toast-error-fg: #991b1b;
    --toast-warn-bg: #fffbeb;
    --toast-warn-fg: #92400e;

    --disclaimer-bg: #fffbeb;
    --disclaimer-fg: #78350f;
    --code-bg: #f3f4f6;

    /* Gradientes (string puro pra usar em backgrounds) */
    --gradient-brand: linear-gradient(135deg, #7c3aed 0%, #06b6d4 100%);
    --gradient-brand-soft: linear-gradient(135deg, #ede9fe 0%, #cffafe 100%);
    --gradient-mesh: radial-gradient(at 27% 37%, #a78bfa 0px, transparent 50%),
                     radial-gradient(at 97% 21%, #67e8f9 0px, transparent 50%),
                     radial-gradient(at 52% 99%, #c4b5fd 0px, transparent 50%),
                     radial-gradient(at 10% 89%, #06b6d4 0px, transparent 50%);
    --gradient-mesh-dark: radial-gradient(at 27% 37%, #6d28d9 0px, transparent 50%),
                          radial-gradient(at 97% 21%, #0e7490 0px, transparent 50%),
                          radial-gradient(at 52% 99%, #4c1d95 0px, transparent 50%),
                          radial-gradient(at 10% 89%, #0891b2 0px, transparent 50%);

    /* Glow ring (para hover de cards / botões) */
    --glow-primary: 0 0 0 1px rgba(124, 58, 237, 0.4), 0 0 40px -8px rgba(124, 58, 237, 0.6);
    --glow-accent: 0 0 0 1px rgba(6, 182, 212, 0.4), 0 0 40px -8px rgba(6, 182, 212, 0.6);

    /* Sombras refinadas */
    --shadow-sm: 0 1px 2px rgba(15, 15, 30, 0.04), 0 1px 3px rgba(15, 15, 30, 0.06);
    --shadow-md: 0 4px 12px -2px rgba(15, 15, 30, 0.05), 0 4px 24px -4px rgba(15, 15, 30, 0.08);
    --shadow-lg: 0 12px 32px -8px rgba(15, 15, 30, 0.08), 0 24px 64px -12px rgba(15, 15, 30, 0.12);
    --shadow-glow-primary: 0 8px 32px -8px rgba(124, 58, 237, 0.4);
    --shadow-glow-accent: 0 8px 32px -8px rgba(6, 182, 212, 0.4);
}

/* DARK MODE — ativado por classe `dark` no <html> via toggle (localStorage) */
html.dark {
    --color-bg: #06060f;
    --color-bg-elev: #0c0c1a;
    --color-surface: #0e0e1c;
    --color-surface-2: #14142a;
    --color-border: #1f1f33;
    --color-border-strong: #2d2d47;
    --color-text: #f5f5fb;
    --color-text-soft: #c4c4d8;
    --color-muted: #8a8aa8;
    --color-primary-soft: #2d1b69;
    --color-cta-soft: #0e4658;

    --toast-success-bg: #052e1f;
    --toast-success-fg: #6ee7b7;
    --toast-error-bg: #3a0a0a;
    --toast-error-fg: #fecaca;
    --toast-warn-bg: #3a1f04;
    --toast-warn-fg: #fde68a;

    --disclaimer-bg: #2a1a04;
    --disclaimer-fg: #fcd34d;
    --code-bg: #1a1a2e;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.4), 0 4px 24px -4px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 32px -8px rgba(0, 0, 0, 0.5), 0 24px 64px -12px rgba(0, 0, 0, 0.6);
}

/* Body usa variáveis — todos os components herdam */
body {
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App shell autenticado: body recebe class .app-shell via Razor (_Layout.cshtml
   linha ~85, condicional em isAuthenticated). Trava o body em 100dvh com
   overflow hidden — o ÚNICO scroll fica no <main>. Sem isso, em algumas
   páginas o body crescia além do viewport (race do Tailwind CDN injetando
   preflight depois do site.css, whitespace de @section, etc.) — sintoma
   visível: faixa cinza vazia depois do conteúdo. */
body.app-shell {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Garante que o main scrollável NÃO crie scroll horizontal acidental
   (alguns componentes do Tailwind, como flex sem wrap em mobile, geram
   overflow-x e a página inteira saca scroll lateral indesejado). */
body.app-shell main.da-scroll-area {
    overflow-x: hidden;
}

html.dark body { background: var(--color-bg) !important; color: var(--color-text); }
html.dark .bg-white { background: var(--color-surface) !important; }
html.dark .bg-gray-50 { background: var(--color-bg) !important; }
html.dark .bg-gray-100 { background: var(--color-surface-2) !important; }
html.dark .border-gray-100,
html.dark .border-gray-200,
html.dark .border-gray-300 { border-color: var(--color-border) !important; }
html.dark .text-gray-900 { color: var(--color-text) !important; }
html.dark .text-gray-800 { color: var(--color-text-soft) !important; }
html.dark .text-gray-700 { color: var(--color-text-soft) !important; }
html.dark .text-gray-600,
html.dark .text-gray-500,
html.dark .text-gray-400 { color: var(--color-muted) !important; }
html.dark .hover\:bg-gray-50:hover { background: var(--color-surface-2) !important; }
html.dark .hover\:bg-gray-100:hover { background: #1f1f33 !important; }
html.dark input,
html.dark textarea,
html.dark select {
    background: var(--color-surface-2) !important;
    color: var(--color-text) !important;
    border-color: var(--color-border) !important;
}
html.dark input::placeholder,
html.dark textarea::placeholder { color: var(--color-muted) !important; }

/* ──────────────────────────────────────────────────────────────────────────
   ANIMAÇÕES
   ────────────────────────────────────────────────────────────────────────── */

@keyframes gradient-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes mesh-drift {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(2%, -2%) scale(1.05); }
    66% { transform: translate(-2%, 2%) scale(0.95); }
}

@keyframes float-y {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0.5); }
    70% { box-shadow: 0 0 0 12px rgba(124, 58, 237, 0); }
    100% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0); }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes scan-line {
    0% { transform: translateY(0); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateY(100%); opacity: 0; }
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes slide-in-up {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes glow-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Classes utilitárias de animação */
.da-mesh-bg {
    background: var(--gradient-mesh);
    background-size: 200% 200%;
    animation: mesh-drift 18s ease-in-out infinite;
    filter: blur(60px);
    opacity: 0.6;
}
html.dark .da-mesh-bg {
    background: var(--gradient-mesh-dark);
    background-size: 200% 200%;
    opacity: 0.5;
}

.da-float { animation: float-y 6s ease-in-out infinite; }
.da-float-slow { animation: float-y 9s ease-in-out infinite; }

.da-pulse-ring { animation: pulse-ring 2.4s ease-out infinite; }

.da-shimmer {
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
}
html.dark .da-shimmer {
    background: linear-gradient(
        90deg,
        transparent,
        rgba(124, 58, 237, 0.2),
        transparent
    );
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
}

.da-gradient-text {
    background: var(--gradient-brand);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.da-blink-cursor::after {
    content: '▍';
    color: var(--color-primary);
    animation: blink 1s step-end infinite;
    margin-left: 2px;
}

.da-rise { animation: slide-in-up 0.6s cubic-bezier(0.16, 1, 0.3, 1) both; }
.da-rise-1 { animation-delay: 0.05s; }
.da-rise-2 { animation-delay: 0.15s; }
.da-rise-3 { animation-delay: 0.25s; }
.da-rise-4 { animation-delay: 0.35s; }

/* Botão "primary tech" — gradiente com glow no hover */
.da-btn-primary {
    background: var(--gradient-brand);
    color: white;
    font-weight: 600;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}
.da-btn-primary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #06b6d4 0%, #7c3aed 100%);
    opacity: 0;
    transition: opacity 0.3s;
}
.da-btn-primary > * { position: relative; z-index: 1; }
.da-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow-primary);
}
.da-btn-primary:hover::before { opacity: 1; }
.da-btn-primary:active { transform: translateY(0); }

/* Botão "ghost tech" — border-only com hover sutil */
.da-btn-ghost {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    font-weight: 500;
    transition: all 0.2s;
}
.da-btn-ghost:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    transform: translateY(-1px);
}

/* Card "tech" — borda sutil, hover com glow primary */
.da-card-tech {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}
.da-card-tech::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: var(--gradient-brand);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.da-card-tech:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.da-card-tech:hover::before { opacity: 1; }

/* Input "tech" — border sutil, ring no foco.
   Double-class (.da-input.da-input) pra vencer o preflight do Tailwind CDN
   que injeta <style> APÓS o link do site.css e zera padding/border de input. */
.da-input.da-input {
    width: 100%;
    padding-top: 0.875rem;
    padding-bottom: 0.875rem;
    padding-left: 1rem;
    padding-right: 1rem;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    font-size: 0.9375rem;
    line-height: 1.4;
    transition: all 0.18s;
}
.da-input.da-input:hover { border-color: var(--color-border-strong); }
.da-input.da-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}
.da-input::placeholder { color: var(--color-muted); }

/* Variantes com ícone à esquerda/direita — abrem espaço pra glyph do lucide. */
.da-input.da-input.has-icon-left { padding-left: 2.75rem; }
.da-input.da-input.has-icon-right { padding-right: 2.75rem; }

/* Label tech — uppercase + tracking + cor suave */
.da-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-soft);
    margin-bottom: 0.5rem;
}

/* Chip / badge tech */
.da-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-text-soft);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.da-chip-brand {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.1) 0%, rgba(6, 182, 212, 0.1) 100%);
    border-color: rgba(124, 58, 237, 0.3);
    color: var(--color-primary);
}

/* Mockup tech (janela falsa) */
.da-window-chrome {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--color-surface-2);
    border-bottom: 1px solid var(--color-border);
}
.da-window-dot {
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 50%;
}

/* Linha de scan animada (overlay para mockup processando) */
.da-scan {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
    box-shadow: 0 0 12px var(--color-primary);
    animation: scan-line 2.5s ease-in-out infinite;
}

/* Toasts */
.da-toast-success { background: var(--toast-success-bg); color: var(--toast-success-fg); border-left: 4px solid var(--color-success); }
.da-toast-error { background: var(--toast-error-bg); color: var(--toast-error-fg); border-left: 4px solid var(--color-danger); }
.da-toast-warn { background: var(--toast-warn-bg); color: var(--toast-warn-fg); border-left: 4px solid var(--color-warn); }

/* Field error inline */
.field-error { color: var(--color-danger); font-size: 0.85rem; margin-top: 0.25rem; display: block; }

/* Disclaimer (jurídico) */
.da-disclaimer {
    background: var(--disclaimer-bg);
    border-left: 4px solid var(--color-warn);
    padding: 0.875rem 1rem;
    border-radius: 6px;
    color: var(--disclaimer-fg);
    font-size: 0.9rem;
}

.markdown-body { line-height: 1.6; color: var(--color-text); }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin-top: 1.5rem; margin-bottom: 0.5rem; font-weight: 600; }
.markdown-body h1 { font-size: 1.4rem; }
.markdown-body h2 { font-size: 1.2rem; color: var(--color-primary-dark); }
.markdown-body h3 { font-size: 1.05rem; }
.markdown-body p { margin-bottom: 0.75rem; }
.markdown-body ul, .markdown-body ol { margin: 0.5rem 0 0.75rem 1.5rem; }
.markdown-body code { background: var(--code-bg); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
.markdown-body blockquote { border-left: 3px solid var(--color-border-strong); padding-left: 0.75rem; margin: 0.5rem 0; color: var(--color-muted); }

/* HTMX htmx-indicator */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

/* ========================================================================
   IMPRESSÃO — esconde sidebar, header, toolbars; mantém só o conteúdo do
   documento. Usado em /Studio/Edit (PDF do documento gerado) e
   /Analyses/Details (parecer da análise). Classes .no-print e .print-only
   permitem controle granular.
   ======================================================================== */
@media print {
    /* App shell — sidebar + header + footer somem ao imprimir */
    aside, header, footer, .no-print { display: none !important; }

    /* Wrapper flex h-screen overflow-hidden vira layout normal pra impressão */
    body, html { background: white !important; height: auto !important; overflow: visible !important; }
    body > div.flex.h-screen, body > div.flex.h-screen > div { display: block !important; height: auto !important; overflow: visible !important; }

    /* Main content sem padding desnecessário */
    main { overflow: visible !important; }
    main > div { max-width: none !important; padding: 0 !important; margin: 0 !important; }

    /* Elementos só de impressão (escondidos no app, visíveis no PDF do browser) */
    .print-only { display: block !important; }

    /* Quebras de página inteligentes */
    h1, h2, h3 { page-break-after: avoid; break-after: avoid; }
    blockquote, pre, table { page-break-inside: avoid; break-inside: avoid; }

    /* Toasts/banners/modais nunca aparecem em print */
    [x-cloak], .da-toast-success, .da-toast-error { display: none !important; }

    /* EasyMDE editor — só queremos o conteúdo, não a toolbar nem o textarea */
    .EasyMDEContainer { display: none !important; }

    /* Prose styles pro conteúdo impresso */
    .prose { max-width: none !important; color: #000 !important; }
    .prose h1, .prose h2, .prose h3 { color: #000 !important; }
    .prose a { color: #000 !important; text-decoration: underline; }

    /* Tipografia legível em papel */
    body { font-size: 11pt; line-height: 1.5; color: #000; }
    @page { margin: 18mm 16mm; }
}

/* Smooth scrolling */
html { scroll-behavior: smooth; }

/* Scrollbar customizado */
.da-scroll-area::-webkit-scrollbar { width: 6px; height: 6px; }
.da-scroll-area::-webkit-scrollbar-thumb { background: var(--color-border-strong); border-radius: 3px; }
.da-scroll-area::-webkit-scrollbar-thumb:hover { background: var(--color-muted); }

/* RESPONSIVIDADE — mobile/tablet */
@media (max-width: 768px) {
    .da-responsive-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .da-responsive-table table { min-width: 600px; }
}

/* Reduce motion para usuários sensíveis */
@media (prefers-reduced-motion: reduce) {
    .da-mesh-bg,
    .da-float,
    .da-float-slow,
    .da-pulse-ring,
    .da-shimmer,
    .da-scan,
    .da-rise { animation: none !important; }
}

/* Acessibilidade: foco visível */
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Barra de progresso indeterminada (upload sem % conhecido / esteira deslizando).
   Usada no overlay de envio do Start e no war-room de execução. */
@keyframes da-indeterminate {
    0%   { left: -33%; }
    100% { left: 100%; }
}

/* Mobile: toda tabela larga vira rolável horizontalmente em vez de estourar o
   layout (~380px). display:block + overflow-x é o padrão pra <table> responsiva
   sem mexer em 19 markups. Em telas >=640px volta ao normal. */
@media (max-width: 639px) {
    table.w-full {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
