:root {
  color-scheme: light;
  --ink: #203044;
  --muted: #5d6c7b;
  --brand: #125a8a;
  --brand-dark: #0c436b;
  --line: #dce4eb;
  --surface: #fff;
  --soft: #f3f7fa;
  --background: #eef3f7;
  --focus: #f1a73c;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--background); color: var(--ink); font: 1rem/1.5 Arial, Helvetica, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1, h2, h3 { line-height: 1.22; }
h1 { margin: 0 0 1rem; font-size: clamp(1.7rem, 3vw, 2.4rem); }
h2 { margin: 1.8rem 0 .8rem; font-size: 1.2rem; }
p { margin: .5rem 0 1rem; }
.muted, .small, .footer { color: var(--muted); }
.small, .footer { font-size: .85rem; }
.eyebrow, .tag { color: var(--brand); font-size: .82rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.site-header, .topbar { background: #fff; border-bottom: 1px solid var(--line); }
.site-header-inner, .topbar-inner { max-width: 1240px; margin: auto; padding: .9rem 1.4rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { color: var(--brand-dark); font-size: 1.3rem; font-weight: 800; letter-spacing: .03em; }
.brand small { display: block; color: var(--muted); font-size: .67rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.site-main { max-width: 1120px; margin: 2.2rem auto; padding: 0 1.2rem; }
.hero, .panel, .box, .admin-content, .auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 5px 22px #17324b0b; }
.hero { padding: clamp(1.5rem, 4vw, 3.2rem); }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(270px, .8fr); gap: 2rem; align-items: center; }
.hero p { max-width: 56ch; }
.lookup, .lookup-card { padding: 1.4rem; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; }
.lookup h2, .lookup-card h2 { margin-top: 0; }
.lookup-row { display: flex; gap: .7rem; align-items: end; }
.lookup-row input { flex: 1; min-width: 0; text-transform: uppercase; }
.notice, .warn { padding: 1rem 1.1rem; margin-top: 1.3rem; background: #edf6fc; border-left: 4px solid var(--brand); border-radius: 8px; }
.footer { margin: 2rem 0 0; }
.admin-layout { max-width: 1360px; margin: auto; padding: 1.2rem; display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 1.2rem; }
.sidebar { align-self: start; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .6rem; }
.sidebar a { display: block; padding: .65rem .8rem; border-radius: 8px; color: var(--ink); font-weight: 600; }
.sidebar a:hover, .sidebar a[aria-current="page"] { background: #e9f3f9; color: var(--brand-dark); text-decoration: none; }
.admin-content { min-width: 0; padding: clamp(1.2rem, 2.5vw, 2rem); }
.topbar-actions { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.auth-shell { max-width: 470px; margin: clamp(2rem, 8vh, 6rem) auto; padding: 0 1rem; }
.auth-card { padding: 2rem; }
.auth-card h1 { font-size: 1.7rem; }
.grid, .metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem; }
.metric-grid { margin-bottom: 1.5rem; }
.card, .panel { padding: 1rem; }
.card { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; min-width: 0; }
.card strong { font-size: 1.45rem; }
.label { color: var(--muted); font-size: .82rem; margin-bottom: .25rem; }
.value { font-weight: 650; overflow-wrap: anywhere; }
.hash { overflow-wrap: anywhere; font-family: Consolas, monospace; font-size: .82rem; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: .7rem; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .75rem .8rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { background: #edf3f7; color: #344a5c; font-size: .78rem; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7fafc; }
.pagination { display: flex; gap: .7rem; margin: 1rem 0; align-items: center; }
.status { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.status-ok { color: #17603a; background: #e7f6ed; border-color: #b8e3c9; }
.status-warning { color: #815509; background: #fff5dd; border-color: #f0d898; }
.status-error { color: #922d36; background: #fff0f0; border-color: #efc8cb; }
.status-pending { color: #275b7e; background: #e9f4fb; border-color: #c6dfef; }
.status-disabled { color: #576372; background: #eef0f2; border-color: #d8dde2; }
form { max-width: 100%; }
label { display: block; font-weight: 600; margin: .75rem 0 .25rem; }
input, select, textarea, button { font: inherit; }
input:not([type="checkbox"]), select, textarea { width: 100%; max-width: 620px; border: 1px solid #aebfcf; background: #fff; color: var(--ink); border-radius: 7px; padding: .62rem .72rem; }
input:not([type="checkbox"]):not([type="radio"]), select { min-height: 2.75rem; }
input[type="checkbox"] { width: 1.05rem; height: 1.05rem; vertical-align: middle; margin-right: .35rem; }
textarea { min-height: 100px; resize: vertical; }
input[readonly], textarea[readonly], select:disabled { background: #f1f4f6; color: #4f5d6a; cursor: not-allowed; }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: 10px; margin: 1rem 0; padding: .7rem 1rem 1rem; }
legend { font-weight: 700; color: var(--brand-dark); padding: 0 .3rem; }
button, .btn { display: inline-block; border: 1px solid var(--brand); border-radius: 7px; padding: .62rem 1rem; background: var(--brand); color: #fff; font-weight: 700; cursor: pointer; text-align: center; text-decoration: none; }
button:hover, .btn:hover { background: var(--brand-dark); color: #fff; text-decoration: none; }
.btn.secondary, button.secondary { background: #fff; color: var(--brand); }
.btn.secondary:hover, button.secondary:hover { background: #edf6fb; }
.btn.danger, button.danger { background: #fff; border-color: #b6565d; color: #993740; }
.btn.danger:hover, button.danger:hover { background: #fff2f3; }
.inline { display: inline; }
.inline button { padding: .4rem .65rem; }
.form-actions, .buttons { display: flex; flex-wrap: wrap; gap: .65rem; margin: 1.2rem 0; }
.error, .field-error { color: #9c2933; }
.field-error { display: block; font-size: .86rem; margin-top: .2rem; }
.form-layout { width: 100%; max-width: 980px; }
.form-row { display: grid; grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr); gap: .3rem 1rem; align-items: start; margin: .75rem 0; }
.form-label { margin: .7rem 0 0; color: #344a5c; font-weight: 650; line-height: 1.35; }
.form-control-wrap { min-width: 0; max-width: 720px; font-weight: 400; }
.form-control-wrap > input:not([type="checkbox"]):not([type="radio"]),
.form-control-wrap > select,
.form-control-wrap > textarea { width: 100%; max-width: none; }
.form-help { display: block; margin-top: .28rem; color: var(--muted); font-size: .84rem; font-weight: 400; line-height: 1.4; }
.form-error { display: block; margin-top: .3rem; color: #9c2933; font-size: .86rem; font-weight: 650; line-height: 1.4; }
.form-error-summary { margin: 0 0 1rem; }
.form-error-summary strong { font-size: 1rem; }
[aria-invalid="true"] { border-color: #b6565d !important; box-shadow: 0 0 0 1px #b6565d24; }
.form-section { margin: 1.25rem 0; padding: .85rem 1.1rem 1.1rem; }
.form-section > legend { font-size: 1.02rem; }
.section-help { margin: .1rem 0 1rem; }
.check-line, .radio-option { display: inline-flex; align-items: flex-start; gap: .35rem; margin: .35rem 0; font-weight: 600; }
.check-line input, .radio-option input { flex: 0 0 auto; margin-top: .22rem; }
.radio-group { display: flex; min-height: 2.75rem; flex-wrap: wrap; align-items: center; gap: .35rem 1rem; }
.form-row-check .form-control-wrap { padding-top: .25rem; }
.form-layout > .form-actions { margin-left: 15rem; }
.admin-content form:not(.inline):has(> .form-row) > button:last-child { margin: 1rem 0 0 15rem; }
.compact-form { max-width: 760px; }

/* Older server-rendered forms keep their markup but receive the same two-column rhythm. */
.admin-content form:not(.inline):not(.form-layout) > label:has(> input:not([type="checkbox"]):not([type="radio"])),
.admin-content form:not(.inline):not(.form-layout) > label:has(> select),
.admin-content form:not(.inline):not(.form-layout) > label:has(> textarea),
.admin-content form:not(.inline):not(.form-layout) > fieldset > label:has(> input:not([type="checkbox"]):not([type="radio"])),
.admin-content form:not(.inline):not(.form-layout) > fieldset > label:has(> select),
.admin-content form:not(.inline):not(.form-layout) > fieldset > label:has(> textarea) {
  display: grid;
  grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr);
  gap: .3rem 1rem;
  align-items: start;
  max-width: 960px;
  margin: .75rem 0;
  color: #344a5c;
}
.admin-content form:not(.inline):not(.form-layout) > label > input:not([type="checkbox"]):not([type="radio"]),
.admin-content form:not(.inline):not(.form-layout) > label > select,
.admin-content form:not(.inline):not(.form-layout) > label > textarea,
.admin-content form:not(.inline):not(.form-layout) > fieldset > label > input:not([type="checkbox"]):not([type="radio"]),
.admin-content form:not(.inline):not(.form-layout) > fieldset > label > select,
.admin-content form:not(.inline):not(.form-layout) > fieldset > label > textarea { max-width: 720px; }
.admin-content form:not(.inline):not(.form-layout) > button:last-child { margin-top: 1rem; }

.repeatable { max-width: none; }
.repeatable-scroll { margin-top: .35rem; }
.repeatable-table { width: max-content; min-width: 100%; table-layout: auto; }
.repeatable-table th, .repeatable-table td { padding: .55rem; vertical-align: top; }
.repeatable-table th { white-space: normal; line-height: 1.25; }
.repeatable-table td { background: #fff; }
.repeatable-table input:not([type="checkbox"]),
.repeatable-table select,
.repeatable-table textarea { width: 100%; max-width: none; min-width: 0; box-sizing: border-box; }
.repeatable-table .table-field { min-width: 0; }
.repeatable-table .form-error { white-space: normal; }
.repeatable[data-table="GoodsLines"] [data-column="Marks"] { min-width: 9rem; }
.repeatable[data-table="GoodsLines"] [data-column="Packages"],
.repeatable[data-table="GoodsLines"] [data-column="GrossWeight"],
.repeatable[data-table="GoodsLines"] [data-column="Volume"] { min-width: 7.5rem; }
.repeatable[data-table="GoodsLines"] [data-column="Packaging"],
.repeatable[data-table="GoodsLines"] [data-column="StatisticalNumber"],
.repeatable[data-table="GoodsLines"] [data-column="Adr"] { min-width: 9rem; }
.repeatable[data-table="GoodsLines"] [data-column="Nature"] { min-width: 20rem; }
.repeatable-row-actions { min-width: 13rem; }
.repeatable-row-buttons { display: flex; gap: .4rem; }
.repeatable-row-actions button { flex: 1 1 auto; padding: .5rem .65rem; white-space: nowrap; }
.repeatable-actions { margin: .8rem 0 0; }
.master-inline { display: flex; align-items: stretch; gap: .4rem; min-width: 0; }
.master-inline > select, .master-inline > input { flex: 1 1 auto; min-width: 0; }
.master-inline > button { flex: 0 0 auto; min-width: 2.75rem; padding-inline: .7rem; }
.master-row .form-control-wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.master-row .form-help { grid-column: 1 / -1; }
.row-master-inline { margin-bottom: .4rem; min-width: 12rem; }
.external-prefill { margin-top: 1rem; }
.auth-form { display: grid; gap: .35rem; }
.auth-form label { margin: .55rem 0 0; }
.auth-form input { max-width: none; }
.auth-form .form-actions { margin: 1rem 0 0; }
.doc-shell { max-width: 1080px; margin: 1.5rem auto; padding: 0 1rem; }
.doc-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.doc-panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: clamp(1.2rem, 3vw, 2rem); }
.doc-panel h2 { border-bottom: 1px solid var(--line); padding-bottom: .45rem; }
.doc-panel .grid { margin-top: .8rem; }
.doc-panel .card { background: #fff; }
.doc-code { font-family: Consolas, monospace; font-weight: 800; letter-spacing: .08em; }
.qr-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.qr-card { margin: 0; padding: 1rem; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; text-align: center; }
.qr-card img { display: block; width: min(190px, 100%); height: auto; margin: 0 auto .75rem; image-rendering: pixelated; }
.qr-card figcaption span { display: block; margin-top: .3rem; color: var(--muted); font-family: Consolas, monospace; font-size: .76rem; overflow-wrap: anywhere; }
.ok { display: inline-block; color: #17603a; background: #e7f6ed; border: 1px solid #b8e3c9; padding: .35rem .65rem; border-radius: 999px; font-size: .8rem; font-weight: 700; }
pre { max-width: 100%; overflow: auto; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 1rem; }
.json-editor, .rule-json, .rule-diff { font-family: Consolas, "Courier New", monospace; font-size: .84rem; line-height: 1.5; tab-size: 2; }
.json-editor { width: 100%; max-width: 100%; min-height: 460px; white-space: pre; overflow: auto; }
.rule-json, .rule-diff { max-height: 560px; overflow: auto; white-space: pre; }
.resolution-chain { padding-left: 1.5rem; line-height: 1.9; }
.breadcrumbs { color: var(--muted); font-size: .9rem; }
.rule-summary strong { font-size: inherit; }
details { max-width: 100%; min-width: 0; }
@media (max-width: 900px) {
  .hero-grid { grid-template-columns: 1fr; }
  .admin-layout { grid-template-columns: 1fr; }
  .sidebar { display: flex; gap: .2rem; overflow-x: auto; }
  .sidebar a { white-space: nowrap; }
}
@media (max-width: 720px) {
  .form-row,
  .admin-content form:not(.inline):not(.form-layout) > label:has(> input:not([type="checkbox"]):not([type="radio"])),
  .admin-content form:not(.inline):not(.form-layout) > label:has(> select),
  .admin-content form:not(.inline):not(.form-layout) > label:has(> textarea),
  .admin-content form:not(.inline):not(.form-layout) > fieldset > label:has(> input:not([type="checkbox"]):not([type="radio"])),
  .admin-content form:not(.inline):not(.form-layout) > fieldset > label:has(> select),
  .admin-content form:not(.inline):not(.form-layout) > fieldset > label:has(> textarea) {
    grid-template-columns: minmax(0, 1fr);
    gap: .25rem;
  }
  .form-label { margin-top: 0; }
  .form-row-check .form-label { display: none; }
  .form-layout > .form-actions { margin-left: 0; }
  .admin-content form:not(.inline):has(> .form-row) > button:last-child { margin-left: 0; }
  .form-section { padding: .75rem; }
}
@media (max-width: 600px) {
  .site-header-inner, .topbar-inner { padding: .8rem 1rem; }
  .site-main, .admin-layout { margin: .7rem auto; padding: .65rem; }
  .hero, .admin-content, .auth-card, .doc-panel { border-radius: 10px; padding: 1rem; }
  .lookup-row { flex-direction: column; align-items: stretch; }
  .lookup-row button, .lookup-row input { width: 100%; }
  .topbar-inner { align-items: flex-start; }
  .topbar-actions { justify-content: flex-end; }
  .doc-header { align-items: flex-start; flex-direction: column; }
  th, td { white-space: nowrap; }
}
.ai-status { min-height: 1.5rem; margin: 1rem 0 0; }
.ai-preview-card { border: 1px solid var(--line, #d5dce5); border-radius: .6rem; padding: 1rem; margin: 1rem 0; }
.ai-preview-card pre, #ai-metadata pre { max-height: 22rem; overflow: auto; white-space: pre-wrap; word-break: break-word; }
#ai-candidate { width: 100%; min-height: 28rem; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
#ai-rule-form input[type=file] { display: block; width: 100%; margin-bottom: 1rem; }
#ai-rule-form .check-line { display: flex; align-items: flex-start; gap: .5rem; margin: 1rem 0; }
#ai-rule-form .check-line input { width: auto; margin-top: .25rem; }
@media (max-width: 600px) { #ai-rule-form .form-actions { display: flex; flex-direction: column; align-items: stretch; } }
