/* ============================================================
   Acqua Revisa — CSS Principal
   Brand: Emerald primary, Lime accent, dark green backgrounds
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Poppins:wght@600;700;800&display=swap');

/* ── Custom Properties — Modo Claro ──────────────────────── */
:root {
    /* Cores primárias */
    --primary:            hsl(161, 100%, 33%);   /* #00A878 Emerald */
    --primary-glow:       hsl(161, 80%, 45%);    /* #19C98E */
    --primary-foreground: hsl(0, 0%, 100%);
    --accent:             hsl(75, 76%, 59%);     /* #C8E645 Lime */

    /* Cores de suporte */
    --coral:              hsl(11, 78%, 57%);     /* #E8593C */
    --warning:            hsl(45, 93%, 55%);     /* #F5C518 Amber */
    --success:            hsl(161, 100%, 33%);   /* mesmo que primary */
    --info:               hsl(200, 80%, 50%);    /* #0A9FD8 Sky */
    --destructive:        hsl(11, 78%, 57%);

    /* Fundo e superfícies — modo claro */
    --background:         hsl(156, 33%, 97%);    /* verde-gelo quase branco */
    --foreground:         hsl(168, 41%, 9%);     /* texto escuro */
    --card:               hsl(0, 0%, 100%);
    --card-foreground:    hsl(168, 41%, 9%);
    --muted:              hsl(156, 30%, 94%);
    --muted-foreground:   hsl(165, 24%, 38%);
    --border:             hsl(162, 38%, 87%);
    --input:              hsl(162, 38%, 87%);
    --ring:               hsl(161, 100%, 33%);

    /* Sidebar — modo claro */
    --sidebar:            hsl(0, 0%, 100%);
    --sidebar-border:     hsl(162, 38%, 87%);
    --sidebar-accent:     hsl(156, 30%, 94%);
    --sidebar-foreground: hsl(168, 41%, 9%);

    /* Gradientes */
    --gradient-primary:   linear-gradient(135deg, hsl(161, 100%, 33%), hsl(161, 80%, 45%));
    --gradient-dark:      linear-gradient(180deg, hsl(168, 41%, 9%), hsl(165, 35%, 13%));

    /* Sombras */
    --shadow-soft:        0 4px 20px -6px hsl(168 41% 9% / 0.08);
    --shadow-glow:        0 0 30px hsl(161 100% 33% / 0.25);

    /* Border radius */
    --radius:             0.75rem;

    /* Transição base */
    --transition:         all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Tints do primary (fallback para color-mix) */
    --primary-tint-04:    rgba(0, 168, 120, 0.04);
    --primary-tint-05:    rgba(0, 168, 120, 0.05);
    --primary-tint-08:    rgba(0, 168, 120, 0.08);
    --primary-tint-10:    rgba(0, 168, 120, 0.10);
    --primary-tint-12:    rgba(0, 168, 120, 0.12);
    --primary-tint-15:    rgba(0, 168, 120, 0.15);
    --primary-tint-20:    rgba(0, 168, 120, 0.20);
    --primary-tint-30:    rgba(0, 168, 120, 0.30);
    --primary-tint-40:    rgba(0, 168, 120, 0.40);
}

/* ── Custom Properties — Modo Escuro ─────────────────────── */
.dark {
    --background:         hsl(168, 41%, 9%);     /* #0D1F1C verde-floresta */
    --foreground:         hsl(156, 35%, 95%);    /* #E8F5F0 */
    --card:               hsl(165, 35%, 12%);    /* #112820 */
    --card-foreground:    hsl(156, 35%, 95%);
    --muted:              hsl(165, 35%, 16%);
    --muted-foreground:   hsl(158, 25%, 60%);    /* #7FB5A0 */
    --border:             hsl(165, 30%, 22%);
    --input:              hsl(165, 30%, 22%);

    /* Fundo de input em dark mode — claramente distinto do card */
    --input-bg:           hsl(165, 32%, 18%);

    /* Sidebar — modo escuro */
    --sidebar:            hsl(165, 35%, 10%);
    --sidebar-border:     hsl(165, 30%, 18%);
    --sidebar-accent:     hsl(165, 35%, 15%);
    --sidebar-foreground: hsl(156, 35%, 90%);
}

