/* Retencao e Microbiologia - estilo base */

* { box-sizing: border-box; }

/* ============ PALETA PADRAO (Frooty) ============ */
:root {
    --topbar-bg: #ffffff;
    --topbar-text: #1e3a8a;
    --topbar-border: #e5e7eb;

    --sidebar-bg: #ffffff;
    --sidebar-text: #1f2937;
    --sidebar-hover-bg: #f3f4f6;
    --sidebar-active-bg: #eff6ff;
    --sidebar-active-text: #1e3a8a;
    --sidebar-active-border: #1e3a8a;

    --content-bg: #f4f6f8;
}

/* ============ PALETAS ALTERNATIVAS ============ */
body.tema-esmeralda {
    --topbar-bg: #065f46;
    --topbar-text: #ecfdf5;
    --topbar-border: #064e3b;

    --sidebar-hover-bg: #ecfdf5;
    --sidebar-active-bg: #d1fae5;
    --sidebar-active-text: #065f46;
    --sidebar-active-border: #065f46;

    --content-bg: #f0fdf4;
}

body.tema-vinho {
    --topbar-bg: #7f1d1d;
    --topbar-text: #fef2f2;
    --topbar-border: #991b1b;

    --sidebar-hover-bg: #fef2f2;
    --sidebar-active-bg: #fee2e2;
    --sidebar-active-text: #7f1d1d;
    --sidebar-active-border: #7f1d1d;

    --content-bg: #fdf6f6;
}

body.tema-roxo {
    --topbar-bg: #5b21b6;
    --topbar-text: #ede9fe;
    --topbar-border: #4c1d95;

    --sidebar-hover-bg: #f5f3ff;
    --sidebar-active-bg: #ede9fe;
    --sidebar-active-text: #5b21b6;
    --sidebar-active-border: #5b21b6;

    --content-bg: #faf5ff;
}

body.tema-cinza {
    --topbar-bg: #1f2937;
    --topbar-text: #f9fafb;
    --topbar-border: #111827;

    --sidebar-hover-bg: #f3f4f6;
    --sidebar-active-bg: #e5e7eb;
    --sidebar-active-text: #111827;
    --sidebar-active-border: #6b7280;

    --content-bg: #f9fafb;
}

/* ============ BASE ============ */
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--content-bg);
    color: #1f2937;
}

a { color: #1d4ed8; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ AUTH ============ */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at 30% 20%, #6d28d9 0%, #4c1d95 55%, #3b0d6e 100%);
}
.auth-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 410px;
}
.auth-logo-top {
    width: 58%;
    max-width: 210px;
    height: auto;
    margin-bottom: 26px;
    filter: drop-shadow(0 6px 14px rgba(0,0,0,0.30));
}
.auth-card {
    background: #fff;
    padding: 36px 32px;
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(0,0,0,0.30);
    width: 100%;
    text-align: center;
}
.auth-card h1 {
    margin: 0 0 4px;
    color: #5b21b6;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1.25;
}
.auth-sub {
    color: #6b7280;
    font-size: 14px;
    margin: 0 0 26px;
}
.auth-card p {
    color: #6b7280;
    margin-bottom: 24px;
    font-size: 14px;
}
.auth-logo {
    display: block;
    margin: 0 auto 16px;
    max-width: 180px;
    height: auto;
}
/* Botão "Entrar com Microsoft" */
.btn-microsoft {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 13px 16px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    color: #1f2937 !important;
    font-weight: 600;
    font-size: 15px;
    text-decoration: none !important;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn-microsoft:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    box-shadow: 0 3px 10px rgba(0,0,0,0.10);
}
.btn-microsoft svg { width: 19px; height: 19px; display: block; }
.auth-rodape {
    margin-top: 22px;
    color: rgba(255,255,255,0.75);
    font-size: 12px;
}

/* ============ BOTOES ============ */
/* Tamanho padrao para todos os botoes do sistema */
.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.4;
    cursor: pointer;
    text-align: center;
    vertical-align: middle;
    transition: background 0.15s, opacity 0.15s;
}

