/* Visual do sistema: mobile primeiro, menu lateral no desktop. */
:root {
    --ink: #11314e;
    --text: #5a6671;
    --muted: #7b8794;
    --primary: #144d8c;
    --primary-dark: #0f3e73;
    --primary-soft: rgba(20, 77, 140, .12);
    --on-primary: #ffffff;
    --navy: #144d8c;
    --cyan: #0fa0d1;
    --bg: #f7f7f7;
    --card: #ffffff;
    --topbar: #ffffff;
    --border: #e3e8ef;
    --ok: #0a7d14;
    --ok-bg: #e7f7ea;
    --fail: #b42318;
    --fail-bg: #fdecea;
    --warn: #92400e;
    --warn-bg: #fff6e0;
    --sidebar: #144d8c;
    --radius: 12px;
    --shadow: 0 8px 24px rgba(17, 49, 78, .08);
    --header: 72px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: Nunito, "Segoe UI", system-ui, sans-serif;
    font-size: 0.9375rem;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    color-scheme: light;
    font-variant-numeric: tabular-nums;
}

a { color: var(--navy); }

.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;
}

.public-body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-shell { min-height: 100vh; }

.workspace {
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 16px;
}

main.container {
    flex: 1;
    padding-top: 20px;
    padding-bottom: 28px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--header);
    min-height: var(--header);
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    background: #ffffff;
    border-bottom: 3px solid var(--navy);
    backdrop-filter: blur(12px);
    z-index: 50;
}

.topbar-public { position: sticky; }

.topbar-centered { justify-content: center; }
.topbar-centered .brand {
    flex: 0 1 auto;
    max-width: 100%;
    justify-content: center;
    text-align: center;
}
.topbar-centered .brand-name { text-align: center; }

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
    color: var(--text);
    font-weight: 700;
    letter-spacing: .04em;
    text-decoration: none;
}

.brand-logo {
    height: 42px;
    width: auto;
    display: block;
    flex-shrink: 0;
}

.brand-name {
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1.25;
    opacity: .95;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.who {
    margin: 0;
    max-width: 220px;
    color: var(--muted);
    font-size: .88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--navy);
    cursor: pointer;
    flex-shrink: 0;
}

.nav-toggle:hover { background: rgba(20, 77, 140, .08); }

.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
    display: block;
    width: 16px;
    height: 1.5px;
    border-radius: 2px;
    background: var(--navy);
    position: relative;
    content: "";
}

.nav-toggle-bars::before { position: absolute; top: -6px; }
.nav-toggle-bars::after { position: absolute; top: 6px; }

.nav-toggle.is-open .nav-toggle-bars { background: transparent; }
.nav-toggle.is-open .nav-toggle-bars::before { top: 0; transform: rotate(45deg); }
.nav-toggle.is-open .nav-toggle-bars::after { top: 0; transform: rotate(-45deg); }

.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 49, 78, .45);
    z-index: 30;
}

.sidebar {
    display: none;
    position: fixed;
    z-index: 40;
    top: 0;
    left: 0;
    width: min(84vw, 300px);
    height: 100dvh;
    padding: 22px 14px 16px;
    background: var(--sidebar);
    border-right: 0;
    color: #ffffff;
    transform: translateX(-105%);
    transition: transform .2s ease;
    overflow: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 8px 16px;
    color: #ffffff;
    text-decoration: none;
    font-weight: 800;
    letter-spacing: .04em;
}

.sidebar-brand .brand-logo {
    height: 36px;
    width: auto;
    background: #ffffff;
    border-radius: 8px;
    padding: 4px 8px;
}
.sidebar-company,
.sidebar-user,
.sidebar-role { margin: 0; }

.sidebar-label {
    margin: 0;
    padding: 0 12px 8px;
    font-size: .75rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .72);
    font-weight: 700;
}

.sidebar-company {
    margin: 0 8px 12px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .12);
    color: #ffffff;
    font-size: .82rem;
    font-weight: 700;
    line-height: 1.35;
}

.side-nav { display: flex; flex-direction: column; gap: 4px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 12px;
    border-radius: 10px;
    color: #ffffff;
    text-decoration: none;
    font-weight: 600;
}

