/* UI-3: estilos exclusivos das telas comuns e da Tela Inicial. */
#appShell .brand-home-button { border: 0; background: transparent; padding: 0; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
#appShell .brand-home-button:focus-visible { outline: 2px solid #6ba7ed; outline-offset: 4px; border-radius: 8px; }
body.viewer-mode #onlinePortalShell .online-portal-logo { cursor: pointer; }
body.viewer-mode #onlinePortalShell .online-portal-logo:focus-visible { outline: 3px solid #9ac9ff; outline-offset: 4px; }

/* A Tela Inicial do Viewer é um módulo novo; recebe os componentes enterprise
   sem alterar o visual dos dashboards legados do portal. */
body.viewer-mode #homeTab .biwa-panel,
body.viewer-mode #homeTab .biwa-card {
  min-width: 0;
  border: 1px solid var(--biwa-color-border);
  border-radius: var(--biwa-radius-lg);
  background: var(--biwa-color-surface);
  box-shadow: var(--biwa-shadow-sm);
  color: var(--biwa-color-text-primary);
}
body.viewer-mode #homeTab .biwa-card--kpi { border-left: 3px solid var(--biwa-color-primary); }
body.viewer-mode #homeTab .biwa-card--action { box-shadow: var(--biwa-shadow-md); }
body.viewer-mode #homeTab .biwa-card--info { background: var(--biwa-color-info-soft); }
body.viewer-mode #homeTab .biwa-card--status { border-left: 3px solid var(--biwa-color-info); }
body.viewer-mode #homeTab .biwa-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--biwa-button-gap);
  min-height: var(--biwa-button-height);
  max-width: 100%;
  padding: var(--biwa-space-2) var(--biwa-button-padding-x);
  border: 1px solid var(--biwa-color-border);
  border-radius: var(--biwa-radius-md);
  background: var(--biwa-color-primary-soft);
  color: var(--biwa-color-primary-pressed);
  font: 650 var(--biwa-font-size-md)/1.25 var(--biwa-font-family);
  white-space: normal;
  cursor: pointer;
}
body.viewer-mode #homeTab .biwa-btn:hover:not(:disabled) { background: var(--biwa-color-surface-hover); }
body.viewer-mode #homeTab .biwa-btn:focus-visible { outline: 2px solid var(--biwa-color-primary); outline-offset: 2px; }
body.viewer-mode #homeTab .biwa-btn:disabled { opacity: .55; cursor: not-allowed; }
body.viewer-mode #homeTab .page-head-dark .biwa-btn--ghost { background: transparent; color: var(--biwa-shell-header-text); border-color: var(--biwa-shell-sidebar-border); }

body.viewer-mode #homeTab {
  --biwa-color-surface: #ffffff;
  --biwa-color-surface-hover: #eef4fc;
  --biwa-color-text-primary: #122033;
  --biwa-color-text-secondary: #475569;
  --biwa-color-border: #dce5f0;
  --biwa-color-primary: #1f6feb;
  --biwa-color-primary-soft: #e8f1ff;
  --biwa-color-primary-pressed: #104da6;
  --biwa-color-info-soft: #eef7ff;
  --biwa-color-info: #1677e8;
  --biwa-radius-md: 10px;
  --biwa-radius-lg: 16px;
  --biwa-shadow-sm: 0 2px 8px rgba(15, 23, 42, .06);
  --biwa-shadow-md: 0 12px 28px rgba(15, 23, 42, .10);
  --biwa-button-gap: 8px;
  --biwa-button-height: 40px;
  --biwa-button-padding-x: 16px;
  --biwa-space-2: 8px;
  --biwa-font-family: Inter, Segoe UI, Arial, sans-serif;
  --biwa-font-size-md: 14px;
}
#homeTab { min-width: 0; }
body.viewer-mode #homeTab.active { display: block; width: 100%; height: 100%; overflow-y: auto; overflow-x: hidden; }
body.viewer-mode #homeTab .biwa-home-runtime { max-width: 1440px; margin: 0 auto; }
#homeTab .biwa-home-runtime,
#homeTab .biwa-home-editor { padding: clamp(12px, 2vw, 28px); min-width: 0; }
#homeTab .biwa-home-intro { padding: clamp(18px, 2.5vw, 34px); margin-bottom: 18px; border-radius: 16px; }
#homeTab .biwa-home-intro h3 { margin: 3px 0 8px; font-size: clamp(24px, 2.5vw, 36px); }
#homeTab .biwa-home-intro p:last-child { margin: 0; color: #52647d; }
#homeTab .biwa-home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px; min-width: 0; }
#homeTab .biwa-home-widget { display: flex; flex-direction: column; gap: 10px; padding: 20px; min-width: 0; overflow-wrap: anywhere; }
#homeTab .biwa-home-widget .biwa-btn { align-self: flex-start; }
#homeTab .biwa-home-widget h4,
#homeTab .biwa-home-ai h4 { margin: 0; font-size: 15px; }
#homeTab .biwa-home-widget p,
#homeTab .biwa-home-ai p { margin: 0; white-space: pre-line; line-height: 1.5; }
#homeTab .biwa-home-widget small { color: #64748b; }
#homeTab .biwa-home-value { font-size: clamp(24px, 3vw, 38px); line-height: 1.1; overflow-wrap: anywhere; }
#homeTab .biwa-home-empty { grid-column: 1 / -1; padding: 28px; }
#homeTab .biwa-home-ai { margin-top: 18px; padding: 18px 20px; }
#homeTab .biwa-home-admin-layout { display: grid; grid-template-columns: minmax(210px, 260px) minmax(0, 1fr); gap: 16px; align-items: start; }
#homeTab .biwa-home-sector-list,
#homeTab .biwa-home-sector-config { min-width: 0; overflow: hidden; }
#homeTab .biwa-home-sector-list .biwa-panel__header,
#homeTab .biwa-home-sector-config .biwa-panel__header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px; }
#homeTab .biwa-home-sector-list .biwa-panel__body,
#homeTab .biwa-home-sector-config .biwa-panel__body { padding: 18px; }
#homeTab .biwa-home-sector-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; border: 1px solid transparent; background: transparent; color: #263951; border-radius: 8px; padding: 10px; text-align: left; cursor: pointer; }
#homeTab .biwa-home-sector-item.active { background: #eaf3fe; border-color: #b9d9fd; }
#homeTab .biwa-home-sector-item span { font-size: 11px; color: #64748b; }
#homeTab .biwa-home-actions,
#homeTab .biwa-home-widget-head > div { display: flex; flex-wrap: wrap; gap: 7px; }
#homeTab .biwa-home-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
#homeTab .biwa-home-wide { grid-column: 1 / -1; }
#homeTab .biwa-home-form-grid textarea { min-height: 78px; resize: vertical; }
#homeTab .biwa-home-widget-list { display: grid; gap: 12px; }
#homeTab .biwa-home-widget-editor { padding: 14px; }
#homeTab .biwa-home-widget-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
#homeTab .biwa-home-editor-note { margin: 16px 0 0; color: #64748b; font-size: 12px; }
body:not(.viewer-mode) .biwa-home-modal .simple-modal { max-width: min(480px, calc(100vw - 32px)); }
body:not(.viewer-mode) .biwa-home-modal .simple-modal-body { display: grid; gap: 12px; }
body:not(.viewer-mode) .biwa-home-modal .biwa-control { width: 100%; }

