/* TEAR interface refinement: same identity, clearer hierarchy. */
.attachment-preview-trigger { padding: 0; cursor: zoom-in; flex-shrink: 0; }
.attachment-preview-trigger:hover { outline: 2px solid var(--tear-red); outline-offset: 2px; }
.attachment-preview-dialog { width: min(1100px, calc(100vw - 24px)); max-width: none; height: min(850px, 90vh); height: min(850px, 90dvh); max-height: 94vh; padding: 0; border: 1px solid #e2e8f0; border-radius: 16px; background: #fff; color: #0f172a; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.attachment-preview-dialog[open] { display: flex; flex-direction: column; }
.attachment-preview-dialog::backdrop { background: rgba(15,23,42,.72); }
.attachment-preview-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid #e2e8f0; }
.attachment-preview-header > div { min-width: 0; }
.attachment-preview-header h2 { margin: 0; font-size: 18px; }
.attachment-preview-name { margin: 5px 0 0; font-size: 13px; color: #475569; overflow-wrap: anywhere; }
.attachment-preview-header button { flex-shrink: 0; min-height: 44px; }
.attachment-preview-canvas { flex: 1; min-height: 0; padding: 12px; background: #f1f5f9; }
.attachment-preview-canvas img { width: 100%; height: 100%; object-fit: contain; display: block; }
.attachment-preview-canvas img[hidden] { display: none; }
.attachment-preview-feedback { margin: 0; padding: 12px 16px; font-size: 12px; color: #475569; }
:root { --shadow: 0 6px 22px rgba(15,23,42,.12); }
.login-shell::before { width: min(540px, 100%); }
body:not([data-page="login"]) .card { background: #fff; backdrop-filter: none; }
.topbar { border-top: 3px solid var(--tear-red); box-shadow: 0 4px 18px rgba(0,0,0,.14); }
.home-hero h1 { font-size: clamp(20px, 2.1vw, 28px); }
.brand-logo { height: 62px; }
.panel-title { line-height: 1.4; }
.field-help, .action-hint { color: #475569; font-size: 13px; line-height: 1.6; margin: 8px 0 14px; }
.required-label { font-size: 12px; color: #9f1239; font-weight: 600; }
.field-validation { color: #a30f1b; font-size: 13px; margin: 6px 0; }
[aria-invalid="true"] { border-color: #b91c1c !important; }
button:focus-visible, a:focus-visible, summary:focus-visible, tr[tabindex]:focus-visible { outline: 3px solid #a30f1b; outline-offset: 3px; }
.tab-bar { gap: 6px; border-bottom: 1px solid #e5e7eb; padding-bottom: 12px; }
button.tab { font: inherit; font-size: 14px; font-weight: 600; min-height: 44px; text-align: left; }
.tab[data-profile-disabled="1"] { display: none; }
.tab.active { box-shadow: none; background: #fff1f2; border-color: var(--tear-red); }
.sac-summary { background: #f8fafc; border: 1px solid #e2e8f0; border-left: 4px solid var(--tear-red); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; }
.sac-summary dl { display: grid; grid-template-columns: minmax(90px,.7fr) minmax(180px,2fr) minmax(110px,1fr) minmax(110px,1fr); gap: 12px; margin: 0; }
.sac-summary dt { font-size: 12px; color: #475569; margin-bottom: 4px; }
.sac-summary dd { margin: 0; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.sac-step-status { margin: 10px 0 0; font-size: 13px; font-weight: 600; color: #8a0f1b; }
body[data-page="sac_novo"] .tab-panel:not(#tab-identificacao) > .panel-title:first-child,
body[data-page="sac_novo"] .tab-panel:not(#tab-identificacao) > .panel-title:first-child + .grid-6 { display: none; }
.sac-form-actions { border-top: 1px solid #e5e7eb; padding-top: 14px; }
.sac-form-actions .btn-cancel { background: #f8fafc; color: #334155; border: 1px solid #cbd5e1; box-shadow: none; }
#tab-identificacao > .grid-5 { grid-template-columns: repeat(3,minmax(0,1fr)); }
#tab-identificacao > .grid-5 > div:nth-child(-n+2) { display: none; }
.nf-details { border: 1px solid #e2e8f0; border-radius: 10px; padding: 12px; }
.nf-details summary { cursor: pointer; color: #334155; font-size: 14px; font-weight: 600; min-height: 24px; }
.nf-details[open] summary { margin-bottom: 14px; }
.nf-details > h4 { color: #334155; font-size: 14px; font-weight: 600; margin: 0 0 14px; }
#tab-identificacao .table-panel.compact .table-scroll { min-height: 80px; height: auto; max-height: 380px; }
#tab-identificacao .table-panel.compact { min-height: 0; }
#tab-identificacao .table-panel.compact td { font-size: 12px; padding: 9px; }
#tab-identificacao .table-panel.compact th { font-size: 11px; padding: 9px; }
body[data-page="sac_novo"] .items-grid { grid-template-columns: minmax(0,1fr); }
body[data-page="sac_novo"] .items-panel-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.items-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.items-actions .btn { min-height: 42px; padding: 9px 14px; font-size: 13px; }
.items-remove-actions { margin: 0; }
.items-remove-actions .btn { min-height: 36px; padding: 6px 10px; font-size: 12px; box-shadow: none; }
.items-actions .btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
.items-empty td { grid-column: 1 / -1; text-align: center; color: #64748b; padding: 20px 12px; white-space: normal; }
.items-action-status { color: #166534; font-size: 13px; margin: 8px 0; }
.items-action-status:empty { display: none; }
#tab-identificacao .items-grid .table-panel { border-color: #dce2ea; border-radius: 12px; }
#tab-identificacao .items-grid .items-panel-header { min-height: 48px; padding: 10px 14px; border-bottom: 1px solid #e2e8f0; background: #f8fafc; }
#tab-identificacao .items-grid .table-scroll { padding: 4px 8px 8px; }
#tab-identificacao .items-grid table { border-collapse: separate; border-spacing: 0; }
#tab-identificacao .items-grid tbody tr:last-child td { border-bottom: 0; }
#itens-nf-body tr[data-index]:not(.selected):not(.is-blocked):hover,
#itens-defeito-body tr[data-index]:not(.selected):hover { background: #f1f5f9; }
#itens-nf-body tr.selected, #itens-defeito-body tr.selected { outline: none; background: #eaf3ff; }
#itens-nf-body tr.selected td:first-child, #itens-defeito-body tr.selected td:first-child { box-shadow: inset 3px 0 0 #2563eb; font-weight: 700; }
#itens-nf-body tr:focus-visible, #itens-defeito-body tr:focus-visible { outline: 2px solid #2563eb; outline-offset: -2px; }
#tab-identificacao .defeito-input { min-height: 36px; border: 1px solid #d4dce6; border-radius: 8px; background: #fff; font-size: 12px; }
#tab-identificacao .defeito-input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
#tab-identificacao .defeito-input[aria-invalid="true"]:focus { border-color: #b91c1c; box-shadow: 0 0 0 3px rgba(185,28,28,.12); }
@media (max-width: 720px) {
  #itens-nf-body tr.selected, #itens-defeito-body tr.selected { box-shadow: inset 3px 0 0 #2563eb; }
  #itens-nf-body tr.selected td:first-child, #itens-defeito-body tr.selected td:first-child { box-shadow: none; }
}
@media (min-width: 721px) {
  #tab-identificacao .items-grid .defeitos-table { table-layout: fixed; }
  .def-col-item { width: 11%; }
  .def-col-reference { width: 14%; }
  .def-col-lot { width: 9%; }
  .def-col-quantity { width: 12%; }
  .def-col-total { width: 14%; }
  .def-col-defect { width: 16%; }
  .def-col-units { width: 12%; }
  #tab-identificacao .defeitos-table th:nth-child(-n+3),
  #tab-identificacao .defeitos-table td:nth-child(-n+3) { text-align: center; }
  #tab-identificacao .defeitos-table th:nth-child(n+6) { text-align: center; white-space: normal; }
  #tab-identificacao .defeitos-table td { vertical-align: middle; font-variant-numeric: tabular-nums; }
}
body[data-page="sac_novo"] .items-grid > .panel-actions { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; }
body[data-page="sac_novo"] .items-grid > .panel-actions button { width: auto; height: auto; min-height: 42px; padding: 9px 14px; font-size: 13px; border-radius: 8px; }
.advanced-filters { margin-top: 16px; border-top: 1px solid #e2e8f0; padding-top: 12px; }
.advanced-filters summary, .secondary-actions summary { cursor: pointer; padding: 10px 8px; font-weight: 600; color: #8a0f1b; min-height: 44px; }
.advanced-filters[open] > .sac-filter-grid { margin-top: 12px; }
.sac-consultar .sac-filter-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px 24px; }
.sac-filter-area { grid-template-columns: minmax(0,1fr); gap: 20px; }
.sac-consultar .sac-filter-main { gap: 12px; }
.sac-consultar .sac-filter-main > .field-help { margin: 0 0 4px; }
.sac-consultar .sac-filter-side { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; margin-top: 0; padding-left: 0; grid-auto-rows: auto; align-items: stretch; }
.sac-consultar .sac-filter-side .selection-box { padding: 14px; height: 100%; }
.sac-consultar .sac-filter-side .selection-title { font-size: 13px; margin-bottom: 12px; white-space: nowrap; overflow-wrap: normal; word-break: normal; }
.sac-consultar .sac-filter-side .selection-options { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
.sac-consultar .sac-filter-side .selection-option { width: auto; flex: 0 0 auto; display: inline-flex; flex-wrap: nowrap; font-size: 12px; min-height: 40px; padding: 9px 12px; gap: 8px; white-space: nowrap; overflow-wrap: normal; }
.sac-consultar .sac-filter-side .selection-option span { white-space: nowrap; overflow-wrap: normal; word-break: normal; }
.sac-consultar .sac-filter-side .selection-option input { flex-shrink: 0; }
.sac-table-panel.compact th, .sac-table-panel.compact td { font-size: 12px; }
.sac-consultar .range-inline { grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); }
.sac-consultar .range-cell .input { min-height: 42px; font-size: 14px; }
.sac-consultar .range-label { font-size: 11px; }
.sac-results { display: block; }
.sac-legend { align-items: center; flex-direction: row; gap: 12px 20px; padding: 12px 16px; border: 1px solid #e2e8f0; border-radius: 12px; background: #f8fafc; }
.sac-legend .legend-title { flex: 0 0 auto; width: auto; padding: 0; color: #475569; font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.sac-legend .legend-items { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; overflow: visible; min-width: 0; }
.sac-legend .legend-item { gap: 7px; padding: 7px 11px; border: 1px solid; border-radius: 8px; font-size: 12px; font-weight: 600; letter-spacing: 0; line-height: 1.4; white-space: nowrap; }
.sac-legend .legend-item svg { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sac-legend .status-aberta { background: #fff1f2; border-color: #fecdd3; color: #9f1239; }
.sac-legend .status-parecer { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.sac-legend .status-concluida { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.sac-action-bar { display: flex !important; flex-wrap: wrap; justify-content: center; gap: 8px; align-items: stretch; margin-top: 14px; padding: 12px; border: 1px solid #e2e8f0; border-radius: 14px; background: #f8fafc; }
.sac-actions-heading { flex: 0 0 100%; margin-bottom: 4px; }
.sac-actions-heading h3 { margin: 0 0 5px; font-size: 16px; color: #0f172a; }
.sac-actions-heading p { margin: 0; font-size: 12px; line-height: 1.5; color: #475569; }
.sac-action-bar .action-btn { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px; flex: 0 0 112px; width: 112px; min-width: 0; height: auto; min-height: 60px; padding: 8px 6px; margin: 0; border: 1px solid #dbe1e8; border-radius: 10px; background: #fff; color: #334155; text-decoration: none; box-shadow: 0 2px 4px rgba(15,23,42,.03); }
.sac-action-bar .action-btn svg, .sac-action-bar .action-btn svg[class] { width: 22px; height: 22px; margin: 0; padding: 0; flex-shrink: 0; color: inherit; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sac-action-bar .action-btn::after { display: none; }
.sac-action-bar .action-btn:hover, .sac-action-bar .action-btn:focus-visible { z-index: 121; }
.sac-action-bar .action-btn .action-tooltip { left: 50%; right: auto; top: calc(100% + 10px); bottom: auto; transform: translateX(-50%) translateY(-4px); }
.sac-action-bar .action-btn:hover .action-tooltip, .sac-action-bar .action-btn:focus-visible .action-tooltip { transform: translateX(-50%) translateY(0); }
.sac-action-bar .action-btn .action-tooltip::after { left: 50%; right: auto; top: -6px; border-top: 1px solid rgba(193,18,31,.25); border-left: 1px solid rgba(193,18,31,.25); border-right: none; border-bottom: none; transform: translateX(-50%) rotate(45deg); }
.sac-action-bar .action-btn:hover { background: #fff1f2; border-color: #c1121f; color: #8a0f1b; box-shadow: 0 3px 10px rgba(15,23,42,.08); transform: translateY(-1px); }
.sac-action-bar .action-new { background: #c1121f; color: #fff; border-color: #c1121f; }
.sac-action-bar .action-new:hover { background: #8a0f1b; color: #fff; }
.sac-action-bar .action-delete { color: #a30f1b; border-color: #fecdd3; }
.sac-action-bar .action-btn:disabled, .sac-action-bar .action-btn.disabled, .sac-action-bar .action-btn.rule-disabled, .sac-action-bar .action-btn[aria-disabled="true"] { background: #f1f5f9; color: #64748b; border-color: #e2e8f0; box-shadow: none; transform: none; cursor: not-allowed; }
.sac-action-bar .action-btn[data-badge]::before, .mobile-action-grid .action-btn[data-badge]::before { display: none; }
.sac-action-bar .action-label { display: block; font-size: 12px; font-weight: 600; line-height: 1.3; white-space: nowrap; text-decoration: none; }
.mobile-action-grid .action-label { display: block; font-size: 12px; white-space: normal; }
body[data-page="consultar"] .mobile-action-collapse { display: none !important; }
.table-scroll { scrollbar-width: thin; }
.settings-sidebar-tab { opacity: 1 !important; pointer-events: auto !important; transform: translateY(-50%) !important; }
@media (max-width: 1100px) {
  .sac-filter-area { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 720px) {
  .sac-summary dl { grid-template-columns: repeat(2,minmax(0,1fr)); }
  #tab-identificacao > .grid-5 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  #tab-identificacao > .grid-5 > div:nth-child(3) { grid-column: 1 / -1; }
  #tab-identificacao .table-panel.compact .table-scroll { max-height: none; }
  .sac-consultar .sac-filter-grid { grid-template-columns: minmax(0,1fr); }
  .sac-consultar .sac-filter-side { grid-template-columns: minmax(0,1fr); }
  .sac-consultar .range-inline { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .sac-consultar .range-sep { display: none; }
  .sac-consultar .range-field:has(input[type="date"]) .range-inline { grid-template-columns: minmax(0,1fr); }
  .sac-pagination .page-actions { flex-wrap: wrap; justify-content: center; }
  .sac-table-panel { min-height: 120px; }
  .sac-table { display: block; }
  .sac-table tbody tr:not([data-sac-number]), .sac-table tbody tr:not([data-sac-number]) td { display: block; width: 100%; white-space: normal; }
  .sac-empty-state { width: 100%; }
  .page-wrapper { padding: 14px 10px 30px; }
  body[data-page="consultar"] .page-wrapper { padding-bottom: 30px; }
  .sac-action-bar { padding: 10px; gap: 8px; }
  .card { padding: 14px; }
  .input, select, textarea, .sac-consultar .range-cell .input { font-size: 16px; }
  #tab-identificacao .table-panel.compact .table-scroll .nf-table,
  #tab-identificacao .table-panel.compact .table-scroll .defeitos-table,
  .sac-table { min-width: 0; width: 100%; table-layout: auto; }
  .nf-table thead, .defeitos-table thead, .sac-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .nf-table tbody, .defeitos-table tbody, .sac-table tbody { display: block; }
  .nf-table tbody tr, .defeitos-table tbody tr, .sac-table tbody tr[data-sac-number] { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); margin: 10px 0; border: 1px solid #cbd5e1; border-radius: 10px; overflow: hidden; }
  .nf-table tbody td, .defeitos-table tbody td, .sac-table tbody tr[data-sac-number] td { display: block; width: auto; min-width: 0; white-space: normal; text-align: left !important; padding: 9px !important; overflow-wrap: anywhere; }
  td[data-label]::before { content: attr(data-label); display: block; color: #475569; font-weight: 600; font-size: 11px; margin-bottom: 4px; }
  .defeitos-table .defeito-input { width: 100%; min-width: 0; min-height: 44px; font-size: 16px; }
  .nf-table tr.selected, .defeitos-table tr.selected, .sac-table tr.selected { outline: 2px solid var(--tear-red); outline-offset: -2px; }
  body[data-page="sac_novo"] .items-grid > .panel-actions button { flex: 1 1 42%; }
  .sac-form-actions { gap: 10px; }
  .sac-form-actions .btn { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Page-level navigation remains independent of the selected SAC. */
body[data-page="consultar"] .topbar > .actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.sac-indicators { display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.sac-indicators svg { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sac-indicators:disabled { color: #64748b; background: #f1f5f9; border-color: #e2e8f0; cursor: not-allowed; box-shadow: none; }
.sac-floating-header {
  position: fixed; z-index: 40; overflow: hidden; pointer-events: none;
  background: #f8fafc; box-shadow: 0 2px 5px rgba(15,23,42,.12);
}
.sac-floating-header .sac-floating-table {
  table-layout: fixed; min-width: 0; margin: 0; border-collapse: collapse;
}
.sac-floating-header th { position: static; box-sizing: border-box; }
@media print { .sac-floating-header { display: none !important; } }

/* Individual dashboard tiles in the Indicators button. */
.sac-indicators svg rect:nth-child(1) { fill: #2563eb; stroke: #2563eb; }
.sac-indicators svg rect:nth-child(2) { fill: #d97706; stroke: #d97706; }
.sac-indicators svg rect:nth-child(3) { fill: #059669; stroke: #059669; }
.sac-indicators svg rect:nth-child(4) { fill: #7c3aed; stroke: #7c3aed; }
.sac-indicators:disabled svg { opacity: .45; }
