*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --accent-soft: #dbeafe;
    --bg: #f5f7fa;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1f2937;
    --muted: #64748b;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --radius: 10px;
    --header-height: 60px;
    --sidebar-width: 248px;
    --sidebar-collapsed: 64px;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ---------- Ícones ---------- */
.icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: inline-block;
}

/* ---------- Header ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: var(--header-height);
    padding: 0 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 700;
    font-size: 17px;
    text-decoration: none;
    white-space: nowrap;
}

.brand:hover {
    text-decoration: none;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
}

.brand-logo .icon {
    width: 18px;
    height: 18px;
}

.brand-name em {
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
    color: var(--accent);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 9px;
    background: none;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
    background: var(--bg);
    color: var(--accent);
}

.sidebar-toggle .icon,
.sidebar-expand-toggle .icon {
    width: 18px;
    height: 18px;
}

.tenant-switcher select {
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    max-width: 260px;
}

.tenant-switcher select:focus {
    outline: none;
    border-color: var(--accent);
}

.tenant-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.tenant-chip .icon {
    width: 15px;
    height: 15px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 9px;
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.user-name {
    font-weight: 600;
    font-size: 13px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.role-badge {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-dark);
}

/* ---------- Layout do corpo ---------- */
.app-layout {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - var(--header-height));
}

/* ---------- Sidebar ---------- */
.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.18s ease;
    overflow: hidden;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px 24px;
}

.sidebar-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--muted);
    padding: 16px 10px 6px;
    white-space: nowrap;
}

.sidebar-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text);
    font-weight: 500;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
}

.sidebar-link:hover {
    background: var(--bg);
    color: var(--accent);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-weight: 600;
}

.sidebar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.sidebar-icon .icon {
    width: 18px;
    height: 18px;
}

.sidebar-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* Sidebar recolhida (desktop) */
body.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed);
}

body.sidebar-collapsed .sidebar-group-label {
    text-align: center;
    padding-left: 0;
    padding-right: 0;
    font-size: 0;
}

body.sidebar-collapsed .sidebar-group-label::after {
    content: "";
    display: block;
    width: 28px;
    margin: 8px auto;
    border-top: 1px solid var(--border);
}

body.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

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

body.sidebar-collapsed .sidebar-footer {
    justify-content: center;
}

body.sidebar-collapsed .sidebar-expand-toggle .icon {
    transform: rotate(180deg);
}

/* Scrim (mobile) */
.sidebar-scrim {
    display: none;
}

/* ---------- Conteúdo ---------- */
.app-main {
    flex: 1;
    min-width: 0;
}

.flash-wrap,
.breadcrumb,
.content {
    max-width: 1160px;
    margin: 0 auto;
    padding-left: 24px;
    padding-right: 24px;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 16px;
    padding-bottom: 4px;
    font-size: 13px;
}

.breadcrumb-link {
    color: var(--muted);
    text-decoration: none;
}

.breadcrumb-link:hover {
    color: var(--accent);
    text-decoration: none;
}

.breadcrumb-sep {
    color: #cbd5e1;
}

.breadcrumb-current {
    color: var(--text);
    font-weight: 600;
}

.flash-wrap {
    padding-top: 16px;
    padding-bottom: 0;
}

