/* ==========================================================================
   QualiHUB — Camada de refinamento visual (carregada depois dos demais estilos)
   Consistência de espaçamento, tipografia, tabelas, formulários, botões, abas, modais e estados.
   ========================================================================== */

:root {
    --ring: 0 0 0 3px rgba(37, 99, 235, .28);
    --ease: cubic-bezier(.2, .7, .2, 1);
    --radius-card: 14px;
    --shadow-card: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 14px rgba(15, 23, 42, .05);
}

html { scroll-behavior: smooth; }
::selection { background: rgba(37, 99, 235, .18); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
button:focus-visible, a:focus-visible { box-shadow: var(--ring); outline-color: transparent; }

/* ---------- Rolagem discreta ---------- */
.content-wrapper, .table-container, .modal-body, .app-sidebar { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
.content-wrapper::-webkit-scrollbar, .table-container::-webkit-scrollbar, .modal-body::-webkit-scrollbar { width: 9px; height: 9px; }
.content-wrapper::-webkit-scrollbar-thumb, .table-container::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------- Cabeçalho superior: nunca estoura a largura ---------- */
.app-header { gap: 12px; padding: 0 20px; box-shadow: 0 1px 0 rgba(15, 23, 42, .03); }
.header-left { min-width: 0; flex: 1 1 auto; }
.header-right { flex: 0 1 auto; min-width: 0; gap: 10px; }
.company-selector-wrapper { min-width: 0; max-width: 320px; }
.company-select { min-width: 0; max-width: 220px; text-overflow: ellipsis; }
.global-search { min-width: 0; flex: 1 1 260px; max-width: 420px; }
.header-user { min-width: 0; }
.header-user-info { min-width: 0; max-width: 220px; }
.header-user-info > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1500px) { .company-selector-label { display: none; } .header-user-info { max-width: 170px; } }
@media (max-width: 1280px) { .quality-score-label { display: none; } .header-user-info { display: none; } }

/* ---------- Páginas: título, subtítulo e ações ---------- */
.content-wrapper { padding: 28px 28px 40px; background: var(--bg-main); }
.content-wrapper > * { animation: qh-fade .22s var(--ease) both; }
@keyframes qh-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.gm-title, .page-title { letter-spacing: -.02em; }
.gm-subtitle, .page-subtitle { max-width: 78ch; }
.gm-header, .page-header { margin-bottom: 20px; gap: 12px 16px; }
.gm-actions, .page-actions { gap: 8px; flex-wrap: wrap; }

/* ---------- Cartões ---------- */
.card { border-radius: var(--radius-card); box-shadow: var(--shadow-card); border-color: var(--line); }
.card-header { padding-bottom: 12px; margin-bottom: 12px; }
.card-title { letter-spacing: -.01em; }
.gm-card { padding: 0; overflow: hidden; }
.gm-kpi, .stat-card, .kpi-card { border-radius: 12px; transition: transform .18s var(--ease), box-shadow .18s var(--ease); }
.gm-kpi:hover, .stat-card:hover, .kpi-card:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(15, 23, 42, .09); }

