
      :root {
        --brand: #782524;
        --slate: #9a1114;
        --accent: #a54143;
        --white: #ffffff;
        --bg: #f5f5f5;
        --panel: #ffffff;
        --line: #e4d8d8;
        --text: #333333;
        --muted: #666666;
        --soft-brand: #f5e9e9;
        --soft-slate: #f7f2f2;
        --success: #edf8f2;
        --success-line: #76b796;
        --success-text: #1d7f4c;
        --danger: #fff1f3;
        --danger-line: #e2a4b2;
        --warn: #fff7ea;
        --warn-line: #e6c98f;
        --shadow: 0 18px 50px rgba(120, 37, 36, 0.08);
        --radius: 22px;
      }

      * {
        box-sizing: border-box;
        min-width: 0;
      }

      html,
      body {
        margin: 0;
        padding: 0;
        background:
          radial-gradient(circle at top right, rgba(120, 37, 36, 0.2), transparent 26%),
          linear-gradient(180deg, #fbfcfc 0%, var(--bg) 100%);
        color: var(--text);
        font-family: "Avenir Next", Avenir, Montserrat, "Segoe UI", sans-serif;
        -webkit-text-size-adjust: 100%;
        max-width: 100%;
        overflow-x: hidden;
      }

      button,
      input,
      select {
        font: inherit;
        touch-action: manipulation;
      }

      .shell {
        width: min(1600px, calc(100% - 56px));
        margin: 0 auto;
        padding: 34px 0 78px;
      }

      .hero {
        background: linear-gradient(135deg, var(--brand), var(--slate) 58%, var(--accent) 100%);
        color: var(--white);
        border-radius: 30px;
        padding: clamp(34px, 4vw, 64px) clamp(28px, 4.4vw, 60px);
        box-shadow: var(--shadow);
      }

      h1,
      h2,
      h3,
      p {
        margin: 0;
      }

      .hero h1 {
        margin-top: 8px;
        font-size: clamp(3.4rem, 5.2vw, 6.1rem);
        line-height: 1;
        max-width: 13ch;
      }

      .hero p {
        margin-top: 24px;
        max-width: 60ch;
        color: rgba(255, 255, 255, 0.88);
        font-size: clamp(1.15rem, 1.65vw, 1.55rem);
        line-height: 1.35;
      }

      .hero-formula {
        margin-top: 34px;
        border-radius: 22px;
        background: rgba(255, 255, 255, 0.12);
        border: 1px solid rgba(255, 255, 255, 0.2);
        overflow: hidden;
      }

      .hero-formula summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-height: 54px;
        padding: 18px 22px;
        cursor: pointer;
        list-style: none;
        font-weight: 700;
        font-size: clamp(1rem, 1.35vw, 1.25rem);
      }

      .hero-formula summary::-webkit-details-marker {
        display: none;
      }

      .hero-formula summary::after {
        content: "";
        width: 10px;
        height: 10px;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: rotate(45deg);
        transition: transform 160ms ease;
        flex: 0 0 auto;
      }

      .hero-formula[open] summary::after {
        transform: rotate(225deg);
      }

      .formula-body {
        display: grid;
        gap: 12px;
        padding: 0 16px 16px;
      }

      .formula {
        overflow-x: auto;
        padding: 12px;
        border-radius: 16px;
        background: rgba(36, 48, 48, 0.28);
        color: var(--white);
        font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
        font-size: clamp(0.82rem, 2.5vw, 1rem);
        white-space: nowrap;
      }

      .formula-legend {
        display: grid;
        gap: 8px;
        max-width: 88ch;
      }

      .formula-legend span {
        display: block;
        color: rgba(255, 255, 255, 0.9);
        font-size: 0.9rem;
        line-height: 1.4;
      }

      .formula-legend b {
        color: var(--white);
      }

      .layout {
        display: grid;
        gap: 24px;
        margin-top: 28px;
      }

      .panel {
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        padding: 26px;
        box-shadow: var(--shadow);
        max-width: 100%;
        overflow-wrap: anywhere;
      }

      .section-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 14px;
      }

      .section-head h2 {
        font-size: 1.35rem;
      }

      .hint {
        margin-top: 6px;
        color: var(--muted);
        font-size: 1.02rem;
        line-height: 1.45;
      }

      .grid {
        display: grid;
        gap: 12px;
      }

      .grid.two {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
      }

      .grid.three {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
      }

      label > span,
      .field-label {
        display: block;
        margin-bottom: 8px;
        font-size: 0.88rem;
        color: var(--muted);
      }

      input,
      select,
      button {
        width: 100%;
        border-radius: 16px;
        border: 1px solid var(--line);
        min-height: 58px;
      }

      input,
      select {
        padding: 11px 14px;
        background: var(--white);
        color: var(--text);
      }

      button {
        padding: 0 16px;
        background: var(--soft-slate);
        color: var(--slate);
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(120, 37, 36, 0.12);
        transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
      }

      button:hover {
        transform: translateY(-1px);
      }

      button.primary {
        background: var(--brand);
        color: var(--white);
        border-color: var(--brand);
      }

      button.secondary {
        background: var(--slate);
        color: var(--white);
        border-color: var(--slate);
      }

      button.soft-brand {
        background: var(--soft-brand);
        color: var(--brand);
        border-color: #ddbbbb;
      }

      button.ghost-danger {
        background: transparent;
        color: #a53a4c;
      }

      .toggle-group {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
        gap: 10px;
      }

      .toggle-card {
        position: relative;
      }

      .toggle-card input {
        position: absolute;
        inset: 0;
        opacity: 0;
        cursor: pointer;
      }

      .toggle-card span {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 56px;
        padding: 10px 14px;
        border-radius: 18px;
        border: 1px solid var(--line);
        background: var(--white);
        font-weight: 700;
      }

      .toggle-card input:checked + span {
        background: var(--soft-brand);
        border-color: var(--accent);
        color: var(--brand);
      }

      .att-list {
        display: grid;
        gap: 10px;
      }

      .category-field {
        min-width: 0;
      }

      .category-description {
        display: block;
        margin-top: 6px;
        color: var(--muted);
        font-size: 0.8rem;
        line-height: 1.3;
      }

      .att-row {
        display: grid;
        grid-template-columns: 1.2fr 1fr auto;
        gap: 10px;
        align-items: start;
      }

      .att-row > select,
      .att-row > button {
        margin-top: 0;
      }

      .tools-row {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
      }

      #targetPanel .tools-row {
        flex-direction: column;
        align-items: stretch;
        width: 230px;
        max-width: 100%;
      }

      .badge {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        border-radius: 999px;
        background: var(--soft-slate);
        color: var(--slate);
        font-size: 0.84rem;
      }

      .badge.brand {
        background: var(--soft-brand);
        color: var(--brand);
      }

      .sync-state {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        width: calc(100% - 24px);
        min-height: 21px;
        margin-left: 24px;
        padding: 2px 9px;
        background: #f7f9fb;
        color: #9aa5b1;
        border-color: #e2e8ee;
        border-radius: 9px;
        font-size: 0.68rem;
        font-weight: 400;
        line-height: 1.15;
      }

      .sync-state::before {
        content: "";
        display: none;
      }

      .sync-state.is-active {
        background: var(--accent);
        color: var(--white);
        border-color: var(--accent);
      }

      .sync-state.is-active::before {
        content: "✓";
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 13px;
        height: 13px;
        border: 1px solid currentColor;
        border-radius: 50%;
        font-size: 0.58rem;
        line-height: 1;
        flex: 0 0 auto;
      }

      .variation-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
        gap: 14px;
      }

      .variation-card {
        padding: 14px;
        border-radius: 20px;
        border: 1px solid var(--line);
        background: linear-gradient(180deg, #ffffff 0%, #fafcfc 100%);
      }

      .variation-card h3 {
        margin-bottom: 6px;
        font-size: 1rem;
      }

      .variation-card p {
        margin-bottom: 12px;
        color: var(--muted);
        font-size: 0.92rem;
        line-height: 1.4;
      }

      .checklist {
        display: grid;
        gap: 10px;
      }

      .check-item {
        display: grid;
        grid-template-columns: auto 1fr;
        gap: 10px;
        align-items: start;
        padding: 10px 12px;
        border-radius: 16px;
        background: var(--soft-slate);
      }

      .check-item input[type="checkbox"] {
        width: 18px;
        min-height: auto;
        margin: 2px 0 0;
      }

      .variation-with-quantity { grid-template-columns: auto minmax(0, 1fr) 78px; }
      .variation-description { min-width: 0; overflow-wrap: anywhere; cursor: pointer; }
      .variation-quantity { display: grid; gap: 4px; font-size: .78rem; color: var(--muted); }
      .variation-quantity input { width: 100%; min-width: 0; padding: 8px; min-height: 38px; }
      .variation-quantity input:disabled { opacity: .45; }
      .variation-quantity input[aria-invalid="true"] { border-color: #a7263d; }
      @media (max-width: 600px) {
        .variation-with-quantity { grid-template-columns: auto minmax(0, 1fr); }
        .variation-quantity { grid-column: 2; justify-self: end; width: 78px; }
      }

      .check-item strong {
        display: block;
        font-size: 0.92rem;
      }

      .check-item small {
        display: block;
        margin-top: 4px;
        color: var(--muted);
        line-height: 1.35;
      }

      .actions {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 10px;
      }

      .summary-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 12px;
      }

      .summary-card {
        padding: 14px;
        border-radius: 20px;
        background: linear-gradient(180deg, #ffffff 0%, #f9fbfb 100%);
        border: 1px solid var(--line);
      }

      .summary-card span {
        display: block;
        color: var(--muted);
        font-size: 0.82rem;
        margin-bottom: 8px;
      }

      .summary-card strong {
        font-size: 1.3rem;
        line-height: 1;
      }

      .summary-card.total {
        background: linear-gradient(135deg, var(--slate), #782524);
        color: var(--white);
        border-color: var(--slate);
      }

      .summary-card.total.net-total {
        background: #ffffff;
        color: var(--text);
        border: 2px solid var(--slate);
      }

      .summary-card.total span {
        color: rgba(255, 255, 255, 0.72);
      }

      .summary-card.total.net-total span {
        color: var(--slate);
        font-weight: 700;
      }

      .summary-card.total strong {
        font-size: 1.7rem;
      }

      .summary-card.total em {
        display: block;
        margin-top: 8px;
        font-size: 0.9rem;
        line-height: 1.35;
        font-style: italic;
        font-weight: 400;
      }

      .summary-card.total.net-total em {
        color: var(--muted);
      }

      .split-panel {
        margin-top: 14px;
        padding: 14px;
        border: 1px solid var(--line);
        border-radius: 20px;
        background: #f9fbfb;
      }

      .split-grid {
        display: grid;
        grid-template-columns: minmax(160px, 220px) repeat(2, minmax(150px, 1fr));
        gap: 12px;
        align-items: end;
      }

      .split-result {
        padding: 11px 12px;
        border-radius: 16px;
        background: var(--white);
        border: 1px solid var(--line);
      }

      .split-result span {
        display: block;
        margin-bottom: 5px;
        color: var(--muted);
        font-size: 0.78rem;
      }

      .split-result strong {
        font-size: 1.08rem;
      }

      .pill-row {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        margin-top: 14px;
      }

      .pill {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 10px 12px;
        border-radius: 999px;
        background: var(--soft-slate);
        font-size: 0.86rem;
      }

      .pill strong {
        white-space: nowrap;
      }

      .amount-pill {
        justify-content: space-between;
        width: 100%;
        border-radius: 22px;
      }

      .amount-pill .pill-label {
        min-width: 0;
        line-height: 1.35;
      }

      .amount-pill strong {
        flex: 0 0 auto;
        margin-left: 12px;
        font-size: clamp(1rem, 4vw, 1.1rem);
      }

      .pill.brand {
        background: var(--soft-brand);
        color: var(--brand);
      }

      .breakdown {
        display: grid;
        gap: 12px;
        margin-top: 16px;
      }

      .break-card {
        border: 1px solid var(--line);
        border-radius: 22px;
        padding: 16px;
      }

      .break-head {
        display: flex;
        justify-content: space-between;
        align-items: start;
        gap: 12px;
      }

      .break-head strong {
        font-size: 1.08rem;
      }

      .break-values {
        text-align: right;
      }

      .break-values span {
        display: block;
        color: var(--muted);
        font-size: 0.82rem;
      }

      .break-values strong {
        font-size: 1.15rem;
      }

      .meta-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
        gap: 8px;
        margin-top: 14px;
      }

      .meta-item {
        padding: 10px;
        border-radius: 16px;
        background: var(--soft-slate);
      }

      .meta-item span {
        display: block;
        color: var(--muted);
        font-size: 0.76rem;
        margin-bottom: 4px;
      }

      .meta-item strong {
        font-size: 0.98rem;
      }

      .line-items {
        display: grid;
        gap: 8px;
        margin-top: 12px;
      }

      .line-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        background: var(--soft-slate);
        border-radius: 16px;
      }

      .calc-note {
        margin-top: 10px;
        padding: 10px 12px;
        border-radius: 14px;
        background: #f7f9fb;
        color: var(--muted);
        font-size: 0.86rem;
        line-height: 1.4;
      }

      .calc-note strong {
        color: var(--text);
      }

      .message {
        padding: 14px;
        border-radius: 18px;
        border: 1px solid var(--success-line);
        background: var(--success);
        color: var(--slate);
      }

      .message.error {
        background: var(--danger);
        border-color: var(--danger-line);
        color: #7b2138;
      }

      .message.warn {
        background: var(--warn);
        border-color: var(--warn-line);
        color: #6b5321;
      }

      .hidden {
        display: none !important;
      }

      @media (max-width: 760px) {
        .shell {
          width: min(100% - 18px, 100%);
          padding-top: 14px;
          overflow-x: hidden;
        }

        .hero {
          border-radius: 24px;
          padding: 20px 18px;
        }

        .hero h1 {
          font-size: clamp(2.1rem, 12vw, 3.6rem);
        }

        .hero p {
          font-size: 1rem;
        }

        .panel {
          border-radius: 22px;
          padding: 16px;
        }

        .att-row {
          grid-template-columns: 1fr;
        }

        .toggle-group,
        .grid.two,
        .grid.three,
        .variation-grid,
        .actions,
        .summary-grid,
        .meta-grid {
          grid-template-columns: minmax(0, 1fr);
        }

        #targetPanel .tools-row {
          width: 100%;
        }

        .sync-state {
          width: 100%;
          margin-left: 0;
        }

        .amount-pill {
          display: grid;
          grid-template-columns: minmax(0, 1fr) auto;
          align-items: center;
          gap: 10px;
        }

        .amount-pill strong {
          font-size: clamp(0.92rem, 3.6vw, 1.04rem);
        }

        .break-head,
        .line-item,
        .section-head {
          flex-direction: column;
          align-items: stretch;
        }

        .break-values {
          text-align: left;
        }

        .split-grid {
          grid-template-columns: minmax(0, 1fr);
          width: 100%;
        }
      }
    
html,body{min-height:0} body{margin:0} .shell{margin-top:0;margin-bottom:0}

/* Attestation recovery popup */
.recover-dialog {
  position: absolute;
  margin: 0 auto;
  width: min(520px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(120, 37, 36, .22);
}
.recover-dialog::backdrop { background: rgba(35, 20, 20, .55); }
.recover-dialog-head { display: flex; align-items: flex-start; gap: 16px; justify-content: space-between; margin-bottom: 24px; }
.recover-dialog-head h2 { color: var(--brand); font-size: 1.55rem; line-height: 1.2; }
.recover-close { flex: 0 0 auto; padding: 0; width: 36px; height: 36px; font-size: 28px; line-height: 1; }
#recoverTaxCode { text-transform: uppercase; margin-top: 8px; }
.recover-dialog .hint { margin-top: 10px; font-size: .9rem; }
.recover-actions { margin-top: 24px; }
.recover-actions button { width: 100%; }
.recover-status { margin-top: 16px; padding: 12px; background: var(--soft-brand); border-radius: 10px; line-height: 1.5; }
@media (max-width: 480px) { .recover-dialog { padding: 20px; } .recover-dialog-head h2 { font-size: 1.3rem; } }
