/* Componentes. Cada bloco corresponde a um ficheiro em web/js/ui/. */

/* ---------- Botões (ui/button.js) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--c-border-strong); border-radius: var(--r-sm); background: var(--c-surface); color: var(--c-text);
  font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; text-decoration: none; transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--c-hover); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); border-color: var(--c-primary); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn.primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.btn.danger { color: var(--t-red-fg); border-color: #f0cdc8; }
.btn.danger:hover { background: var(--t-red-bg); }
.btn.danger-solid { background: var(--s-critical); border-color: var(--s-critical); color: #fff; }
.btn.danger-solid:hover { background: #bd3e30; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--c-text-2); }
.btn.ghost:hover { background: #f0f0f4; color: var(--c-text); }
.btn.soft { background: var(--c-primary-soft); border-color: var(--c-primary-line); color: #4f74cf; }
.btn.soft:hover { background: #e9effd; }
.btn.link { border: 0; background: none; height: auto; padding: 0; color: var(--c-primary); }
.btn.link:hover { text-decoration: underline; background: none; }
.btn.sm { height: 27px; padding: 0 9px; font-size: var(--fs-xs); }
.btn.sm svg { width: 13px; height: 13px; }
.btn.lg { height: 38px; padding: 0 16px; font-size: var(--fs-md); }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled=true] { opacity: .45; pointer-events: none; }
.btn.loading { pointer-events: none; }
.btn.loading > svg:first-child { animation: spin .8s linear infinite; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: var(--r-sm); color: var(--c-muted); flex-shrink: 0;
}
.icon-btn:hover { background: #f0f0f4; color: var(--c-text-2); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.sm { width: 24px; height: 24px; } .icon-btn.sm svg { width: 14px; height: 14px; }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Etiquetas (ui/badge.js) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 21px; padding: 0 7px; border-radius: var(--r-xs);
  font-size: var(--fs-xs); font-weight: 500; line-height: 1; white-space: nowrap; background: var(--t-neutral-bg); color: var(--t-neutral-fg);
  vertical-align: middle;
}
.badge svg { width: 12px; height: 12px; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.neutral { background: var(--t-neutral-bg); color: var(--t-neutral-fg); }
.badge.blue { background: var(--t-blue-bg); color: var(--t-blue-fg); }
.badge.green { background: var(--t-green-bg); color: var(--t-green-fg); }
.badge.yellow { background: var(--t-yellow-bg); color: var(--t-yellow-fg); }
.badge.orange { background: var(--t-orange-bg); color: var(--t-orange-fg); }
.badge.red { background: var(--t-red-bg); color: var(--t-red-fg); }
.badge.purple { background: var(--t-purple-bg); color: var(--t-purple-fg); }
.badge.pink { background: var(--t-pink-bg); color: var(--t-pink-fg); }
.badge.critical { background: var(--t-red-bg); color: #b23d30; font-weight: 600; box-shadow: inset 0 0 0 1px #f3c4bd; }
.badge.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--c-border-strong); color: var(--c-muted); }
.badge.lg { height: 24px; padding: 0 9px; font-size: var(--fs-sm); }

/* ---------- Cartões e painéis ---------- */
.card { background: var(--c-surface); border: 1px solid #e3e3e9; border-radius: var(--r-md); min-width: 0; }
.card-pad { padding: var(--sp-5); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--c-border-soft); min-height: 52px; }
.card-head h2, .card-head h3 { font-size: var(--fs-md); font-weight: 600; margin: 0; }
.card-head .sub { color: var(--c-muted); font-size: var(--fs-sm); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-foot { padding: 10px 18px; border-top: 1px solid var(--c-border-soft); color: var(--c-muted); font-size: var(--fs-sm); display: flex; align-items: center; gap: 10px; }
.card.clickable { cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.card.clickable:hover { border-color: #cfd6ea; box-shadow: var(--sh-1); }
.section { margin-bottom: var(--sp-6); }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.section-head h2 { font-size: var(--fs-md); font-weight: 600; }
.section-head .sub { color: var(--c-muted); font-size: var(--fs-sm); }
.section-head .spacer { flex: 1; }

/* Avisos dentro da página */
.callout { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.55; border: 1px solid; }
.callout > svg { width: 16px; height: 16px; margin-top: 1px; }
.callout strong { font-weight: 600; }
.callout .grow { flex: 1; min-width: 0; }
.callout.info { background: var(--c-primary-soft); border-color: var(--c-primary-line); color: #4767b8; }
.callout.warn { background: #fff8ec; border-color: #f3e0bf; color: #8a6424; }
.callout.bad { background: #fdf1ef; border-color: #f4d0ca; color: #a8473b; }
.callout.ok { background: #eff8f3; border-color: #cfe8db; color: #3f7f5f; }

/* ---------- KPI (ui/kpi.js) ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 16px 18px 14px; min-height: 108px;
  background: var(--c-surface); border: 1px solid #e3e3e9; border-radius: var(--r-md); color: inherit; text-decoration: none; min-width: 0;
}
a.kpi:hover, .kpi.clickable:hover { border-color: #cfd6ea; box-shadow: var(--sh-1); text-decoration: none; }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--c-muted); }
.kpi-label svg { width: 14px; height: 14px; }
.kpi-value { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -.3px; line-height: 1.15; font-variant-numeric: tabular-nums; color: var(--c-text); }
.kpi-value small { font-size: var(--fs-md); font-weight: 500; color: var(--c-muted); margin-left: 3px; letter-spacing: 0; }
.kpi-foot { display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--c-muted); margin-top: auto; min-height: 18px; }
.kpi-delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi-delta svg { width: 12px; height: 12px; }
.kpi-delta.good { color: var(--t-green-fg); } .kpi-delta.bad { color: var(--t-red-fg); } .kpi-delta.flat { color: var(--c-muted); }
.kpi::before { content: ''; position: absolute; left: -1px; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: transparent; }
.kpi.tone-ok::before { background: var(--s-ok); }
.kpi.tone-warn::before { background: var(--s-warn); }
.kpi.tone-bad::before { background: var(--s-bad); }
.kpi-side { position: absolute; right: 14px; top: 14px; }
.kpi-skel .kpi-value { width: 60%; }

/* ---------- Tabela (ui/table.js) ---------- */
.table-wrap { overflow: auto; min-height: 0; background: var(--c-surface); scrollbar-width: thin; scrollbar-color: #dbdbe0 transparent; }
.card > .table-wrap { border-radius: 0 0 var(--r-md) var(--r-md); }
.card > .table-wrap:first-child { border-radius: var(--r-md); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
.table th {
  position: sticky; top: 0; z-index: 1; text-align: left; background: var(--c-surface-3); color: #8e8e9a; font-size: var(--fs-sm); font-weight: 500;
  padding: 10px 14px; border-bottom: 1px solid var(--c-border); white-space: nowrap; user-select: none;
}
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.center, .table td.center { text-align: center; }
.table th button.th-sort { display: inline-flex; align-items: center; gap: 4px; color: inherit; font-weight: inherit; border-radius: 3px; }
.table th button.th-sort:hover { color: var(--c-text); }
.table th button.th-sort svg { width: 12px; height: 12px; opacity: .35; }
.table th[aria-sort=ascending] button.th-sort svg, .table th[aria-sort=descending] button.th-sort svg { opacity: 1; color: var(--c-primary); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--c-border-soft); color: var(--c-text-2); vertical-align: middle; }
.table td.strong, .table td .strong { color: var(--c-text); font-weight: 500; }
.table td .sub { display: block; color: var(--c-muted); font-size: var(--fs-xs); margin-top: 1px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fbfbfd; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:focus-visible { outline: none; }
.table tbody tr.clickable:focus-visible td { background: var(--c-primary-soft); }
.table tbody tr.selected td { background: #f5f8ff; }
.table tbody tr.active td { background: #eef3fe; }
.table .col-check { width: 40px; padding-right: 0; }
.table.dense td { padding: 8px 12px; } .table.dense th { padding: 8px 12px; }
.table .cell-ellipsis { max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table-empty td:hover, .table-empty td { background: var(--c-surface) !important; }
.table-bulk { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--c-primary-soft); border-bottom: 1px solid var(--c-primary-line); font-size: var(--fs-sm); color: #4767b8; }

/* ---------- Paginação (ui/pagination.js) ---------- */
.pagination { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--c-muted); }
.pagination .info { margin-right: 6px; font-variant-numeric: tabular-nums; }

/* ---------- Campos (ui/form.js, ui/search.js) ---------- */
.input {
  height: 34px; width: 100%; padding: 0 10px; border: 1px solid var(--c-border-strong); border-radius: var(--r-sm);
  background: var(--c-surface); font-size: var(--fs-md); color: var(--c-text); min-width: 0; transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; padding: 9px 10px; line-height: 1.55; resize: vertical; min-height: 80px; }
.input::placeholder { color: #b0b0b8; }
.input:hover { border-color: #cfcfd8; }
.input:focus { border-color: var(--c-primary); box-shadow: var(--focus); outline: none; }
.input:disabled { background: #f6f6f8; color: var(--c-muted); }
.input.invalid { border-color: var(--s-bad); }
.input-group { display: flex; align-items: center; position: relative; }
.input-group .input { padding-right: 52px; }
.input-reveal {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); height: 26px; padding: 0 8px; border-radius: var(--r-sm);
  font-size: var(--fs-xs); font-weight: 500; color: var(--c-text-2);
}
.input-reveal:hover { background: #f0f0f4; color: var(--c-text); }
.input-unit { position: absolute; right: 10px; color: var(--c-muted); font-size: var(--fs-sm); pointer-events: none; }
.input.num { width: 120px; text-align: right; font-variant-numeric: tabular-nums; padding-right: 50px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field { margin-top: 14px; }
.field-label { font-size: var(--fs-sm); font-weight: 500; color: var(--c-text); }
.field-label .opt { color: var(--c-muted); font-weight: 400; }
.field-hint { font-size: var(--fs-xs); color: var(--c-muted); line-height: 1.5; }
.field-error { font-size: var(--fs-xs); color: var(--t-red-fg); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .field + .field { margin-top: 0; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { padding-top: 18px; margin-top: 18px; border-top: 1px solid var(--c-border-soft); }
.form-section > h3 { margin-bottom: 4px; }
.form-section > p { color: var(--c-muted); font-size: var(--fs-sm); margin-bottom: 14px; }

.search { position: relative; display: flex; align-items: center; min-width: 0; }
.search > svg { position: absolute; left: 10px; width: 14px; height: 14px; color: #a8a8b0; pointer-events: none; }
.search .input { padding-left: 31px; padding-right: 30px; background: #fbfbfc; border-color: #e7e7ec; }
.search .input:focus { background: #fff; }
.search .search-clear { position: absolute; right: 4px; }

.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--fs-md); color: var(--c-text); text-align: left; }
.toggle-track { position: relative; width: 34px; height: 20px; border-radius: 10px; background: #d5d5dd; transition: background .15s; flex-shrink: 0; }
.toggle-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s var(--ease); }
.toggle[aria-checked=true] .toggle-track { background: var(--c-primary); }
.toggle[aria-checked=true] .toggle-track::after { transform: translateX(14px); }
.toggle:disabled { opacity: .5; cursor: default; }
.toggle:focus-visible { outline: none; } .toggle:focus-visible .toggle-track { box-shadow: var(--focus); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-md); }

/* Linha de definição: rótulo e descrição à esquerda, controlo à direita */
.setting-row { display: flex; align-items: center; gap: 24px; padding: 16px 20px; border-bottom: 1px solid var(--c-border-soft); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .setting-text { flex: 1; min-width: 0; }
.setting-row .setting-title { font-weight: 500; color: var(--c-text); }
.setting-row .setting-desc { color: var(--c-muted); font-size: var(--fs-sm); margin-top: 2px; line-height: 1.5; }
.setting-row .setting-default { color: var(--c-faint); font-size: var(--fs-xs); margin-top: 4px; }
.setting-row .setting-control { flex-shrink: 0; display: flex; align-items: center; gap: 10px; }

/* ---------- Dropdown, menus e popovers (ui/dropdown.js, ui/menu.js, ui/popover.js) ---------- */
.dd-trigger {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 10px; max-width: 280px;
  border: 1px solid var(--c-border-strong); border-radius: var(--r-sm); background: var(--c-surface); font-size: var(--fs-sm); color: var(--c-text);
}
.dd-trigger:hover { background: var(--c-hover); }
.dd-trigger:focus-visible { outline: none; box-shadow: var(--focus); border-color: var(--c-primary); }
.dd-trigger[aria-expanded=true] { border-color: var(--c-primary); box-shadow: var(--focus); }
.dd-trigger .dd-prefix { color: var(--c-muted); }
.dd-trigger .dd-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.dd-trigger .dd-value.placeholder { color: #a8a8b0; font-weight: 400; }
.dd-trigger > svg { width: 14px; height: 14px; color: var(--c-muted); }
.dd-trigger > svg.dd-chev { margin-left: auto; }
.dd-trigger.block { width: 100%; max-width: none; height: 34px; }
.dd-trigger.ghost { border-color: transparent; background: transparent; }
.dd-trigger.ghost:hover { background: #f0f0f4; }
.dd-trigger:disabled { opacity: .5; pointer-events: none; }

.popover {
  position: fixed; z-index: var(--z-pop); background: var(--c-surface); border: 1px solid #dbdeeb; border-radius: var(--r-md);
  box-shadow: var(--sh-pop); min-width: 180px; max-width: 360px; overflow: hidden; display: flex; flex-direction: column;
  animation: pop-in .12s var(--ease);
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-3px); } }
.popover-search { padding: 8px; border-bottom: 1px solid var(--c-border-soft); }
.popover-search .input { height: 30px; font-size: var(--fs-sm); }
.popover-list { overflow: auto; max-height: 320px; padding: 4px; scrollbar-width: thin; }
.popover-item {
  display: flex; align-items: center; gap: 9px; width: 100%; min-height: 32px; padding: 6px 10px; border-radius: var(--r-sm);
  font-size: var(--fs-md); color: var(--c-text); text-align: left; cursor: pointer;
}
.popover-item svg { width: 15px; height: 15px; color: var(--c-muted); }
.popover-item .pi-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.popover-item .pi-hint { color: var(--c-muted); font-size: var(--fs-xs); }
.popover-item .pi-check { color: var(--c-primary); }
.popover-item.focused, .popover-item:hover { background: #f3f4f8; }
.popover-item[aria-selected=true] { font-weight: 500; }
.popover-item.danger { color: var(--t-red-fg); } .popover-item.danger svg { color: var(--t-red-fg); }
.popover-item[aria-disabled=true] { opacity: .45; pointer-events: none; }
.popover-sep { height: 1px; background: var(--c-border-soft); margin: 4px 0; }
.popover-group { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--c-faint); padding: 8px 10px 4px; }
.popover-head { padding: 8px 10px 8px; margin-bottom: 2px; border-bottom: 1px solid var(--c-border-soft); }
.popover-head .ph-title { font-size: var(--fs-md); font-weight: 600; color: var(--c-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.popover-head .ph-sub { font-size: var(--fs-xs); color: var(--c-muted); margin-top: 2px; }
.popover-empty { padding: 12px; color: var(--c-muted); font-size: var(--fs-sm); text-align: center; }

/* ---------- Separadores e controlo segmentado (ui/tabs.js) ---------- */
.tabs { display: flex; align-items: flex-end; gap: 22px; border-bottom: 1px solid var(--c-border); overflow-x: auto; scrollbar-width: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 1px; margin-bottom: -1px; border-bottom: 2px solid transparent;
  font-size: var(--fs-md); color: var(--c-muted); white-space: nowrap;
}
.tab:hover { color: var(--c-text); }
.tab[aria-selected=true] { color: var(--c-text); border-bottom-color: var(--c-primary); font-weight: 500; }
.tab svg { width: 15px; height: 15px; }
.tab .tab-count { font-size: var(--fs-xs); background: var(--t-neutral-bg); color: var(--t-neutral-fg); border-radius: 8px; padding: 1px 7px; font-weight: 500; }
.tab[aria-selected=true] .tab-count { background: var(--t-blue-bg); color: var(--t-blue-fg); }
.tabs.sm .tab { height: 34px; font-size: var(--fs-sm); }

.segmented { display: inline-flex; padding: 2px; gap: 2px; background: #f0f0f4; border-radius: 6px; }
.segmented button { height: 28px; padding: 0 11px; border-radius: 4px; font-size: var(--fs-sm); color: var(--c-text-2); white-space: nowrap; }
.segmented button:hover { color: var(--c-text); }
.segmented button[aria-checked=true] { background: var(--c-surface); color: var(--c-text); font-weight: 500; box-shadow: 0 1px 2px rgba(30,30,50,.12); }
.segmented button:focus-visible { outline-offset: 0; }
.segmented.sm button { height: 24px; padding: 0 8px; font-size: var(--fs-xs); }

/* ---------- Modal e gaveta (ui/overlay.js) ---------- */
.overlay-scrim { position: fixed; inset: 0; z-index: var(--z-modal); background: rgba(22, 22, 30, .38); animation: fade-in .15s var(--ease); }
@keyframes fade-in { from { opacity: 0; } }
.modal {
  position: fixed; z-index: var(--z-modal); left: 50%; top: 12vh; transform: translateX(-50%); width: min(520px, calc(100vw - 32px));
  max-height: 76vh; display: flex; flex-direction: column; background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--sh-modal);
  animation: modal-in .18s var(--ease);
}
.modal.sm { width: min(420px, calc(100vw - 32px)); }
.modal.lg { width: min(760px, calc(100vw - 32px)); }
@keyframes modal-in { from { opacity: 0; transform: translate(-50%, 8px); } }
.overlay-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 14px 22px; border-bottom: 1px solid var(--c-border-soft); }
.overlay-head h2 { flex: 1; font-size: var(--fs-lg); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overlay-body { padding: 20px 22px; overflow: auto; flex: 1; min-height: 0; }
.overlay-body > p { color: var(--c-text-2); }
.overlay-body > p + p { margin-top: 10px; }
.overlay-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--c-border-soft); background: var(--c-surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.overlay-foot .spacer { flex: 1; }
.drawer {
  position: fixed; z-index: var(--z-modal); top: 0; right: 0; bottom: 0; width: min(480px, 100vw); display: flex; flex-direction: column;
  background: var(--c-surface); box-shadow: var(--sh-modal); animation: drawer-in .2s var(--ease);
}
.drawer .overlay-foot { border-radius: 0; }
.drawer.lg { width: min(680px, 100vw); }
@keyframes drawer-in { from { transform: translateX(30px); opacity: 0; } }

/* ---------- Toast (ui/toast.js) ---------- */
.toasts { position: fixed; z-index: var(--z-toast); right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 420px; padding: 11px 12px 11px 14px;
  background: #2b2b30; color: #f2f2f4; border-radius: var(--r-md); box-shadow: var(--sh-pop); font-size: var(--fs-md); animation: toast-in .2s var(--ease);
}
.toast > svg { width: 16px; height: 16px; }
.toast.success > svg { color: #7fd2a6; } .toast.error > svg { color: #ff9c8f; } .toast.warning > svg { color: #f3c477; } .toast.info > svg { color: #9db8ff; }
.toast .toast-text { flex: 1; line-height: 1.45; }
.toast button { color: #a9c0ff; font-weight: 500; font-size: var(--fs-sm); }
.toast .icon-btn { color: #9a9aa2; } .toast .icon-btn:hover { background: #3a3a40; color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Tooltip (ui/tooltip.js) ---------- */
.tooltip {
  position: fixed; z-index: var(--z-tip); max-width: 280px; padding: 6px 9px; border-radius: 5px; background: #2b2b30; color: #f4f4f6;
  font-size: var(--fs-xs); line-height: 1.45; pointer-events: none; white-space: pre-line; box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

/* ---------- Estados vazios, erro e carregamento (ui/empty.js) ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 48px 24px; color: var(--c-muted); }
.empty-icon { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; background: #f1f2f6; color: #9a9db0; margin-bottom: 14px; }
.empty-icon svg { width: 22px; height: 22px; }
.empty.ok .empty-icon { background: var(--t-green-bg); color: var(--t-green-fg); }
.empty.bad .empty-icon { background: var(--t-red-bg); color: var(--t-red-fg); }
.empty h3 { color: var(--c-text); font-size: var(--fs-md); font-weight: 600; margin-bottom: 4px; }
.empty p { max-width: 440px; font-size: var(--fs-sm); line-height: 1.6; }
.empty .empty-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }
.empty.compact { padding: 24px 16px; }
.empty.compact .empty-icon { width: 34px; height: 34px; margin-bottom: 10px; }
.empty.compact .empty-icon svg { width: 17px; height: 17px; }
.empty.large { padding: 80px 24px; }
.skel { display: block; background: linear-gradient(90deg, #f0f0f4 0%, #f7f7fa 50%, #f0f0f4 100%); background-size: 200% 100%; border-radius: 4px; animation: skel 1.3s ease-in-out infinite; height: 12px; }
.skel + .skel { margin-top: 10px; }
@keyframes skel { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.page-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 60px; color: var(--c-muted); font-size: var(--fs-sm); }
.spinner { width: 16px; height: 16px; border: 2px solid #dfe3ee; border-top-color: var(--c-primary); border-radius: 50%; animation: spin .7s linear infinite; }

/* ---------- Linha do tempo (ui/timeline.js) ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { position: relative; display: grid; grid-template-columns: 20px 1fr; gap: 12px; padding-bottom: 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before { content: ''; position: absolute; left: 9.5px; top: 18px; bottom: -2px; width: 1px; background: var(--c-border); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: #f0f0f4; color: #9a9aa5; box-shadow: 0 0 0 3px var(--c-surface); position: relative; z-index: 1; }
.tl-dot svg { width: 11px; height: 11px; }
.tl-dot.small::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tl-item.ok .tl-dot { background: var(--t-green-bg); color: var(--t-green-fg); }
.tl-item.warn .tl-dot { background: var(--t-orange-bg); color: var(--t-orange-fg); }
.tl-item.bad .tl-dot { background: var(--t-red-bg); color: var(--t-red-fg); }
.tl-item.info .tl-dot { background: var(--t-blue-bg); color: var(--t-blue-fg); }
.tl-item.current .tl-title { font-weight: 600; }
.tl-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.tl-title { color: var(--c-text); font-weight: 500; }
.tl-time { color: var(--c-muted); font-size: var(--fs-xs); margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tl-meta { color: var(--c-muted); font-size: var(--fs-xs); margin-top: 1px; }
.tl-text { color: var(--c-text-2); font-size: var(--fs-md); margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.tl-item.bubble .tl-text { background: var(--c-surface-2); border: 1px solid var(--c-border-soft); border-radius: var(--r-md); padding: 10px 12px; }
.tl-item.note .tl-text { background: #fffaee; border-color: #f2e6c4; color: #8a7340; }

/* ---------- Gráficos (ui/charts.js) ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; overflow: visible; }
.chart text { font-family: var(--font); font-size: 10.5px; fill: var(--chart-axis); font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--chart-grid); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: rgba(77,121,237,.06); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: var(--fs-xs); color: var(--c-text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; }
.hbars { display: flex; flex-direction: column; gap: 4px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; align-items: center; gap: 12px; padding: 5px 8px; margin: 0 -8px; border-radius: var(--r-sm); color: inherit; text-decoration: none; font-size: var(--fs-md); }
a.hbar:hover { background: #f6f7fb; text-decoration: none; }
.hbar-label { display: flex; align-items: center; gap: 7px; color: var(--c-text-2); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 8px; background: #f1f2f6; border-radius: 4px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 4px; background: var(--chart-3); min-width: 2px; transition: width .3s var(--ease); }
.hbar-fill.zero { min-width: 0; }
.hbar-fill.ok { background: var(--s-ok); } .hbar-fill.warn { background: var(--s-warn); } .hbar-fill.bad { background: var(--s-bad); }
.hbar-fill.muted { background: #c5c7d3; } .hbar-fill.light { background: var(--chart-2); }
.hbar-value { font-variant-numeric: tabular-nums; color: var(--c-text); font-weight: 500; min-width: 40px; text-align: right; }
.hbar-value small { color: var(--c-muted); font-weight: 400; margin-left: 6px; }
.ring text { font-family: var(--font); font-weight: 600; fill: var(--c-text); }
.stacked { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; background: #f1f2f6; }
.stacked > span { height: 100%; }

/* ---------- Link de loja (ui/store-link.js) ---------- */
.store-link { display: inline-flex; align-items: center; gap: 5px; color: var(--c-text); font-weight: 500; max-width: 100%; }
.store-link span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.store-link svg { width: 12px; height: 12px; color: var(--c-faint); }
.store-link:hover { color: var(--c-primary); text-decoration: none; }
.store-link:hover svg { color: var(--c-primary); }

/* ---------- Padrões de página ---------- */
/* Lista + conversa + detalhes (estilo Gorgias). Usar com page.layout = 'fill'. */
.split { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; flex: 1; min-height: 0; background: var(--c-surface); }
.split.two { grid-template-columns: 340px minmax(0, 1fr); }
.split-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--c-border); }
.split-col:last-child { border-right: 0; }
.split-col.details { background: var(--c-surface-2); }
.split-head { display: flex; align-items: center; gap: 8px; min-height: 50px; padding: 0 14px; border-bottom: 1px solid var(--c-border); flex-shrink: 0; }
.split-head h2 { font-size: var(--fs-md); font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split-scroll { flex: 1; min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: #dbdbe0 transparent; }
.split-foot { padding: 10px 14px; border-top: 1px solid var(--c-border); color: var(--c-muted); font-size: var(--fs-xs); flex-shrink: 0; }
.list-item { display: block; width: 100%; text-align: left; padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--c-border-soft); border-left: 3px solid transparent; color: inherit; text-decoration: none; }
.list-item:hover { background: #fafbfd; text-decoration: none; }
.list-item.active { background: #eef3fe; border-left-color: var(--c-primary); }
.list-item.selected { background: #f4f7ff; border-left-color: var(--c-primary-line); }
.list-item .li-top { display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--c-muted); }
.list-item .li-top .grow { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-title { font-weight: 600; color: var(--c-text); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-text { color: var(--c-muted); font-size: var(--fs-sm); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.5; }
.list-item .li-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
@media (max-width: 1280px) { .split { grid-template-columns: 300px minmax(0, 1fr); } .split > .split-col.details { display: none; } }

/* Barra de filtros por cima de uma tabela */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { flex: 1; max-width: 380px; min-width: 200px; }
.toolbar .spacer { flex: 1; }

/* Lista chave: valor (detalhes) */
.kv { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 9px 14px; font-size: var(--fs-md); }
.kv dt { color: var(--c-muted); }
.kv dd { margin: 0; color: var(--c-text); min-width: 0; overflow-wrap: anywhere; }

/* Grelhas */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-main-side { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .form-grid { grid-template-columns: 1fr; } }

/* ---------- Mosaico de contagem (ex.: anomalias por tipo na Visão geral) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.tile {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 16px; min-width: 0;
  background: var(--c-surface); border: 1px solid #e3e3e9; border-radius: var(--r-md); color: inherit; text-decoration: none;
}
a.tile:hover { border-color: #cfd6ea; box-shadow: var(--sh-1); text-decoration: none; }
.tile::before { content: ''; position: absolute; left: -1px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: #c5c7d3; }
.tile.critical::before { background: var(--s-critical); } .tile.high::before { background: var(--s-warn); }
.tile.medium::before { background: #d9c25e; } .tile.low::before { background: #b5b8c6; }
.tile-text { flex: 1; min-width: 0; }
.tile-title { color: var(--c-text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { margin-top: 3px; }
.tile-count { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--c-text); }
.tile.critical .tile-count { color: #b23d30; }
.tile > svg { width: 14px; height: 14px; color: var(--c-faint); }

/* Cartão de boas-vindas (base vazia) */
.hero { display: flex; gap: 24px; align-items: center; padding: 28px; }
.hero-icon { width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; background: #fff1ed; color: #d4664f; flex-shrink: 0; }
.hero-icon svg { width: 26px; height: 26px; }
.hero h2 { font-size: var(--fs-xl); margin-bottom: 6px; }
.hero p { color: var(--c-text-2); max-width: 620px; }
.steps { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; counter-reset: st; }
.steps li { counter-increment: st; display: flex; gap: 10px; align-items: baseline; color: var(--c-text-2); }
.steps li::before { content: counter(st); width: 20px; height: 20px; border-radius: 50%; background: var(--t-blue-bg); color: var(--t-blue-fg); font-size: 11px; font-weight: 600; display: inline-grid; place-items: center; flex-shrink: 0; transform: translateY(-1px); }

.search input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }

/* ---------- Calendário de intervalo (ui/calendar.js, ui/period.js) ---------- */
.cal-pop { padding: 10px; width: 280px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.cal-title { font-weight: 600; font-size: var(--fs-md); }
.cal-nav { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 1px solid var(--c-border-strong); border-radius: var(--r-sm); background: var(--c-surface); color: var(--c-text-2); }
.cal-nav:hover:not(:disabled) { background: var(--c-hover); }
.cal-nav:focus-visible, .cal-day:focus-visible { outline: none; box-shadow: var(--focus); }
.cal-nav:disabled { opacity: .35; }
.cal-nav svg { width: 14px; height: 14px; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-week span { text-align: center; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; color: var(--c-faint); padding: 4px 0; }
.cal-day { height: 34px; border: 0; background: transparent; color: var(--c-text); font-size: var(--fs-sm); border-radius: 0; position: relative; }
.cal-day:hover:not(:disabled) { background: var(--c-hover); }
.cal-day:disabled { color: var(--c-faint); opacity: .45; cursor: default; }
.cal-day.today { font-weight: 700; color: var(--c-primary); }
.cal-day.today::after { content: ''; position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; }
.cal-day.in-range { background: var(--c-primary-soft); }
.cal-day.range-start, .cal-day.range-end { background: var(--c-primary); color: #fff; font-weight: 600; }
.cal-day.range-start { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.cal-day.range-end { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.cal-day.range-start.range-end { border-radius: var(--r-sm); }
.cal-hint { min-height: 18px; margin: 8px 2px 0; font-size: var(--fs-xs); color: var(--c-muted); }
.cal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--c-border-soft); }