/* ---------- Botões ---------- */
.btn { min-height: 36px; border-radius: 9px; letter-spacing: .005em; transition: background-color .15s, box-shadow .15s, transform .08s, border-color .15s; }
.btn svg { flex: 0 0 auto; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, #2f6df0 0%, #2563eb 100%); box-shadow: 0 1px 2px rgba(37, 99, 235, .35), inset 0 1px 0 rgba(255, 255, 255, .15); }
.btn-primary:hover { background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%); box-shadow: 0 4px 12px rgba(37, 99, 235, .3); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink-3); box-shadow: 0 1px 1px rgba(15, 23, 42, .04); }
.btn-secondary:hover { background: var(--surface-2); border-color: #b9c4d3; }
.btn-xs, .btn-sm { min-height: 28px; padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { filter: saturate(.7); }

/* ---------- Distintivos ---------- */
.badge { border-radius: 999px; padding: 3px 10px; white-space: nowrap; line-height: 1.35; }
.badge-primary { background: var(--info-soft-2); color: var(--info-ink); }
.badge-neutral { background: #eef2f7; }

/* ---------- Tabelas: cabeçalho discreto, linhas respiradas, sem quebra em códigos ---------- */
.table-container, .gm-table-wrap { border-radius: 12px; border-color: var(--line); background: var(--surface); }
.card > .table-container, .card > .gm-table-wrap { border: 0; border-radius: 0; }
.table th, .data-table th, .gm-table th {
    background: var(--surface-1); color: var(--ink-5); font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
    padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.table td, .data-table td, .gm-table td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td, .data-table tbody tr:last-child td, .gm-table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr, .data-table tbody tr, .gm-table tbody tr { transition: background-color .12s; }
.table tbody tr:hover td, .data-table tbody tr:hover td, .gm-table tbody tr:hover td { background: #f6f9fe; }
.table td:first-child, .data-table td:first-child, .gm-table td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.table td .badge, .data-table td .badge, .gm-table td .badge { white-space: nowrap; }
.table td:last-child .btn, .data-table td:last-child .btn { white-space: nowrap; }
.table, .data-table, .gm-table { font-variant-numeric: tabular-nums; }
.datatable-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; }
.datatable-search { min-width: 240px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 9px; font: inherit; font-size: 13px; background: var(--surface); }
.datatable-search:focus { border-color: var(--primary); box-shadow: var(--ring); outline: none; }
.datatable-pagination { padding: 10px 14px; }
.gm-empty, .qp-empty { color: var(--ink-6); text-align: center; padding: 36px 16px; font-size: 13.5px; }
.gm-loading { color: var(--ink-6); text-align: center; padding: 28px; background: linear-gradient(90deg, transparent, var(--surface-2), transparent) 0 0/200% 100%; animation: qh-shimmer 1.4s infinite; }
@keyframes qh-shimmer { to { background-position: -200% 0; } }

/* ---------- Formulários ---------- */
.form-control { min-height: 38px; border-color: var(--line-strong); border-radius: 9px; background-color: var(--surface); }
.form-control:hover { border-color: #b9c4d3; }
.form-control:focus { border-color: var(--primary); box-shadow: var(--ring); }
select.form-control { appearance: none; -webkit-appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.6' 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 12px center; }
.form-label { font-size: 12.5px; font-weight: 600; color: var(--ink-4); margin-bottom: 5px; display: block; }
.form-control::placeholder { color: #a3b0c2; }
.form-control:disabled, .form-control[readonly] { background: #f4f6fa; color: var(--ink-5); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }
.gm-error { color: #dc2626; font-size: 12px; min-height: 0; }

/* ---------- Abas ---------- */
.nav-tabs { gap: 4px; border-bottom: 1px solid var(--line); }
.nav-tab-btn { border-radius: 9px 9px 0 0; transition: color .15s, background-color .15s; }
.nav-tab-btn:hover { background: var(--surface-2); }
.nav-tab-btn.active { background: transparent; }

/* ---------- Modais ---------- */
.modal-backdrop { backdrop-filter: blur(3px); background: rgba(15, 23, 42, .5); }
.modal-dialog { border-radius: 16px; box-shadow: 0 24px 60px rgba(15, 23, 42, .3); border: 1px solid rgba(255, 255, 255, .6); }
.modal-header { padding: 16px 22px; border-bottom: 1px solid var(--line); background: var(--surface); border-radius: 16px 16px 0 0; }
.modal-header h3, .modal-title { letter-spacing: -.01em; }
.modal-footer { border-top: 1px solid var(--line); background: var(--surface-1); border-radius: 0 0 16px 16px; }

/* ---------- Barra lateral ---------- */
.app-sidebar { box-shadow: 1px 0 0 rgba(255, 255, 255, .04); }
.nav-item { border-radius: 9px; transition: background-color .15s, color .15s; }
.nav-item.active { box-shadow: 0 2px 8px rgba(37, 99, 235, .35); }
.nav-group-toggle { border-radius: 9px; transition: background-color .15s; }
.nav-group-toggle:hover { background: rgba(255, 255, 255, .05); }
.nav-group.has-active > .nav-group-toggle .nav-group-label { color: #fff; }
.nav-submenu-inner { border-left: 1px solid rgba(148, 163, 184, .18); margin-left: 18px; }

/* ---------- Avisos, vazios e utilidades ---------- */
.gm-alert { border-radius: 10px; }
.gm-muted { color: var(--ink-6); }
kbd { background: var(--surface-2); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 11.5px; }
code { background: var(--surface-2); border-radius: 5px; padding: 1px 5px; font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--line); }

/* ---------- Login ---------- */
.auth-container, .login-container, .auth-card, .login-card { border-radius: 18px; box-shadow: 0 30px 70px rgba(2, 6, 23, .45); }
body:has(.auth-card) , body:has(.login-card) { background: radial-gradient(1200px 600px at 15% -10%, rgba(37, 99, 235, .28), transparent 60%), radial-gradient(900px 500px at 100% 110%, rgba(14, 165, 233, .18), transparent 55%), #0b1220; }

/* ---------- Responsivo ---------- */
@media (max-width: 960px) {
    .content-wrapper { padding: 18px 14px 32px; }
    .gm-header, .page-header { flex-direction: column; align-items: stretch; }
    .gm-actions, .page-actions { width: 100%; }
    .gm-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .modal-dialog { border-radius: 12px; }
}
@media (max-width: 560px) {
    .gm-kpis { grid-template-columns: 1fr; }
    .btn { min-height: 40px; }
}

/* ---------- Acessibilidade e impressão ---------- */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .content-wrapper > *, .gm-loading { animation: none; }
    * { transition-duration: .01ms !important; }
}
@media print {
    .content-wrapper > * { animation: none; }
    .table th { position: static; }
}

/* Tabelas dentro de cartões comuns (dashboard etc.): mais compactas para caber lado a lado */
.card:not(.gm-card) .table th { padding: 9px 10px; font-size: 11px; letter-spacing: .04em; }
.card:not(.gm-card) .table td { padding: 9px 10px; font-size: 13px; }
.card:not(.gm-card) .table td:first-child { font-size: 12.5px; }
.card:not(.gm-card) .table td .badge { padding: 2px 8px; font-size: 10.5px; }

/* Indicação de rolagem horizontal nas tabelas largas (sombras nas bordas) */
.table-container, .gm-table-wrap {
    background:
        linear-gradient(to right, var(--surface) 30%, rgba(255, 255, 255, 0)) left center / 28px 100% no-repeat local,
        linear-gradient(to left, var(--surface) 30%, rgba(255, 255, 255, 0)) right center / 28px 100% no-repeat local,
        radial-gradient(farthest-side at 0 50%, rgba(15, 23, 42, .16), rgba(15, 23, 42, 0)) left center / 12px 100% no-repeat scroll,
        radial-gradient(farthest-side at 100% 50%, rgba(15, 23, 42, .16), rgba(15, 23, 42, 0)) right center / 12px 100% no-repeat scroll,
        var(--surface);
}
