:root {
  --ink: #333c48;
  --muted: #6a7785;
  --muted-2: #9199a1;
  --line: #dfe3e6;
  --line-strong: #c6cdd3;
  --canvas: #eef2f4;
  --surface: #ffffff;
  --surface-subtle: #f5f7f8;
  --wine: #1686c9;
  --wine-dark: #116fa9;
  --wine-soft: #eef8fd;
  --green: #198847;
  --green-soft: #eef9f2;
  --amber: #a96500;
  --amber-soft: #fff8e8;
  --red: #c8333f;
  --radius: 11px;
  --shadow: 0 8px 28px rgba(51, 60, 72, 0.08);
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color: var(--ink); background: var(--canvas); scroll-behavior: smooth; }
body { min-width: 320px; margin: 0; font-family: var(--sans); font-size: 14px; line-height: 1.5; background: var(--canvas); color: var(--ink); }
button, input, textarea, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
svg.icon { flex: 0 0 auto; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.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; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; transform: translateY(-150%); padding: 9px 14px; background: var(--ink); color: #fff; border-radius: 6px; }
.skip-link:focus { transform: translateY(0); }

.site-header { position: sticky; z-index: 30; top: 0; width: 100%; min-width: 0; min-height: 78px; display: flex; align-items: stretch; gap: 36px; padding: 0 32px; background: rgba(255,255,255,.97); border-bottom: 1px solid var(--line); }
.brand { width: 270px; display: flex; align-items: center; padding-right: 30px; border-right: 1px solid var(--line); text-decoration: none; }
.brand img { display: block; width: 238px; height: auto; }
.primary-nav { display: flex; align-items: stretch; gap: 22px; }
.primary-nav a { position: relative; display: flex; align-items: center; gap: 9px; min-width: max-content; padding: 0 7px; color: #4a5669; text-decoration: none; font-size: 15px; }
.primary-nav a:hover { color: var(--wine); }
.primary-nav a.active { color: var(--wine); font-weight: 650; }
.primary-nav a.active::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 3px; background: var(--wine); }
.account-nav { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.account-nav > span { display: flex; align-items: center; gap: 7px; min-width: max-content; color: #435066; font-size: 12px; }
.account-nav > span .icon { color: var(--wine); }
.account-nav > span small { padding: 2px 6px; border-radius: 999px; color: var(--wine); background: var(--wine-soft); font-size: 9px; font-weight: 700; text-transform: uppercase; }
.account-nav form { margin: 0; }
.account-nav button { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: #fff; cursor: pointer; }
.account-nav button:hover { color: var(--wine); border-color: #9ccdea; background: var(--wine-soft); }
.guest-header { justify-content: flex-start; }
.guest-header .brand { border-right: 0; }

.page-shell { width: min(1480px, 100%); max-width: 100%; min-width: 0; min-height: calc(100vh - 133px); margin: 0 auto; padding: 28px 32px 44px; }
.site-footer { display: flex; justify-content: space-between; gap: 24px; min-height: 55px; align-items: center; padding: 0 max(32px, calc((100vw - 1416px) / 2)); color: var(--muted); border-top: 1px solid var(--line); background: #fff; font-size: 12px; }
.page-heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 24px; }
.page-heading h1, .result-heading h1 { margin: 0 0 5px; font-family: var(--serif); font-size: clamp(31px, 3vw, 48px); line-height: 1.1; font-weight: 500; letter-spacing: -.025em; }
.page-heading p, .result-heading p { margin: 0; color: var(--muted); font-size: 15px; }
.heading-with-action { align-items: center; }
.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.button { min-height: 40px; display: inline-flex; justify-content: center; align-items: center; gap: 8px; padding: 9px 16px; border: 1px solid transparent; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 650; line-height: 1.2; text-decoration: none; transition: background .16s ease, border-color .16s ease, transform .16s ease, box-shadow .16s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible, .icon-button:focus-visible, .info-button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(22,134,201,.24); outline-offset: 2px; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button[aria-disabled="true"] { cursor: progress; opacity: .65; pointer-events: none; }
.button-primary { color: #fff; background: var(--wine); border-color: var(--wine); box-shadow: 0 5px 13px rgba(22,134,201,.18); }
.button-primary:hover:not(:disabled) { background: var(--wine-dark); border-color: var(--wine-dark); }
.button-secondary { color: var(--ink); background: #fff; border-color: var(--line-strong); }
.button-secondary:hover:not(:disabled) { border-color: #9ba5b2; background: var(--surface-subtle); }
.button-secondary.danger, .icon-button.danger { color: var(--red); }
.button-secondary.danger:hover { border-color: #e4a9ae; background: #fff7f7; }
.button-large { width: 100%; min-height: 48px; margin-top: 14px; font-size: 15px; }
.button-inline { margin-top: 12px; }
.button-full { width: 100%; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.text-link { color: var(--wine); font-weight: 650; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.back-link { width: max-content; display: inline-flex; align-items: center; gap: 5px; margin-bottom: 10px; color: var(--muted); text-decoration: none; font-size: 13px; }
.back-link:hover { color: var(--wine); }
.icon-button { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer; }
.icon-button:hover { background: var(--surface-subtle); border-color: var(--line-strong); }
.heading-with-help { display: flex; align-items: center; gap: 7px; min-width: 0; }
.heading-with-help > h1, .heading-with-help > h2, .heading-with-help > h3 { min-width: 0; }
.info-help { position: relative; display: inline-flex; flex: 0 0 auto; vertical-align: middle; }
.info-button { width: 25px; height: 25px; display: inline-grid; place-items: center; padding: 0; border: 1px solid #cbd3dd; border-radius: 50%; color: #5d6b7e; background: #fff; cursor: pointer; }
.info-button:hover, .info-button[aria-expanded="true"] { color: var(--wine); border-color: #9ccdea; background: var(--wine-soft); }
.info-popover { position: fixed; z-index: 95; width: min(300px, calc(100vw - 24px)); padding: 11px 12px; border: 1px solid #cdd4de; border-radius: 8px; color: #344054; background: #fff; box-shadow: 0 12px 30px rgba(17,31,51,.16); font-family: var(--sans); font-size: 12px; font-weight: 400; line-height: 1.48; text-align: left; text-transform: none; letter-spacing: normal; white-space: normal; }

.home-layout { display: grid; grid-template-columns: minmax(0, 1.04fr) minmax(430px, .96fr); gap: 28px; align-items: start; }
.upload-workspace, .recent-panel, .data-panel, .term-form-panel, .term-list-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.upload-workspace { padding: 12px; }
.drop-zone { min-height: 196px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 22px; border: 1px dashed var(--wine); border-radius: 9px; cursor: pointer; text-align: center; background: #fff; transition: background .16s ease, border-color .16s ease; }
.drop-zone:hover, .drop-zone.drag-active { background: var(--wine-soft); border-color: var(--wine-dark); }
.drop-zone > .icon { color: var(--wine); margin-bottom: 10px; }
.drop-zone strong { font-size: 21px; font-weight: 600; }
.drop-zone > span:not(.button) { color: var(--muted); }
.drop-zone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-queue { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.empty-queue { padding: 16px; color: var(--muted); text-align: center; }
.queued-file { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 12px; min-height: 58px; padding: 9px 13px; border-bottom: 1px solid var(--line); }
.queued-file:last-child { border-bottom: 0; }
.queued-file > .icon { color: var(--wine); }
.queued-file strong, .queued-file span { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queued-file strong { font-size: 13px; }
.queued-file span { color: var(--muted); font-size: 12px; }
.remove-file { width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; color: var(--muted); font-size: 22px; }
.remove-file:hover { color: var(--red); background: #fff2f2; }
.validation-note { display: flex; gap: 11px; align-items: flex-start; margin: 10px 0 16px; padding: 12px 14px; border: 1px solid #add9ba; border-radius: 8px; color: var(--green); background: var(--green-soft); }
.validation-note strong, .validation-note span { display: block; }
.validation-note span { margin-top: 1px; color: #47705a; font-size: 12px; }

.form-grid { display: grid; gap: 14px; }
.form-grid.two-columns { grid-template-columns: 1fr 1fr; }
.field { display: grid; gap: 6px; }
.field > span { min-height: 25px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; color: #344054; font-size: 12px; font-weight: 650; }
.field-label-with-help .info-help { margin-left: 2px; }
.field-label-with-help .info-button { width: 21px; height: 21px; }
.field small { color: var(--muted); font-weight: 400; }
.field input, .field textarea, .field select, .table-search input { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; }
.field input[readonly] { color: #44515f; border-color: #d2d9de; background: #f1f4f6; cursor: not-allowed; }
.field textarea { resize: vertical; }
.field input::placeholder, .field textarea::placeholder, .table-search input::placeholder { color: #9da5b1; }
.field-help { color: var(--muted); font-size: 11px; }
.term-picker { margin-top: 17px; padding: 15px 2px 5px; border-top: 1px solid var(--line); }
.section-toolbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.section-toolbar h2, .recent-panel h2, .group-rail h2, .workspace-toolbar h2, .term-form-panel h2, .term-list-panel h2 { margin: 0; font-family: var(--serif); font-size: 21px; font-weight: 500; }
.section-toolbar p, .workspace-toolbar p, .term-form-panel > p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.checkbox-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 12px; margin-top: 13px; }
.check-option { min-width: 0; display: flex; align-items: center; gap: 8px; color: #394558; font-size: 12px; cursor: pointer; }
.check-option input, .result-table input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--wine); }
.check-option span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.consultation-actions { display: grid; grid-template-columns: 1.15fr .85fr; gap: 10px; align-items: start; margin-top: 14px; }
.consultation-actions .button-large { margin-top: 0; }
.consultation-actions p { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 11px; text-align: center; }

.recent-panel { overflow: hidden; }
.recent-heading { padding: 20px 22px 15px; border-bottom: 1px solid var(--line); }
.recent-row { display: grid; grid-template-columns: minmax(180px,1.1fr) 1.7fr; gap: 18px; align-items: center; min-height: 74px; padding: 13px 22px; border-bottom: 1px solid var(--line); text-decoration: none; transition: background .14s ease; }
.recent-row:last-child { border-bottom: 0; }
.recent-row:hover { background: var(--surface-subtle); }
.recent-row strong, .recent-row span { display: block; }
.recent-row strong { color: var(--wine); font-size: 13px; }
.recent-row > div:first-child span { margin-top: 3px; color: #4e5a6c; font-size: 12px; }
.recent-meta { display: grid; grid-template-columns: auto auto minmax(110px,1fr); gap: 13px; align-items: center; color: var(--muted); font-size: 11px; }
.recent-meta time { text-align: right; }
.status { display: inline-flex; align-items: center; gap: 6px; width: max-content; color: #485467; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: #8b95a4; }
.status-concluida i { background: #25a45a; }
.status-falha i { background: #db3948; }
.status-processando i { background: #e7a30b; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.flash-region { position: fixed; z-index: 80; right: 22px; top: 90px; width: min(440px, calc(100vw - 32px)); display: grid; gap: 9px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.alert-success { color: var(--green); border-color: #add9ba; background: var(--green-soft); }
.alert-danger { color: #a72231; border-color: #e5b1b7; background: #fff5f6; }
.alert-warning { color: var(--amber); border-color: #e8cf96; background: var(--amber-soft); }
.alert span { flex: 1; color: #334054; }
.alert-close { border: 0; background: transparent; color: currentColor; cursor: pointer; font-size: 19px; }

.data-panel { overflow: hidden; }
.table-scroll { width: 100%; overflow-x: auto; scrollbar-width: thin; }
table { width: 100%; border-collapse: collapse; }
.jobs-table { min-width: 1280px; }
.jobs-table th, .jobs-table td { padding: 14px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.jobs-table th, .result-table th { color: var(--muted); background: #fbfcfd; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .035em; }
.jobs-table tbody tr:hover { background: #fbfcfd; }
.jobs-table tbody tr:last-child td { border-bottom: 0; }
.job-id { color: var(--wine); font-weight: 700; text-decoration: none; }
.job-id:hover { text-decoration: underline; }
.history-user { font-weight: 650; white-space: nowrap; }
.deal-id { color: #344054; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; justify-content: flex-end; }
.row-actions form, .term-actions form { margin: 0; }

.result-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; margin-bottom: 18px; }
.result-heading h1 { font-size: clamp(28px, 2.5vw, 40px); }
.title-line { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.result-heading b { padding: 0 5px; color: var(--ink); }
.summary-band { display: grid; grid-template-columns: repeat(4,1fr); min-height: 96px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.summary-band > div { position: relative; display: flex; justify-content: center; flex-direction: column; padding: 18px 28px; border-right: 1px solid var(--line); }
.summary-band > div:last-child { border-right: 0; }
.summary-band strong { font-family: var(--serif); font-size: 28px; font-weight: 500; line-height: 1; }
.summary-band span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.summary-band .needs-review { background: var(--amber-soft); }
.warning-details { margin-bottom: 12px; padding: 10px 14px; border: 1px solid #ead9ad; border-radius: 8px; color: #76510b; background: #fffbef; }
.warning-details summary { display: flex; gap: 8px; align-items: center; cursor: pointer; font-weight: 650; }
.warning-details pre { overflow: auto; margin: 10px 0 2px; white-space: pre-wrap; font-family: var(--sans); font-size: 12px; }
.bitrix-panel { display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 12px; align-items: start; margin-bottom: 12px; padding: 13px 14px; border: 1px solid #cbd8e6; border-radius: var(--radius); background: #f7faff; }
.bitrix-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 8px; color: #285b8b; background: #e5eff9; }
.bitrix-copy { min-width: 0; }
.bitrix-title { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.bitrix-title strong { font-size: 13px; }
.bitrix-title span { padding: 3px 7px; border-radius: 999px; color: #285b8b; background: #e5eff9; font-size: 10px; font-weight: 700; }
.bitrix-copy p { margin: 4px 0; color: #526174; font-size: 12px; }
.bitrix-copy small { color: var(--muted); font-size: 10px; }
.bitrix-copy details { margin-top: 5px; color: #41536a; font-size: 11px; }
.bitrix-copy details summary { width: max-content; cursor: pointer; font-weight: 650; }
.bitrix-copy dl { display: grid; gap: 7px; margin: 8px 0 2px; }
.bitrix-copy dl div { display: grid; grid-template-columns: 85px minmax(0,1fr); gap: 8px; }
.bitrix-copy dt { color: var(--muted); font-weight: 700; }
.bitrix-copy dd { margin: 0; line-height: 1.45; }
.bitrix-copy .bitrix-error { color: #9b2734; }
.bitrix-falha, .bitrix-nao_configurado, .bitrix-incerta { border-color: #e5b1b7; background: #fff7f8; }
.bitrix-falha .bitrix-title span, .bitrix-nao_configurado .bitrix-title span, .bitrix-incerta .bitrix-title span { color: #9b2734; background: #fbe3e6; }
.bitrix-parcial { border-color: #e8cf96; background: #fffbef; }
.free-consultation-panel { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; padding: 15px 17px; border: 1px solid #cbd8e6; border-radius: var(--radius); background: #f7faff; }
.free-consultation-panel > .icon { color: #285b8b; }
.free-consultation-panel h2 { margin: 0; font-family: var(--serif); font-size: 19px; font-weight: 500; }
.free-consultation-panel p { margin: 2px 0 0; color: #526174; font-size: 12px; }
.results-layout { display: grid; grid-template-columns: 230px minmax(0,1fr); gap: 14px; align-items: start; }
.group-rail { position: sticky; top: 95px; padding: 16px 12px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.group-rail-heading { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 0 8px 12px; }
.group-rail h2 { padding: 0; font-size: 18px; }
.group-rail nav { display: grid; gap: 3px; margin-bottom: 14px; }
.group-rail nav a { display: flex; justify-content: space-between; gap: 8px; align-items: center; min-height: 42px; padding: 9px 10px; border: 1px solid transparent; border-radius: 7px; color: #425064; text-decoration: none; }
.group-rail nav a:hover { background: var(--surface-subtle); }
.group-rail nav a.selected { color: var(--wine); border-color: #9ccdea; background: var(--wine-soft); font-weight: 650; }
.group-rail nav span { overflow: hidden; text-overflow: ellipsis; }
.group-rail nav b { font-size: 12px; }
.copy-badge { display: block; width: max-content; margin-top: 2px; color: #33749a; font-size: 8px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.results-workspace { width: 100%; min-width: 0; max-width: 100%; }
.workspace-toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 10px 4px 12px; }
.workspace-toolbar h2 { font-size: 30px; }
.toolbar-actions, .editor-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.copy-group-panel { margin-bottom: 12px; padding: 15px; border: 1px solid #bfd0e1; border-radius: var(--radius); background: #f7faff; }
.copy-group-panel h3 { margin: 0; font-family: var(--serif); font-size: 19px; font-weight: 500; }
.copy-group-panel .section-toolbar p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.copy-group-controls { display: grid; grid-template-columns: minmax(250px,1fr) auto; gap: 10px; align-items: end; margin-top: 13px; }
.bulk-rename-form { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(180px, .75fr) auto; gap: 12px; align-items: end; margin-bottom: 12px; padding: 13px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-subtle); }
.bulk-rename-form p { align-self: center; margin: 17px 0 0; color: var(--muted); font-size: 11px; }
.bulk-rename-form .button { white-space: nowrap; }
.row-editor { width: 100%; min-width: 0; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.editor-actions { min-height: 58px; justify-content: flex-end; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.table-search { margin-right: auto; display: flex; align-items: center; gap: 6px; width: min(260px, 100%); padding-left: 10px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--muted); }
.table-search input { min-height: 36px; padding-left: 0; border: 0; outline: 0; }
.transaction-kind-filter { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 650; white-space: nowrap; }
.transaction-kind-filter select { min-height: 38px; padding: 7px 30px 7px 9px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; font-size: 12px; }
.filter-bulk-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px; padding: 8px 12px; border-bottom: 1px solid #bed9e9; background: var(--wine-soft); }
.filter-bulk-bar > span { color: #315a74; font-size: 11px; font-weight: 650; }
.filter-bulk-bar > div { display: flex; gap: 7px; flex-wrap: wrap; }
.filter-bulk-bar .button { min-height: 36px; padding: 7px 11px; font-size: 11px; }
.dirty-note { color: var(--muted); font-size: 11px; }
.dirty-note.is-dirty { color: var(--amber); font-weight: 650; }
.result-table { min-width: 1050px; table-layout: fixed; }
.result-col-select { width: 42px; }
.result-col-date { width: 116px; }
.result-col-amount, .result-col-balance { width: 112px; }
.result-col-classification { width: 118px; }
.result-col-source { width: 150px; }
.result-table th { position: sticky; z-index: 2; top: 0; padding: 10px 9px; border-bottom: 1px solid var(--line); text-align: left; }
.result-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.result-table tbody tr:last-child td { border-bottom: 0; }
.result-table tbody tr:has(input[type=checkbox]:checked) { background: var(--wine-soft); }
.result-table tbody tr.loan-emp-row:not(:has(input[type=checkbox]:checked)) { background: #fff2f2; }
.result-table tbody tr.loan-vc-row:not(:has(input[type=checkbox]:checked)) { background: #fff9df; }
.result-table tbody tr.loan-emp-row .description-input { color: #9d2532; font-weight: 650; }
.result-table tbody tr.loan-vc-row .description-input { color: #87600a; font-weight: 650; }
.result-table td:first-child, .result-table th:first-child { width: 40px; text-align: center; }
.table-input { width: 100%; min-height: 36px; padding: 6px 7px; border: 1px solid transparent; border-radius: 5px; background: transparent; font-size: 12px; }
.table-input:hover { border-color: var(--line); background: #fff; }
.table-input:focus { border-color: var(--wine); background: #fff; outline: 2px solid rgba(22,134,201,.12); }
.date-input { min-width: 0; }
.description-input { display: block; min-width: 0; min-height: 38px; resize: vertical; line-height: 1.35; overflow-wrap: anywhere; }
.money-input { min-width: 0; text-align: right; font-variant-numeric: tabular-nums; }
.money-input.negative { color: var(--red); }
.inferred-date { display: block; margin: -3px 0 3px 7px; color: var(--amber); font-size: 9px; font-weight: 700; }
.classification { display: inline-flex; width: max-content; padding: 4px 7px; border: 1px solid var(--line-strong); border-radius: 5px; color: #475468; background: #fff; font-size: 10px; white-space: nowrap; }
.classification-trienal { color: #14743d; border-color: #b4dbc1; background: var(--green-soft); }
.classification-quinquenal { color: #78530b; border-color: #ead49c; background: var(--amber-soft); }
.classification-decenal { color: #2a5f96; border-color: #b9d0e8; background: #f2f7fc; }
.classification-fora_do_prazo { color: var(--muted); background: var(--surface-subtle); }
.source-cell { min-width: 0; max-width: none; }
.source-cell a, .source-cell span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 10px; }
.source-cell a { color: #344b69; text-decoration: none; }
.source-cell a:hover { text-decoration: underline; }
.add-row-panel { margin-top: 12px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-subtle); }
.add-row-grid { grid-template-columns: 150px minmax(220px,1fr) 130px 130px; margin: 14px 0; }
.stats-band { display: grid; grid-template-columns: repeat(3,1fr); margin-top: 12px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stat-period { padding: 15px 18px; border-right: 1px solid var(--line); }
.stat-period:last-child { border-right: 0; }
.stat-period h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 11px; font-family: var(--serif); font-size: 17px; font-weight: 500; }
.stat-period h3 .icon { color: var(--wine); }
.stat-period dl { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 16px; margin: 0; }
.stat-period dl div { min-width: 0; }
.stat-period dt { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .03em; }
.stat-period dd { margin: 1px 0 0; color: var(--wine); font-size: 12px; font-weight: 700; }
.petition-bar { margin-top: 12px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.petition-heading h3 { margin: 0; font-family: var(--serif); font-size: 21px; font-weight: 500; }
.petition-heading p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.petition-model-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 9px; margin-top: 14px; }
.petition-model-option { position: relative; min-width: 0; cursor: pointer; }
.petition-model-option > input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.petition-model-card { position: relative; min-height: 144px; display: flex; flex-direction: column; padding: 13px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); pointer-events: none; transition: border-color .16s ease, background .16s ease, box-shadow .16s ease; }
.petition-model-card em { width: max-content; max-width: 100%; overflow: hidden; padding: 3px 7px; border-radius: 999px; color: #526174; background: #eef1f5; font-size: 9px; font-style: normal; font-weight: 750; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.petition-model-card strong { margin-top: 10px; font-family: var(--serif); font-size: 17px; font-weight: 500; line-height: 1.2; }
.petition-model-card small { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.petition-model-card i { position: absolute; right: 9px; bottom: 9px; width: 22px; height: 22px; display: none; place-items: center; border-radius: 50%; color: #fff; background: var(--wine); }
.petition-model-option:hover .petition-model-card { border-color: #b6bec9; background: var(--surface-subtle); }
.petition-model-option > input:focus-visible + .petition-model-card { outline: 3px solid rgba(22,134,201,.24); outline-offset: 2px; }
.petition-model-option > input:checked + .petition-model-card { border-color: var(--wine); background: var(--wine-soft); box-shadow: inset 0 0 0 1px var(--wine); }
.petition-model-option > input:checked + .petition-model-card em { color: var(--wine); background: #f8dce2; }
.petition-model-option > input:checked + .petition-model-card i { display: grid; }
.petition-footer { display: grid; grid-template-columns: minmax(240px, 1fr) auto; gap: 14px; align-items: end; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.petition-card-field { display: none; max-width: 360px; }
.petition-card-field > small { color: var(--muted); font-size: 10px; }
.petition-bar.card-model-selected .petition-card-field, .petition-bar:has(input[value="pi_produto_cartao"]:checked) .petition-card-field { display: grid; }
.petition-actions { display: flex; gap: 8px; justify-content: flex-end; }
.petition-actions .button { min-width: 190px; }
.generated-panel { display: grid; grid-template-columns: 210px minmax(0,1fr); gap: 18px; margin-top: 12px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-subtle); }
.generated-panel h3 { margin: 0; font-family: var(--serif); font-size: 17px; font-weight: 500; }
.generated-panel p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.generated-panel ul { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.generated-panel a { display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; color: #344b69; background: #fff; text-decoration: none; }
.generated-panel a:hover { border-color: var(--line-strong); }
.generated-panel a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.generated-panel a small { color: var(--muted); font-size: 9px; white-space: nowrap; }

.terms-layout { display: grid; grid-template-columns: minmax(300px, .65fr) minmax(0, 1.35fr); gap: 18px; align-items: start; }
.term-form-panel { position: sticky; top: 96px; padding: 20px; }
.term-form-panel > p { margin-bottom: 17px; }
.term-form-panel form { display: grid; gap: 15px; }
.switch-option { display: flex; gap: 9px; align-items: center; cursor: pointer; }
.switch-option input { width: 18px; height: 18px; accent-color: var(--wine); }
.term-list-panel { overflow: hidden; }
.term-list-panel.full-width { grid-column: 1 / -1; }
.term-list-panel > .section-toolbar { padding: 20px; border-bottom: 1px solid var(--line); }
.term-list { display: grid; }
.term-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 16px; align-items: center; min-height: 82px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.term-row:last-child { border-bottom: 0; }
.term-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.term-row h3 { margin: 0; font-size: 14px; }
.term-row p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.term-row .term-meta { margin-top: 8px; color: #66758a; font-size: 10px; }
.term-meta strong { color: #3d4b60; font-weight: 650; }
.term-actions { display: flex; gap: 7px; align-items: center; }

.failure-panel { display: flex; align-items: flex-start; gap: 18px; padding: 24px; border: 1px solid #e6aeb5; border-radius: var(--radius); color: #a72231; background: #fff6f7; }
.failure-panel h2, .failure-panel h1 { margin: 0 0 7px; font-family: var(--serif); color: var(--ink); font-weight: 500; }
.failure-panel p { margin: 0 0 17px; color: #5e4350; white-space: pre-wrap; }
.failure-panel.standalone { align-items: center; max-width: 760px; margin: 10vh auto; }
.failure-panel.standalone > strong { font-family: var(--serif); font-size: 72px; }
.empty-state { padding: 36px 20px; color: var(--muted); text-align: center; }
.empty-state.compact { padding: 28px 20px; }

.login-shell { display: grid; place-items: center; }
.login-panel { width: min(470px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.login-mark { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 12px; color: var(--wine); background: var(--wine-soft); }
.login-heading { margin: 17px 0 20px; }
.login-heading h1 { margin: 0; font-family: var(--serif); font-size: 32px; font-weight: 500; }
.login-heading p { margin: 5px 0 0; color: var(--muted); }
.login-form { display: grid; gap: 14px; }
.login-form .button-large { margin-top: 2px; }
.login-security { margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; text-align: center; }

.users-layout { display: grid; grid-template-columns: minmax(290px, .7fr) minmax(0, 1.3fr); gap: 18px; align-items: start; }
.user-create-panel, .user-list-panel { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.user-create-panel { position: sticky; top: 96px; }
.user-create-form { display: grid; gap: 13px; margin-top: 18px; }
.admin-check { min-height: 38px; }
.user-list { display: grid; gap: 10px; margin-top: 18px; }
.user-card { display: grid; grid-template-columns: minmax(190px, 1fr) minmax(250px, .9fr) auto; gap: 16px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 9px; }
.user-identity { display: flex; gap: 11px; align-items: center; min-width: 0; }
.user-avatar { width: 39px; height: 39px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 9px; color: var(--wine); background: var(--wine-soft); }
.user-identity strong, .user-identity span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-identity span { color: var(--muted); font-size: 10px; }
.user-card dl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
.user-card dt { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.user-card dd { margin: 2px 0 0; font-size: 11px; }
.password-editor { position: relative; }
.password-editor summary { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font-size: 11px; font-weight: 650; list-style: none; }
.password-editor summary::-webkit-details-marker { display: none; }
.password-editor[open] summary { color: var(--wine); border-color: #9ccdea; background: var(--wine-soft); }
.password-editor form { position: absolute; z-index: 20; right: 0; top: 45px; width: 300px; display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: var(--shadow); }

@media (max-width: 1120px) {
  .site-header { gap: 18px; padding: 0 22px; }
  .brand { width: 218px; padding-right: 18px; }
  .brand img { width: 195px; }
  .primary-nav { gap: 10px; }
  .primary-nav a { font-size: 13px; }
  .account-nav button span { display: none; }
  .home-layout { grid-template-columns: 1fr; }
  .recent-panel { order: 2; }
  .recent-list { display: grid; grid-template-columns: 1fr 1fr; }
  .recent-row { grid-template-columns: 1fr; align-content: center; border-right: 1px solid var(--line); }
  .recent-meta { grid-template-columns: auto auto; }
  .recent-meta time { grid-column: 1 / -1; text-align: left; }
  .summary-band > div { padding-inline: 18px; }
  .results-layout { grid-template-columns: 190px minmax(0,1fr); }
  .editor-actions .dirty-note { display: none; }
  .petition-model-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .users-layout { grid-template-columns: 1fr; }
  .user-create-panel { position: static; }
}

@media (max-width: 1050px) {
  .site-header { position: static; min-height: auto; display: block; padding: 10px 18px 0; }
  .brand { width: 100%; height: 48px; padding: 0; border: 0; }
  .brand img { width: 210px; }
  .primary-nav { width: 100%; gap: 18px; overflow-x: auto; scrollbar-width: thin; }
  .primary-nav a { min-height: 48px; font-size: 13px; }
  .account-nav { justify-content: space-between; margin: 0; padding: 9px 0; border-top: 1px solid var(--line); }
  .account-nav button span { display: inline; }
  .results-layout { display: block; }
  .group-rail { position: static; margin-bottom: 12px; padding-bottom: 8px; overflow: hidden; }
  .group-rail h2 { padding-bottom: 8px; }
  .group-rail nav { display: flex; overflow-x: auto; padding-bottom: 5px; scrollbar-width: thin; }
  .group-rail nav a { min-width: max-content; }
  .workspace-toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; }
}

@media (max-width: 820px) {
  .site-header { position: static; min-height: auto; display: block; padding: 10px 16px 0; }
  .brand { width: 100%; height: 48px; padding: 0; border: 0; }
  .brand img { width: 210px; }
  .primary-nav { width: 100%; gap: 18px; overflow-x: auto; }
  .primary-nav a { min-height: 50px; font-size: 13px; }
  .account-nav { justify-content: space-between; margin: 0; padding: 9px 0; border-top: 1px solid var(--line); }
  .account-nav button span { display: inline; }
  .page-shell { padding: 22px 16px 34px; }
  .site-footer { align-items: flex-start; flex-direction: column; padding: 16px; }
  .page-heading, .result-heading { align-items: flex-start; flex-direction: column; }
  .heading-with-action { align-items: stretch; }
  .heading-actions { width: 100%; }
  .heading-actions .button { flex: 1; }
  .form-grid.two-columns { grid-template-columns: 1fr; }
  .consultation-actions { grid-template-columns: 1fr; }
  .consultation-actions p { grid-column: auto; }
  .checkbox-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .recent-list { grid-template-columns: 1fr; }
  .recent-row { border-right: 0; }
  .summary-band { grid-template-columns: 1fr 1fr; }
  .summary-band > div:nth-child(2) { border-right: 0; }
  .summary-band > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .results-layout { display: block; }
  .group-rail { position: static; margin-bottom: 12px; padding-bottom: 8px; overflow: hidden; }
  .group-rail h2 { padding-bottom: 8px; }
  .group-rail nav { display: flex; overflow-x: auto; padding-bottom: 5px; }
  .group-rail nav a { min-width: max-content; }
  .group-rail .button { display: none; }
  .workspace-toolbar { align-items: flex-start; flex-direction: column; }
  .bulk-rename-form { grid-template-columns: minmax(0, 1fr) auto; }
  .bulk-rename-form p { grid-column: 1 / -1; grid-row: 2; margin: 0; }
  .editor-actions { justify-content: flex-start; }
  .table-search { width: 100%; margin: 0; }
  .transaction-kind-filter { flex: 1 1 260px; }
  .transaction-kind-filter select { flex: 1; }
  .filter-bulk-bar { align-items: flex-start; flex-direction: column; }
  .add-row-grid { grid-template-columns: 1fr 1fr; }
  .add-row-grid .field:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .stats-band { grid-template-columns: 1fr; }
  .stat-period { border-right: 0; border-bottom: 1px solid var(--line); }
  .stat-period:last-child { border-bottom: 0; }
  .petition-model-grid { grid-template-columns: 1fr 1fr; }
  .petition-footer { grid-template-columns: 1fr; }
  .petition-actions { justify-content: stretch; }
  .petition-actions .button { flex: 1; min-width: 0; }
  .generated-panel { grid-template-columns: 1fr; }
  .bitrix-panel { grid-template-columns: auto minmax(0,1fr); }
  .bitrix-panel form { grid-column: 2; }
  .terms-layout { grid-template-columns: 1fr; }
  .term-form-panel { position: static; }
  .user-card { grid-template-columns: 1fr; }
  .password-editor form { position: static; width: 100%; margin-top: 8px; box-shadow: none; }
}

@media (max-width: 520px) {
  .page-heading h1, .result-heading h1 { font-size: 31px; }
  .drop-zone { min-height: 180px; padding-inline: 12px; }
  .checkbox-grid { grid-template-columns: 1fr 1fr; }
  .recent-row { padding-inline: 16px; }
  .recent-meta { grid-template-columns: 1fr; }
  .recent-meta time { grid-column: auto; }
  .summary-band > div { padding: 15px; }
  .summary-band strong { font-size: 23px; }
  .editor-actions .button { flex: 1; }
  .transaction-kind-filter { width: 100%; flex-basis: auto; }
  .filter-bulk-bar > div { width: 100%; }
  .filter-bulk-bar .button { flex: 1 1 100%; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .button { flex: 1; }
  .copy-group-controls { grid-template-columns: 1fr; }
  .copy-group-controls .button { width: 100%; }
  .bulk-rename-form { grid-template-columns: 1fr; }
  .bulk-rename-form p { grid-column: auto; grid-row: auto; }
  .bulk-rename-form .button { width: 100%; }
  .add-row-grid { grid-template-columns: 1fr; }
  .add-row-grid .field:nth-child(2) { grid-column: auto; grid-row: auto; }
  .stat-period dl { gap-inline: 8px; }
  .petition-model-grid { grid-template-columns: 1fr; }
  .petition-model-card { min-height: 116px; }
  .petition-actions { display: grid; grid-template-columns: 1fr; }
  .bitrix-panel { grid-template-columns: 1fr; }
  .bitrix-mark { display: none; }
  .bitrix-panel form { grid-column: auto; }
  .bitrix-panel .button { width: 100%; }
  .term-row { align-items: flex-start; grid-template-columns: 1fr; }
  .term-actions { justify-content: flex-end; }
  .flash-region { right: 16px; top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
