:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #151922;
    --muted: #667085;
    --line: #d9dee7;
    --brand: #0f766e;
    --brand-strong: #134e4a;
    --ink: #1f2937;
    --amber: #b45309;
    --blue: #2563eb;
    --green: #15803d;
    --red: #b91c1c;
    --purple: #7c3aed;
    --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

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

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    width: 264px;
    height: 100vh;
    flex-direction: column;
    gap: 22px;
    padding: 22px;
    color: #f8fafc;
    background: #172033;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    display: inline-flex;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #f59e0b;
    color: #111827;
    font-weight: 900;
    letter-spacing: 0;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #cbd5e1;
    font-size: 12px;
}

.sidebar-nav {
    display: grid;
    gap: 6px;
}

.nav-group {
    display: grid;
    gap: 6px;
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    padding-top: 12px;
}

.nav-group-title {
    padding: 0 12px 3px;
    color: #94a3b8;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sidebar-nav a,
.logout-link {
    display: flex;
    min-height: 44px;
    align-items: center;
    gap: 10px;
    border-radius: 8px;
    padding: 10px 12px;
    color: #dbe4ef;
    font-weight: 700;
}

.sidebar-nav a.active,
.sidebar-nav a:hover,
.logout-link:hover {
    background: #ffffff;
    color: #172033;
}

.logout-link {
    margin-top: auto;
}

.main-wrap {
    min-width: 0;
    flex: 1;
    padding-bottom: 24px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 22px 32px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(14px);
}

.topbar h1,
.page-actions h2,
.panel-header h2,
.form-subsection h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.18;
}

