:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --border: #e4e7ec;
    --primary: #176b4d;
    --primary-dark: #10543c;
    --primary-soft: #e9f7f1;
    --warning: #b54708;
    --danger: #b42318;
    --success: #067647;
    --info: #175cd3;
    --shadow: 0 10px 30px rgba(16, 24, 40, .07);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
body { margin: 0; min-height: 100vh; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 16px; background: #102820; color: #fff; display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; gap: 12px; align-items: center; padding: 5px 8px 24px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: #d8f4e7; color: #103e2f; font-weight: 900; font-size: 22px; }
.brand strong { display: block; font-size: 16px; }
.brand small { display: block; margin-top: 3px; color: rgba(255,255,255,.65); font-size: 11px; }
.nav { display: grid; gap: 7px; margin-top: 22px; }
.nav a { padding: 12px 14px; border-radius: 11px; color: rgba(255,255,255,.78); text-decoration: none; font-weight: 700; font-size: 14px; }
.nav a:hover, .nav a.active { color: #fff; background: rgba(255,255,255,.12); }
.sidebar-footer { margin-top: auto; padding: 16px 10px 2px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-footer span, .sidebar-footer small { display: block; }
.sidebar-footer small { color: rgba(255,255,255,.6); margin-top: 3px; }
.sidebar-footer a { display: inline-block; color: #d8f4e7; margin-top: 12px; font-weight: 700; text-decoration: none; }

.main-area { min-width: 0; }
.topbar { min-height: 90px; padding: 20px 30px; background: rgba(255,255,255,.9); border-bottom: 1px solid var(--border); display: flex; gap: 15px; align-items: center; position: sticky; top: 0; z-index: 10; backdrop-filter: blur(10px); }
.topbar h1 { margin: 0; font-size: 24px; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.menu-button { display: none; border: 0; background: var(--surface-soft); border-radius: 10px; padding: 9px 12px; cursor: pointer; }
.content { padding: 28px 30px 45px; max-width: 1600px; width: 100%; margin: 0 auto; }

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card h2, .card h3 { margin-top: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.card-header h2 { margin: 0; font-size: 18px; }
.card-header p { margin: 4px 0 0; color: var(--muted); }
.stat-card { min-height: 130px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat-value { margin-top: 12px; font-size: 29px; font-weight: 900; letter-spacing: -.03em; }
.stat-note { margin-top: 8px; color: var(--muted); font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.field { grid-column: span 4; }
.field.span-2 { grid-column: span 2; }
.field.span-3 { grid-column: span 3; }
.field.span-4 { grid-column: span 4; }
.field.span-6 { grid-column: span 6; }
.field.span-8 { grid-column: span 8; }
.field.span-12 { grid-column: span 12; }
.field label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 800; }
.field .hint { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }
input, select, textarea { width: 100%; border: 1px solid #d0d5dd; border-radius: 10px; padding: 11px 12px; background: #fff; color: var(--text); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23,107,77,.12); }
textarea { min-height: 100px; resize: vertical; }
input[readonly] { background: #f2f4f7; font-weight: 800; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 10px 14px; border: 1px solid transparent; border-radius: 10px; text-decoration: none; font-weight: 800; cursor: pointer; white-space: nowrap; }
.btn-primary { color: #fff; background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { color: var(--text); background: #fff; border-color: var(--border); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-small { padding: 7px 10px; font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; min-width: 950px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: var(--surface-soft); color: #475467; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
td { font-size: 13px; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }
.amount { font-weight: 850; white-space: nowrap; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

.status { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 900; }
.status-pending { color: #93370d; background: #fffaeb; }
.status-verified { color: #175cd3; background: #eff8ff; }
.status-approved { color: #6941c6; background: #f4f3ff; }
.status-paid { color: #067647; background: #ecfdf3; }
.status-cancelled { color: #b42318; background: #fef3f2; }

.alert { padding: 13px 15px; border-radius: 11px; margin-bottom: 18px; font-weight: 700; border: 1px solid transparent; }
.alert-success { background: #ecfdf3; color: #067647; border-color: #abefc6; }
.alert-error { background: #fef3f2; color: #b42318; border-color: #fecdca; }
.alert-info { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }

.filter-bar { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 12px; align-items: end; }
.filter-bar .field { grid-column: auto; }
.result-box { background: var(--primary-soft); border: 1px solid #b7e4d1; border-radius: 14px; padding: 18px; }
.result-box .formula { color: var(--muted); font-size: 12px; }
.result-box .result { font-size: 28px; font-weight: 900; margin-top: 8px; }
.detail-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
.detail-item { background: var(--surface-soft); border-radius: 12px; padding: 14px; }
.detail-item small { display: block; color: var(--muted); margin-bottom: 5px; }
.detail-item strong { overflow-wrap: anywhere; }
.receipt-preview { width: 100%; max-height: 520px; object-fit: contain; border: 1px solid var(--border); border-radius: 12px; background: #f8fafc; }
.history { display: grid; gap: 11px; }
.history-item { border-left: 3px solid var(--primary); padding: 4px 0 4px 13px; }
.history-item small { color: var(--muted); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.inline-form { display: inline; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 25px; background: radial-gradient(circle at top left, #daf3e7, #f7f9fc 45%); }
.login-card { width: min(440px, 100%); background: #fff; border: 1px solid var(--border); border-radius: 22px; box-shadow: 0 25px 70px rgba(16,24,40,.12); padding: 30px; }
.login-card .brand { color: var(--text); border-bottom-color: var(--border); padding-left: 0; }
.login-card .brand small { color: var(--muted); }
.login-card h1 { margin: 25px 0 6px; }
.login-card > p { color: var(--muted); margin-top: 0; }
.login-card .field { margin-top: 16px; }
.login-card .btn { width: 100%; margin-top: 20px; }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .field, .field.span-2, .field.span-3, .field.span-4 { grid-column: span 6; }
    .detail-list { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; left: -280px; width: 260px; transition: left .22s ease; box-shadow: 12px 0 35px rgba(0,0,0,.18); }
    .sidebar.open { left: 0; }
    .menu-button { display: inline-flex; }
    .topbar { min-height: 75px; padding: 15px 18px; }
    .topbar h1 { font-size: 19px; }
    .content { padding: 20px 14px 35px; }
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .form-grid { display: block; }
    .field { margin-bottom: 14px; }
    .filter-bar { grid-template-columns: 1fr; }
    .detail-list { grid-template-columns: 1fr; }
    .card { padding: 16px; border-radius: 13px; }
    .card-header { align-items: flex-start; flex-direction: column; }
}

@media print {
    .sidebar, .topbar, .no-print, .btn { display: none !important; }
    .app-shell { display: block; }
    .content { padding: 0; }
    .card { box-shadow: none; border: 0; }
}

/* Melhorias de compatibilidade móvel — v1.1.0 */
html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}
body {
    min-width: 0;
    overflow-x: hidden;
}
a, button, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
}
button, .btn, .nav a {
    touch-action: manipulation;
}
.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(16, 24, 40, .52);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .22s ease, visibility .22s ease;
}
.sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.mobile-only { display: none; }
.sidebar-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 12px;
    background: rgba(255,255,255,.10);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}
.receipt-frame {
    display: block;
    width: 100%;
    height: min(520px, 70vh);
    min-height: 320px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-soft);
}
body.menu-open { overflow: hidden; }

@media (max-width: 760px) {
    .mobile-only { display: inline-grid; place-items: center; }
    .sidebar {
        top: 0;
        bottom: 0;
        height: 100dvh;
        max-width: min(86vw, 300px);
        padding-top: max(22px, env(safe-area-inset-top));
        padding-bottom: max(18px, env(safe-area-inset-bottom));
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .sidebar .brand { padding-right: 45px; }
    .topbar {
        padding-top: max(15px, env(safe-area-inset-top));
        padding-right: max(18px, env(safe-area-inset-right));
        padding-left: max(18px, env(safe-area-inset-left));
    }
    .menu-button {
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
        font-size: 20px;
    }
    .content {
        padding-right: max(14px, env(safe-area-inset-right));
        padding-bottom: max(35px, env(safe-area-inset-bottom));
        padding-left: max(14px, env(safe-area-inset-left));
    }
    input, select, textarea {
        min-height: 46px;
        font-size: 16px;
    }
    input[type="file"] {
        min-height: auto;
        padding: 10px;
    }
    textarea { min-height: 120px; }
    .btn {
        min-height: 44px;
        padding: 11px 14px;
    }
    .card-header .actions,
    .filter-bar .actions {
        width: 100%;
    }
    .card-header .actions .btn,
    .filter-bar .actions .btn {
        flex: 1 1 145px;
    }
    .actions.no-print {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }
    .actions.no-print > .btn,
    .actions.no-print > form,
    .actions.no-print > form .btn,
    .inline-form,
    .inline-form .btn {
        width: 100%;
    }
    .result-box .result,
    .stat-value {
        overflow-wrap: anywhere;
    }
    .result-box .result { font-size: clamp(23px, 8vw, 31px); }

    /* Cada linha vira um cartão no celular. */
    .table-wrap {
        overflow: visible;
        border: 0;
        border-radius: 0;
        background: transparent;
    }
    table.responsive-table {
        display: block;
        min-width: 0 !important;
        width: 100%;
    }
    table.responsive-table thead { display: none; }
    table.responsive-table tbody {
        display: grid;
        gap: 12px;
    }
    table.responsive-table tr {
        display: block;
        overflow: hidden;
        border: 1px solid var(--border);
        border-radius: 13px;
        background: var(--surface);
        box-shadow: 0 5px 16px rgba(16, 24, 40, .05);
    }
    table.responsive-table td {
        display: grid;
        grid-template-columns: minmax(95px, 38%) minmax(0, 1fr);
        gap: 12px;
        width: 100%;
        padding: 11px 12px;
        text-align: right;
        white-space: normal;
        overflow-wrap: anywhere;
        border-bottom: 1px solid var(--border);
    }
    table.responsive-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 900;
        letter-spacing: .025em;
        text-align: left;
        text-transform: uppercase;
    }
    table.responsive-table td:last-child { border-bottom: 0; }
    table.responsive-table td[data-action-cell="true"] {
        display: block;
        padding: 12px;
    }
    table.responsive-table td[data-action-cell="true"]::before { display: none; }
    table.responsive-table td[data-action-cell="true"] .btn,
    table.responsive-table td[data-action-cell="true"] form,
    table.responsive-table td[data-action-cell="true"] form .btn {
        width: 100%;
    }
    table.responsive-table td form.actions {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }
    table.responsive-table td form input {
        width: 100% !important;
    }
    .receipt-frame {
        height: 62vh;
        min-height: 300px;
    }
    .login-page {
        min-height: 100dvh;
        padding-top: max(18px, env(safe-area-inset-top));
        padding-right: max(14px, env(safe-area-inset-right));
        padding-bottom: max(18px, env(safe-area-inset-bottom));
        padding-left: max(14px, env(safe-area-inset-left));
    }
    .login-card { padding: 22px 18px; }
}

@media (max-width: 420px) {
    .topbar p { display: none; }
    .topbar h1 { font-size: 17px; }
    .card { padding: 14px; }
    .stat-card { min-height: 112px; }
    table.responsive-table td {
        grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
        gap: 8px;
    }
}
