:root {
    --blue-950: #082b4d;
    --blue-800: #0b4e86;
    --blue-700: #0b5cad;
    --blue-100: #eaf4ff;
    --cyan-600: #0785a5;
    --ink: #172033;
    --muted: #637083;
    --line: #dce4ee;
    --surface: #ffffff;
    --background: #f3f7fb;
    --success: #087a55;
    --success-bg: #e8f7f1;
    --warning: #945b00;
    --warning-bg: #fff4dc;
    --danger: #b4232f;
    --danger-bg: #fff0f1;
    --shadow: 0 8px 24px rgba(31, 54, 82, .08);
}

* { box-sizing: border-box; }

html { max-width: 100%; overflow-x: hidden; font-size: 16px; }

body {
    margin: 0;
    color: var(--ink);
    background: var(--background);
    font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: 0;
}

button, input, select { font: inherit; }
a { color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 26px 18px 18px;
    background: var(--blue-950);
    color: #fff;
    display: flex;
    flex-direction: column;
}

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; margin: 0 8px 34px; }
.brand img { width: 132px; height: auto; display: block; }
.brand span { display: none; }

.nav { display: grid; gap: 5px; }
.nav a {
    min-height: 44px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    text-decoration: none;
    font-size: .92rem;
    font-weight: 600;
    border-radius: 6px;
}
.nav a:hover { background: rgba(255,255,255,.1); }
.nav a.active { color: var(--blue-950); background: #fff; }
.nav svg { width: 20px; height: 20px; flex: 0 0 20px; }

.sidebar-footer {
    margin-top: auto;
    padding: 18px 8px 0;
    border-top: 1px solid rgba(255,255,255,.16);
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-summary { min-width: 0; flex: 1; }
.user-summary strong, .user-summary span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-summary strong { font-size: .88rem; }
.user-summary span { color: #bdd2e6; font-size: .75rem; }

.main { min-width: 0; padding: 28px 30px 48px; overflow-x: hidden; }
.main.narrow { max-width: 1050px; }
.topbar { min-height: 72px; margin-bottom: 24px; display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.topbar h1 { margin: 0; font-size: 1.65rem; line-height: 1.25; font-weight: 700; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: .94rem; }

.metrics { margin-bottom: 22px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.metrics article { min-width: 0; padding: 19px 22px; border-right: 1px solid var(--line); }
.metrics article:last-child { border-right: 0; }
.metrics span, .job-summary span { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; }
.metrics strong { display: block; margin-top: 5px; font-size: 1.8rem; line-height: 1.1; }

.panel { min-width: 0; margin-bottom: 22px; padding: 22px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); border-radius: 6px; }
.section-heading { margin-bottom: 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.section-heading h2 { margin: 0; font-size: 1.08rem; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: .86rem; }

.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th { padding: 11px 12px; color: var(--muted); background: #f7f9fc; text-align: left; font-size: .72rem; text-transform: uppercase; white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfdff; }
td strong, .subtext { display: block; }
.subtext { margin-top: 2px; color: var(--muted); font-size: .76rem; }
.empty { padding: 34px; color: var(--muted); text-align: center; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: .78rem; }

.button, .icon-button {
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 650;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.button { min-height: 40px; padding: 9px 15px; gap: 8px; font-size: .88rem; }
.button svg { width: 18px; height: 18px; }
.button.primary { color: #fff; background: var(--blue-700); }
.button.primary:hover { background: var(--blue-800); }
.button.secondary { color: var(--ink); background: #edf2f7; border: 1px solid var(--line); }
.button.danger { color: var(--danger); background: var(--danger-bg); border: 1px solid #f0c4c8; }
.button.small { min-height: 32px; padding: 6px 10px; font-size: .78rem; }
.button.full { width: 100%; }
.icon-button { width: 34px; height: 34px; color: var(--blue-700); background: var(--blue-100); }
.icon-button svg { width: 18px; height: 18px; }
.icon-button.light { color: #fff; background: rgba(255,255,255,.12); }
.text-link { color: var(--blue-700); font-size: .84rem; font-weight: 650; text-decoration: none; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }
.form-stack { display: grid; gap: 16px; }
label > span, legend { display: block; margin-bottom: 6px; color: #39465a; font-size: .82rem; font-weight: 650; }
input, select {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #bcc9d8;
    border-radius: 5px;
    outline: none;
}
input:focus, select:focus { border-color: var(--blue-700); box-shadow: 0 0 0 3px rgba(11,92,173,.13); }
input[type="file"] { padding: 7px; }
input[type="checkbox"] { width: 17px; min-height: 17px; accent-color: var(--blue-700); }
.span-2 { grid-column: span 2; }
.span-full { grid-column: 1 / -1; }
.upload-field small { display: block; margin-top: 6px; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.checkbox-group { margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 5px; display: flex; flex-wrap: wrap; gap: 10px 18px; }
.checkbox-group legend { padding: 0 5px; }
.checkbox-group label { display: flex; align-items: center; gap: 7px; font-size: .82rem; }
.checkbox-group label span { margin: 0; }
.checkbox-line { display: flex; align-items: center; gap: 9px; min-height: 42px; }
.checkbox-line input { flex: 0 0 17px; }
.checkbox-line span { margin: 0; }
.catalog-companies { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.catalog-companies label { align-items: flex-start; padding: 8px; }
.catalog-companies label strong, .catalog-companies label small { display: block; }
.catalog-companies label small { color: var(--muted); font-size: .75rem; font-weight: 400; }
.company-access-editor { margin-top: 8px; min-width: 260px; }
.company-access-editor summary { color: var(--blue-700); cursor: pointer; font-size: .78rem; font-weight: 650; }
.company-access-editor form { margin-top: 8px; display: grid; gap: 8px; }
.company-access-editor .checkbox-group { max-height: 260px; overflow-y: auto; display: grid; }
.company-access-editor .checkbox-group label { align-items: flex-start; }
.inline-form { display: flex; align-items: center; gap: 7px; min-width: 220px; }
.inline-form input { min-height: 34px; padding: 6px 9px; }

.flash { margin-bottom: 18px; padding: 12px 14px; border-radius: 5px; font-size: .88rem; }
.flash.success { color: var(--success); background: var(--success-bg); border: 1px solid #b7e5d3; }
.flash.error { color: var(--danger); background: var(--danger-bg); border: 1px solid #f0c4c8; }
.notice { padding: 16px 18px; border-left: 4px solid var(--cyan-600); background: #eefafd; }
.notice strong { font-size: .9rem; }
.notice p { margin: 4px 0 0; color: #425267; font-size: .86rem; }

.status { display: inline-flex; width: max-content; padding: 4px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.status-concluido, .status-baixado, .status-active { color: var(--success); background: var(--success-bg); }
.status-na_fila, .status-pendente { color: var(--blue-700); background: var(--blue-100); }
.status-processando { color: var(--cyan-600); background: #e7f8fb; }
.status-concluido_com_pendencias, .status-nao_localizado { color: var(--warning); background: var(--warning-bg); }
.status-falhou, .status-erro, .status-error, .status-cancelado, .status-inactive { color: var(--danger); background: var(--danger-bg); }
.tag { display: inline-block; margin: 2px 4px 2px 0; padding: 3px 7px; border-radius: 4px; color: var(--blue-800); background: var(--blue-100); font-size: .72rem; }

.job-summary { margin-bottom: 22px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); background: #fff; }
.job-summary > div { padding: 16px 18px; border-right: 1px solid var(--line); }
.job-summary > div:last-child { border-right: 0; }
.job-summary strong { display: block; margin-top: 5px; font-size: .92rem; }
.technical-detail { max-width: 640px; max-height: 180px; overflow: auto; margin: 0; white-space: pre-wrap; font-size: .74rem; }

.login-page { min-height: 100vh; background: var(--blue-950); }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(280px, .9fr) minmax(430px, 1.1fr); }
.login-brand { padding: 9vw 7vw; color: #fff; display: flex; flex-direction: column; justify-content: center; background: var(--blue-950); }
.login-brand img { width: min(310px, 80%); height: auto; margin-bottom: 38px; }
.login-brand strong, .login-brand span { display: block; }
.login-brand strong { font-size: 2.1rem; }
.login-brand span { margin-top: 5px; color: #c4d8e9; font-size: 1rem; }
.login-panel { padding: 9vw; background: #fff; display: flex; flex-direction: column; justify-content: center; }
.login-panel form { max-width: 460px; }
.login-heading { margin-bottom: 28px; }
.login-heading h1 { margin: 5px 0 6px; font-size: 1.8rem; }
.login-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--blue-700); font-size: .75rem; font-weight: 750; text-transform: uppercase; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1050px) {
    .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
    .main { padding: 24px 20px 40px; }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metrics article:nth-child(2) { border-right: 0; }
    .metrics article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
    .form-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: static; width: 100%; height: auto; padding: 16px; }
    .brand { margin: 0 4px 16px; }
    .brand img { width: 112px; }
    .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .nav a { font-size: .8rem; }
    .sidebar-footer { margin-top: 18px; }
    .main { padding: 20px 14px 36px; }
    .topbar { min-height: 0; flex-direction: column; }
    .topbar .button { width: 100%; }
    .metrics, .job-summary, .form-grid, .form-grid.compact { grid-template-columns: 1fr; }
    .metrics article, .job-summary > div { border-right: 0; border-bottom: 1px solid var(--line); }
    .metrics article:last-child, .job-summary > div:last-child { border-bottom: 0; }
    .span-2 { grid-column: span 1; }
    .catalog-companies { grid-template-columns: 1fr; }
    .section-heading { flex-direction: column; }
    .panel { padding: 16px; }
    .table-wrap table { min-width: 720px; }
    .login-shell { display: block; }
    .login-brand { min-height: 240px; padding: 50px 28px; }
    .login-brand img { width: 220px; margin-bottom: 20px; }
    .login-panel { min-height: calc(100vh - 240px); padding: 42px 24px; }
}