.eyebrow,
.section-kicker {
    display: block;
    margin: 0 0 4px;
    color: var(--brand);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.user-chip {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    background: #fff;
    color: var(--muted);
    font-weight: 700;
}

.content {
    display: grid;
    gap: 18px;
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px 32px;
}

.page-actions,
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.btn,
.icon-btn {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 900;
}

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

.btn.primary:hover {
    background: var(--brand-strong);
}

.btn.secondary,
.icon-btn {
    border-color: var(--line);
    background: #fff;
    color: var(--ink);
}

.btn.full,
.full-mobile {
    width: 100%;
}

.icon-btn {
    width: 42px;
    padding: 0;
}

.flash {
    max-width: 1240px;
    margin: 16px auto 0;
    border-radius: 8px;
    padding: 12px 16px;
    font-weight: 800;
}

.flash.sucesso {
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.flash.erro,
.auth-error {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
}

.metric,
.panel,
.form-panel,
.filter-bar,
.auth-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.metric {
    min-height: 112px;
    padding: 16px;
}

.metric span {
    display: block;
    min-height: 34px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.metric strong {
    display: block;
    margin-top: 10px;
    font-size: 26px;
    line-height: 1.1;
}

.metric.blue strong { color: var(--blue); }
.metric.amber strong { color: var(--amber); }
.metric.green strong { color: var(--green); }
.metric.red strong { color: var(--red); }
.metric.purple strong { color: var(--purple); }
.metric.gray strong { color: #475569; }

.panel,
.form-panel,
.filter-bar {
    padding: 18px;
}

.filter-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
}

label span {
    display: block;
    margin-bottom: 7px;
    color: #4b5563;
    font-size: 12px;
    font-weight: 900;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    outline: none;
    background: #fff;
    color: var(--text);
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

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

.form-grid.compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.span-2 {
    grid-column: span 2;
}

.toggle-row {
    display: flex;
    min-height: 44px;
    align-items: center;
    gap: 10px;
    margin-top: 21px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #fbfcfe;
}

.toggle-row input {
    width: 18px;
    min-height: 18px;
}

.toggle-row span {
    margin: 0;
}

.sticky-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.form-subsection {
    margin-top: 18px;
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.responsive-table {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.05em;
    text-align: left;
    text-transform: uppercase;
}

th,
td {
    border-bottom: 1px solid #eef1f5;
    padding: 13px 10px;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    background: #edf2f7;
    color: #334155;
    font-size: 12px;
    font-weight: 900;
}

.badge.ok {
    background: #dcfce7;
    color: #166534;
}

.badge.muted {
    background: #f1f5f9;
    color: #64748b;
}

.status-aguardando_aprovacao { background: #fef3c7; color: #92400e; }
.status-aprovada,
.status-faturada,
.status-confirmada { background: #dcfce7; color: #166534; }
.status-cancelada { background: #fee2e2; color: #991b1b; }
.status-rascunho { background: #f1f5f9; color: #64748b; }

.mobile-list {
    display: none;
    gap: 10px;
}

.mobile-list.always {
    display: grid;
    margin-top: 14px;
}

.list-card {
    display: grid;
    gap: 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px;
    background: #fff;
}

.list-card span,
.list-card small,
.muted-text {
    color: var(--muted);
    font-size: 13px;
}

.split-sections {
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 18px;
}

.compact-form {
    display: grid;
    gap: 14px;
    margin-top: 14px;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
}

.permission-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    color: #374151;
    font-size: 12px;
    font-weight: 800;
}

.permission-grid input {
    width: 16px;
    min-height: 16px;
}

.timeline {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.timeline article {
    display: grid;
    gap: 3px;
    border-left: 3px solid var(--brand);
    padding: 8px 0 8px 12px;
}

.timeline small {
    color: var(--muted);
}

.empty-state {
    display: grid;
    place-items: center;
    gap: 8px;
    padding: 40px 16px;
    color: var(--muted);
    text-align: center;
}

.empty-state h2 {
    margin: 0;
    color: var(--text);
}

.auth-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 18px;
    background:
        linear-gradient(135deg, rgba(15, 118, 110, 0.16), rgba(245, 158, 11, 0.12)),
        #f8fafc;
}

.auth-card {
    width: min(100%, 390px);
    padding: 24px;
}

.auth-brand {
    display: grid;
    justify-items: center;
    gap: 8px;
    margin-bottom: 22px;
    text-align: center;
}

.auth-brand h1 {
    margin: 6px 0 0;
    font-size: 28px;
}

.auth-brand p {
    margin: 0;
    color: var(--muted);
}

.form-stack {
    display: grid;
    gap: 14px;
}

.mobile-nav {
    display: none;
}

.total-chip {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    border-radius: 8px;
    padding: 8px 12px;
    background: #ecfdf5;
    color: var(--green);
}

.mt-compact {
    margin-top: 14px;
}

.icon-btn.danger {
    color: var(--red);
}

.combo-field {
    position: relative;
}

.combo-field > span {
    display: block;
    margin-bottom: 7px;
    color: #4b5563;
    font-size: 12px;
    font-weight: 900;
}

.combo-list {
    position: absolute;
    z-index: 30;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    display: grid;
    max-height: 286px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.combo-list button {
    display: grid;
    gap: 2px;
    width: 100%;
    border: 0;
    border-bottom: 1px solid #eef1f5;
    padding: 11px 12px;
    cursor: pointer;
    background: #fff;
    color: var(--text);
    text-align: left;
}

.combo-list button:hover,
.combo-list button:focus {
    background: #f8fafc;
}

.combo-list button[hidden] {
    display: none;
}

.combo-list small {
    color: var(--muted);
    font-size: 12px;
}

.combo-add {
    position: sticky;
    bottom: 0;
    display: flex !important;
    min-height: 44px;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--line) !important;
    background: #ecfdf5 !important;
    color: var(--brand-strong) !important;
    font-weight: 900;
}

.modal {
    width: min(680px, calc(100vw - 28px));
    border: 0;
    border-radius: 8px;
    padding: 0;
    background: transparent;
}

.modal::backdrop {
    background: rgba(15, 23, 42, 0.42);
}

.modal-box {
    display: grid;
    gap: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #fff;
    box-shadow: var(--shadow);
}

.modal-header,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-actions {
    justify-content: flex-end;
}

[data-lucide] {
    width: 19px;
    height: 19px;
    stroke-width: 2.3;
}

@media (max-width: 1100px) {
    .metrics-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .permission-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .split-sections {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .app-shell {
        display: block;
        padding-bottom: 76px;
    }

    .sidebar {
        display: none;
    }

    .main-wrap {
        padding-bottom: 0;
    }

    .topbar {
        align-items: flex-start;
        padding: 16px;
    }

    .topbar h1 {
        font-size: 20px;
    }

    .user-chip span {
        display: none;
    }

    .content {
        gap: 14px;
        padding: 16px;
    }

    .page-actions,
    .panel-header {
        align-items: stretch;
        flex-direction: column;
    }

    .page-actions .btn,
    .panel-header .btn {
        width: 100%;
    }

    .metrics-grid,
    .form-grid,
    .form-grid.compact,
    .filter-bar {
        grid-template-columns: 1fr;
    }

    .metric {
        min-height: 92px;
    }

    .span-2 {
        grid-column: auto;
    }

    .responsive-table {
        display: none;
    }

    .mobile-list {
        display: grid;
    }

    .panel,
    .form-panel,
    .filter-bar {
        padding: 14px;
    }

    .sticky-actions {
        position: sticky;
        bottom: 70px;
        z-index: 5;
        display: grid;
        grid-template-columns: 1fr;
        margin-right: -6px;
        margin-left: -6px;
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 8px;
        background: rgba(255, 255, 255, 0.94);
        box-shadow: var(--shadow);
        backdrop-filter: blur(12px);
    }

    .toggle-row {
        margin-top: 0;
    }

    .combo-list {
        max-height: 238px;
    }

    .modal {
        width: calc(100vw - 20px);
    }

    .modal-box {
        max-height: calc(100vh - 34px);
        overflow-y: auto;
        padding: 14px;
    }

    .modal-header,
    .modal-actions {
        align-items: stretch;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .permission-grid {
        grid-template-columns: 1fr;
    }

    .mobile-nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 20;
        display: grid;
        grid-template-columns: repeat(8, minmax(0, 1fr));
        border-top: 1px solid var(--line);
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(16px);
    }

    .mobile-nav a {
        display: grid;
        min-height: 64px;
        place-items: center;
        gap: 2px;
        color: #64748b;
        font-size: 9px;
        font-weight: 900;
    }

    .mobile-nav a.active {
        color: var(--brand);
    }
}
