.sale-history { display: grid; gap: 20px; min-width: 0; --event-color: #475569; --event-soft: #f1f5f9; }
.sale-history [data-category=commercial] { --event-color: #4659a7; --event-soft: #eef1fc; }
.sale-history [data-category=fiscal] { --event-color: #08755f; --event-soft: #eaf7f1; }
.sale-history [data-category=logistics] { --event-color: #146a9a; --event-soft: #eaf4fb; }
.sale-history [data-category=channel] { --event-color: #9a5511; --event-soft: #fff4e5; }
.sale-history [data-category=payment] { --event-color: #42701e; --event-soft: #f0f7e8; }
.sale-history [data-category=support] { --event-color: #7450a0; --event-soft: #f5effb; }
.sale-history [data-category=returns] { --event-color: #a04561; --event-soft: #fceff3; }
.sale-history h2 { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; }
.history-context { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.history-customer, .history-surface, .history-linked { background: var(--eh-card); border: 1px solid var(--eh-border); border-radius: 14px; min-width: 0; box-shadow: 0 3px 12px #17233d04; }
.history-customer { padding: 20px; overflow-wrap: anywhere; }
.history-customer h2 { color: #52627a; font-size: 12px; margin-bottom: 12px; }
.history-customer h2 svg { box-sizing: content-box; padding: 8px; border-radius: 10px; background: #eef2fa; color: #4659a7; }
.history-customer:nth-child(2) h2 svg { background: #eaf4fb; color: #146a9a; }
.history-customer > strong { font-size: 17px; display: block; }
.history-customer p { margin: 6px 0; font-size: 13px; }
.history-contact { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--eh-text-secondary); margin-top: 12px; }
.history-muted { color: var(--eh-text-muted); font-size: 12px; }
.history-shortcuts { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.history-shortcuts button { display: flex; align-items: flex-start; gap: 12px; text-align: left; background: white; border: 1px solid var(--eh-border); border-radius: 12px; padding: 16px; min-width: 0; transition: border-color .15s, box-shadow .15s; }
.history-shortcuts button > svg { flex-shrink: 0; color: var(--event-color); }
.history-shortcuts button > svg:first-child { box-sizing: content-box; padding: 10px; border-radius: 10px; background: var(--event-soft); }
.history-shortcuts button > svg:last-child { margin-left: auto; width: 12px; }
.history-shortcuts span { min-width: 0; font-size: 12px; color: var(--eh-text-secondary); }
.history-shortcuts strong { display: block; color: var(--eh-text); font-size: 13px; margin: 5px 0; overflow-wrap: anywhere; }
.history-shortcuts small { font-size: 11px; }
.history-shortcuts button:hover { border-color: var(--event-color); box-shadow: 0 4px 14px #17233d0a; }
.history-eyebrow { display: block; color: #65748a; font-size: 10px; font-weight: 700; letter-spacing: .12em; margin-bottom: 7px; }
.history-heading h2 { font-size: 22px; color: #26354c; letter-spacing: -.025em; }
.history-heading h2 svg { color: #5269aa; }
.history-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 24px 24px 12px; }
.history-heading p { font-size: 13px; color: var(--eh-text-secondary); margin-top: 4px; }
.history-sources { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 0 24px 16px; font-size: 11px; color: var(--eh-text-secondary); }
.history-sources [data-warning=true] { color: var(--eh-error); }
.history-sources > span { display: inline-flex; align-items: center; gap: 5px; }
.history-sources [data-state=ready] svg { color: #08755f; }
.history-categories { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--eh-border); }
.history-categories button { display: inline-flex; align-items: center; gap: 6px; padding: 8px 11px; border: 1px solid var(--eh-border); border-radius: 9px; font-size: 12px; font-weight: 600; color: var(--event-color); background: white; }
.history-categories button:hover { background: var(--event-soft); }
.history-categories button[aria-pressed=true] { color: white; background: var(--event-color); border-color: var(--event-color); box-shadow: 0 2px 5px #17233d12; }
.history-categories button span { font-size: 10px; min-width: 19px; padding: 1px 4px; border-radius: 5px; background: #8791a51a; }
.history-categories button[aria-pressed=true] span { background: #ffffff26; }
.history-filters { display: flex; flex-wrap: wrap; gap: 12px; padding: 0 24px 16px; }
.history-filters label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--eh-border-strong); border-radius: 6px; padding: 0 10px; min-width: 0; }
.history-filters label:first-child { flex: 1; }
.history-filters input, .history-filters select { min-width: 0; width: 100%; background: white; border: 0; font-size: 13px; padding: 10px 0; }
.history-filters svg { flex-shrink: 0; }
.history-result { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; background: var(--eh-bg-muted); padding: 10px 24px; font-size: 11px; color: var(--eh-text-secondary); }
.history-month:last-child { padding-bottom: 0; }
.history-month h3 span { font-size: 11px; font-weight: 400; color: var(--eh-text-secondary); }
.history-event-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: 10px; color: var(--eh-text-secondary); }
.history-event-meta span { display: flex; align-items: center; gap: 5px; color: var(--event-color); background: var(--event-soft); border-radius: 5px; padding: 3px 7px; font-weight: 600; }
.history-event-meta strong { font-weight: 500; background: var(--eh-bg-muted); padding: 1px 5px; border-radius: 4px; }
.history-event-card h4 { font-weight: 700; font-size: 14px; margin: 8px 0; }
.history-description { font-size: 13px; white-space: pre-wrap; color: var(--eh-text-secondary); }
.history-reference { font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.history-event-card footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--eh-text-secondary); margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--eh-border); }
.sale-history a { display: inline-flex; align-items: center; gap: 4px; color: var(--eh-link); font-weight: 600; }
.history-footnote { color: var(--eh-text-secondary); font-size: 11px; border-top: 1px solid var(--eh-border); padding: 16px 24px; }
.history-warning, .history-note { font-size: 13px; margin: 12px 24px; padding: 12px; border-radius: 6px; background: var(--eh-warning-bg); color: var(--eh-text); }
.history-empty { display: grid; justify-items: center; gap: 12px; text-align: center; padding: 40px 20px 12px; font-size: 13px; }
.history-linked { padding: 20px; }
.history-linked > div { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; margin-top: 16px; }
.history-linked article { border: 1px solid var(--eh-border); border-radius: 6px; padding: 16px; display: grid; gap: 6px; font-size: 13px; overflow-wrap: anywhere; }
.history-linked small { color: var(--eh-text-secondary); }
.sale-history :is(button,a,input,select):focus-visible { outline: 2px solid var(--eh-link); outline-offset: 3px; }
@media(max-width: 1000px) { .history-shortcuts { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media(max-width: 700px) {
  .history-context, .history-linked > div { grid-template-columns: minmax(0,1fr); }
  .history-heading { align-items: flex-start; flex-direction: column; padding: 16px; }
  .history-sources, .history-categories, .history-filters { padding: 12px 16px; }
  .history-filters label { width: 100%; flex: 1 1 100%; }
  .history-filters input, .history-filters select { font-size: 16px; }
  .history-footnote, .history-result { padding: 12px 16px; }
  .history-warning, .history-note { margin: 12px 16px; }
}
@media(max-width: 420px) { .history-shortcuts { grid-template-columns: minmax(0,1fr); } }
.history-heading-actions, .history-summary-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.history-summary-dialog { width: min(900px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); margin: auto; padding: 0; border: 1px solid #dce3ed; border-radius: 14px; color: #26354c; background: white; box-shadow: 0 20px 80px #17233d30; }
.history-summary-dialog::backdrop { background: #17233d80; }
.history-summary-dialog > header { display: flex; justify-content: space-between; align-items: start; gap: 12px; padding: 20px 24px; border-bottom: 1px solid #e0e6ee; }
.history-summary-dialog > header p { font-size: 12px; color: #526070; margin-top: 5px; }
.history-summary-actions { padding: 16px 24px 8px; }
.history-summary-actions > span { flex-basis: 100%; font-size: 12px; color: #526070; }
.history-summary-feedback { padding: 0 24px; font-size: 13px; }
.history-summary-dialog > textarea { display: block; width: calc(100% - 48px); margin: 12px 24px; border: 1px solid #aab6c6; padding: 12px; border-radius: 6px; font-size: 13px; }
.history-summary-content { padding: 16px 24px 24px; font-size: 13px; overflow-wrap: anywhere; }
.history-summary-scope { color: #526070; font-size: 12px; margin-bottom: 14px; }
.history-summary-content li { display: grid; grid-template-columns: 190px minmax(0,1fr); gap: 16px; padding: 12px 0; border-bottom: 1px solid #e0e6ee; break-inside: avoid; }
.history-summary-content time { font-size: 12px; font-variant-numeric: tabular-nums; color: #526070; }
.history-summary-content li p { margin: 4px 0; white-space: pre-wrap; }
.history-summary-content small { display: block; font-size: 11px; color: #526070; margin-top: 4px; }
.history-summary-content footer { margin-top: 16px; font-size: 11px; color: #526070; }
.history-summary-print-frame { position: absolute; width: 1px; height: 1px; border: 0; opacity: 0; pointer-events: none; }
@media(max-width: 600px) {
  .history-summary-content li { grid-template-columns: minmax(0,1fr); gap: 4px; }
  .history-summary-dialog > header, .history-summary-content { padding: 16px; }
  .history-summary-actions { padding: 12px 16px; }
}
/* Compact chronological layout keeps details expandable. */
.history-event-card h4 { margin: 4px 0; font-size: 13px; }
.history-event-card footer { margin-top: 6px; padding-top: 5px; }
.history-description { font-size: 12px; }
.history-description summary { cursor: pointer; white-space: normal; }
.history-description summary span { color: var(--eh-link); font-weight: 600; }
.history-result button { color: var(--eh-link); text-decoration: underline; }
.order-conversation-messages { display: grid; gap: 8px; }
.order-conversation-messages li { padding: 10px 12px; border-radius: 8px; background: #f1f5f9; max-width: 90%; overflow-wrap: anywhere; }
.order-conversation-messages li[data-direction=out] { background: #eaf7f1; margin-left: auto; }
.order-conversation-messages strong { display: block; font-size: 12px; }
.order-conversation-messages time { font-size: 11px; color: var(--eh-text-muted); }
.order-conversation-messages p { font-size: 13px; white-space: pre-wrap; margin-top: 4px; }
@media(max-width: 760px) {
}
.history-shortcuts[data-management=true] { grid-template-columns: repeat(5,minmax(0,1fr)); }
.history-months { padding: 20px; background: #f8fafc; }
.history-month { position: relative; padding-bottom: 16px; }
.history-month::before { content: ""; position: absolute; width: 2px; background: #dce3ed; top: 16px; bottom: 0; left: calc(50% - 1px); }
.history-month h3 { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 8px; width: fit-content; max-width: 100%; margin: 0 auto 16px; border: 1px solid #dce3ed; border-radius: 20px; padding: 6px 14px; font-size: 13px; font-weight: 700; text-transform: capitalize; background: #eaf0f7; color: #354762; box-shadow: 0 0 0 6px #f8fafc; }
.sale-history .history-event { position: relative; display: grid; grid-template-columns: minmax(0,1fr) 48px minmax(0,1fr); align-items: start; margin-bottom: 12px; }
.sale-history .history-marker { grid-column: 2; grid-row: 1; z-index: 1; margin: 14px auto 0; background: var(--event-soft); border: 2px solid white; outline: 1px solid #dce3ed; color: var(--event-color); border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; box-shadow: 0 0 0 4px #f8fafc; }
.sale-history .history-event-card { grid-column: 1; grid-row: 1; border: 1px solid #e0e6ee; border-left: 3px solid var(--event-color); border-radius: 8px; background: white; padding: 12px 14px; min-width: 0; overflow-wrap: anywhere; box-shadow: 0 3px 10px #17233d05; }
.sale-history .history-event[data-side=right] .history-event-card { grid-column: 3; }
.sale-history .history-event .history-date { display: block; margin-bottom: 8px; padding: 0; text-align: left; color: var(--eh-text-secondary); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow-wrap: normal; }
@media(max-width: 1100px) { .history-shortcuts[data-management=true] { grid-template-columns: repeat(3,minmax(0,1fr)); } }
@media(max-width: 760px) {
 .history-shortcuts[data-management=true] { grid-template-columns: repeat(2,minmax(0,1fr)); }
 .history-months { padding: 16px 12px; }
 .history-month::before { left: 13px; }
 .history-month h3 { margin-left: 40px; font-size: 12px; }
 .sale-history .history-event { grid-template-columns: 28px minmax(0,1fr); gap: 10px; }
 .sale-history .history-marker { grid-column: 1; }
 .sale-history .history-event .history-event-card, .sale-history .history-event[data-side=right] .history-event-card { grid-column: 2; grid-row: 1; padding: 12px; }
}
@media(max-width: 420px) { .history-shortcuts[data-management=true] { grid-template-columns: minmax(0,1fr); } }

/* Orders: compact rows, explicit cancellation, stable identifiers. */
.sale-header-actions, .sale-freight-actions { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
.sale-header-actions { justify-content:flex-end; }
article[aria-label="Pedido de venda"] > .view-tabs { flex-wrap:nowrap; gap:4px; overflow-x:auto; min-width:0; }
article[aria-label="Pedido de venda"] > .view-tabs > button { flex:none; padding:10px; font-size:12px; white-space:nowrap; }
.sale-cancel-action { display:flex; flex-direction:column; align-items:flex-start; gap:4px; max-width:300px; }
.sale-cancel-action small { font-size:11px; color:var(--eh-text-secondary); }
.sale-header-actions .sale-cancel-button { color:var(--eh-error); border-color:var(--eh-error); }
.sale-header-actions .sale-cancel-button:hover:not(:disabled) { background:var(--eh-error-bg); }
.sale-freight-actions { padding:12px 16px; background:white; border:1px solid var(--eh-border); border-radius:8px; }
.sale-freight-actions > button { margin-right:auto; }
.sale-freight-action { min-width:0; }
.sale-freight-action > p { max-width:420px; font-size:12px; }
.return-pendency-row { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:16px; align-items:start; }
.return-pendency-info { min-width:0; }
.return-pendency-actions { display:flex; flex-direction:column; align-items:flex-end; gap:8px; }
@media(max-width:600px) {
 .sale-header-actions { justify-content:flex-start; }
 .sale-freight-actions { padding:12px; }
 .return-pendency-row { grid-template-columns:minmax(0,1fr); gap:12px; }
 .return-pendency-actions { align-items:flex-start; }
}

.auto-billing-period { padding:12px 16px; border:1px solid var(--eh-border); background:white; border-radius:8px; font-size:13px; color:var(--eh-text-secondary); }
.auto-billing-settings > summary { cursor:pointer; padding:12px 0; font-size:13px; font-weight:600; color:var(--eh-link); }