/* ── Alpine.js: anti-flash ───────────────────────────────── */
[x-cloak] { display: none !important; }

/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color-scheme: light; /* segue o tema da página, não o SO */
}

html.dark {
    color-scheme: dark;
}

body {
    background-color: var(--background);
    color: var(--foreground);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── Pixel Pattern (fundo da tela de login) ──────────────── */
.pixel-pattern {
    background-image: radial-gradient(
        circle at 1px 1px,
        var(--primary-tint-15) 1px,
        transparent 0
    );
    background-size: 16px 16px;
}

/* ── Tipografia ──────────────────────────────────────────── */
h1, h2, h3 {
    font-family: 'Poppins', 'Inter', system-ui, sans-serif;
}

.metric-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--foreground);
    line-height: 1.2;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-soft);
    transition: var(--transition);
}

.card:hover {
    border-color: color-mix(in srgb, var(--primary) 40%, transparent);
}

/* ── Botões ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 0.5rem;
    height: 2.75rem;
    padding: 0 1.5rem;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--gradient-primary);
    color: var(--primary-foreground);
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--foreground);
}

.btn-outline:hover {
    background-color: var(--muted);
}

.btn-destructive {
    background-color: color-mix(in srgb, var(--destructive) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--destructive) 30%, transparent);
    color: var(--destructive);
}

.btn-destructive:hover {
    background-color: color-mix(in srgb, var(--destructive) 20%, transparent);
}

.btn-sm {
    height: 2rem;
    padding: 0 0.75rem;
    font-size: 0.8125rem;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Inputs & Formulários ────────────────────────────────── */

/* Garante que TODOS os inputs sigam o tema da página (light/dark)
   independentemente do color-scheme do sistema operacional */
input:not([type="submit"]):not([type="button"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
select,
textarea {
    background-color: var(--input-bg, var(--background));
    color: var(--foreground);
    border-color: var(--border);
}

/* Classe Tailwind bg-background mapeada para a variável correta */
.bg-background {
    background-color: var(--background) !important;
}

/* ── Override de autofill do browser ────────────────────────
   O browser (Chrome/Edge/Safari) aplica -webkit-autofill com
   cor de fundo própria que ignora background-color.
   O único jeito de sobrescrever é via box-shadow inset. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px hsl(156, 33%, 97%) inset !important;
    -webkit-text-fill-color: hsl(168, 41%, 9%) !important;
    caret-color: hsl(168, 41%, 9%);
    transition: background-color 9999s ease-in-out 0s;
}

.dark input:-webkit-autofill,
.dark input:-webkit-autofill:hover,
.dark input:-webkit-autofill:focus,
.dark input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px hsl(165, 32%, 18%) inset !important;
    -webkit-text-fill-color: hsl(156, 35%, 95%) !important;
    caret-color: hsl(156, 35%, 95%);
    transition: background-color 9999s ease-in-out 0s;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    background-color: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    color: var(--foreground);
    font-family: inherit;
    transition: var(--transition);
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-tint-20);
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--foreground);
    margin-bottom: 0.375rem;
}

.form-error {
    font-size: 0.8125rem;
    color: var(--destructive);
    margin-top: 0.375rem;
}

.form-group {
    margin-bottom: 1rem;
}

/* ── Badges de Status ────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-success {
    background-color: color-mix(in srgb, var(--success) 15%, transparent);
    color: var(--success);
    border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
}

.badge-warning {
    background-color: color-mix(in srgb, var(--warning) 15%, transparent);
    color: color-mix(in srgb, var(--warning) 80%, var(--foreground));
    border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
}

.badge-danger {
    background-color: color-mix(in srgb, var(--coral) 15%, transparent);
    color: var(--coral);
    border: 1px solid color-mix(in srgb, var(--coral) 30%, transparent);
}

.badge-info {
    background-color: color-mix(in srgb, var(--info) 15%, transparent);
    color: var(--info);
    border: 1px solid color-mix(in srgb, var(--info) 30%, transparent);
}

.badge-neutral {
    background-color: var(--muted);
    color: var(--muted-foreground);
    border: 1px solid var(--border);
}

/* ── Tabelas ─────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead {
    background-color: var(--muted);
}

th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted-foreground);
    white-space: nowrap;
}

td {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border);
    color: var(--foreground);
    vertical-align: middle;
}

tbody tr:hover {
    background-color: color-mix(in srgb, var(--primary) 4%, transparent);
}

tbody tr:nth-child(even) {
    background-color: color-mix(in srgb, var(--muted) 50%, transparent);
}

/* ── Alertas Flash ───────────────────────────────────────── */
.alert {
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 1rem;
}

.alert-success {
    background-color: color-mix(in srgb, var(--success) 12%, transparent);
    color: var(--success);
    border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
}

.alert-error {
    background-color: color-mix(in srgb, var(--destructive) 12%, transparent);
    color: var(--destructive);
    border: 1px solid color-mix(in srgb, var(--destructive) 30%, transparent);
}

.alert-warning {
    background-color: color-mix(in srgb, var(--warning) 12%, transparent);
    color: color-mix(in srgb, var(--warning) 80%, var(--foreground));
    border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
}

.alert-info {
    background-color: color-mix(in srgb, var(--info) 12%, transparent);
    color: var(--info);
    border: 1px solid color-mix(in srgb, var(--info) 30%, transparent);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    background-color: var(--sidebar);
    border-right: 1px solid var(--sidebar-border);
    width: 240px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    transition: transform 0.3s ease, width 0.3s ease;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--sidebar-foreground);
    text-decoration: none;
    transition: var(--transition);
    margin: 0.125rem 0.5rem;
    cursor: pointer;
}

.sidebar-nav-item:hover {
    background-color: var(--sidebar-accent);
}

.sidebar-nav-item.active {
    background-color: color-mix(in srgb, var(--primary) 15%, transparent);
    color: var(--primary);
}

.sidebar-nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ── Layout Principal ────────────────────────────────────── */
.main-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: 240px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0; /* evita overflow em flex — necessário para tabelas scrolláveis */
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background-color: var(--background);
    border-bottom: 1px solid var(--border);
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
}