.nav-ico {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-group { display: flex; flex-direction: column; }

.nav-parent {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #ffffff;
    font: inherit;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.nav-parent:hover { background: rgba(255, 255, 255, .12); }

.nav-caret {
    width: 16px;
    height: 16px;
    margin-left: auto;
    flex: 0 0 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .2s ease;
}

.nav-group.is-open > .nav-parent .nav-caret { transform: rotate(180deg); }

.nav-sub {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows .2s ease;
}

.nav-group.is-open > .nav-sub { grid-template-rows: 1fr; }

.nav-sub-inner {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-sub .nav-link {
    min-height: 38px;
    padding-left: 16px;
    font-weight: 600;
}

.nav-link:hover,
.nav-link.is-active {
    background: rgba(255, 255, 255, .16);
    color: #ffffff;
}

.nav-link.is-active { box-shadow: inset 3px 0 0 var(--cyan); }

.sidebar-foot {
    margin-top: 24px;
    padding: 14px 12px 0;
    border-top: 1px solid rgba(255, 255, 255, .22);
}

.sidebar-user { font-weight: 700; }
.sidebar-role { color: rgba(255, 255, 255, .75); font-size: .85rem; margin-bottom: 12px; }

body.nav-open { overflow: hidden; }
body.nav-open .sidebar { display: flex; flex-direction: column; transform: none; }
body.nav-open .nav-backdrop { display: block; }
body.nav-open .side-nav { flex: 1; }
body.nav-open .sidebar-foot { margin-top: auto; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.card + .card,
.grid-2 + .card,
.card + .grid-2 { margin-top: 16px; }

.page-head { margin-bottom: 8px; }
.eyebrow {
    margin: 0 0 4px;
    color: var(--cyan);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

h1 {
    margin: 0 0 8px;
    color: var(--ink);
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1.25;
}

h2 { margin: 0 0 8px; font-size: 1.05rem; font-weight: 700; color: var(--ink); letter-spacing: 0; }

.muted { color: var(--muted); }
.intro { margin-bottom: 16px; }
.list { padding-left: 20px; }
code { background: #eef4f8; padding: 1px 6px; border-radius: 6px; }

.card-head, .row-actions, .actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.actions { flex-wrap: nowrap; }
.table td.actions-cell { width: 1%; white-space: nowrap; }

.card-head { justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-head h1, .card-head h2 { margin-bottom: 0; }
.list-note { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 14px;
    align-items: flex-end;
    margin: 0 0 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.form.filter-bar .field { margin: 0; flex: 1 1 180px; min-width: 0; }
.filter-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.actions form, .row-actions form, .sidebar-foot form { margin: 0; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 46px;
    min-height: 46px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    border: 1px solid var(--primary-dark);
    background: var(--primary);
    color: var(--on-primary);
    font: inherit;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    box-shadow: none;
}

.btn:hover { filter: brightness(1.08); box-shadow: 0 0 0 4px rgba(20, 77, 140, .18); }

.btn:focus-visible,
.nav-link:focus-visible,
.nav-parent:focus-visible,
.nav-toggle:focus-visible,
.form input:focus,
.form select:focus,
.form textarea:focus {
    outline: 3px solid rgba(15, 160, 209, .45);
    outline-offset: 2px;
}

.btn.secondary,
.btn-ghost {
    background: #ffffff;
    color: var(--navy);
    border: 1px solid var(--navy);
    box-shadow: none;
}

.btn.secondary:hover,
.btn-ghost:hover { background: #eef4fb; filter: none; box-shadow: none; }

.btn.btn-row {
    height: auto;
    min-height: 30px;
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid rgba(20, 77, 140, .22);
    background: rgba(20, 77, 140, .06);
    color: var(--navy);
    font-size: .8rem;
    font-weight: 600;
    box-shadow: none;
}

.btn.btn-row:hover {
    background: rgba(20, 77, 140, .12);
    filter: none;
    box-shadow: none;
}

.filter-actions .btn,
.row-actions .btn,
.card-head .btn { height: 46px; min-height: 46px; }

.btn-danger {
    background: transparent;
    color: var(--fail);
    border: 1px solid rgba(255, 180, 180, .45);
    box-shadow: none;
}

.btn-warn {
    background: var(--warn-bg);
    color: var(--warn);
    border: 1px solid #fde68a;
    box-shadow: none;
}

.btn-ok {
    background: var(--ok-bg);
    color: var(--ok);
    border: 1px solid rgba(182, 240, 122, .35);
    box-shadow: none;
}

.btn-danger:hover { background: rgba(185, 28, 28, .18); }
.btn-warn:hover { background: rgba(217, 119, 6, .28); }
.btn-ok:hover { background: #dff5e3; }

.btn-block { width: 100%; }
.btn-text {
    background: none;
    border: 0;
    color: var(--primary-dark);
    font: inherit;
    cursor: pointer;
    padding: 6px 2px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 700;
}

.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }

.table-wrap { overflow-x: auto; margin: 12px 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table th {
    color: var(--muted);
    font-size: 0.8125rem;
    letter-spacing: 0;
    text-transform: uppercase;
    background: #f4f7fb;
}
.table th:first-child { border-radius: 8px 0 0 0; }
.table th:last-child { border-radius: 0 8px 0 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover { background: #f4f7fb; }
.table a { font-weight: 700; text-decoration: none; }
.table td.note-number,
.table td.note-number a {
    white-space: nowrap;
}
.table td.note-number a {
    font-size: 0.8125rem;
    line-height: 1.2;
}
.table select, .table input { width: 100%; min-width: 90px; }

.shortcut-grid, .grid-2 { display: grid; gap: 14px; }
.form .grid-2 { align-items: end; margin-bottom: 14px; }
.form .grid-2 .field { margin-bottom: 0; }

.shortcut {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    min-height: 132px;
    padding: 18px;
    border-radius: var(--radius);
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
}

.shortcut:hover { border-color: var(--primary); transform: translateY(-1px); }
.shortcut-title { font-size: 1.05rem; font-weight: 800; color: var(--ink); }
.shortcut-text { color: var(--muted); }

.metric-grid { display: grid; gap: 12px; margin-bottom: 16px; }
.metric {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
}
.metric:hover { border-color: var(--cyan); }
.metric-label { color: var(--muted); font-size: .8rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.metric-value { color: var(--ink); font-size: 1.5rem; font-weight: 700; letter-spacing: 0; line-height: 1.2; }
.metric-note { color: var(--text); font-size: .88rem; }

.split { display: grid; gap: 16px; }
.split .card + .card { margin-top: 0; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.activity li:last-child { border-bottom: 0; padding-bottom: 0; }
.activity-meta { color: var(--muted); font-size: .78rem; }
.activity-text { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }

.process-steps {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 16px;
    padding: 0;
}
.process-steps li {
    padding: 6px 12px;
    border-radius: 999px;
    background: #f4f7fb;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}
.process-steps li.is-current { background: rgba(20, 77, 140, .12); color: var(--navy); }
.process-steps li.is-done { background: var(--ok-bg); color: var(--ok); }
.term-box {
    margin: 0 0 14px;
    padding: 14px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    background: #f8fafc;
}
.term-box p:last-child { margin-bottom: 0; }
.part-line { display: grid; gap: 12px; margin-bottom: 12px; }
.part-line .field { margin-bottom: 0; }
@media (min-width: 761px) {
    .part-line { grid-template-columns: 1.4fr .7fr .9fr; }
}

.empty {
    margin: 4px 0 0;
    padding: 22px 14px;
    text-align: center;
    color: var(--muted);
    background: #f8fafc;
    border: 1px dashed #d5dde6;
    border-radius: 12px;
}

.access-card { display: flex; flex-direction: column; min-height: 180px; }
.access-card p { flex: 1; }
.hero p:last-child { margin-bottom: 0; max-width: 62ch; }

.form .field { margin-bottom: 14px; }
.form label {
    display: block;
    min-height: 1.25em;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--ink);
    font-size: 0.875rem;
    line-height: 1.25;
}
.form > p { margin: 0 0 14px; }
.form .row-actions { margin-top: 2px; }
.form .table td { vertical-align: middle; }
.form .table input,
.form .table select { height: 46px; min-height: 46px; }

.form input:not([type="email"]):not([type="password"]):not([type="url"]):not([type="file"]):not([type="checkbox"]):not([type="radio"]):not(.js-digits):not(.js-decimal):not(.js-date):not(.js-secret),
.form textarea {
    text-transform: uppercase;
}

.password-field { position: relative; }
.password-field input { padding-right: 92px; }
.password-toggle {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: var(--navy);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    padding: 4px 6px;
}
.form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.form select,
.form textarea {
    width: 100%;
    height: 46px;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid #d5dde6;
    border-radius: 10px;
    font: inherit;
    background: #ffffff;
    color: var(--ink);
}
.form input[type="file"] { height: auto; padding: 9px 12px; }
.form textarea { height: auto; min-height: 110px; resize: vertical; }
.field.checkbox label { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.field.checkbox input { width: 20px; height: 20px; min-height: 20px; }
#state { text-transform: uppercase; }

.alert { border-radius: 12px; padding: 12px 14px; margin: 0 0 16px; }
.alert.error { background: var(--fail-bg); color: var(--fail); }
.alert.success { background: var(--ok-bg); color: var(--ok); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

.auth-wrap { max-width: 460px; width: 100%; margin-top: 12px; }
.auth-wrap .form .btn { width: 100%; }
.narrow { max-width: 640px; }
.footer {
    color: var(--muted);
    font-size: .85rem;
    padding: 8px 0 20px;
    text-align: center;
}
.pager {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}
.pager a,
.pager span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--navy);
    font-weight: 700;
    text-decoration: none;
}
.pager .is-current { background: var(--navy); border-color: var(--navy); color: #fff; }
.footer-line { margin: 0; line-height: 1.45; }
.footer a { font-weight: 700; color: var(--navy); }

@media (max-width: 760px) {
    .who { display: none; }
    .card-head { align-items: stretch; flex-direction: column; }
    .card-head .btn, .card-head .row-actions { width: 100%; }
    .card-head .row-actions .btn { flex: 1; }
    .filter-bar .field { flex-basis: 100%; }
    .filter-actions { width: 100%; }
    .filter-actions .btn { flex: 1; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr {
        margin-bottom: 12px;
        padding: 8px 12px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--card);
    }
    .table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        border: 0;
        padding: 8px 0;
    }
    .table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 700;
        flex: 0 0 42%;
    }
    .table td:has(input),
    .table td:has(select) {
        flex-direction: column;
        align-items: stretch;
    }
    .table td:has(input)::before,
    .table td:has(select)::before { flex-basis: auto; margin-bottom: 6px; }
    .table td input,
    .table td select { width: 100%; min-width: 0; }
    #sale-items tr { padding-left: 0; padding-right: 0; }
    .table td.note-number { align-items: center; }
    .table td.note-number a { font-size: 0.75rem; }
    .table td.actions-cell { display: block; width: auto; white-space: normal; }
    .table td.actions-cell::before { display: block; margin-bottom: 8px; }
    .actions .btn.btn-row { flex: 0 0 auto; }
}

@media (min-width: 761px) {
    .card { padding: 24px; }
    h1 { font-size: 1.5rem; }
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .shortcut-grid, .metric-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
    :root { --header: 64px; }
    .brand-logo { height: 32px; }
    .sidebar-brand .brand-logo { height: 30px; }
    .brand-name { font-size: 12px; letter-spacing: .02em; }
}

@media (max-width: 900px) {
    .sidebar {
        top: var(--header);
        height: calc(100dvh - var(--header));
        padding-top: 16px;
    }
    .nav-backdrop { top: var(--header); }
}

@media (max-width: 420px) {
    .nav-toggle { width: 40px; height: 40px; }
}

@media (min-width: 901px) {
    .nav-backdrop { display: none !important; }
    .app-shell { display: flex; }
    .sidebar {
        display: flex;
        flex-direction: column;
        position: sticky;
        top: 0;
        width: 260px;
        height: 100vh;
        transform: none;
        flex-shrink: 0;
        transition: width .2s ease, padding .2s ease;
    }
    html.sidebar-collapsed .sidebar {
        width: 0;
        min-width: 0;
        padding: 0;
        overflow: hidden;
        border: 0;
        visibility: hidden;
        pointer-events: none;
    }
    .side-nav { flex: 1; }
    .sidebar-foot { margin-top: auto; }
    .workspace { flex: 1; }
}

@media (min-width: 1100px) {
    .shortcut-grid { grid-template-columns: 1fr 1fr 1fr; }
    .metric-grid { grid-template-columns: repeat(4, 1fr); }
    .metric-grid.summary-metrics { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .split { grid-template-columns: 1.25fr .75fr; }
}
