:root {
	--bg: #f6f4ef;
	--surface: #ffffff;
	--surface-2: #faf8f3;
	--ink: #0d2231;
	--ink-soft: #34404b;
	--muted: #6b7580;
	--border: #e7e2d8;
	--border-strong: #d8d2c4;
	--gold: #cfaf3e;
	--gold-text: #8a6e1f;
	--danger: #c0392b;
	--radius: 10px;
	--radius-sm: 6px;
	--shadow: 0 1px 2px rgba(13,34,49,0.04), 0 6px 20px rgba(13,34,49,0.05);
	--font: 'Montserrat', system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
a { color: var(--ink); text-decoration: none; }
a:hover { color: var(--gold-text); }
:focus-visible { outline: 2px solid rgba(176,136,32,0.5); outline-offset: 2px; }
.tnum { font-variant-numeric: tabular-nums; }

/* Flash */
.flash { padding: 11px 18px; margin: 0; font-size: 0.9rem; text-align: center; border-bottom: 1px solid var(--border); }
.flash--ok { background: #e6f2ea; color: #256844; }
.flash--error { background: #fbeceb; color: #a1291c; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth__card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 34px; box-shadow: var(--shadow); }
.auth__eyebrow { font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold-text); font-weight: 700; margin: 0 0 6px; }
.auth__title { margin: 0 0 18px; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.01em; }
.auth__notice { color: var(--muted); font-size: 0.9rem; margin: 0 0 16px; }
.auth__error { color: var(--danger); font-size: 0.9rem; margin: 0 0 16px; }
.auth__form { display: flex; flex-direction: column; gap: 10px; }
.auth__label { font-size: 0.85rem; color: var(--muted); }
.auth__input { padding: 13px 15px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--ink); font: inherit; }
.auth__input:focus { outline: none; border-color: var(--gold); background: var(--surface); }
.auth__btn { margin-top: 8px; padding: 13px 16px; background: var(--ink); color: #fff; border: none; border-radius: var(--radius-sm); font-weight: 700; font-size: 1rem; cursor: pointer; font-family: var(--font); }
.auth__btn:hover { background: #0a1a26; }

/* Topbar + shell */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar__brand { font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; color: var(--ink); white-space: nowrap; }
.topbar__search { flex: 1; max-width: 460px; }
.topbar__search input { width: 100%; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; color: var(--ink); }
.topbar__search input:focus { outline: none; border-color: var(--gold); background: var(--surface); }
.topbar__user { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 0.9rem; color: var(--muted); }
.topbar__email { white-space: nowrap; }
.topbar__logout { background: none; border: none; font: inherit; color: var(--muted); cursor: pointer; padding: 8px 10px; border-radius: var(--radius-sm); }
.topbar__logout:hover { color: var(--ink); background: var(--surface-2); }
.shell__main { max-width: 1240px; margin: 0 auto; padding: 24px; }
.shell__head h1 { margin: 0 0 18px; font-size: 1.4rem; font-weight: 800; letter-spacing: -0.01em; }

/* Status pill (semantic language, used list + detail) */
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.pill--pending { background: #fdf3e2; color: #8a5a12; } .pill--pending .dot { background: #c98a1e; }
.pill--unsure { background: #efecfb; color: #4b3fa0; } .pill--unsure .dot { background: #6d5bd0; }
.pill--manual_submission_required { background: #eaf1ec; color: #4a6152; } .pill--manual_submission_required .dot { background: #6f8a78; }
.pill--hold { background: #eef1f4; color: #3f4a55; } .pill--hold .dot { background: #52606d; }
.pill--sent_for_signing { background: #e8f0f9; color: #1e4e82; } .pill--sent_for_signing .dot { background: #2b6cb0; }
.pill--signed { background: #fbe9d6; color: #9a4a12; } .pill--signed .dot { background: #d9791f; }
.pill--faxed_to_irs { background: #e6f2ea; color: #256844; } .pill--faxed_to_irs .dot { background: #2f855a; }
.pill--removed { background: #f0f1f2; color: #79818a; } .pill--removed .dot { background: #8a929b; }

/* Buttons */
.btn { font: inherit; font-weight: 600; font-size: 0.85rem; padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
.btn--ghost:hover { border-color: var(--ink); }
.btn--primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn--primary:hover { background: #0a1a26; }
.btn--chip { font-size: 0.78rem; font-weight: 600; padding: 6px 12px; background: var(--surface-2); border-color: var(--border); color: var(--ink-soft); transition: background 0.12s, border-color 0.12s, color 0.12s; }
.btn--chip:hover { background: var(--surface); border-color: var(--border-strong); color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Stats chips (Welle-1 list; superseded by cockpit strip in Welle 2) */
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 0.85rem; color: var(--muted); }
.stat b { color: var(--ink); font-variant-numeric: tabular-nums; }
.stat--chip { color: var(--gold-text); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; align-items: center; }
.filters__input { padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--ink); font: inherit; font-size: 0.9rem; }
.filters__input:focus { outline: none; border-color: var(--gold); }
.filters__btn { padding: 10px 18px; background: var(--ink); color: #fff; border: none; border-radius: var(--radius-sm); font-weight: 700; cursor: pointer; font-family: var(--font); }
.filters__btn:hover { background: #0a1a26; }
.filters__reset { align-self: center; font-size: 0.85rem; color: var(--muted); }

/* Table */
.tablewrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th { text-align: left; padding: 11px 16px; color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table tbody tr { cursor: pointer; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table__empty { text-align: center; color: var(--muted); padding: 40px; }
.cell-key { color: var(--ink); font-weight: 700; }
.badge { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 0.8rem; color: var(--ink-soft); }
.pager { margin-top: 16px; }

/* Detail */
.detail { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.detail__col { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 14px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; }
.muted { color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; color: var(--ink); }
.kv--dense { font-size: 0.82rem; gap: 4px 14px; }
.forms { list-style: none; padding: 0; margin: 0 0 14px; }
.forms li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.forms li:last-child { border-bottom: none; }
.forms .dl { color: var(--muted); }
.forms .dl:hover { color: var(--gold-text); }
.pdfframe { width: 100%; height: 560px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }

/* Edit fields */
.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 0.85rem; color: var(--muted); }
.fld span { font-size: 0.8rem; }
.fld select, .fld input[type="text"] { padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--ink); font: inherit; font-size: 0.9rem; }
.fld select:focus, .fld input:focus { outline: none; border-color: var(--gold); }
.fld--check { flex-direction: row; align-items: center; gap: 10px; }
.fld--check input { width: 18px; height: 18px; accent-color: var(--ink); }

.notice { background: #fdf3e2; color: #8a5a12; border: 1px solid #f0dcae; border-radius: var(--radius-sm); padding: 10px 14px; font-size: 0.85rem; margin-bottom: 16px; }

/* Cockpit strip + list bar (Welle 2) */
.listbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 12px; flex: 1; }
.tile { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; transition: border-color .12s, box-shadow .12s; font-family: var(--font); }
.tile:hover { border-color: var(--border-strong); }
.tile.is-active { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.tile__n { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; color: var(--ink); }
.tile__l { font-size: 0.82rem; color: var(--muted); }
.tile--attention .tile__n { color: #b7791f; }
.tile--progress .tile__n { color: #2b6cb0; }
.tile--done .tile__n { color: #2f855a; }
.tile--removed .tile__n { color: #8a929b; }
.tile--removed { opacity: 0.85; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.toolbar .filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 0; flex: 1; }
.toolbar #exportCsv { margin-left: auto; }
.selectwrap--sm select { min-width: 168px; }
.morefilter { position: relative; }
.morefilter__sum { cursor: pointer; font-size: 0.85rem; color: var(--muted); font-weight: 600; list-style: none; padding: 9px 4px; }
.morefilter__sum::-webkit-details-marker { display: none; }
.morefilter__sum:hover { color: var(--ink); }
.morefilter__body { position: absolute; z-index: 10; top: 100%; left: 0; margin-top: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 8px; min-width: 220px; }
.finefilter { margin-bottom: 18px; }
.finefilter > summary { cursor: pointer; font-size: 0.82rem; color: var(--muted); font-weight: 600; list-style: none; padding: 4px 0; }
.finefilter > summary::-webkit-details-marker { display: none; }
.finefilter[open] > summary { margin-bottom: 10px; }
.bulkbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding: 10px 14px; background: var(--ink); border-radius: var(--radius); color: #fff; flex-wrap: wrap; }
.bulkbar[hidden] { display: none; }
.bulkbar__count { font-size: 0.85rem; font-weight: 600; }
.bulkbar .filters__input { background: var(--surface); color: var(--ink); }
.bulkbar .btn--primary { background: var(--gold); color: var(--ink); border-color: var(--gold); }
.bulkbar .btn--primary:hover { background: #dcc054; }
.bulkbar .btn--ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,0.4); }
.bulkbar .btn--ghost:hover { border-color: #fff; }
.col-check { width: 36px; text-align: center; }
.col-check input { width: 16px; height: 16px; accent-color: var(--ink); cursor: pointer; vertical-align: middle; }
.cell-llc__name { display: block; font-weight: 700; color: var(--ink); }
a.cell-llc__name:hover { color: var(--gold-text); }
.cell-llc__sub { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 1px; }

/* Detail drawer (Welle 4) — detail over the persistent list, no reload */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer[hidden] { display: none; }
.drawer__backdrop { position: absolute; inset: 0; background: rgba(13,34,49,0.42); animation: drawerFade .15s ease; }
.drawer__panel { position: absolute; top: 0; right: 0; height: 100%; width: min(1720px, 96vw); background: var(--bg); box-shadow: -8px 0 34px rgba(13,34,49,0.18); overflow-y: auto; padding: 12px 32px 48px; animation: drawerSlide .18s ease; }
.drawer__bar { position: sticky; top: 0; z-index: 3; display: flex; justify-content: flex-end; padding: 4px 0 8px; background: var(--bg); }
.drawer__close { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); width: 34px; height: 34px; font-size: 0.95rem; cursor: pointer; color: var(--muted); }
.drawer__close:hover { color: var(--ink); border-color: var(--ink); }
.drawer__loading { color: var(--muted); padding: 48px 0; text-align: center; }
body.has-drawer { overflow: hidden; }
@keyframes drawerSlide { from { transform: translateX(28px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes drawerFade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer__panel, .drawer__backdrop { animation: none; } }
.cell-date { color: var(--ink-soft); }
.table--dense th { cursor: pointer; user-select: none; }
.table--dense th[data-sort]:hover { color: var(--ink); }

/* Detail (Welle 2) */
.detail { grid-template-columns: 1fr 1.1fr; }
.backlink { margin: 0 0 14px; }
.backlink a { color: var(--muted); }
.backlink a:hover { color: var(--ink); }
.card--head h2 { margin: 10px 0 2px; font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }
.head__meta { font-size: 0.82rem; margin: 0 0 14px; }
.head__bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; border-top: 1px solid var(--border); padding-top: 16px; margin-top: 2px; }
.statuschange { display: inline-flex; }
.selectwrap { position: relative; display: inline-block; }
.selectwrap select { appearance: none; -webkit-appearance: none; padding: 10px 38px 10px 14px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: inherit; font-size: 0.9rem; font-weight: 600; color: var(--ink); cursor: pointer; min-width: 210px; }
.selectwrap select:hover:not(:disabled) { border-color: var(--ink); }
.selectwrap select:focus { outline: none; border-color: var(--gold); }
.selectwrap select:disabled { opacity: 0.6; cursor: not-allowed; }
.selectwrap::after { content: "▾"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--muted); font-size: 0.85rem; }
.editbtn { display: inline-flex; align-items: center; gap: 7px; }
.editbtn__i { color: var(--gold-text); }
.editbtn.is-active { border-color: var(--ink); background: var(--surface-2); }
.editpanel[hidden] { display: none; }
.fldgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 18px; }
.pdfbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.pdfbar .pdftabs { margin-bottom: 0; flex: 1; }
.pdfdl-btn { flex: none; white-space: nowrap; font-size: 0.82rem; font-weight: 600; color: var(--ink); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 13px; align-self: flex-start; }
.pdfdl-btn:hover { border-color: var(--ink); }
.lock { font-size: 0.82rem; color: #a1291c; background: #fbeceb; border-radius: var(--radius-sm); padding: 8px 10px; margin: -2px 0 14px; }
.raw > summary, .edit > summary { cursor: pointer; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; list-style: none; }
.raw > summary::-webkit-details-marker, .edit > summary::-webkit-details-marker { display: none; }
.raw[open] > summary, .edit[open] > summary { margin-bottom: 14px; }
.edit > summary:hover { color: var(--ink); }
.pdftabs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.pdftab { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 12px; font: inherit; font-size: 0.82rem; font-weight: 500; cursor: pointer; color: var(--ink-soft); transition: background 0.12s, border-color 0.12s, color 0.12s; }
.pdftab:hover { border-color: var(--border-strong); color: var(--ink); background: var(--surface); }
.pdftab.is-active { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.pdftab.is-active:hover { background: #0a1a26; color: #fff; }
.pdftab--signed::before { content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--gold); margin-right: 7px; vertical-align: middle; }
.pdftabs__sep { flex-basis: 100%; display: flex; align-items: center; gap: 10px; margin: 6px 0 1px; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.pdftabs__sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.pdfdl { color: var(--muted); padding: 0 6px; }
.pdfdl:hover { color: var(--gold-text); }
.pdfframe { height: 640px; display: block; }
.pdfwrap { position: relative; }
.pdfspin { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; background: rgba(246,244,239,0.82); color: var(--muted); font-size: 0.88rem; font-weight: 600; border-radius: var(--radius-sm); z-index: 2; }
.pdfwrap:not(.is-loading) .pdfspin { display: none; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--ink); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* Empty / error */
.empty { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 40px; color: var(--muted); box-shadow: var(--shadow); }
.empty__who { margin-top: 10px; font-size: 0.85rem; color: var(--gold-text); }
.error { min-height: 100vh; display: grid; place-content: center; text-align: center; gap: 8px; }
.error h1 { font-size: 3rem; margin: 0; color: var(--ink); }

@media (max-width: 720px) {
	.topbar { flex-wrap: wrap; }
	.topbar__search { order: 3; flex-basis: 100%; max-width: none; }
	.detail { grid-template-columns: 1fr; }
	.tablewrap { overflow-x: auto; }
	.listbar { flex-direction: column; }
	.strip { grid-template-columns: repeat(2, 1fr); width: 100%; }
	.table--dense { min-width: 620px; }
}
/* Keep the PDF in view while scrolling the (long) data column, so it can be checked against the data. */
@media (min-width: 721px) {
	.detail__col--docs { position: sticky; top: 76px; align-self: start; }
	.detail__col--docs > .card { display: flex; flex-direction: column; height: calc(100vh - 100px); min-height: 420px; }
	.detail__col--docs .pdfwrap { flex: 1 1 auto; min-height: 0; }
	.detail__col--docs .pdfframe { height: 100%; }
	.drawer__panel .detail__col--docs { top: 58px; }
	.drawer__panel .detail__col--docs > .card { height: calc(100vh - 78px); }
}

.toast { position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translate(-50%, 12px); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: var(--radius-sm); box-shadow: 0 8px 28px rgba(13,34,49,0.28); font-size: 0.9rem; font-weight: 600; max-width: 90vw; opacity: 0; pointer-events: none; transition: opacity .16s ease, transform .16s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast--error { background: var(--danger); }
.formshead { margin: 0 0 14px; }
.formshead h3 { margin: 0 0 10px; }
.formactions { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.formactions .regen { display: contents; }
.formactions .regen__msg { order: 1; flex-basis: 100%; margin: 3px 0 0; }
.formactions .regen__msg:empty { margin: 0; }
.regen { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.regen__msg { font-size: 0.8rem; color: var(--muted); }
