:root {
  color-scheme: light;
  --ink: #302f2a;
  --muted: #6c6a62;
  --paper: #f3efe9;
  --surface: #fffcf8;
  --line: #ded8ce;
  --green: #3f5140;
  --green-deep: #28372c;
  --green-soft: #e9eee6;
  --rose: #8d6971;
  --rose-soft: #f2e8e9;
  --amber: #a77948;
  --amber-soft: #f6eddf;
  --red: #9a454a;
  --red-soft: #f9e9e8;
  --blue-soft: #e9eff3;
  --shadow: 0 12px 30px rgba(48, 43, 35, .07);
  font-family: "Segoe UI Variable", "Segoe UI", Arial, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); scrollbar-color: #aaa397 #e9e3da; scrollbar-width: thin; }
body { min-height: 100vh; margin: 0; color: var(--ink); background: radial-gradient(ellipse 62% 42% at 94% 3%, rgba(184, 141, 125, .16), transparent 77%), radial-gradient(ellipse 56% 35% at 4% 66%, rgba(165, 159, 125, .12), transparent 78%), var(--paper); }
* { scrollbar-color: #aaa397 #e9e3da; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: #e9e3da; }
*::-webkit-scrollbar-thumb { background: #aaa397; border: 2px solid #e9e3da; border-radius: 20px; }
*::-webkit-scrollbar-thumb:hover { background: #797e72; }
a { color: var(--green); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; }
button, a.button { touch-action: manipulation; }

.topbar { position: sticky; z-index: 10; top: 0; padding: 10px 18px 0; background: rgba(243, 239, 233, .96); }
.topbar nav { display: flex; align-items: center; gap: 6px; max-width: 1504px; min-height: 58px; margin: auto; padding: 7px 16px; border: 1px solid rgba(205, 183, 148, .28); border-radius: 15px; background: var(--green-deep); }
.nav-link, .link-button { border: 1px solid transparent; border-radius: 9px; padding: 9px 12px; color: #e7e2d7; background: transparent; font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer; }
.nav-link:hover, .link-button:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.nav-link:active, .link-button:active { background: rgba(255, 255, 255, .15); }
.nav-link.active { border-color: rgba(218, 183, 136, .28); color: #fffaf0; background: rgba(199, 165, 124, .14); }
.nav-link.needs-attention { color: #ffdfad; background: rgba(172, 130, 82, .18); }
.nav-attention-count { display: inline-block; min-width: 20px; margin-left: 7px; padding: 2px 5px; border-radius: 999px; color: #26362c; background: #f5d19d; text-align: center; font-size: 11px; font-weight: 800; }
.logout { margin-left: auto; }
.page { width: min(1480px, calc(100% - 48px)); margin: 29px auto 70px; }
footer { padding: 24px; color: var(--muted); text-align: center; font-size: 13px; }

h1 { margin: 0 0 8px; font: 620 clamp(31px, 3vw, 43px)/1.08 "Segoe UI Variable Display", "Segoe UI Variable", "Segoe UI", Arial, sans-serif; letter-spacing: -.045em; }
h2 { margin: 0 0 16px; font-size: 21px; font-weight: 650; line-height: 1.2; letter-spacing: -.03em; }
h3 { margin: 24px 0 10px; font-size: 15px; line-height: 1.3; }
p { line-height: 1.55; }
.eyebrow { margin: 0 0 8px; color: var(--rose); font-size: 11px; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; }
.muted, small { color: var(--muted); }
.hero, .page-header, .detail-header { margin-bottom: 22px; }
.hero { position: relative; display: flex; align-items: center; min-height: 96px; padding: 13px 0 21px 23px; border-bottom: 1px solid #d3c9ba; color: var(--green-deep); }
.hero::before { content: ""; position: absolute; top: 15px; bottom: 25px; left: 0; width: 4px; border-radius: 4px; background: linear-gradient(180deg, var(--rose), var(--amber)); }
.hero h1 { margin: 0; }
.hero > div > p:last-child, .page-header > p:last-child, .detail-header p { color: var(--muted); }
.page-header, .detail-header { padding: 11px 0 19px; border-bottom: 1px solid #d3c9ba; }
.page-header h1, .detail-header h1 { color: var(--green-deep); }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.detail-hero-meta { display: flex; flex: 0 0 auto; flex-direction: column; align-items: flex-end; gap: 6px; padding-top: 8px; }
.detail-hero-meta strong { color: var(--green-deep); font-size: 24px; font-weight: 800; letter-spacing: -.025em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.detail-report-link { margin-top: 7px; color: var(--rose); font-size: 12px; font-weight: 750; text-decoration-thickness: 1px; }
.breadcrumbs { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; color: var(--muted); font-size: 14px; }

.metrics { display: grid; gap: 0; margin: 22px 0; }
.status-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 0 19px; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: #f9f6f0; }
.metric { min-width: 0; padding: 18px 21px; }
.status-metrics .metric + .metric { border-left: 1px solid var(--line); }
.metric > span:first-child { display: block; margin-bottom: 8px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.metric strong { display: block; font-size: 17px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.subvalue { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.ai-metrics { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--line); }
.ai-metrics .metric { background: var(--surface); }
.ai-metrics .metric strong { font-variant-numeric: tabular-nums; }
.sync-panel { margin: 12px 0 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.sync-panel > summary { margin: 0; padding: 12px 17px; color: var(--green-deep); font-size: 12px; font-weight: 750; }
.sync-panel[open] > summary { margin: 0; border-bottom: 1px solid var(--line); }
.sync-panel .table-wrap { margin: 13px; }
.danger { color: var(--red) !important; }

.card, .preview-panel, .data-panel, .problem-card { margin: 18px 0; padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.notice { margin: 12px 0; padding: 12px 15px; border: 1px solid #d2d9d0; border-left: 3px solid var(--green); border-radius: 11px; background: #f2f5f0; line-height: 1.45; }
.notice.success { border-color: #bbd4c0; border-left-color: var(--green); color: #2f5541; background: var(--green-soft); }
.notice.error { border-color: #e3bfc0; border-left-color: var(--red); color: #792e34; background: var(--red-soft); }
.notice.warning { border-color: #e5d0ac; border-left-color: var(--amber); color: #694b29; background: var(--amber-soft); }
.notice.neutral { background: var(--blue-soft); }

.money-burst { position: fixed; z-index: 100; inset: 0; overflow: hidden; pointer-events: none; }
.money-note { position: absolute; top: 47%; left: 50%; display: grid; place-items: center; width: 72px; height: 38px; border: 2px solid #69806a; border-radius: 5px; color: #344c39; background: linear-gradient(135deg, #eaf0df, #d6e1ca); box-shadow: 0 4px 12px rgba(48, 43, 35, .16); font-size: 23px; font-weight: 800; opacity: 0; animation: money-fly var(--money-duration) ease-out var(--money-delay) forwards; }
.money-note::before, .money-note::after { content: ""; position: absolute; top: 5px; bottom: 5px; width: 7px; border: 1px solid rgba(52, 76, 57, .34); border-radius: 2px; }
.money-note::before { left: 5px; }
.money-note::after { right: 5px; }
.money-coin { width: 43px; height: 43px; border: 3px solid #a77948; border-radius: 50%; color: #684a2c; background: radial-gradient(circle at 32% 26%, #fff0ca 0, #e8c886 52%, #b8874d 100%); box-shadow: 0 4px 12px rgba(92, 65, 35, .22); font-size: 21px; }
.money-coin::before { inset: 3px; width: auto; border: 1px solid rgba(104, 74, 44, .58); border-radius: 50%; }
.money-coin::after { display: none; }
@keyframes money-fly {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.315) rotate(0); }
  14% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--money-x)), calc(-50% + var(--money-y))) scale(.665) rotate(var(--money-angle)); }
}
@media (prefers-reduced-motion: reduce) { .money-burst { display: none; } }

.filters, .bulk-bar, .status-card, .classification-card, .payer-card, .recognize-again-card, .resolution-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin: 15px 0; padding: 17px 19px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.filters { background: #f9f6f0; }
.payer-card { background: #f3f6f1; }
.recognize-again-card { border-color: #e5d0ac; background: var(--amber-soft); }
.form-help { flex: 1 0 100%; margin: 0 0 4px; color: var(--muted); font-size: 13px; }
.bulk-bar { position: static; z-index: 5; top: 72px; background: #f9f6f0; }
@media (min-width: 761px) {
  body:has(.row-check:checked) .bulk-bar { position: sticky; }
}
label { display: flex; flex-direction: column; gap: 6px; color: #55544e; font-size: 12px; font-weight: 650; }
input, select, textarea { min-height: 42px; border: 1px solid #ccc5b9; border-radius: 10px; padding: 8px 12px; color: var(--ink); background: #fffcf8; font-size: 14px; }
input:hover, select:hover, textarea:hover { border-color: #aeb4a6; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid rgba(91, 117, 79, .42); outline-offset: 2px; border-color: var(--green); }
input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--rose); }
textarea { min-height: 120px; resize: vertical; }
.filters input[type="search"] { min-width: 290px; }
.check-label { flex-direction: row; align-items: center; min-height: 40px; }
.check-label input { min-height: 0; }
.form-grid { display: grid; grid-template-columns: 180px minmax(260px, 1fr); gap: 12px; }
.form-actions { position: sticky; bottom: 12px; display: flex; justify-content: flex-end; margin: 16px 0 0; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fffcf8; box-shadow: var(--shadow); }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; border: 1px solid #c8c4b9; border-radius: 10px; padding: 8px 15px; color: var(--green-deep); background: var(--surface); font-size: 13px; font-weight: 650; text-decoration: none; cursor: pointer; }
.button:hover { border-color: var(--green); background: #f1f5ee; }
.button:active { background: #e1e9df; }
.button.primary { border-color: var(--green); color: white; background: var(--green); }
.button.primary:hover { background: #2f4233; }
.button.ghost { border-color: transparent; color: var(--green); background: transparent; }
.button.ghost:hover { background: #e8eee8; }
.button.full { width: 100%; margin-top: 8px; }
.button:disabled { border-color: var(--line); color: var(--muted); background: #efeee9; cursor: not-allowed; opacity: .72; }
.bulk-summary { min-width: 245px; color: var(--muted); font-weight: 700; }
.copy { min-height: 32px; border: 1px solid #cdd6c8; border-radius: 9px; padding: 5px 9px; color: var(--green); background: #edf2e9; font-size: 11px; font-weight: 750; cursor: pointer; }
.copy:hover { border-color: var(--green); background: #e7efe5; }
.copy:active { background: #dae6d8; }
.copy.copied { color: white; background: var(--green); }
.input-copy { display: grid; grid-template-columns: minmax(160px, 1fr) auto; overflow: hidden; border: 1px solid #ccc9c0; border-radius: 9px; }
.input-copy input, .input-copy textarea { width: 100%; border: 0; border-radius: 0; }
.input-copy textarea { min-height: 130px; }
.hidden { display: none !important; }

.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
.registry-group { margin-top: 26px; }
.registry-group > h2 { margin: 0 0 14px; color: var(--green-deep); font-size: 22px; font-weight: 650; }
.registry-archive { margin-top: 40px; padding-top: 23px; border-top: 1px solid #bfc6b9; }
.mail-invoice-list { display: grid; gap: 12px; }
.mail-invoice-card { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.mail-invoice + .mail-invoice { border-top: 1px solid var(--line); }
.mail-invoice-head { position: relative; display: flex; align-items: stretch; }
.mail-select { flex: 0 0 42px; justify-content: center; margin: 0; padding: 16px 4px; background: #f4f0e9; }
.mail-select-repeat { display: grid; place-items: center; color: var(--muted); font-size: 11px; font-weight: 750; }
.mail-invoice-disclosure { min-width: 0; flex: 1 1 auto; }
.mail-invoice-disclosure[open] > summary { margin-bottom: 0; }
.mail-invoice-summary { display: grid; grid-template-columns: minmax(130px, .65fr) minmax(175px, 1.05fr) minmax(190px, 1.25fr) minmax(140px, .75fr) minmax(205px, .95fr) 14px; align-items: center; gap: 15px; min-height: 80px; padding: 13px 18px; list-style: none; color: var(--ink); background: var(--surface); cursor: pointer; }
.mail-invoice-summary:hover { background: #f7f6ef; }
.mail-invoice-disclosure[open] > .mail-invoice-summary { background: #f8f6f1; box-shadow: inset 3px 0 var(--green); }
.mail-invoice:has(.row-check:checked) .mail-invoice-summary { background: var(--rose-soft); box-shadow: inset 3px 0 var(--rose); }
.mail-invoice-summary::-webkit-details-marker { display: none; }
.mail-summary-main, .mail-summary-parties, .mail-summary-amount, .mail-summary-status { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; gap: 4px; }
.mail-summary-number { color: var(--green-deep); font-size: 17px; font-weight: 700; letter-spacing: -.025em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mail-summary-subject { max-width: 100%; color: var(--muted); font-size: 12px; font-weight: 450; line-height: 1.35; overflow-wrap: anywhere; }
.mail-summary-parties strong { font-size: 14px; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.mail-summary-parties small { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .11em; line-height: 1.3; text-transform: uppercase; }
.mail-summary-amount small { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
.mail-summary-amount strong { font-size: 19px; line-height: 1.2; font-weight: 700; letter-spacing: -.025em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mail-summary-quick-status { position: absolute; z-index: 1; top: 17px; right: 47px; display: flex; width: 205px; min-width: 0; flex-direction: column; gap: 5px; cursor: default; }
.mail-summary-quick-placeholder { min-width: 0; }
.mail-summary-quick-status > label { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.mail-summary-quick-row { display: flex; min-width: 0; align-items: center; gap: 5px; }
.mail-summary-quick-row select { width: 100%; min-width: 0; min-height: 36px; padding: 5px 7px; font-size: 12px; }
.mail-summary-quick-row .button { min-height: 36px; padding: 5px 8px; font-size: 11px; }
.mail-summary-status { gap: 7px; padding-right: 10px; border-right: 1px solid var(--line); }
.mail-summary-date { color: var(--muted); font-size: 11px; line-height: 1.3; }
.mail-invoice-summary .badge { width: fit-content; }
.mail-summary-arrow { width: 8px; height: 8px; border-right: 2px solid var(--green); border-bottom: 2px solid var(--green); transform: rotate(45deg); }
.mail-invoice-disclosure[open] .mail-summary-arrow { transform: rotate(225deg); }
.mail-scroll-top { height: 20px; overflow-x: auto; overflow-y: hidden; border-top: 1px solid var(--line); background: #eeeae2; }
.mail-scroll-track { height: 1px; }
.mail-scroll-content { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
.mail-wide { min-width: 0; }
.mail-sections { display: grid; grid-template-columns: minmax(240px, .75fr) minmax(0, 1.25fr); background: var(--surface); }
.mail-column { min-width: 0; padding: 15px 20px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.mail-email-column:first-child { border-right: 1px solid var(--line); }
.mail-column h3, .mail-source h3, .mail-recipient h3, .mail-goods h3 { margin: 0 0 9px; color: var(--green-deep); font-size: 13px; font-weight: 700; }
.mail-column p { margin: 4px 0 8px; font-size: 13px; }
.mail-column small { display: block; margin-top: 5px; }
.mail-subject { font-weight: 750; }
.mail-body, .mail-body-preview { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
.mail-body { max-height: 420px; overflow: auto; }
.mail-fact { position: relative; margin: 9px 0 14px; line-height: 1.4; }
.fact-label { display: block; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .06em; margin-bottom: 3px; }
.fact-text { font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.mail-fact .copy { min-height: 24px; padding: 3px 7px; margin-left: 7px; font-size: 10px; }
.small-fact .fact-text { font-size: 11px; color: var(--muted); }
.payer-bank { margin: 12px 0; grid-column: 1 / -1; }
summary { cursor: pointer; color: var(--green); font-size: 13px; line-height: 1.5; }
.mail-continuation { grid-column: 1 / -1; }
.mail-source, .mail-recipient, .mail-payer-details { grid-column: 1 / -1; min-width: 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.mail-source { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 13px 20px; background: #f4f3ec; font-size: 12px; }
.mail-source h3, .mail-source p { margin: 0; }
.mail-source .button { min-height: 29px; padding: 5px 9px; font-size: 11px; }
.mail-source small { flex-basis: 100%; color: var(--muted); }
.mail-recipient { padding: 19px 20px; background: #fbf9f4; }
.mail-recipient h3 { margin-bottom: 8px; font-size: 15px; }
.mail-facts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 22px; }
.mail-facts-grid > .mail-fact { min-width: 0; margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mail-facts-grid > .mail-fact:first-child { grid-column: 1 / -1; }
.mail-payer-details { background: var(--surface); }
.mail-payer-summary { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 14px; padding: 13px 20px; }
.mail-payer-summary strong { color: var(--green-deep); }
.mail-payer-summary span { color: var(--muted); font-weight: 500; }
.mail-payer-details[open] > summary { margin-bottom: 0; border-bottom: 1px solid var(--line); }
.mail-payer-details > .mail-facts-grid { padding: 10px 20px 18px; }
.mail-goods { min-width: 0; padding: 19px 21px; overflow-x: auto; }
.mail-additional { border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.mail-additional > summary { padding: 12px 16px; font-weight: 700; }
.mail-additional-body { padding: 0 16px 12px; }
.mail-additional-body p { font-size: 12px; line-height: 1.55; white-space: pre-wrap; }
.mail-workflow { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 11px 18px; padding: 18px 21px; border-bottom: 1px solid var(--line); background: var(--surface); }
.mail-pay-primary { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.mail-pay-number { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.mail-pay-vat-mode { align-self: center; min-width: 0; }
.mail-pay-vat-mode .mail-fact { margin: 0; }
.mail-workflow .money { color: var(--green-deep); font-size: 20px; letter-spacing: -.025em; }
.mail-workflow .copy { min-height: 28px; border-radius: 9px; }
.mail-pay-meta, .mail-workflow .notice { grid-column: 1 / -1; }
.mail-pay-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.mail-pay-meta .mail-fact { margin: 0; }
.mail-pay-actions { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.mail-pay-actions .button { min-height: 32px; padding: 5px 10px; font-size: 11px; }
.invoice-status-form { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: end; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.invoice-status-form > label { min-width: 180px; }
.mail-report-link { color: var(--rose); font-size: 12px; font-weight: 750; text-decoration-thickness: 1px; }
.mail-workflow .notice { margin: 0; }
.goods-toolbar { display: flex; justify-content: flex-end; margin: 0 0 10px; }
.goods-toolbar .button { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.goods-table { width: max-content; min-width: 100%; font-size: 12px; }
.goods-table th { text-transform: none; letter-spacing: 0; font-size: 11px; white-space: pre-wrap; }
.goods-table td { white-space: pre-wrap; min-width: 60px; font-variant-numeric: tabular-nums; }
.goods-table td, .goods-table th { padding: 9px 8px; overflow-wrap: anywhere; }
.goods-table td.goods-number { white-space: nowrap; overflow-wrap: normal; }
.goods-table td .copy { display: block; min-height: 24px; margin-top: 5px; padding: 3px 6px; border: 0; border-radius: 8px; font-size: 10px; }
.goods-table .user-corrected { background: var(--green-soft); }
.table-note { margin: 7px 0 10px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.printed-totals { margin-top: 14px; font-size: 12px; line-height: 1.65; white-space: pre-wrap; }
.item-editor { margin-top: 20px; }
.item-editor > summary { padding: 12px; background: #faf9f5; border-radius: 8px; }
@media (max-width: 1100px) {
  .mail-invoice-summary { grid-template-columns: 120px minmax(0, 1fr) minmax(125px, .7fr) minmax(205px, .95fr) 14px; gap: 9px 12px; }
  .mail-summary-status { grid-column: 1; grid-row: 1 / span 2; }
  .mail-summary-main { grid-column: 2; grid-row: 1; }
  .mail-summary-parties { grid-column: 2; grid-row: 2; }
  .mail-summary-amount { grid-column: 3; grid-row: 1 / span 2; }
  .mail-summary-quick-placeholder { grid-column: 4; grid-row: 1 / span 2; }
  .mail-summary-arrow { grid-column: 5; grid-row: 1 / span 2; }
}
@media (max-width: 800px) {
  .mail-invoice-head { flex-wrap: wrap; }
  .mail-invoice-disclosure { flex-basis: calc(100% - 42px); }
  .mail-invoice-summary { grid-template-columns: minmax(92px, .55fr) minmax(0, 1fr) 12px; gap: 8px 10px; padding: 12px 10px; }
  .mail-summary-status { grid-column: 1; grid-row: 1 / span 3; padding-right: 7px; }
  .mail-summary-main { grid-column: 2; grid-row: 1; }
  .mail-summary-parties { grid-column: 2; grid-row: 2; }
  .mail-summary-amount { grid-column: 2; grid-row: 3; }
  .mail-summary-quick-placeholder { display: none; }
  .mail-summary-arrow { grid-column: 3; grid-row: 1 / span 3; }
  .mail-summary-quick-status { position: static; flex: 0 0 calc(100% - 42px); width: auto; margin-left: 42px; padding: 0 10px 12px; }
  .mail-invoice-disclosure[open] + .mail-summary-quick-status { display: none; }
}
@media (max-width: 640px) {
  .mail-invoice-summary { grid-template-columns: minmax(92px, .55fr) minmax(0, 1fr) 12px; gap: 8px 10px; padding: 12px 10px; }
  .mail-summary-status { grid-column: 1; grid-row: 1 / span 3; padding-right: 7px; }
  .mail-summary-main { grid-column: 2; grid-row: 1; }
  .mail-summary-parties { grid-column: 2; grid-row: 2; }
  .mail-summary-amount { grid-column: 2; grid-row: 3; }
  .mail-summary-arrow { grid-column: 3; grid-row: 1 / span 3; }
  .mail-sections, .mail-facts-grid { grid-template-columns: 1fr; }
  .mail-sections > * { grid-column: 1; }
  .mail-email-column:first-child { border-right: 0; }
  .mail-workflow { grid-template-columns: 1fr; }
  .mail-pay-actions { grid-column: 1; grid-row: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .invoice-status-form > label { flex: 1 1 100%; min-width: 0; }
  .invoice-status-form > .button { width: 100%; }
  .mail-pay-meta, .mail-workflow .notice { grid-column: 1; }
  .mail-select { flex-basis: 34px; }
  .mail-summary-amount strong { font-size: 17px; }
  .bulk-bar { position: static; }
}
.items-edit-table { min-width: 1450px; }
.items-edit-table th:nth-child(2), .items-edit-table td:nth-child(2) { min-width: 290px; }
.item-input { width: 100%; min-width: 105px; }
.items-edit-table td small { max-width: 220px; overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { color: #5e6258; background: #f0eee7; font-size: 10px; font-weight: 750; text-transform: uppercase; letter-spacing: .09em; }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:hover { background: #f7f6ef; }
td small, .strong-link + small { display: block; margin-top: 5px; }
.strong-link { color: var(--ink); font-weight: 700; text-decoration: none; }
.money { font-variant-numeric: tabular-nums; font-weight: 700; overflow-wrap: anywhere; }
.empty { padding: 34px; color: var(--muted); text-align: center; }
.list-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 14px; color: var(--muted); }
.pagination { display: flex; align-items: center; gap: 12px; }
.fields th { width: 210px; text-transform: none; letter-spacing: 0; }
.fields .recognized { width: 28%; color: var(--muted); word-break: break-word; }
.fields td:last-child { min-width: 330px; }
.data-panel form:has(> .fields) { min-width: 0; max-width: 100%; overflow-x: auto; }
.headers th { width: 240px; text-transform: none; word-break: break-word; }
.headers td { word-break: break-word; }

.badge { display: inline-flex; align-items: center; margin: 1px 3px 1px 0; border-radius: 999px; padding: 5px 10px; color: #465649; background: #e9eee8; font-size: 11px; font-weight: 700; line-height: 1.2; }
.badge.danger, .problem-error .badge:first-child { color: #7e3034; background: var(--red-soft); }
.status-not_accepted { color: #765126; background: #f4e8d2; }
.status-entered_1c { color: #3c5e71; background: var(--blue-soft); }
.status-uploaded_bank { color: #654d68; background: #efe5ef; }
.status-payment_order_sent { color: #315f45; background: var(--green-soft); }

.split-view { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(520px, 1.2fr); gap: 18px; align-items: start; }
.preview-panel, .data-panel { margin: 0; min-width: 0; }
.preview-panel { position: sticky; top: 82px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-heading h2 { margin: 0; }
.file-meta { color: var(--muted); font-size: 12px; word-break: break-word; }
.document-frame { width: 100%; height: 72vh; min-height: 600px; border: 1px solid var(--line); border-radius: 14px; background: #eae7e0; }
.document-image { display: block; max-width: 100%; max-height: 76vh; margin: auto; border: 1px solid var(--line); border-radius: 10px; object-fit: contain; }
.empty-preview { display: grid; min-height: 420px; align-content: center; padding: 40px; border: 2px dashed #d9d5cb; border-radius: 12px; color: var(--muted); text-align: center; }
.two-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.two-columns > .card { min-width: 0; }
.two-columns > :only-child { grid-column: 1 / -1; }
.payment-parties { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 12px; margin: 16px 0; }
.requisites-card { min-width: 0; padding: 19px 21px; border: 1px solid var(--line); border-radius: 14px; background: #f9f7f1; }
.requisites-card h3 { margin: 0 0 8px; font-size: 17px; }
.requisites-card > p { margin: 0 0 12px; font-size: 12px; }
.requisites { display: grid; grid-template-columns: minmax(105px, 145px) minmax(0, 1fr); gap: 0 12px; margin: 0; }
.requisites dt { padding: 9px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.requisites dd { display: flex; flex-wrap: wrap; min-width: 0; align-items: flex-start; justify-content: space-between; gap: 8px; margin: 0; padding: 9px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.requisites .fact-value { min-width: 0; flex: 1 1 180px; }
.requisites .fact-note { display: block; margin-top: 4px; color: var(--red); font-size: 11px; font-weight: 700; }
.requisites .copy { flex: 0 0 auto; min-height: 28px; border: 1px solid var(--line); border-radius: 7px; }

.facts { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.facts.compact { grid-template-columns: 110px 1fr; font-size: 13px; }
.email-body { max-height: 520px; overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 14px; white-space: pre-wrap; word-break: break-word; color: var(--ink); background: #f9f7f1; font: 14px/1.55 "Segoe UI", system-ui, sans-serif; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; margin-left: 8px; padding: 0 0 18px 20px; border-left: 2px solid var(--line); }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.timeline li:last-child { border-color: transparent; }
.timeline small, .timeline .change-values { display: block; margin-top: 4px; }
.changes del { color: var(--red); }
.changes ins { color: var(--green); text-decoration: none; }
.attachments li { margin: 8px 0; line-height: 1.45; }
.attachments { list-style: none; padding: 0; }
.attachment { padding: 12px; border-left: 3px solid var(--line); background: #faf9f5; }
.attachment-classification { padding: 12px; background: white; }
.attachment.depth-1 { margin-left: 18px; }
.attachment.depth-2 { margin-left: 36px; }
.attachment.depth-3 { margin-left: 54px; }
.attachment.depth-4, .attachment.depth-5 { margin-left: 72px; }
.comment { padding: 12px 0; border-bottom: 1px solid var(--line); }
.comment p { margin: 0 0 6px; white-space: pre-wrap; }
.problem { margin: 10px 0; padding: 12px; border-left: 4px solid var(--amber); border-radius: 8px; background: var(--amber-soft); }
.problem.problem-error { border-color: var(--red); background: var(--red-soft); }
.problem p { margin: 8px 0; white-space: pre-wrap; }
.problem-list { display: grid; gap: 14px; }
.problem-card { margin: 0; }
.problem-card.problem-error { border-left: 5px solid var(--red); }
.problem-heading { display: flex; justify-content: space-between; gap: 20px; }
.problem-heading h2 { margin-top: 10px; }
.relation { font-weight: 700; }
.resolution-form label:nth-of-type(2) { flex: 1 1 320px; }
.report { scroll-margin-top: 90px; border-color: #b9d7c6; }
.settings-creators > .card { margin-top: 0; }
.settings-create form, .settings-entity > form, .account-settings > form { display: grid; gap: 14px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(190px, 1fr)); gap: 12px; }
.settings-grid .check-label { align-self: end; }
.settings-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.settings-heading h2 { margin: 10px 0 0; }
.settings-heading form { flex: 0 0 auto; }
.settings-entity { scroll-margin-top: 90px; }
.settings-accounts { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.account-settings { scroll-margin-top: 90px; margin: 14px 0; padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: #fafbf9; }
.account-settings strong { display: inline-block; margin-left: 6px; }
.account-grid { grid-template-columns: repeat(3, minmax(160px, 1fr)); }
details summary { cursor: pointer; font-weight: 750; }
details[open] summary { margin-bottom: 16px; }

.center-card { width: min(440px, calc(100% - 32px)); margin: 12vh auto; padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.center-card form { display: grid; gap: 14px; margin-top: 22px; text-align: left; }

@media (max-width: 1100px) {
  .status-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-metrics .metric:nth-child(3) { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .ai-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ai-metrics .metric:last-child { grid-column: 1 / -1; }
}

@media (max-width: 1010px) {
  .split-view { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .document-frame { height: 65vh; }
}

@media (max-width: 760px) {
  .topbar { position: static; padding: 8px 10px 0; }
  .topbar nav { flex-wrap: wrap; min-height: 0; padding: 9px 10px; border-radius: 13px; }
  .logout { margin-left: auto; }
  .nav-link, .link-button { padding: 7px 8px; font-size: 12px; }
  .page { width: min(100% - 22px, 1480px); margin-top: 20px; }
  .hero { min-height: 74px; padding: 8px 0 16px 16px; }
  .status-metrics { margin: 0 0 18px; }
  .status-metrics .metric { padding: 13px; }
  .status-metrics .metric strong { font-size: 13px; }
  .ai-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-columns, .form-grid, .payment-parties { grid-template-columns: 1fr; }
  .settings-grid, .account-grid { grid-template-columns: 1fr; }
  .bulk-bar { position: static; }
  .filters > label, .bulk-bar > label, .filters input[type="search"] { width: 100%; min-width: 0; }
  .split-view { display: block; }
  .detail-header { flex-wrap: wrap; }
  .detail-hero-meta { align-items: flex-start; }
  .data-panel, .preview-panel, .card { padding: 15px; }
  .fields th { min-width: 150px; }
  .document-frame { min-height: 430px; }
  .list-footer, .problem-heading { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 430px) {
  .status-metrics { grid-template-columns: 1fr; }
  .status-metrics .metric:nth-child(2) { border-left: 0; border-top: 1px solid var(--line); }
  .status-metrics .metric:nth-child(3) { grid-column: 1; }
  .status-metrics .metric { padding: 12px 10px; }
  .ai-metrics { grid-template-columns: 1fr; }
  .ai-metrics .metric:last-child { grid-column: 1; }
  .requisites { grid-template-columns: 1fr; }
  .requisites dt { padding-bottom: 2px; border-bottom: 0; }
  .requisites dd { padding-top: 2px; }
}

@media print {
  .topbar, .filters, .bulk-bar, .logout, .button, .copy, footer, .report { display: none !important; }
  body { background: white; }
  .page { width: 100%; margin: 0; }
  .card, .preview-panel, .data-panel { box-shadow: none; break-inside: avoid; }
}
