:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --text: #15231d;
  --muted: #63716b;
  --line: #dfe6e2;
  --primary: #176b4a;
  --primary-dark: #105139;
  --primary-soft: #e7f4ed;
  --danger: #b42318;
  --shadow: 0 8px 30px rgba(21, 35, 29, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
a { color: inherit; }
.container { width: min(1120px, calc(100% - 32px)); margin-inline: auto; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.nav { min-height: 68px; display: flex; gap: 28px; align-items: center; }
.nav a { text-decoration: none; font-weight: 650; }
.nav .brand { font-size: 21px; margin-right: auto; letter-spacing: -0.04em; }
.brand span { color: var(--primary); }
.page { padding-block: 48px 72px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 28px; }
.page-heading.compact { align-items: start; }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; margin: 0 0 7px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(28px, 4vw, 42px); line-height: 1.08; letter-spacing: -.04em; margin-bottom: 8px; }
h2 { font-size: 19px; letter-spacing: -.02em; }
.muted, .section-heading p { color: var(--muted); margin-bottom: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.button { border: 1px solid transparent; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 16px; font: inherit; font-weight: 750; text-decoration: none; cursor: pointer; }
.button-primary { background: var(--primary); color: white; }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--primary); border-color: #b8d6c8; background: var(--primary-soft); }
.button-ghost { border-color: var(--line); background: var(--surface); }
.button-danger { color: white; background: var(--danger); }
.button-danger:hover { background: #8f1d14; }
.button-danger-ghost { color: var(--danger); border-color: #efc2be; background: #fff7f6; }
.button-danger-ghost:hover { background: #ffe8e5; }
.button-group { display: flex; gap: 10px; flex-wrap: wrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.filters { display: grid; grid-template-columns: 1fr 220px; gap: 16px; padding: 18px; margin-bottom: 18px; }
label > span, .item-labels { display: block; font-size: 13px; font-weight: 700; margin-bottom: 7px; }
input, select, textarea { width: 100%; min-height: 43px; border: 1px solid #cbd6d0; border-radius: 8px; background: white; color: var(--text); padding: 9px 11px; font: inherit; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(23, 107, 74, .14); border-color: var(--primary); }
.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px 18px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #fafbfa; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
tbody tr:hover { background: #fbfdfc; }
.number { text-align: right; }
.money { font-weight: 750; font-variant-numeric: tabular-nums; }
.table-link { color: var(--primary); font-weight: 800; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 800; }
.badge-entrada { color: #176b4a; background: #e4f4eb; }
.badge-saida { color: #9f3a12; background: #fff0e8; }
.category-tag { display: inline-flex; padding: 5px 9px; border-radius: 7px; color: #355e4b; background: #edf5f1; font-size: 12px; font-weight: 750; }
.empty-state { padding: 64px 24px; text-align: center; }
.empty-state p { color: var(--muted); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 20px; padding: 17px; }
.pagination a { color: var(--primary); font-weight: 750; }
.pagination span { color: var(--muted); font-size: 14px; }
.back-link { color: var(--primary); display: inline-block; margin-bottom: 16px; font-weight: 700; text-decoration: none; }
.stack { display: grid; gap: 20px; }
.form-section { padding: 26px; }
.section-heading, .heading-with-step { display: flex; gap: 14px; align-items: flex-start; }
.section-heading { margin-bottom: 24px; }
.section-heading h2, .section-heading p { margin-bottom: 3px; }
.step { flex: 0 0 auto; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 850; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 19px; }
.full-width { grid-column: 1 / -1; }
.items-heading { justify-content: space-between; align-items: center; }
.item-labels, .item-row { display: grid; grid-template-columns: minmax(220px, 1fr) 190px 140px 170px 44px; gap: 12px; }
.item-labels { color: var(--muted); padding-inline: 2px; }
.item-forms { display: grid; gap: 10px; }
.item-row { align-items: start; padding: 12px; background: #fafcfa; border: 1px solid var(--line); border-radius: 10px; }
.item-row label > span.mobile-label { display: none; }
.delete-field { display: none; }
.icon-button { display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 8px; background: transparent; color: var(--danger); font-size: 25px; cursor: pointer; }
.icon-button:hover { background: #fff0ef; }
.field-error, .form-error { display: block; color: var(--danger); font-size: 13px; margin-top: 6px; }
.form-error { padding: 11px; background: #fff0ef; border-radius: 8px; margin-bottom: 14px; }
.form-error ul { margin-block: 0; }
.item-error { grid-column: 1 / -1; margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; }
.alert { padding: 13px 16px; border-radius: 9px; margin-bottom: 20px; }
.alert-success { color: #12563b; background: #def3e7; border: 1px solid #b9dfc9; }
.alert-warning { color: #73510d; background: #fff7d6; border: 1px solid #ead58a; }
.alert-error { color: #8f241b; background: #fff0ef; border: 1px solid #efc2be; }
.alert-error span { display: block; margin-top: 4px; }
.source-ok { color: #12563b; font-weight: 700; }
.source-error { color: #8f241b; font-size: .875rem; }
.source-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.source-card { border: 1px solid var(--line); padding: 20px; }
.source-card-ok { border-color: #b9dfc9; }
.source-card-pending { border-color: #d9dfe0; }
.source-card-error { border: 2px solid #d73a2f; background: #fff7f6; }
.source-fixed-card { margin-bottom: 18px; }
.source-fixed-description { margin-top: 16px; }
.source-card-header, .source-card-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.source-card-header h2 { margin: 4px 0 0; font-size: 1.2rem; }
.source-status { border-radius: 999px; background: #edf2f0; padding: 5px 10px; font-size: .78rem; font-weight: 700; }
.source-card-error .source-status { color: #8f241b; background: #ffdeda; }
.source-card-ok .source-status { color: #12563b; background: #def3e7; }
.source-details { margin: 18px 0; display: grid; gap: 8px; }
.source-details div { display: flex; justify-content: space-between; gap: 16px; }
.source-details dt { color: var(--muted); }
.source-details dd { margin: 0; text-align: right; font-weight: 600; }
.source-error-message { margin: 14px 0; border-radius: 8px; color: #8f241b; background: #ffe8e5; padding: 12px; font-size: .875rem; overflow-wrap: anywhere; }
.item-filters { display: grid; grid-template-columns: 2fr repeat(2, minmax(145px, .8fr)) 1fr; gap: 16px; align-items: end; padding: 18px; margin-bottom: 18px; }
.filter-q { grid-column: span 2; }
.filter-actions { display: flex; align-items: end; }
.results-summary { display: flex; align-items: baseline; gap: 7px; margin: 0 2px 10px; color: var(--muted); font-size: 14px; }
.results-summary strong { color: var(--text); font-size: 20px; }
.items-table .item-description { min-width: 260px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.quote-toolbar { display: flex; align-items: end; gap: 14px; margin-bottom: 18px; }
.quote-search { flex: 1; grid-template-columns: 1fr; margin-bottom: 0; }
.market-heading { margin-bottom: 20px; }
.action-menu { position: relative; flex: 0 0 auto; z-index: 12; }
.action-menu summary { list-style: none; }
.action-menu summary::-webkit-details-marker { display: none; }
.action-menu-toggle { width: 46px; min-width: 46px; padding: 0; }
.action-menu[open] .action-menu-toggle { color: white; border-color: var(--primary); background: var(--primary); }
.action-menu-panel { position: absolute; top: calc(100% + 8px); right: 0; display: grid; width: 250px; padding: 7px; box-shadow: 0 16px 42px rgba(21, 35, 29, .16); }
.action-menu-panel a { padding: 11px 12px; border-radius: 8px; font-weight: 700; text-decoration: none; }
.action-menu-panel a:hover { background: var(--primary-soft); color: var(--primary-dark); }
.action-menu-panel .action-menu-primary { margin-top: 4px; color: white; background: var(--primary); }
.action-menu-panel .action-menu-primary:hover { color: white; background: var(--primary-dark); }
.source-strip { display: flex; align-items: center; gap: 20px; padding: 14px 16px; margin-bottom: 16px; box-shadow: none; }
.source-strip-title { display: flex; align-items: center; gap: 10px; }
.source-strip-title > div { display: grid; gap: 1px; }
.source-strip-title small, .source-note { color: var(--muted); }
.source-pulse { width: 9px; height: 9px; border-radius: 50%; background: #28a46d; box-shadow: 0 0 0 5px #e2f4ea; }
.source-list { display: flex; gap: 7px; flex-wrap: wrap; }
.source-badge { display: inline-flex; align-items: center; padding: 4px 8px; border: 1px solid transparent; border-radius: 999px; font-size: 11px; font-weight: 750; text-decoration: none; }
.source-badge-ok { color: #12563b; background: #def3e7; border-color: #b9dfc9; }
.source-badge-pending { color: #73510d; background: #fff7d6; border-color: #ead58a; }
.source-badge-error { color: #8f241b; background: #ffdeda; border-color: #e69b94; }
.source-badge:hover { color: inherit; filter: brightness(.97); }
.quote-row-warning td { background: #fffdf3; }
.quote-row-warning td:first-child { box-shadow: inset 3px 0 #d9a928; }
.quote-row-error td { background: #fff7f6; }
.quote-row-error td:first-child { box-shadow: inset 3px 0 #d73a2f; }
.source-note { margin-left: auto; text-align: right; }
.quote-update-form { position: relative; }
.quote-update-button { width: 48px; min-width: 48px; padding: 0; }
.quote-update-button .default-label { line-height: 0; }
.loading-label { display: none; align-items: center; gap: 8px; }
.mini-spinner { width: 16px; height: 16px; border: 2px solid #a8cfbd; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
.quote-update-form.htmx-request .default-label { display: none; }
.quote-update-form.htmx-request .loading-label { display: inline-flex; }
.quote-update-form button:disabled { cursor: wait; opacity: .78; }
.quote-loading { display: none; position: absolute; z-index: 10; top: calc(100% + 9px); right: 0; width: min(390px, calc(100vw - 24px)); align-items: center; gap: 12px; padding: 14px; border: 1px solid #b8d6c8; border-radius: 11px; color: #17583f; background: var(--surface); box-shadow: 0 14px 36px rgba(21, 35, 29, .14); }
.quote-loading > span:last-child { display: grid; gap: 2px; }
.quote-loading small { color: var(--muted); line-height: 1.35; }
.quote-update-form.htmx-request .quote-loading { display: flex; }
.quote-section-title { display: flex; justify-content: space-between; align-items: end; gap: 20px; padding: 38px 2px 12px; }
.quote-section-title.first { padding-top: 8px; }
.quote-section-title h2, .quote-section-title p { margin-bottom: 0; }
.table-secondary { display: block; margin-top: 4px; color: var(--muted); }
.scope-tag { display: block; width: fit-content; margin: 4px 0 0 auto; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .02em; }
.quote-row-actions, .fuel-price-action { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.quote-row-actions { justify-content: flex-start; }
.quote-manual-link { flex: 0 0 auto; display: inline-grid; place-items: center; width: 28px; height: 28px; border: 1px solid #b8d6c8; border-radius: 50%; color: var(--primary); background: var(--primary-soft); font-size: 20px; font-weight: 500; line-height: 1; text-decoration: none; }
.quote-manual-link:hover { color: white; background: var(--primary); }
.compact-form { width: min(620px, 100%); padding: 26px; }
.title-line { display: flex; align-items: center; gap: 12px; }
.title-line h1 { margin-bottom: 0; }
.summary-grid { display: grid; grid-template-columns: 1.5fr .7fr 1fr; gap: 16px; margin-bottom: 20px; }
.summary-card { padding: 20px; display: grid; gap: 8px; }
.summary-card span { color: var(--muted); font-size: 13px; }
.summary-card strong { font-size: 19px; }
.summary-card.accent { background: var(--primary); color: white; border-color: var(--primary); }
.summary-card.accent span { color: #cce8db; }
.section-title { padding: 20px 18px 0; }
.detail-table { margin-bottom: 20px; }
tfoot td { background: #fafbfa; font-weight: 800; border-bottom: 0; }
.note { padding: 22px; }
.note h2 { margin-bottom: 10px; }
.note p { margin-bottom: 0; color: var(--muted); }
.import-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, .7fr); gap: 20px; align-items: start; }
.import-card, .help-card { padding: 26px; }
.movement-field { border: 0; padding: 0; margin: 0; }
.movement-field legend { font-size: 13px; font-weight: 750; margin-bottom: 8px; }
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.radio-card { position: relative; display: block; margin: 0; cursor: pointer; }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card > span { display: grid; gap: 3px; min-height: 72px; padding: 14px; border: 1px solid #cbd6d0; border-radius: 10px; }
.radio-card small, .help-text, .file-drop small { color: var(--muted); font-weight: 450; }
.radio-card input:checked + span { border-color: var(--primary); outline: 3px solid rgba(23, 107, 74, .12); background: var(--primary-soft); }
.help-text { display: block; margin-top: 8px; }
.file-drop { display: grid; gap: 8px; padding: 22px; border: 1px dashed #9eb5aa; border-radius: 12px; background: #fafcfa; }
.file-drop > span { margin: 0; }
.file-drop input { padding: 8px; background: var(--surface); }
.privacy-note { margin: -5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.import-error { display: grid; gap: 5px; margin: 0; }
.processing-hint { display: none; align-items: center; gap: 12px; padding: 13px; border-radius: 9px; color: #17583f; background: var(--primary-soft); }
.processing-hint span:last-child { display: grid; gap: 2px; }
.processing-hint small { color: var(--muted); }
.htmx-request .processing-hint { display: flex; }
.spinner { width: 24px; height: 24px; border: 3px solid #b5d9c7; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.help-card { background: #f0f7f3; }
.help-card ul { color: var(--muted); padding-left: 20px; line-height: 1.8; }
.help-card p { color: var(--muted); font-size: 14px; }
.ai-note { padding-top: 13px; border-top: 1px solid #cfe1d7; }
.htmx-indicator { display: none; }
.htmx-request .default-label { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.import-actions { margin-top: 4px; }
.import-dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 16px; background: transparent; box-shadow: 0 24px 80px rgba(10, 30, 21, .24); }
.import-dialog[open] { display: block; position: fixed; inset: 16px 0 auto; margin: auto; z-index: 20; }
.import-dialog::backdrop { background: rgba(12, 24, 18, .58); backdrop-filter: blur(3px); }
.dialog-card { padding: 26px; background: var(--surface); border-radius: 16px; overflow-y: auto; max-height: calc(100vh - 32px); }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.dialog-heading h2 { font-size: 26px; margin-bottom: 5px; }
.dialog-heading p:last-child { color: var(--muted); margin-bottom: 0; }
.dialog-close { flex: 0 0 auto; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #eef2f0; color: var(--text); font-size: 25px; cursor: pointer; }
.format-cards .radio-card > span { min-height: 82px; }
.confirm-heading { align-items: center; }
.extracted-total { flex: 0 0 auto; min-width: 210px; padding: 15px 18px; border-radius: 12px; background: var(--primary); color: white; display: grid; gap: 4px; }
.extracted-total span { color: #cce8db; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.extracted-total strong { font-size: 23px; font-variant-numeric: tabular-nums; }
.review-notice { display: grid; gap: 3px; margin-bottom: 20px; padding: 14px 17px; border: 1px solid #e7ce8a; border-radius: 10px; color: #694c08; background: #fff8df; }
.review-notice span { font-size: 14px; }
.confirm-actions { position: sticky; bottom: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, .94); box-shadow: var(--shadow); backdrop-filter: blur(8px); }

@media (max-width: 760px) {
  .container { width: min(100% - 24px, 1120px); }
  .nav { gap: 14px; }
  .nav > a:not(.brand):not(.button) { display: none; }
  .page { padding-top: 30px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading.market-heading { align-items: flex-start; flex-direction: row; }
  .market-heading > div { min-width: 0; }
  .market-heading h1 { font-size: clamp(28px, 9vw, 42px); }
  .filters, .form-grid, .summary-grid, .item-filters { grid-template-columns: 1fr; }
  .filter-q { grid-column: auto; }
  .filter-actions .button { width: 100%; }
  .quote-toolbar { align-items: stretch; flex-direction: column; }
  .quote-section-title { align-items: flex-start; flex-direction: column; }
  .source-strip { align-items: flex-start; flex-direction: column; gap: 11px; }
  .source-note { margin-left: 0; text-align: left; }
  .quote-update-form { align-self: flex-end; }
  .quote-update-form .quote-update-button { width: 48px; }
  .quote-loading { position: static; width: 100%; margin-top: 9px; }
  .import-layout, .radio-cards { grid-template-columns: 1fr; }
  .form-section { padding: 18px; }
  .items-heading { align-items: stretch; flex-direction: column; }
  .item-labels { display: none; }
  .item-row { grid-template-columns: 1fr 1fr 42px; }
  .item-row label:first-of-type { grid-column: 1 / -1; }
  .item-row label > span.mobile-label { display: block; }
  .remove-cell { grid-column: 3; grid-row: 3; }
  .form-actions .button { flex: 1; }
}

.account-menu { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.account-menu form { margin: 0; }
.nav-logout { border: 0; padding: 6px; color: var(--muted); background: transparent; cursor: pointer; font: inherit; }
.nav-logout:hover { color: var(--primary); }
.auth-shell { min-height: 68vh; display: grid; place-items: center; }
.auth-card { width: min(430px, 100%); }
.auth-card h1 { margin-bottom: 22px; }
.auth-card label { display: grid; gap: 7px; margin-bottom: 15px; font-weight: 700; }
.auth-card .button { width: 100%; margin-top: 8px; }
.state-card { max-width: 680px; margin: 8vh auto; padding: 32px; }
.state-card-warning { border-color: #e7ce8a; background: #fff8df; }