/* Raw data view: full values stay accessible through horizontal scrolling. */
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-view-result .visual-table { width: max-content; min-width: 100%; table-layout: auto; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-view-result .visual-table th,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-view-result .visual-table td { white-space: nowrap; overflow-wrap: normal; word-break: normal; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-view-result .visual-table th .th-content { white-space: nowrap; overflow: visible; text-overflow: clip; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-view-result { overflow: auto; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .visualizacao-layout { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: start; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableViewerPanel { min-width: 0; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterSidebar { width: 286px; max-height: calc(100vh - 180px); overflow: auto; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterSidebar[hidden] { display: none; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterSidebar .biwa-panel__header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterSidebar .biwa-panel__header h3 { margin: 2px 0 0; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterSidebar .biwa-panel__body { display: grid; gap: 12px; padding: 14px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterSidebar .biwa-home-actions { display: flex; flex-wrap: wrap; gap: 6px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterRows { display: grid; gap: 8px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-filter-group { border: 1px solid #dae3ee; border-radius: 9px; background: #fff; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-filter-group summary { display: flex; justify-content: space-between; gap: 7px; padding: 9px; cursor: pointer; font-weight: 600; font-size: 12px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-filter-group .table-filter-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 0 9px 9px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-filter-group .table-filter-row select,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-filter-group .table-filter-row input { width: 100%; min-width: 0; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-filter-group .icon-btn.danger { width: 100%; }

body:not(.viewer-mode) #appShell.biwa-enterprise-ui :is(#dashboardTab, #schemaTab, #onlineTab, #historyTab, #settingsTab) > .page-head { margin-bottom: 14px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui :is(#historyTab, #settingsTab) .biwa-panel { min-width: 0; }

@media (max-width: 900px) {
  #homeTab .biwa-home-admin-layout { grid-template-columns: 1fr; }
  #homeTab .biwa-home-sector-list .biwa-panel__body { display: flex; gap: 6px; overflow-x: auto; }
  #homeTab .biwa-home-sector-item { width: auto; min-width: 155px; flex-shrink: 0; }
}
@media (max-width: 1250px) {
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .visualizacao-layout { grid-template-columns: 1fr; }
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterSidebar { width: 100%; max-height: 330px; }
}
@media (max-width: 600px) {
  #homeTab .biwa-home-runtime,
  #homeTab .biwa-home-editor { padding: 12px; }
  #homeTab .biwa-home-grid,
  #homeTab .biwa-home-form-grid { grid-template-columns: 1fr; }
  #homeTab .biwa-home-widget { padding: 16px; }
  #homeTab .biwa-home-sector-config .biwa-panel__header,
  #homeTab .biwa-home-widget-head { align-items: stretch; flex-direction: column; }
}