.content {
    padding-top: 16px;
    padding-bottom: 20px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.card-title {
    margin: 0 0 14px;
    font-size: 17px;
    font-weight: 700;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.page-header h1 {
    margin: 0;
    font-size: 22px;
}

.page-header p.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
}

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-success {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

.alert-warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

.alert-danger,
.alert-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

/* ---------- Forms ---------- */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 13.5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group {
    margin-bottom: 14px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
}

.field-with-button {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.field-with-button input {
    flex: 1;
    min-width: 0;
}

.form-error {
    color: var(--danger);
    font-size: 12.5px;
    margin-top: 4px;
}

.field-hint {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.hint {
    color: var(--muted);
    font-size: 12px;
}

.password-wrap {
    position: relative;
}

.password-wrap input {
    padding-right: 42px;
}

.password-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 17px;
    cursor: pointer;
    padding: 6px;
    color: var(--muted);
    display: inline-flex;
}

.password-toggle .icon {
    width: 18px;
    height: 18px;
}

.password-toggle:hover {
    color: var(--accent);
}

/* ---------- Buttons ---------- */
/* <button> usa line-height normal do navegador; links herdam 1.5 do body.
   Normalizar na base mantém todos os .btn com a mesma altura do <button>. */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    background: var(--accent);
    color: #fff;
    line-height: normal;
}

.btn:hover {
    background: var(--accent-dark);
    text-decoration: none;
}

.btn-secondary {
    background: #fff;
    border-color: #cbd5e1;
    color: var(--text);
}

.btn-secondary:hover {
    background: #f8fafc;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-link {
    background: none;
    border: 1px solid transparent;
    color: var(--accent);
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
}

.btn-link:hover {
    background: var(--bg);
}

.text-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: inherit;
    padding: 0;
    font-weight: 500;
}

.text-link:hover {
    text-decoration: underline;
}

/* ---------- Tables ---------- */
.table-wrap {
    overflow-x: auto;
}

table.grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

table.grid th,
table.grid td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

table.grid th {
    background: #f8fafc;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--muted);
    white-space: nowrap;
}

table.grid tr:hover td {
    background: #f8fafc;
}

/* Grid de Gestão de Documentos: nenhum conteúdo das células pode estender a
   largura da tabela (células clipam; colunas fixas do colgroup). */
table.grid.docs-grid td {
    overflow: hidden;
}

.section-row td {
    background: #eef2ff !important;
    font-weight: 700;
}

.section-row td:hover {
    background: #e0e7ff !important;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-neutral {
    background: #f1f5f9;
    color: #475569;
}

.badge-blue {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-green {
    background: #dcfce7;
    color: #15803d;
}

.badge-red {
    background: #fee2e2;
    color: #b91c1c;
}

.badge-amber {
    background: #fef3c7;
    color: #b45309;
}

.crit-alta {
    background: #fee2e2;
    color: #b91c1c;
}

.crit-media {
    background: #fef3c7;
    color: #b45309;
}

.crit-gir {
    background: #7f1d1d;
    color: #fff;
}

.badge-setor {
    background: #ede9fe;
    color: #5b21b6;
}

.crit-em-partes {
    background: #fef9c3;
    color: #a16207;
}

.crit-nao-aplicada {
    background: #e2e8f0;
    color: #64748b;
}

/* ---------- Picker de setores ---------- */
.setores-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.setores-mini {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.setores-mini .badge-setor {
    max-width: 200px;
    white-space: normal;
    word-break: break-word;
}

.setores-list .badge-setor {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    white-space: normal;
    word-break: break-word;
}

.badge-remove {
    border: 0;
    padding: 0;
    background: none;
    color: inherit;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.setores-add {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setores-add select {
    flex: 1;
    min-width: 0;
}

/* ---------- Cards / stats ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.stat-card .stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--accent-dark);
}

.stat-card .stat-label {
    color: var(--muted);
    font-size: 13px;
}

.progress {
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    min-width: 90px;
}

.progress-bar {
    height: 100%;
    background: var(--success);
    border-radius: 999px;
}

/* ---------- Misc ---------- */
.muted {
    color: var(--muted);
}

.small {
    font-size: 12.5px;
}

.mt-2 {
    margin-top: 8px;
}

.mt-4 {
    margin-top: 16px;
}

.mb-4 {
    margin-bottom: 16px;
}

.text-right {
    text-align: right;
}

.pill-list li {
    margin-bottom: 6px;
}

.docs-empty {
    text-align: center;
    color: var(--muted);
    padding: 30px 0;
}

.footer {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    padding: 24px 20px 40px;
}

.detail-grid dt {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.detail-grid dd {
    margin: 0 0 12px;
}

.evidence-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
}

.evidence-thumb {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #f1f5f9;
}

.evidence-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ---------- Autenticação ---------- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eef2ff 0%, #eef4fb 45%, #e2eafc 100%);
    padding: 20px;
}

.auth-card {
    background: var(--card);
    width: 100%;
    max-width: 420px;
    border-radius: 14px;
    padding: 32px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
    border: 1px solid var(--border);
}

.auth-card h1 {
    margin: 0 0 4px;
    font-size: 20px;
}

.auth-card .subtitle {
    color: var(--muted);
    margin: 0 0 22px;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 18px;
}

.auth-logo em {
    font-style: normal;
    font-weight: 400;
    color: var(--accent);
}

.auth-logo .brand-logo .icon {
    width: 18px;
    height: 18px;
}

/* ---------- Responsivo ---------- */
@media (max-width: 900px) {
    .app-header {
        padding: 0 12px;
    }

    .brand-name {
        display: none;
    }

    .app-sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        height: calc(100vh - var(--header-height));
        z-index: 40;
        width: var(--sidebar-width) !important;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 0 10px 30px rgba(15, 23, 42, 0.2);
    }

    body.sidebar-open .app-sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-scrim {
        display: block;
    }

    .sidebar-scrim {
        position: fixed;
        inset: 0;
        top: var(--header-height);
        background: rgba(15, 23, 42, 0.4);
        z-index: 35;
        border: none;
        cursor: pointer;
    }

    .sidebar-footer {
        display: none;
    }

    .flash-wrap,
    .breadcrumb,
    .content {
        padding-left: 16px;
        padding-right: 16px;
    }
}