.page-content {
    flex: 1;
    padding: 1.5rem 2rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* ── Progress Steps (Nova Análise) ───────────────────────── */
.step-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: 0.5rem;
    transition: var(--transition);
}

.step-item.active {
    background-color: color-mix(in srgb, var(--primary) 8%, transparent);
}

.step-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-icon.pending {
    background-color: var(--muted);
    color: var(--muted-foreground);
}

.step-icon.active {
    background-color: color-mix(in srgb, var(--primary) 20%, transparent);
    color: var(--primary);
}

.step-icon.done {
    background-color: color-mix(in srgb, var(--success) 20%, transparent);
    color: var(--success);
}

.step-icon.error {
    background-color: color-mix(in srgb, var(--destructive) 20%, transparent);
    color: var(--destructive);
}

/* ── Animações ───────────────────────────────────────────── */
@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

@keyframes progress-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

.animate-spin    { animation: spin 1s linear infinite; }
.animate-pulse   { animation: pulse 2s ease-in-out infinite; }
.animate-fade-in { animation: fade-in 0.2s ease-out; }

.progress-bar-indeterminate {
    position: relative;
    overflow: hidden;
    background-color: color-mix(in srgb, var(--primary) 20%, transparent);
    border-radius: 9999px;
    height: 4px;
}