.btn-primary {
    background: #1e3a8a;
    color: #fff !important;
    font-weight: 600;
}
.btn-primary:hover { background: #1e40af; text-decoration: none; }

.btn-secondary {
    background: #e5e7eb;
    color: #1f2937 !important;
}
.btn-secondary:hover { background: #d1d5db; text-decoration: none; }

.btn-danger {
    background: #dc2626;
    color: #fff !important;
    font-weight: 600;
}
.btn-danger:hover { background: #b91c1c; text-decoration: none; }

/* Variante maior para CTAs principais (ex.: tela de login) */
.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
}

/* Botoes que mostram apenas icone (acoes em tabelas) */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 34px;
    height: 34px;
    line-height: 1;
}
.btn-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* Botoes com icone + texto (ex.: "Nova retenção" com +) */
.btn-with-icon {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-with-icon svg { width: 16px; height: 16px; display: block; }

/* Espacamento entre acoes inline em tabelas */
td .btn-icon + .btn-icon,
td .btn-icon + form,
td form + .btn-icon,
td form + form,
td a + a,
td a + form,
td form + a { margin-left: 4px; }

td form { display: inline-block; vertical-align: middle; margin: 0; }
td .btn-icon { vertical-align: middle; }

/* Forca a ultima coluna (acoes) a manter botoes em uma linha so */
table tr > td:last-child {
    white-space: nowrap;
}

.btn-link {
    color: var(--topbar-text) !important;
    margin-left: 12px;
}

/* ============ LAYOUT ============ */
.topbar {
    background: var(--topbar-bg);
    color: var(--topbar-text);
    border-bottom: 1px solid var(--topbar-border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--topbar-text) !important;
    font-size: 18px;
    text-decoration: none;
}
.topbar .brand:hover { text-decoration: none; opacity: 0.85; }
.topbar .brand img { height: 32px; width: auto; display: block; }
.topbar .user {
    color: var(--topbar-text);
    font-size: 14px;
    opacity: 0.92;
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.35);
}
.user-avatar-fallback {
    background: rgba(255, 255, 255, 0.25);
    color: var(--topbar-text);
    font-weight: 600;
    font-size: 14px;
}

.layout {
    display: flex;
    min-height: calc(100vh - 57px);
}

.sidebar {
    width: 220px;
    flex-shrink: 0; /* nao deixa o menu ser espremido por conteudo largo */
    background: var(--sidebar-bg);
    border-right: 1px solid #e5e7eb;
    padding: 16px 0;
}
.sidebar a.menu-item {
    display: block;
    padding: 10px 20px;
    color: var(--sidebar-text) !important;
    border-left: 3px solid transparent;
}
.sidebar a.menu-item:hover { background: var(--sidebar-hover-bg); text-decoration: none; }
.sidebar a.menu-item.active {
    background: var(--sidebar-active-bg);
    border-left-color: var(--sidebar-active-border);
    color: var(--sidebar-active-text) !important;
    font-weight: 600;
}

/* ============ GRUPOS DE MENU ============ */
.sidebar .menu-group {
    margin: 0;
}
.sidebar .menu-group > summary {
    list-style: none;
    cursor: pointer;
    padding: 10px 20px;
    color: var(--sidebar-text);
    font-weight: 600;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-left: 3px solid transparent;
}
.sidebar .menu-group > summary::-webkit-details-marker { display: none; }
.sidebar .menu-group > summary::marker { display: none; content: ''; }
.sidebar .menu-group > summary:hover { background: var(--sidebar-hover-bg); }
.sidebar .menu-group > summary::after {
    content: '▸';
    font-size: 12px;
    color: #9ca3af;
    transition: transform 0.15s;
    margin-left: 8px;
}
.sidebar .menu-group[open] > summary::after {
    transform: rotate(90deg);
}
.sidebar .menu-sub a.menu-item {
    padding-left: 36px;
    font-size: 14px;
}

/* ============ TOGGLE DO MENU LATERAL ============ */
.btn-toggle-sidebar {
    background: transparent;
    border: none;
    color: var(--topbar-text);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    padding: 4px 10px;
    margin-right: 10px;
    border-radius: 6px;
    transition: opacity 0.15s;
}
.btn-toggle-sidebar:hover { opacity: 0.75; }
.topbar-left {
    display: flex;
    align-items: center;
}

.sidebar-collapsed .sidebar { display: none; }

/* ============ AUTOCOMPLETE ============ */
.autocomplete-wrap { position: relative; }
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 360px;
    max-width: 600px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
    margin-top: 4px;
}
.autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid #f3f4f6;
    line-height: 1.4;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover,
