:root {
  --ink: #18231f;
  --muted: #64736c;
  --line: #dfe7e3;
  --surface: #ffffff;
  --canvas: #f3f7f5;
  --green: #176b49;
  --green-2: #0f5a3b;
  --green-soft: #e8f4ee;
  --amber: #a46106;
  --amber-soft: #fff5d9;
  --red: #b63535;
  --red-soft: #fff0ef;
  --blue-soft: #eef4ff;
  --shadow: 0 18px 50px rgba(28, 55, 43, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% -10%, rgba(42, 150, 99, .12), transparent 30rem),
    var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(36, 129, 86, .3);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 130px 1fr auto;
  align-items: center;
  gap: 18px;
  min-height: 68px;
  padding: 10px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid rgba(214, 225, 220, .9);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(18px);
}
.back-link { color: var(--green); font-size: 13px; font-weight: 700; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.brand-block { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; color: white; background: var(--green); font: 800 18px/1 ui-monospace, monospace; }
.brand-title { font-size: 15px; font-weight: 800; letter-spacing: .01em; }
.brand-subtitle { margin-top: 1px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.identity-strip { display: flex; align-items: center; gap: 8px; max-width: 460px; min-height: 36px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; color: #405149; background: #f9fbfa; font-size: 12px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #97a39d; }
.status-dot.pending { animation: pulse 1.3s ease-in-out infinite; }
.status-dot.ok { background: #19a765; box-shadow: 0 0 0 4px rgba(25, 167, 101, .12); }
.status-dot.denied { background: var(--red); box-shadow: 0 0 0 4px rgba(182, 53, 53, .1); }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }

.page-shell { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 70px; }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 28px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.hero h1 { margin: 0; max-width: 760px; font-size: clamp(28px, 4.2vw, 48px); line-height: 1.04; letter-spacing: -.04em; }
.hero p:not(.eyebrow) { max-width: 820px; margin: 13px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.hero-security { display: flex; align-items: center; gap: 12px; min-width: 270px; padding: 15px 17px; border: 1px solid #cfe0d7; border-radius: 16px; background: rgba(255,255,255,.72); box-shadow: 0 10px 30px rgba(22, 79, 53, .05); }
.hero-security > span { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: var(--green); background: var(--green-soft); font-size: 22px; }
.hero-security strong, .hero-security small { display: block; }
.hero-security strong { font-size: 13px; }
.hero-security small { margin-top: 3px; color: var(--muted); font-size: 11px; }

.primary-tabs { display: flex; gap: 6px; padding: 5px; overflow-x: auto; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.78); }
.primary-tab { min-height: 40px; padding: 0 18px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; cursor: pointer; font-size: 13px; font-weight: 750; white-space: nowrap; transition: color .16s ease, background-color .16s ease, box-shadow .16s ease; }
.primary-tab:hover { color: var(--ink); background: #f1f5f3; }
.primary-tab.active { color: #fff; background: var(--green); box-shadow: 0 6px 15px rgba(23, 107, 73, .2); }

.workspace-panel { margin-top: 16px; padding: clamp(20px, 3vw, 34px); border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.panel-heading, .subsection-heading, .card-heading, .dialog-heading, .action-bar, .filter-row { display: flex; align-items: center; gap: 18px; }
.panel-heading, .subsection-heading, .card-heading, .dialog-heading { justify-content: space-between; }
.panel-heading h2, .subsection-heading h3, .card-heading h3, .dialog-heading h2 { margin: 0; letter-spacing: -.02em; }
.panel-heading h2 { font-size: 23px; }
.subsection-heading h3, .card-heading h3 { font-size: 16px; }
.panel-heading p:not(.eyebrow), .subsection-heading p:not(.eyebrow), .card-heading p { max-width: 780px; margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.template-download-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; gap: 12px; margin-top: 18px; }
.template-download-card { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfb; }
.template-download-copy { width: 100%; margin-bottom: 14px; }
.template-download-copy h3 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.template-download-copy p:not(.eyebrow) { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.template-download-link { min-width: 166px; margin-top: auto; }
.template-download-link[data-state="accepted"] { color: #fff; border-color: var(--green); background: var(--green); }

.button { display: inline-flex; justify-content: center; align-items: center; min-height: 40px; min-width: 112px; padding: 0 16px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; font-size: 12px; font-weight: 800; text-decoration: none; white-space: nowrap; transition: transform .12s ease, color .15s ease, background-color .15s ease, border-color .15s ease, box-shadow .15s ease; }
.button:active:not(:disabled) { transform: scale(.98); }
.button:disabled { opacity: .48; cursor: not-allowed; }
.button.primary { color: #fff; background: var(--green); box-shadow: 0 7px 18px rgba(23,107,73,.16); }
.button.primary:hover:not(:disabled) { background: var(--green-2); }
.button.secondary { color: var(--green); border-color: #bdd5c9; background: #f8fcfa; }
.button.secondary:hover:not(:disabled) { background: var(--green-soft); }
.button.ghost { color: #52615a; border-color: var(--line); background: #fff; }
.button.ghost:hover:not(:disabled) { background: #f3f6f4; }
.button.danger, .button.danger.armed { color: white; background: var(--red); }
.button.danger-outline { color: var(--red); border-color: #e9bdbc; background: #fffafa; }
.button.danger-outline:hover:not(:disabled) { background: var(--red-soft); }
.confirm-button.armed { color: white; border-color: var(--red); background: var(--red); box-shadow: 0 0 0 4px rgba(182, 53, 53, .12); }
.button.loading { color: transparent; position: relative; pointer-events: none; }
.button.loading::after { content: ""; position: absolute; width: 15px; height: 15px; border: 2px solid currentColor; border-color: rgba(255,255,255,.4) rgba(255,255,255,.4) #fff #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stepper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; margin: 28px 0 22px; padding: 0; list-style: none; }
.stepper li { position: relative; display: flex; align-items: center; gap: 9px; min-width: 0; color: #91a098; }
.stepper li::after { content: ""; position: absolute; left: 38px; right: 8px; top: 15px; height: 2px; background: #e2e9e5; }
.stepper li:last-child::after { display: none; }
.stepper span { position: relative; z-index: 1; display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 auto; border: 2px solid #d7e0db; border-radius: 50%; background: white; font-size: 11px; font-weight: 850; transition: color .18s ease, border-color .18s ease, background-color .18s ease; }
.stepper strong, .stepper small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stepper strong { font-size: 12px; }
.stepper small { margin-top: 2px; font-size: 10px; }
.stepper li.active, .stepper li.done { color: var(--green); }
.stepper li.active span, .stepper li.done span { color: white; border-color: var(--green); background: var(--green); }
.stepper li.done::after { background: var(--green); }

.drop-zone { display: grid; place-items: center; min-height: 176px; padding: 28px; border: 1.5px dashed #a9c9b9; border-radius: 18px; background: linear-gradient(150deg, #fbfdfc, #eef7f2); cursor: pointer; text-align: center; transition: border-color .16s ease, background-color .16s ease, transform .16s ease; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); background: #eaf6ef; transform: translateY(-1px); }
.drop-zone.disabled { opacity: .55; cursor: not-allowed; }
.drop-zone strong { margin-top: 10px; font-size: 15px; }
.drop-zone span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.drop-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 15px; color: white; background: var(--green); font-size: 24px; }
.inline-message { margin-top: 14px; padding: 12px 14px; border: 1px solid #c8d9d0; border-radius: 12px; color: #294a3b; background: #f0f7f3; font-size: 12px; line-height: 1.55; white-space: pre-line; }
.inline-message.error { color: #8e2b2b; border-color: #edc3c1; background: var(--red-soft); }
.inline-message.warning { color: #70501a; border-color: #edd69d; background: var(--amber-soft); }

.file-list { display: grid; gap: 8px; margin-top: 14px; }
.file-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; min-height: 48px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfb; }
.file-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.file-row small, .file-row .file-meta { color: var(--muted); font-size: 10px; }
.file-status { padding: 4px 8px; border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: 10px; font-weight: 800; }

.import-setup, .mapping-section, .repair-section, .local-preview, .server-result { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line); }
.type-choice { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 15px; }
.type-choice label { display: flex; align-items: center; gap: 11px; min-height: 66px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; cursor: pointer; }
.type-choice label:has(input:checked) { border-color: #8fbca6; background: var(--green-soft); box-shadow: 0 0 0 3px rgba(23,107,73,.07); }
.type-choice input, .fee-rule input[type="radio"] { accent-color: var(--green); }
.type-choice strong, .type-choice small, .fee-rule strong, .fee-rule small { display: block; }
.type-choice strong, .fee-rule strong { font-size: 12px; }
.type-choice small, .fee-rule small { margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.batch-config { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.config-field { position: relative; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; }
.config-field > label { display: block; margin-bottom: 6px; color: #44544c; font-size: 10px; font-weight: 850; }
.config-field > input, .selection-button, .rate-input input, .mapping-table select, .edit-field input, .edit-field select { width: 100%; min-height: 40px; padding: 0 11px; border: 1px solid #d5dfda; border-radius: 9px; color: var(--ink); background: white; font-size: 12px; }
.config-field > small { display: block; min-height: 30px; margin-top: 6px; color: var(--muted); font-size: 9px; line-height: 1.5; }
.resolution-value { display: flex; align-items: center; min-height: 40px; padding: 0 11px; border: 1px solid #b9d3c6; border-radius: 9px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 850; }
.selection-button { display: flex; align-items: center; justify-content: space-between; cursor: pointer; text-align: left; }
.selection-button:hover { border-color: #8fbca6; }
.association-field { z-index: 4; }
.search-results { position: absolute; left: 13px; right: 13px; top: 80px; z-index: 10; max-height: 260px; padding: 5px; overflow-y: auto; border: 1px solid #cfdad4; border-radius: 11px; background: white; box-shadow: 0 16px 35px rgba(25,54,41,.16); }
.search-option { display: flex; justify-content: space-between; align-items: center; gap: 14px; width: 100%; min-height: 42px; padding: 7px 9px; border: 0; border-radius: 8px; color: var(--ink); background: transparent; cursor: pointer; text-align: left; }
.search-option:hover, .search-option:focus-visible { background: var(--green-soft); }
.search-option strong, .search-option small { display: block; }
.search-option strong { font-size: 11px; }
.search-option small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.media-label { display: inline-flex; align-items: center; gap: 5px; vertical-align: middle; }
.media-label img { display: block; flex: 0 0 16px; width: 16px; height: 16px; object-fit: contain; }
.search-option > span:last-child { flex: 0 0 auto; color: var(--green); font-size: 10px; font-weight: 800; }
.fee-rule { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 14px 0 0; padding: 13px; border: 1px solid var(--line); border-radius: 15px; }
.fee-rule legend { padding: 0 7px; color: #44544c; font-size: 11px; font-weight: 850; }
.fee-card { display: flex; min-width: 0; min-height: 112px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; }
.fee-card:has(input[name="fee-source"]:checked) { border-color: #8fbca6; background: var(--green-soft); box-shadow: 0 0 0 3px rgba(23,107,73,.07); }
.fee-card-main { display: flex; align-items: center; gap: 11px; width: 100%; cursor: pointer; }
.fee-card-file { flex-direction: column; gap: 10px; }
.fee-card-file .fee-card-main { flex: 1 1 auto; }
.fee-submode { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-left: 25px; }
.fee-submode label { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 30px; padding: 0 8px; border: 1px solid #cfdad4; border-radius: 8px; color: var(--muted); background: rgba(255,255,255,.72); cursor: pointer; font-size: 10px; font-weight: 800; }
.fee-submode label:has(input:checked) { color: var(--green); border-color: #8fbca6; background: white; }
.fee-submode:has(input:disabled) { opacity: .5; }
.fee-submode input { margin: 0; }
.rate-input { display: flex; align-items: center; gap: 5px; width: 92px; margin-left: auto; }
.rate-input input { min-width: 0; text-align: right; }
.rate-input b { color: var(--muted); font-size: 11px; }
.mapping-cards { display: grid; gap: 14px; margin-top: 16px; }
.mapping-card { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: white; }
.mapping-card-header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.mapping-card-header { margin: 0; padding: 13px 15px; border-bottom: 1px solid var(--line); background: #fbfcfb; }
.mapping-card-header strong { font-size: 13px; }
.mapping-card-header span { color: var(--muted); font-size: 10px; }
.mapping-table th, .mapping-table td { padding: 10px 14px; }
.mapping-table th:nth-child(1), .mapping-table td:nth-child(1) { width: 48%; text-align: left; }
.mapping-table th:nth-child(2), .mapping-table td:nth-child(2) { width: 20%; text-align: right; }
.mapping-table th:nth-child(3), .mapping-table td:nth-child(3) { width: 32%; text-align: left; }
.mapping-source { font: 650 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; white-space: normal; }
.mapping-total { color: #3d4a44; font-variant-numeric: tabular-nums; }
.mapping-table tr.invalid td { background: #fffafa; }
.required-mark { color: var(--red); }
.filter-row input { width: 100%; min-height: 38px; padding: 0 10px; border: 1px solid #d5dfda; border-radius: 9px; color: var(--ink); background: white; font-size: 12px; }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-top: 15px; }
.metric { min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; }
.metric small, .metric strong { display: block; }
.metric small { color: var(--muted); font-size: 10px; }
.metric strong { margin-top: 6px; overflow: hidden; text-overflow: ellipsis; font-size: 14px; font-variant-numeric: tabular-nums; }
.conflict-list { margin-top: 13px; padding: 12px; border: 1px solid #edd69d; border-radius: 12px; color: #6b4e18; background: var(--amber-soft); font-size: 12px; }
.warning-list { display: grid; gap: 5px; margin-top: 13px; padding: 12px; border: 1px solid #e4b25f; border-radius: 12px; color: #6b4308; background: #fff7df; font-size: 11px; line-height: 1.45; }
.warning-list strong { margin-bottom: 2px; font-size: 12px; }
.warning-list.critical { color: #8e2b2b; border-color: #e4a5a2; background: var(--red-soft); box-shadow: 0 0 0 3px rgba(182,53,53,.07); }
.action-bar { margin-top: 22px; min-height: 42px; }
.action-spacer { flex: 1; }
.reset-button { width: 166px; font-variant-numeric: tabular-nums; }
.reset-button.armed { color: white; border-color: var(--red); background: var(--red); box-shadow: 0 0 0 4px rgba(182, 53, 53, .12); }

.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #f6f8f7; }
.segmented button { min-height: 32px; padding: 0 13px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 800; }
.segmented button.active { color: white; background: var(--green); }
.filter-row { margin: 20px 0 15px; flex-wrap: wrap; }
.filter-row label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; font-weight: 800; }
.filter-row input { width: 150px; }
.data-grid.two-columns { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(330px, .6fr); gap: 14px; }
.data-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.data-card .card-heading { min-height: 58px; padding: 13px 15px; border-bottom: 1px solid var(--line); background: #fbfcfb; }
.card-heading span { color: var(--muted); font-size: 11px; }
.billing-close-card { margin-bottom: 14px; }
.billing-close-card .card-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.billing-close-card .card-heading h3, .billing-close-card .card-heading p { margin: 0; }
.billing-close-card .card-heading p { margin-top: 4px; color: var(--muted); font-size: 10px; }
.billing-close-metrics { padding: 13px 15px 4px; }
.billing-close-warning { margin: 10px 15px; padding: 10px 12px; border: 1px solid #df9995; border-radius: 10px; color: #862d2a; background: var(--red-soft); font-size: 11px; line-height: 1.55; }
.billing-close-actions { display: flex; align-items: end; justify-content: flex-end; gap: 9px; padding: 10px 15px 15px; }
.billing-close-actions label { display: grid; flex: 1; gap: 5px; color: var(--muted); font-size: 9px; font-weight: 800; }
.billing-close-actions input { width: 100%; min-height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; }
.status-pill.closed { color: var(--green); background: var(--green-soft); }
.status-pill.open, .status-pill.unlocked { color: #775421; background: var(--amber-soft); }
.status-pill.historical-reference { color: #69716d; background: #eef0ef; }
.history-tree { display: grid; gap: 8px; padding: 10px; }
.history-tree-node { min-width: 0; }
.history-tree-toggle, .history-tree-leaf {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: #fbfcfb;
  cursor: pointer;
  text-align: left;
}
.history-tree-toggle:hover, .history-tree-toggle:focus-visible, .history-tree-leaf:hover, .history-tree-leaf:focus-visible { border-color: #a7c8b8; background: var(--green-soft); }
.history-tree-chevron { display: grid; place-items: center; width: 22px; height: 22px; color: var(--green); font-size: 15px; transition: transform .16s ease; }
.history-tree-toggle[aria-expanded="true"] .history-tree-chevron { transform: rotate(90deg); }
.history-tree-label { min-width: 0; }
.history-tree-label strong, .history-tree-label small { display: block; }
.history-tree-label strong { overflow: hidden; text-overflow: ellipsis; font-size: 12px; white-space: nowrap; }
.history-tree-label small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.history-tree-metrics { color: #44544c; font-size: 10px; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.history-tree-children { display: grid; gap: 7px; margin: 7px 0 2px 16px; padding-left: 12px; border-left: 2px solid #dfe9e4; }
.history-tree-leaf { background: white; }
.history-tree-leaf .history-tree-chevron { font-size: 13px; }
.history-only-badge { display: inline-flex; margin-left: 6px; padding: 2px 5px; border-radius: 999px; color: #775421; background: var(--amber-soft); font-size: 8px; font-weight: 850; vertical-align: middle; }
.history-reference-badge { display: inline-flex; margin-left: 6px; padding: 2px 6px; border-radius: 999px; color: #69716d; background: #eef0ef; font-size: 8px; font-weight: 850; vertical-align: middle; }
.history-reference-badge.mixed { color: #5f6c66; background: #e8eeeb; }
.history-tree-node.scope-historical_reference > .history-tree-toggle,
.history-tree-node.scope-historical_reference > .history-tree-leaf { border-color: #d9dddb; background: #f4f5f4; color: #626b67; box-shadow: none; }
.history-tree-node.scope-historical_reference > .history-tree-toggle:hover,
.history-tree-node.scope-historical_reference > .history-tree-toggle:focus-visible,
.history-tree-node.scope-historical_reference > .history-tree-leaf:hover,
.history-tree-node.scope-historical_reference > .history-tree-leaf:focus-visible { border-color: #c5cbc8; background: #ecefed; }
.history-tree-node.issue-node > .history-tree-toggle, .history-tree-node.issue-node > .history-tree-leaf { border-color: #df9995; background: #fff7f6; box-shadow: inset 3px 0 #b63535; }
.history-tree-node.issue-node > .history-tree-toggle:hover, .history-tree-node.issue-node > .history-tree-toggle:focus-visible, .history-tree-node.issue-node > .history-tree-leaf:hover, .history-tree-node.issue-node > .history-tree-leaf:focus-visible { border-color: var(--red); background: var(--red-soft); }
.history-tree-node.issue-node > button .history-tree-chevron, .history-tree-node.issue-node > button .history-tree-label small { color: #9b3430; }
.history-issue-badge { display: inline-flex; margin-left: 6px; padding: 2px 6px; border-radius: 999px; color: #922f2c; background: #f9d9d6; font-size: 8px; font-weight: 850; vertical-align: middle; }
.table-scroll { overflow: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th, td { padding: 10px 11px; border-bottom: 1px solid #edf1ef; text-align: right; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; color: #65756d; background: #f8faf9; font-size: 10px; font-weight: 850; }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover td { background: #f7fbf9; }
.table-action { min-height: 28px; padding: 0 9px; border: 1px solid #cadbd2; border-radius: 8px; color: var(--green); background: white; cursor: pointer; font-size: 10px; font-weight: 800; }
.table-action.danger-outline { color: var(--red); border-color: #e9bdbc; background: #fffafa; }
.table-action.danger-outline:hover { background: var(--red-soft); }
.detail-card { margin-top: 14px; }
.detail-card .table-scroll { max-height: min(66vh, 680px); }
.batch-list { display: grid; gap: 8px; max-height: 510px; padding: 10px; overflow-y: auto; }
.batch-item { padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcfb; }
.batch-item.historical-reference { border-color: #d9dddb; background: #f3f5f4; color: #626b67; }
.batch-top { display: flex; justify-content: space-between; gap: 8px; }
.batch-top strong { font: 700 10px/1.4 ui-monospace, monospace; }
.batch-meta { margin-top: 7px; color: var(--muted); font-size: 10px; line-height: 1.6; }
.batch-files { display: grid; gap: 5px; margin-top: 8px; }
.source-file-link, .source-file-unavailable { display: block; min-height: 28px; padding: 6px 8px; border-radius: 8px; font-size: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.source-file-link { color: var(--green); border: 1px solid #c8d9d0; background: #fff; text-decoration: none; font-weight: 800; }
.source-file-link:hover, .source-file-link:focus-visible { border-color: var(--green); background: var(--green-soft); }
.source-file-unavailable { color: var(--muted); border: 1px dashed #d6ded9; background: #f5f7f6; }
.batch-actions { display: flex; gap: 7px; margin-top: 8px; }
.status-pill { padding: 3px 7px; border-radius: 999px; font-size: 9px; font-weight: 850; }
.status-pill.active { color: var(--green); background: var(--green-soft); }
.status-pill.deleted, .status-pill.superseded { color: #68746e; background: #edf0ee; }
.empty-box { padding: 36px 20px; color: var(--muted); text-align: center; font-size: 12px; }
.danger-card { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-top: 14px; padding: 16px; border: 1px solid #ecc5c3; border-radius: 15px; background: var(--red-soft); }
.danger-card h3 { margin: 0; font-size: 15px; }
.danger-card p:not(.eyebrow) { margin: 6px 0 0; color: #7a4340; font-size: 11px; line-height: 1.5; }

.audit-list { display: grid; gap: 9px; margin-top: 18px; }
.audit-item { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 14px; align-items: start; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; }
.audit-time { color: var(--muted); font-size: 10px; }
.audit-content strong { display: block; font-size: 12px; }
.audit-content p { margin: 5px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }

dialog { width: min(860px, calc(100% - 30px)); max-height: min(90vh, 900px); padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; color: var(--ink); background: white; box-shadow: 0 30px 100px rgba(20, 45, 33, .3); }
dialog::backdrop { background: rgba(17, 34, 26, .52); backdrop-filter: blur(4px); }
.dialog-shell { display: flex; flex-direction: column; max-height: min(90vh, 900px); }
.dialog-heading { padding: 20px 22px 15px; border-bottom: 1px solid var(--line); }
.icon-button { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 10px; color: var(--muted); background: #f1f4f2; cursor: pointer; font-size: 22px; }
.review-callout { margin: 15px 22px 0; padding: 11px 13px; border: 1px solid #ead595; border-radius: 11px; color: #644815; background: var(--amber-soft); font-size: 11px; line-height: 1.55; }
.review-risk-confirmation { display: grid; gap: 7px; margin: 12px 22px 0; padding: 13px 14px; border: 1px solid #df9995; border-radius: 12px; color: #862d2a; background: var(--red-soft); box-shadow: 0 0 0 3px rgba(182,53,53,.07); font-size: 12px; line-height: 1.55; }
.review-risk-confirmation[hidden] { display: none; }
.review-risk-confirmation strong { font-size: 13px; }
.review-risk-confirmation p { margin: 0; }
.review-risk-confirmation label { display: flex; align-items: flex-start; gap: 9px; font-weight: 750; cursor: pointer; }
.review-risk-confirmation input { width: 17px; height: 17px; margin-top: 1px; accent-color: var(--red); }
.review-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; padding: 15px 22px; overflow-y: auto; }
.review-field { padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcfb; }
.review-field small, .review-field strong { display: block; }
.review-field small { color: var(--muted); font-size: 9px; }
.review-field strong { margin-top: 5px; overflow-wrap: anywhere; font-size: 12px; }
.review-files { padding: 0 22px 16px; overflow-y: auto; }
.review-files h3 { margin: 0 0 8px; font-size: 12px; }
.review-file { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid #edf1ef; color: var(--muted); font-size: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 22px; border-top: 1px solid var(--line); background: #fafcfb; }
.edit-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 18px 22px; overflow-y: auto; }
.edit-field label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; }
.compact-dialog { max-height: min(70vh, 620px); }
.media-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 20px 22px; overflow-y: auto; }
.media-option { display: flex; align-items: center; justify-content: space-between; min-height: 54px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #fbfcfb; cursor: pointer; font-weight: 800; }
.media-option:hover { border-color: #8fbca6; background: var(--green-soft); }
.media-option.selected { color: var(--green); border-color: var(--green); background: var(--green-soft); }
.history-detail-dialog { width: min(1380px, calc(100% - 30px)); }
.history-detail-dialog .dialog-shell { height: min(90vh, 900px); }
.history-detail-dialog .dialog-heading p:not(.eyebrow) { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.history-detail-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 12px 22px; border-bottom: 1px solid var(--line); background: #fafcfb; }
.history-detail-toolbar .segmented button[aria-selected="true"] { color: white; background: var(--green); }
.history-legends { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.edited-legend, .issue-legend { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.edited-legend i, .issue-legend i { width: 12px; height: 12px; border-radius: 3px; }
.edited-legend i { border: 1px solid #e39a42; background: #fff0dc; }
.issue-legend i { border: 1px solid #cf7772; background: var(--red-soft); }
.history-detail-view { flex: 1 1 auto; min-height: 0; overflow: auto; }
.history-detail-table-scroll { max-height: none; }
.history-detail-table-scroll table { min-width: 1120px; }
td.edited-cell { background: #fff0dc !important; box-shadow: inset 3px 0 #e58a22; }
tr.issue-row td { background: #fff1f0; }
tr.issue-row:hover td { background: #fee6e4; }
tr.historical-reference-row td { background: #f3f5f4; color: #626b67; }
tr.historical-reference-row:hover td { background: #ecefed; }
.history-detail-cards { display: none; gap: 10px; padding: 12px; }
.history-row-card { overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: white; }
.history-row-card.issue-row { border-color: #df9995; box-shadow: inset 3px 0 #b63535; }
.history-row-card.issue-row .history-row-card-heading { background: #fff1f0; }
.history-row-card.historical-reference-row { border-color: #d9dddb; background: #f3f5f4; color: #626b67; }
.history-row-card.historical-reference-row .history-row-card-heading { background: #ecefed; }
.history-row-issue-text { margin: 0; padding: 8px 12px; color: #922f2c; border-bottom: 1px solid #efd0ce; background: #fff7f6; font-size: 9px; line-height: 1.5; }
.history-row-card-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 12px; border-bottom: 1px solid var(--line); background: #fbfcfb; }
.history-row-card-heading strong { overflow: hidden; text-overflow: ellipsis; font-size: 11px; white-space: nowrap; }
.history-row-card-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.history-row-field { min-width: 0; padding: 9px 11px; border-bottom: 1px solid #edf1ef; }
.history-row-field:nth-child(odd) { border-right: 1px solid #edf1ef; }
.history-row-field small, .history-row-field span { display: block; }
.history-row-field small { color: var(--muted); font-size: 8px; font-weight: 800; }
.history-row-field span { margin-top: 4px; overflow-wrap: anywhere; font-size: 10px; }
.history-row-field.edited-cell { background: #fff0dc; box-shadow: inset 3px 0 #e58a22; }
.history-row-card-actions { padding: 10px 12px; }
.history-detail-dialog .batch-list { max-height: none; padding: 14px 22px; }
.primary-supplier-value { display: grid; gap: 3px; min-width: 130px; }
.primary-supplier-value small { color: var(--muted); font-size: 8px; line-height: 1.35; }
.primary-supplier-value.current-master small { color: #9a5d12; }
.resolution-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; min-width: 148px; }
.resolution-state { display: inline-flex; padding: 5px 8px; border-radius: 999px; color: #6b4b16; background: var(--amber-soft); font-size: 9px; font-weight: 800; line-height: 1.35; }
.resolution-state.confirmed { color: var(--green); background: var(--green-soft); }
.resolution-reconciliation-summary { flex-basis: 100%; color: var(--muted); font-size: 9px; line-height: 1.45; }
.reconciliation-dialog { width: min(700px, calc(100% - 30px)); }
.reconciliation-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; padding: 18px 22px 10px; }
.reconciliation-summary .metric { min-width: 0; }
.reconciliation-guidance { margin: 2px 22px 12px; padding: 12px 14px; border: 1px solid #df9995; border-radius: 12px; color: #862d2a; background: var(--red-soft); font-size: 11px; line-height: 1.6; }
.reconciliation-reason { padding: 0 22px 18px; }
.reconciliation-reason label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; font-weight: 800; }
.reconciliation-reason textarea { width: 100%; resize: vertical; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 100; max-width: min(560px, calc(100% - 30px)); padding: 11px 16px; border-radius: 12px; color: white; background: #26352e; box-shadow: 0 14px 40px rgba(20,35,28,.24); font-size: 12px; line-height: 1.5; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8f2e2e; }
.toast.success { background: var(--green); }

[hidden] { display: none !important; }

@media (max-width: 1050px) {
  .topbar { grid-template-columns: auto 1fr; }
  .identity-strip { grid-column: 1 / -1; justify-self: stretch; max-width: none; }
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .batch-config, .fee-rule { grid-template-columns: 1fr; }
  .data-grid.two-columns { grid-template-columns: 1fr; }
  .batch-list { max-height: none; }
}

@media (max-width: 720px) {
  .page-shell { width: min(100% - 22px, 1480px); padding-top: 22px; }
  .topbar { padding: 10px 14px; }
  .brand-subtitle { display: none; }
  .hero { align-items: stretch; flex-direction: column; }
  .hero-security { min-width: 0; }
  .workspace-panel { padding: 17px; border-radius: 17px; }
  .panel-heading, .subsection-heading, .danger-card, .billing-close-actions { align-items: stretch; flex-direction: column; }
  .panel-heading .button, .subsection-heading .button { align-self: flex-start; }
  .template-download-grid { grid-template-columns: 1fr; align-items: start; }
  .stepper { grid-template-columns: repeat(5, 32px); justify-content: space-between; }
  .stepper li { display: block; }
  .stepper li div { display: none; }
  .stepper li::after { left: 30px; right: -10vw; }
  .type-choice { grid-template-columns: 1fr; }
  .metric-grid, .review-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-row { align-items: stretch; }
  .filter-row label { width: 100%; justify-content: space-between; }
  .filter-row input { flex: 1; }
  .edit-fields { grid-template-columns: 1fr; }
  .media-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .audit-item { grid-template-columns: 1fr; gap: 6px; }
  .dialog-actions .button { flex: 1; min-width: 0; }
  .history-tree-toggle, .history-tree-leaf { grid-template-columns: 20px minmax(0, 1fr); }
  .history-tree-metrics { grid-column: 2; text-align: left; white-space: normal; }
  .history-tree-children { margin-left: 8px; padding-left: 8px; }
  .history-detail-dialog { width: calc(100% - 14px); max-height: calc(100dvh - 14px); border-radius: 16px; }
  .history-detail-dialog .dialog-shell { height: calc(100dvh - 14px); max-height: calc(100dvh - 14px); }
  .history-detail-toolbar { align-items: flex-start; flex-direction: column; padding: 10px 14px; }
  .history-detail-table-scroll { display: none; }
  .history-detail-cards { display: grid; }
  .history-detail-dialog .batch-list { padding: 12px; }
  .reconciliation-summary { grid-template-columns: 1fr; }
}

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