.progress-bar-indeterminate::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 25%;
    height: 100%;
    background-color: var(--primary);
    border-radius: 9999px;
    animation: progress-slide 1.6s ease-in-out infinite;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: hsl(168 41% 4% / 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-box {
    background-color: hsl(0, 0%, 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 25px 60px -10px hsl(168 41% 9% / 0.45);
    width: 100%;
    max-width: 32rem;
    max-height: 90vh;
    overflow-y: auto;
    animation: fade-in 0.2s ease-out;
}

/* Dark mode: fundo verde escuro visível e sólido */
.dark .modal-box {
    background-color: hsl(165, 38%, 17%);
    border-color: hsl(165, 35%, 28%);
    box-shadow: 0 25px 60px -10px hsl(168 41% 4% / 0.7);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: hsl(161, 100%, 33%);
    border-radius: var(--radius) var(--radius) 0 0;
}

/* Título e botão fechar em branco no header verde */
.modal-header h3 { color: #ffffff !important; }
.modal-header button { color: rgba(255,255,255,0.75) !important; }
.modal-header button:hover { color: #ffffff !important; background-color: hsl(161 100% 33% / 0.3) !important; }

.modal-body    { padding: 1.5rem; }
.modal-footer  { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 0.75rem; justify-content: flex-end; }

/* ── Upload Zone ─────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary);
    background-color: color-mix(in srgb, var(--primary) 5%, transparent);
}

.upload-zone.has-file {
    border-color: var(--success);
    background-color: color-mix(in srgb, var(--success) 5%, transparent);
}

/* ── Paginação ───────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    text-decoration: none;
    transition: var(--transition);
    border: 1px solid transparent;
}

.pagination a {
    color: var(--foreground);
}

.pagination a:hover {
    background-color: var(--muted);
    border-color: var(--border);
}

.pagination span[aria-current="page"] {
    background-color: var(--primary);
    color: var(--primary-foreground);
}

/* ── Responsivo ──────────────────────────────────────────── */

/* Tablet: sidebar recolhida (só ícones) — apenas entre 769px e 1024px */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 68px;
    }
    .sidebar .sidebar-label,
    .sidebar .sidebar-logo-text,
    .sidebar .sidebar-user-info {
        display: none;
    }
    .main-content {
        margin-left: 68px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 240px;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .page-content {
        padding: 1rem;
    }
    .topbar {
        padding: 0 1rem;
    }
}

/* ── Extra-pequeno (smartphones ≤ 480px) ─────────────────── */
@media (max-width: 480px) {
    .page-content {
        padding: 0.75rem;
    }

    .card {
        padding: 1rem;
    }

    .metric-value {
        font-size: 1.5rem;
    }

    .topbar {
        height: 56px;
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .upload-zone {
        padding: 1.25rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 0;
    }

    .btn {
        height: 2.5rem;
        padding: 0 1rem;
    }
}

/* ── Skip Link (acessibilidade por teclado) ──────────────── */
.skip-link {
    position: fixed;  /* fixed garante que fique fora da viewport independente do scroll */
    top: -100px;
    left: 1rem;
    z-index: 9999;
    padding: 0.5rem 1rem;
    background-color: var(--primary);
    color: #ffffff;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 0 0 0.5rem 0.5rem;
    text-decoration: none;
    transition: top 0.2s ease;
}
.skip-link:focus {
    top: 0;
}

/* ── Prefers Reduced Motion ──────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .animate-spin,
    .animate-pulse,
    .animate-fade-in,
    .progress-bar-indeterminate::after {
        animation: none !important;
    }
}

/* ── Print CSS (Relatório) ───────────────────────────────── */
@media print {
    /* Ocultar elementos de navegação */
    .sidebar,
    .topbar,
    [href="{{ route('relatorio.pdf', '') }}"],
    a[href*="/pdf"],
    button,
    .pagination,
    form,
    nav { display: none !important; }

    /* Layout sem sidebar */
    .main-content { margin-left: 0 !important; }
    .page-content  { padding: 0 !important; max-width: 100% !important; }

    /* Cores base */
    body  { background: #fff !important; color: #1a2e2a !important; font-size: 12px !important; }
    *     { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

    /* Cards sem sombra */
    .card,
    [class*="bg-card"] { box-shadow: none !important; border: 1px solid #d0e8de !important; }

    /* Links sem sublinhado */
    a { color: inherit !important; text-decoration: none !important; }

    /* Tabelas não quebram no meio de linha */
    table { page-break-inside: auto !important; width: 100% !important; }
    tr    { page-break-inside: avoid !important; }
    thead { display: table-header-group !important; }

    /* Gauge: garantir tamanho fixo */
    svg.gauge { width: 140px !important; height: 140px !important; }

    /* Forçar quebra de página antes das seções */
    h2.section-break { page-break-before: always; }

    /* Rodapé de impressão */
    @page {
        margin: 15mm 12mm;
        size: A4 portrait;
    }
}