.autocomplete-item.highlighted { background: #eff6ff; }
.autocomplete-item .ac-codigo { color: #1e3a8a; font-weight: 600; margin-right: 8px; }
.autocomplete-item .ac-desc { color: #4b5563; }
.autocomplete-empty {
    padding: 10px 12px;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
}

.content {
    flex: 1;
    /* Sem isto o item flex nao encolhe abaixo do conteudo: uma tabela larga
       estica o .content, estica o .layout e a PAGINA INTEIRA passa a rolar
       na horizontal (cortando o topo). Com min-width:0 quem rola e a
       .table-scroll, como deveria. */
    min-width: 0;
    padding: 24px;
}

/* ============ COMPONENTES ============ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.page-header h1 {
    margin: 0;
    font-size: 22px;
    color: #1f2937;
}

.card {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 16px;
}

table {
    width: 100%;
    background: #fff;
    border-collapse: collapse;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
th, td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
}
th { background: #f9fafb; font-weight: 600; color: #4b5563; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f9fafb; }

.row {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.field { flex: 1; min-width: 180px; }
.row label,
.field label {
    display: block;
    font-size: 13px;
    color: #4b5563;
    margin-bottom: 4px;
    font-weight: 500;
}
.row input, .row select, .row textarea,
.field input, .field select, .field textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
.row input:focus, .row select:focus, .row textarea:focus,
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: #1e3a8a;
    box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}
.row textarea, .field textarea { min-height: 80px; resize: vertical; }
.form-actions { margin-top: 16px; display: flex; gap: 8px; }

/* Tabela com inputs/selects/textareas dentro das celulas (ex.: tolerancias por pais) */
.tabela-form td select,
.tabela-form td input,
.tabela-form td textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}
.tabela-form td textarea {
    min-height: 60px;
    resize: vertical;
}
.tabela-form td select:focus,
.tabela-form td input:focus,
.tabela-form td textarea:focus {
    outline: none;
    border-color: #1e3a8a;
    box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}
.tabela-form td { vertical-align: top; }

/* Validação visual do campo Resultado (entre m e M) */
.input-conforme {
    background: #d1fae5 !important;
    border-color: #10b981 !important;
    color: #065f46 !important;
    font-weight: 600;
}
.input-nao-conforme {
    background: #fee2e2 !important;
    border-color: #ef4444 !important;
    color: #991b1b !important;
    font-weight: 600;
}

/* Grid de 6 colunas iguais (para alinhar campos em multiplas linhas) */
.grid-6 {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 16px;
    margin-bottom: 12px;
}
@media (max-width: 1024px) {
    .grid-6 { grid-template-columns: repeat(3, 1fr); }
    .grid-6 .field[style*="grid-column"] { grid-column: span 3 !important; }
}
@media (max-width: 600px) {
    .grid-6 { grid-template-columns: repeat(2, 1fr); }
    .grid-6 .field[style*="grid-column"] { grid-column: span 2 !important; }
}

/* ============ LOADING ============ */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 9999;
    animation: fadeIn 0.15s ease-out;
}
.loading-overlay .spinner {
    width: 56px;
    height: 56px;
    border: 5px solid #e5e7eb;
    border-top-color: #1e3a8a;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}
.loading-overlay .msg {
    font-size: 15px;
    color: #1e3a8a;
    font-weight: 600;
}
.loading-overlay .submsg {
    font-size: 13px;
    color: #6b7280;
    margin-top: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.flash {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
}
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash-info    { background: #dbeafe; color: #1e3a8a; border: 1px solid #93c5fd; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}
.badge-success   { background: #d1fae5; color: #065f46; }
.badge-danger    { background: #fee2e2; color: #991b1b; }
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-info      { background: #dbeafe; color: #1e40af; }
.badge-primary   { background: #c7d2fe; color: #3730a3; }
.badge-purple    { background: #ede9fe; color: #5b21b6; }
.badge-pink      { background: #fce7f3; color: #9d174d; }
.badge-orange    { background: #ffedd5; color: #9a3412; }
.badge-secondary { background: #e5e7eb; color: #4b5563; }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

/* Grids genericos do dashboard quebram em telas pequenas */
@media (max-width: 900px) {
    div[style*="grid-template-columns: 2fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}
.stat-card {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.stat-card .label { color: #6b7280; font-size: 13px; margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; color: #1e3a8a; }

.empty {
    text-align: center;
    padding: 40px;
    color: #6b7280;
}

.filters-bar {
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 16px;
}

/* ============ SELETOR DE TEMA ============ */
.tema-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 8px;
}
.tema-card {
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
    position: relative;
}
.tema-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.tema-card.selected {
    border-color: #1e3a8a;
    box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}
.tema-card .preview {
    display: flex;
    height: 90px;
}
.tema-card .preview .pv-topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 24px;
}
.tema-card .preview .pv-sidebar {
    width: 38%;
    margin-top: 24px;
    border-right: 1px solid #e5e7eb;
}
.tema-card .preview .pv-content {
    flex: 1;
    margin-top: 24px;
}
.tema-card .info {
    padding: 12px 14px;
    border-top: 1px solid #f3f4f6;
}
.tema-card .info .nome {
    font-weight: 600;
    color: #1f2937;
    font-size: 15px;
}
.tema-card .info .selecionado {
    display: none;
    font-size: 12px;
    color: #065f46;
    background: #d1fae5;
    padding: 2px 8px;
    border-radius: 12px;
    margin-top: 4px;
}
.tema-card.selected .info .selecionado { display: inline-block; }
.tema-card input[type=radio] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* ============ ARVORE DE ANALISES (agrupado por retencao) ============ */
.tree-toolbar {
    display: flex;
    gap: 16px;
    margin-bottom: 8px;
}
.tree-toolbar .btn-link {
    margin-left: 0;
    color: var(--sidebar-active-text) !important;
    font-size: 13px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 0;
}
.tree-toolbar .btn-link:hover { text-decoration: underline; }

.tree-parent {
    cursor: pointer;
    background: #f9fafb;
}
.tree-parent > td { font-weight: 500; }
.tree-parent:hover > td { background: #f1f5f9; }

/* Contador de reanálises ao lado do status na linha fechada.
   Discreto de proposito: o destaque e do badge de status. */
.tree-qtd {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #e5e7eb;
    color: #4b5563;
    font-size: 11px;
    font-weight: 700;
    vertical-align: middle;
    cursor: help;
}

.tree-toggle {
    background: none;
    border: none;
    padding: 0;
    margin-right: 8px;
    cursor: pointer;
    color: #6b7280;
    vertical-align: middle;
    line-height: 0;
}
.tree-chevron {
    transition: transform 0.15s ease;
    transform: rotate(90deg); /* aberto: aponta para baixo */
}
.tree-parent.collapsed .tree-chevron {
    transform: rotate(0deg); /* recolhido: aponta para a direita */
}

.tree-child > td:first-child { padding-left: 34px; }
.tree-child-num { margin-right: 10px; }
.tree-child-tag {
    display: inline-block;
    font-size: 11px;
    color: #6b7280;
    background: #eef2f7;
    padding: 1px 8px;
    border-radius: 10px;
}
.tree-row-hidden { display: none; }

/* ============ TABELA DE PARAMETROS (form de mistura) ============ */
.param-table td { vertical-align: middle; }
.param-table th:not(:first-child),
.param-table td:not(:first-child) { text-align: center; }
.param-table input[type=text] {
    width: 100%;
    max-width: 150px;
    padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    text-align: center;
}
.param-table input[type=text]:focus {
    outline: none;
    border-color: #1e3a8a;
    box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}
.param-table .param-nome { font-size: 14px; }
.param-table .param-vazio { color: #9ca3af; }
.param-table input.res-ok {
    border-color: #16a34a;
    background: #f0fdf4;
    color: #166534;
    font-weight: 600;
}
.param-table input.res-bad {
    border-color: #dc2626;
    background: #fef2f2;
    color: #991b1b;
    font-weight: 600;
}

/* ============ TABELA DE PARAMETROS SENSORIAIS (form de retencao) ============ */
.sensorial-table td { vertical-align: middle; }
.sensorial-table td:first-child { width: 200px; }
.sensorial-table input[type=text] {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
.sensorial-table input[type=text]:focus {
    outline: none;
    border-color: #1e3a8a;
    box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}

/* Pilulas de resultado (visualizacao da retencao) */
.result-ok {
    display: inline-block;
    color: #166534;
    background: #f0fdf4;
    border: 1px solid #16a34a;
    border-radius: 6px;
    padding: 2px 10px;
    font-weight: 600;
}
.result-bad {
    display: inline-block;
    color: #991b1b;
    background: #fef2f2;
    border: 1px solid #dc2626;
    border-radius: 6px;
    padding: 2px 10px;
    font-weight: 600;
}
/* Estado intermediario: dentro da faixa, mas proximo do limite */
.result-warn {
    display: inline-block;
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    padding: 2px 10px;
    font-weight: 600;
}

/* Bolinha de conformidade (mesmo indicador da planilha) */
.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
}
.dot-ok     { background: #16a34a; }
.dot-alerta { background: #f59e0b; }
.dot-ruim   { background: #dc2626; }

.legenda-conformidade {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-top: 12px;
    font-size: 12px;
    color: #6b7280;
}
.legenda-conformidade .dot { margin-left: 0; margin-right: 4px; }

/* Campo de resultado no formulario, pintado conforme o valor digitado */
.param-table input.res-warn {
    border-color: #f59e0b;
    background: #fffbeb;
    color: #92400e;
    font-weight: 600;
}

/* Dica curta ao lado do rotulo (ex.: "auto", "da fórmula") */
.label-hint {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 10px;
    background: #eef2ff;
    color: #4f46e5;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    vertical-align: middle;
    cursor: help;
}

/* ============ AVALIACAO SENSORIAL (cartoes com botoes) ============ */
.sensorial-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}
.sensorial-card {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px 14px;
    background: #fff;
}
.sensorial-nome {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 10px;
    color: #374151;
}
.sensorial-opcoes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.sensorial-card > input[type=text] { width: 100%; }

/* Descricao livre: complementa a opcao escolhida (OK / Nao conforme).
   Fica visualmente secundaria para nao competir com as pilulas. */
.sensorial-desc {
    width: 100%;
    margin-top: 10px;
    font-size: 13px;
}
.sensorial-desc::placeholder { color: #9ca3af; font-style: italic; }

/* Pilula de opcao: o radio fica escondido e o <span> vira o botao */
.opt-pill { position: relative; margin: 0; font-weight: normal; cursor: pointer; }
.opt-pill input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.opt-pill span {
    display: inline-block;
    padding: 6px 14px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    background: #fff;
    color: #4b5563;
    font-size: 13px;
    line-height: 1.2;
    transition: background .12s, border-color .12s, color .12s;
}
.opt-pill:hover span { border-color: #9ca3af; background: #f9fafb; }
.opt-pill input:focus-visible + span {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

/* Selecionado — a cor vem da flag "conforme" da opcao */
.opt-ok   input:checked + span { background: #dcfce7; border-color: #16a34a; color: #14532d; font-weight: 600; }
.opt-bad  input:checked + span { background: #fee2e2; border-color: #dc2626; color: #7f1d1d; font-weight: 600; }
.opt-none input:checked + span { background: #e5e7eb; border-color: #9ca3af; color: #4b5563; font-weight: 600; }
.opt-none span { padding-left: 12px; padding-right: 12px; }

/* ============ PAINEL DE FILTROS RECOLHIVEL ============ */
.filtros-box {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 14px;
    overflow: hidden;
}
.filtros-resumo {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #4b5563;
    user-select: none;
}
.filtros-resumo::-webkit-details-marker { display: none; }
.filtros-resumo::before {
    content: '';
    width: 0; height: 0;
    border-left: 5px solid #9ca3af;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform .15s;
}
.filtros-box[open] .filtros-resumo::before { transform: rotate(90deg); }
.filtros-resumo:hover { background: #f9fafb; }
.filtros-badge {
    background: #eef2ff;
    color: #4f46e5;
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 700;
}
.filtros-box form { padding: 0 16px 14px; }
.filtros-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px 14px;
    align-items: end;
}
.filtros-grid .field { min-width: 0; }
/* Formula tem o texto mais longo (codigo + descricao) — ocupa 3 colunas.
   Com isso os 8 filtros somam 10 unidades e preenchem a linha inteira,
   sem sobrar coluna vazia antes da borda direita. */
.filtros-grid .filtro-largo { grid-column: span 3; }
.filtros-acoes {
    display: flex;
    gap: 8px;
    align-items: end;
    grid-column: 1 / -1;
    margin-top: 2px;
}

/* ============ RESUMO DA LISTAGEM ============ */
.lista-resumo {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-bottom: 10px;
    font-size: 13px;
    color: #4b5563;
}
.resumo-total strong { font-size: 15px; color: #111827; }
.resumo-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.resumo-chip .dot { margin-left: 0; }
.resumo-neutro { background: #eef2ff; color: #3730a3; }
.resumo-ok     { background: #f0fdf4; color: #166534; }
.resumo-alerta { background: #fffbeb; color: #92400e; }
.resumo-ruim   { background: #fef2f2; color: #991b1b; }
.resumo-legenda {
    margin-left: auto;
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: #9ca3af;
}
.resumo-legenda .dot { margin-left: 0; margin-right: 3px; width: 8px; height: 8px; }

/* ============ EVOLUCAO DA MISTURA (painel) ============ */
.evo-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    padding-bottom: 14px;
    margin-bottom: 14px;
    border-bottom: 1px solid #f3f4f6;
}
.evo-header-txt h3 {
    margin: 0 0 4px;
    font-size: 14px;
    color: #5b21b6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.evo-header-txt {
    flex: 1 1 260px;
    min-width: 0;
}
.evo-header-txt p {
    margin: 0;
    font-size: 12px;
    color: #6b7280;
    max-width: 380px;
    line-height: 1.45;
}

/* A Formula fica com todo o espaco que sobrar (o texto da opcao e longo);
   o Periodo tem largura fixa, senao os dois cresceriam igual por causa do
   flex:1 que .field traz do CSS global — e o nome da formula era cortado. */
.evo-controles {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex: 1 1 480px;
    max-width: 680px;
}
.evo-controles .field { min-width: 0; }
.evo-controles select { width: 100%; min-width: 0; }
.evo-campo-formula { flex: 1 1 auto; }
.evo-campo-periodo { flex: 0 0 140px; }

.evo-legenda {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    font-size: 12px;
    color: #6b7280;
}
.evo-legenda span { display: inline-flex; align-items: center; gap: 6px; }
.evo-ln {
    display: inline-block;
    width: 20px;
    height: 0;
    border-top-width: 2px;
}
.evo-ln-res { border-top: 2px solid #7c3aed; }
.evo-ln-lim { border-top: 2px dashed #dc2626; }

.evo-vazio {
    text-align: center;
    padding: 30px 20px;
    color: #6b7280;
    font-size: 13px;
    background: #fafafa;
    border: 1px dashed #e5e7eb;
    border-radius: 10px;
}

.evo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 14px;
}
.evo-card {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px 14px 8px;
    background: #fff;
}
.evo-titulo {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}
.evo-canvas {
    height: 190px;
    position: relative;
}

/* ============ MODAL GENERICO ============ */
.modal-bg {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.55);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-bg.aberto { display: flex; }
.modal-caixa {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
    overflow: hidden;
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid #e5e7eb;
}
.modal-head h3 { margin: 0; font-size: 15px; color: #1f2937; }
.modal-fechar {
    border: 0;
    background: none;
    font-size: 24px;
    line-height: 1;
    color: #9ca3af;
    cursor: pointer;
    padding: 0 4px;
}
.modal-fechar:hover { color: #4b5563; }
.modal-corpo { padding: 16px 18px; overflow-y: auto; }
.modal-ajuda { margin: 0 0 12px; font-size: 12px; color: #6b7280; line-height: 1.5; }
.modal-rodape {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}
.modal-acoes-massa { margin-bottom: 10px; font-size: 12px; }
.modal-acoes-massa .sep { color: #d1d5db; margin: 0 6px; }
.btn-link-acao {
    border: 0;
    background: none;
    padding: 0;
    color: #4f46e5;
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
}

/* ===== Lista de etiquetas a imprimir ===== */
.etq-lista { display: flex; flex-direction: column; gap: 2px; }
.etq-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    font-weight: normal;
    cursor: pointer;
    margin: 0;
}
.etq-item:hover { background: #f9fafb; }
.etq-nome { flex: 1; font-size: 14px; color: #374151; }
.etq-tag {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #92400e;
    background: #fef3c7;
    border-radius: 999px;
    padding: 2px 8px;
}
.etq-contador { font-size: 13px; color: #4b5563; font-weight: 600; }

/* ============ RECOLETA DA MESMA MISTURA ============ */
.recoleta-box {
    margin: 16px 0 4px;
    padding: 12px 14px;
    border: 1px solid #fcd34d;
    border-left: 4px solid #f59e0b;
    border-radius: 10px;
    background: #fffbeb;
}
.recoleta-check {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin: 0;
    font-weight: normal;
    cursor: pointer;
    font-size: 14px;
    color: #78350f;
}
.recoleta-check input[type=checkbox] { margin-top: 2px; flex-shrink: 0; }
.recoleta-check strong { color: #92400e; }
.recoleta-ajuda {
    margin-top: 8px;
    padding-left: 26px;
    font-size: 12.5px;
    color: #a16207;
    line-height: 1.5;
}

/* Etiqueta "2a coleta" ao lado do numero da mistura na grade */
.tag-coleta {
    display: inline-block;
    margin-left: 5px;
    padding: 1px 7px;
    border-radius: 999px;
    background: #fef3c7;
    color: #92400e;
    font-size: 10.5px;
    font-weight: 700;
    white-space: nowrap;
    cursor: help;
}

/* ============ CENTRAL DE AJUDA ============ */
.btn-link-ajuda { display: inline-flex; align-items: center; gap: 6px; }
.ajuda-icone {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.aj-busca-box { margin-bottom: 14px; }
.aj-busca {
    width: 100%;
    max-width: 620px;
    padding: 11px 14px;
    font-size: 14px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
}
.aj-busca:focus { outline: none; border-color: #7c3aed; box-shadow: 0 0 0 3px rgba(124,58,237,0.12); }
.aj-vazio {
    margin-top: 10px;
    padding: 14px;
    background: #fafafa;
    border: 1px dashed #e5e7eb;
    border-radius: 10px;
    color: #6b7280;
    font-size: 13px;
}

.aj-atalhos { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.aj-atalho {
    padding: 6px 13px;
    border-radius: 999px;
    background: #f5f3ff;
    border: 1px solid #ddd6fe;
    color: #5b21b6 !important;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
}
.aj-atalho:hover { background: #ede9fe; text-decoration: none; }

.aj-secao { margin-bottom: 14px; scroll-margin-top: 16px; }
.aj-secao-head { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #f3f4f6; }
.aj-secao-head h2 { margin: 0 0 3px; font-size: 17px; color: #5b21b6; }
.aj-secao-head p  { margin: 0; font-size: 12.5px; color: #6b7280; }

.aj-item { border-bottom: 1px solid #f3f4f6; }
.aj-item:last-child { border-bottom: 0; }
.aj-item > summary {
    list-style: none;
    cursor: pointer;
    padding: 11px 4px 11px 26px;
    position: relative;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    user-select: none;
}
.aj-item > summary::-webkit-details-marker { display: none; }
.aj-item > summary::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 17px;
    width: 0; height: 0;
    border-left: 5px solid #9ca3af;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform .15s;
}
.aj-item[open] > summary::before { transform: rotate(90deg); }
.aj-item > summary:hover { color: #5b21b6; }
.aj-resposta {
    padding: 0 4px 14px 26px;
    font-size: 13.5px;
    color: #4b5563;
    line-height: 1.65;
}
.aj-resposta strong { color: #374151; }

.aj-dot {
    display: inline-block;
    width: 9px; height: 9px;
    border-radius: 50%;
    margin-right: 3px;
    vertical-align: middle;
}
.aj-verde    { background: #16a34a; }
.aj-laranja  { background: #f59e0b; }
.aj-vermelho { background: #dc2626; }

.aj-rodape {
    font-size: 13px;
    color: #4b5563;
    line-height: 1.6;
    border-left: 4px solid #7c3aed;
}

/* ============ PAGINACAO ============ */
.paginacao {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    margin: 14px 0 4px;
}
.pag-btn {
    display: inline-block;
    min-width: 34px;
    padding: 6px 11px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    color: #4b5563 !important;
    font-size: 13px;
    text-align: center;
    text-decoration: none;
}
.pag-btn:hover { background: #f9fafb; border-color: #d1d5db; text-decoration: none; }
.pag-atual {
    background: var(--sidebar-active-bg, #ede9fe);
    border-color: var(--sidebar-active-border, #7c3aed);
    color: #5b21b6 !important;
    font-weight: 700;
}
.pag-off {
    opacity: .45;
    pointer-events: none;
}
.pag-sep { color: #9ca3af; padding: 0 2px; }

/* ============ ESTADO VAZIO ============ */
.empty-state {
    text-align: center;
    padding: 44px 24px;
}
.empty-titulo {
    font-size: 16px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}
.empty-texto {
    font-size: 13px;
    color: #6b7280;
    max-width: 440px;
    margin: 0 auto 18px;
    line-height: 1.5;
}

/* ============ GRADE DO CONTROLE DE FORMULAS ============ */
/* A grade tem muitas colunas de parametro. Antes, a barra de rolagem
   horizontal ficava no rodape da tabela inteira: com 50 linhas era preciso
   descer a pagina toda para alcanca-la e depois voltar. Agora a caixa tem
   altura maxima e rola nos DOIS eixos, entao a barra horizontal fica sempre
   visivel na base da area util. */
.table-scroll {
    overflow: auto;
    max-width: 100%;
    /* Fallback: o valor real e recalculado por JS a partir da posicao da
       tabela na tela (ver index.php). Usar so vh nao funciona porque o
       cabecalho, os filtros e o resumo ficam ACIMA e somam altura. */
    max-height: 60vh;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    background: #fff;

    /* Barra sempre visivel. Sem isto o Windows 11 usa barra sobreposta,
       que some quando o usuario para de rolar — e o operador acha que ela
       nao existe. Definir ::-webkit-scrollbar forca a barra classica. */
    scrollbar-width: thin;
    scrollbar-color: #a78bfa #f1f5f9;
}
.table-scroll::-webkit-scrollbar { width: 14px; height: 14px; }
.table-scroll::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 8px;
}
.table-scroll::-webkit-scrollbar-thumb {
    background: #a78bfa;
    border: 3px solid #f1f5f9;
    border-radius: 8px;
}
.table-scroll::-webkit-scrollbar-thumb:hover { background: #7c3aed; }
.table-scroll::-webkit-scrollbar-corner { background: #f1f5f9; }
.grade-formulas {
    white-space: nowrap;
    font-size: 13px;
    /* O `overflow:hidden` do seletor `table` cria um contexto de rolagem
       proprio e anularia o position:sticky das celulas. */
    overflow: visible;
    border-radius: 0;
    box-shadow: none;
}

/* ===== Cabecalho fixo ao rolar verticalmente ===== */
.grade-formulas thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f9fafb;
    /* Com border-collapse a borda de celula sticky nao pinta: usa sombra. */
    box-shadow: inset 0 -1px 0 #e5e7eb;
}
.grade-formulas thead th.th-param { background: #f3f4f6; }

/* ===== Nº e Data congelados ao rolar para a direita ===== */
.grade-formulas thead th:nth-child(1),
.grade-formulas tbody td:nth-child(1) {
    position: sticky;
    left: 0;
    min-width: 112px;
}
.grade-formulas thead th:nth-child(2),
.grade-formulas tbody td:nth-child(2) {
    position: sticky;
    left: 112px;
    min-width: 112px;
    /* Sombra marca onde termina a area congelada */
    box-shadow: 2px 0 5px -3px rgba(0,0,0,0.28);
}
.grade-formulas tbody td:nth-child(1),
.grade-formulas tbody td:nth-child(2) {
    background: #fff;
    z-index: 1;
}
.grade-formulas tbody tr:hover td:nth-child(1),
.grade-formulas tbody tr:hover td:nth-child(2) { background: #f9fafb; }
.grade-formulas thead th:nth-child(1),
.grade-formulas thead th:nth-child(2) { z-index: 3; }
.grade-formulas thead th:nth-child(2) {
    box-shadow: inset 0 -1px 0 #e5e7eb, 2px 0 5px -3px rgba(0,0,0,0.28);
}
.grade-formulas .col-formula {
    white-space: normal;
    min-width: 230px;
}
.grade-formulas .cel-num,
.grade-formulas .cel-sens { text-align: center; }
.grade-formulas .col-acoes { white-space: nowrap; }
.grade-formulas .cel-vazia { color: #d1d5db; }
.grade-formulas .th-param  { text-align: center; background: #f3f4f6; }
.grade-formulas .th-uni    { font-weight: normal; color: #9ca3af; }
.grade-formulas .cel-num   { font-variant-numeric: tabular-nums; }

/* Resultado sensorial como etiqueta compacta (nao a pilula grande) */
.tag-sens {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    background: #f3f4f6;
    color: #4b5563;
}
.tag-sens.tag-ok  { background: #dcfce7; color: #14532d; }
.tag-sens.tag-bad { background: #fee2e2; color: #7f1d1d; }

/* ============ UPLOAD DE ANEXOS ============ */
.anexo-form {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}
.anexo-form .row { align-items: flex-start; gap: 16px; }
.anexo-form .field-botao label { visibility: hidden; }   /* espaçador p/ alinhar o botão com os inputs */
.field input[type=file] {
    cursor: pointer;
    background: #fff;
    padding: 0;                 /* o botao interno cuida do respiro */
    overflow: hidden;
    line-height: 38px;
}
.field input[type=file]::file-selector-button {
    margin-right: 12px;
    padding: 0 16px;
    height: 38px;
    border: none;
    border-right: 1px solid #d1d5db;
    background: #f3f4f6;
    color: #1e3a8a;
    font-weight: 600;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease;
}
.field input[type=file]::file-selector-button:hover { background: #e5e7eb; }
.anexo-form .btn-primary { white-space: nowrap; }
