/* TechRib discovery - isolado; preserva os temas Mushroom/Industrial */
.trd-section{--iot-card:var(--tr-card);--iot-text:var(--tr-text);--iot-muted:var(--tr-muted);--iot-border:var(--tr-border);--iot-accent:var(--tr-accent);--iot-raised:var(--tr-raised);--iot-radius:var(--tr-radius);margin:0 0 18px;background:var(--tr-card);border:1px solid var(--tr-border);border-radius:var(--tr-radius);padding:21px;box-shadow:var(--tr-shadow);color:var(--tr-text)}
.trd-section[hidden],.trd-sensors[hidden]{display:none!important}
.trd-heading{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;flex-wrap:wrap;margin-bottom:13px}
.trd-heading h2{margin:0 0 5px;font-size:19px}.trd-sub{font-size:12px;color:var(--tr-muted);margin:0}
.trd-dev-id{font-size:11px;color:var(--tr-muted);overflow-wrap:anywhere}.trd-chip{padding:5px 12px;border:1px solid var(--tr-border);border-radius:30px;font-size:12px;font-weight:800}
.trd-online{color:var(--tr-success)}.trd-offline{color:var(--tr-danger)}
.trd-info{border:1px solid var(--tr-border);border-radius:9px;padding:9px 12px;color:var(--tr-muted);font-size:12px;background:var(--tr-surface);margin-bottom:13px}
.trd-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(215px,100%),1fr));gap:12px}
.trd-channel{--trd-accent:var(--tr-accent);min-width:0;padding:13px;border:1px solid var(--tr-border);border-left:4px solid var(--trd-accent);border-radius:12px;background:var(--tr-raised,var(--tr-surface))}
.trd-card-head{display:flex;align-items:flex-start;justify-content:space-between;gap:10px}.trd-card-title{display:flex;min-width:0;flex:1;gap:6px;align-items:center;flex-wrap:wrap}
.trd-icon{color:var(--trd-accent);font-weight:900}.trd-name{font-size:14px;font-weight:760;overflow-wrap:anywhere}.trd-number{display:block;width:100%;font-size:10px;letter-spacing:.5px;color:var(--tr-muted)}
.trd-edit{font-size:11px;background:transparent;border:1px solid var(--tr-border);color:var(--tr-text)!important;padding:5px 8px;flex:0 0 auto}
.trd-card-body{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;margin:16px 0 13px}
.trd-state{font-size:15px}.trd-on{color:var(--tr-success)}.trd-off{color:var(--tr-muted)}.trd-unknown{color:var(--tr-muted)}.trd-mode{font-size:11px;color:var(--tr-muted)}
.trd-card-actions{display:flex;gap:7px}.trd-command{width:100%;font-size:11px;padding:7px 8px;background:var(--tr-surface);border:1px solid var(--tr-border);color:var(--tr-muted)!important;cursor:not-allowed;opacity:1!important}
.trd-sensors{margin-top:18px}.trd-sensors h3{font-size:15px;margin:0 0 10px}.trd-sensor{display:flex;flex-direction:column;gap:5px;border:1px solid var(--tr-border);border-radius:10px;padding:12px;background:var(--tr-surface);overflow-wrap:anywhere}.trd-sensor-label{font-size:12px;color:var(--tr-muted)}.trd-sensor-value{font-size:19px}
.trd-empty{padding:13px;font-size:13px;color:var(--tr-muted);grid-column:1/-1}
.trd-editor{border:1px solid var(--tr-border);border-radius:16px;background:var(--tr-card);color:var(--tr-text);width:min(440px,calc(100vw - 30px));padding:20px}.trd-editor::backdrop{background:rgba(0,0,0,.62)}
.trd-editor h2{margin-top:0}.trd-editor input,.trd-editor select{width:100%;margin:5px 0 10px}.trd-editor-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:14px}.trd-editor-actions button{padding:10px 13px}
.trd-error{color:var(--tr-danger);font-size:12px}
@media(max-width:700px){.trd-section{padding:13px}.trd-heading h2{font-size:16px}.trd-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}.trd-channel{padding:9px}.trd-name{font-size:12px}.trd-grid .trd-command{font-size:10px}}
@media(max-width:390px){.trd-grid{grid-template-columns:1fr}}

.trd-icon{display:inline-flex;align-items:center}.trd-icon svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}

/* AutoDiscovery 1.1: painel de canais substitui as áreas redundantes. */
#iotWidgets[hidden],#metricGrid section[hidden],section.iot-card[hidden]{display:none!important}
.trd-section{padding:15px 17px;margin:0 0 16px}
.trd-heading{margin-bottom:8px}
.trd-heading h2{font-size:17px;margin:0 0 3px}
.trd-info{margin-bottom:11px;padding:7px 10px}
.trd-grid{grid-template-columns:repeat(4,minmax(0,1fr));gap:10px}
.trd-channel{padding:11px}
.trd-card-body{margin:10px 0}
.trd-card-title{flex-wrap:nowrap}
.trd-name{font-size:13px}
.trd-number{width:auto;white-space:nowrap}
.trd-card-head{gap:5px}
.trd-command{min-height:34px;border-radius:8px;font-size:12px;font-weight:750;opacity:.75!important;}
.trd-command:disabled{cursor:not-allowed}
@media(max-width:1100px){.trd-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:600px){.trd-grid{grid-template-columns:repeat(1,minmax(0,1fr))}.trd-section{padding:12px}}

/* v1.3: canais físicos com o MESMO visual dos cards virtuais de 32 canais. */
.trd-section .trd-grid{display:grid;grid-template-columns:repeat(8,minmax(0,1fr));gap:10px}
.trd-section .trd-channel{--tile-accent:#468fef;min-width:0;min-height:116px;padding:11px 9px;gap:7px;border-left:1px solid var(--iot-border);background:var(--iot-card);border-radius:calc(var(--iot-radius) - 2px)}
.trd-section .trd-channel.on{background:color-mix(in srgb,var(--tile-accent) 13%,var(--iot-card));border-color:color-mix(in srgb,var(--tile-accent) 54%,var(--iot-border))}
.trd-section .trd-channel.on .bench-channel-icon{background:var(--tile-accent);color:#0c2632}
.trd-section .trd-channel.on .bench-toggle{color:var(--tile-accent)!important}
.trd-section .trd-channel.on .bench-switch{background:var(--tile-accent)}
.trd-section .trd-channel .bench-channel-name{margin:0;min-height:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:11px}
.trd-section .trd-channel .bench-channel-sub{font-size:9px;color:var(--iot-muted);min-height:13px}
.trd-section .trd-channel .bench-toggle{opacity:1!important;cursor:not-allowed!important}
.trd-section .trd-channel .bench-toggle:disabled{opacity:1!important}
.trd-section .trd-channel .bench-edit{z-index:1}
.trd-section .trd-channel.trd-unknown .bench-toggle{color:var(--iot-muted)!important}
.trd-section .trd-editor{padding:0;max-width:min(610px,calc(100vw - 26px));width:100%}
.trd-section .trd-editor .iot-config-form{padding:23px}
.trd-section .trd-editor .iot-icon-picker .tr-icon{width:21px;height:21px}
.trd-section .trd-editor .iot-picker-tools{display:flex;gap:8px;margin-top:7px}
.trd-section .trd-editor .iot-picker-tools select{width:175px;max-width:40%;flex:none}
.trd-section .trd-editor .iot-picker-tools input{min-width:0;flex:1}
.trd-section .trd-editor .trd-editor-actions{display:flex;justify-content:flex-end;gap:9px;padding-top:10px}
.trd-section .trd-editor .trd-editor-actions button{padding:10px 15px;border-radius:8px}
.trd-section .trd-editor .trd-editor-actions button[type=submit]{background:var(--iot-accent);color:#fff;border:none}
@media(max-width:1240px){.trd-section .trd-grid{grid-template-columns:repeat(6,minmax(0,1fr))}}
@media(max-width:900px){.trd-section .trd-grid{grid-template-columns:repeat(4,minmax(0,1fr))}.trd-section .bench-edit{opacity:1}}
@media(max-width:550px){.trd-section .trd-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.trd-section .trd-editor .iot-picker-tools{flex-wrap:wrap}.trd-section .trd-editor .iot-picker-tools select{max-width:none;width:100%}}

/* TechRib v1.5: interruptores remotos habilitados são clicáveis. */
.trd-section .trd-channel .bench-toggle:not(:disabled){cursor:pointer!important}
.trd-section .trd-channel .bench-toggle:disabled{cursor:not-allowed!important}

/* Patch 03: organizador seguro dos cards físicos. */
.trd-layout-actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
.trd-layout-button{border:1px solid var(--iot-border);border-radius:9px;background:var(--iot-card);color:var(--iot-text);padding:8px 12px;font-weight:700;cursor:pointer}
.trd-layout-hint{font-size:12px;color:var(--iot-muted);margin:5px 0 12px}
.trd-section .trd-grid .trd-channel.trd-wide{grid-column:span 2}
.trd-section .trd-grid .trd-channel.trd-layout-edit{outline:1px dashed var(--iot-accent);cursor:grab;position:relative;padding-bottom:27px}
.trd-section .trd-grid .trd-channel.trd-layout-edit:active{cursor:grabbing}
.trd-section .trd-size-btn{position:absolute;right:8px;bottom:4px;border:1px solid var(--iot-border);background:var(--iot-card);color:var(--iot-text);border-radius:5px;cursor:pointer;padding:1px 8px;font-weight:800}
.trd-section .trd-size-btn[hidden]{display:none}
@media(max-width:550px){.trd-section .trd-grid .trd-channel.trd-wide{grid-column:span 2}}

/* Patch 03a: corrigir contraste dos controles do organizador em ambos os temas. */
.trd-section .trd-layout-button{appearance:none;background:var(--tr-surface,#172c3f);color:var(--tr-text,#f2f7ff)!important;border:1px solid var(--tr-border,#42617b);border-radius:9px;padding:8px 12px;font:inherit;font-size:12px;font-weight:700;line-height:1.35;opacity:1;cursor:pointer;transition:background-color .15s,border-color .15s,color .15s}
.trd-section .trd-layout-button:hover{background:var(--tr-raised,var(--tr-surface,#213a50));border-color:var(--tr-accent,#4a99e7)}
.trd-section .trd-layout-button:focus-visible{outline:2px solid var(--tr-accent,#4a99e7);outline-offset:2px}
.trd-section .trd-size-btn{background:var(--tr-surface,#172c3f);color:var(--tr-text,#f2f7ff)!important;border-color:var(--tr-border,#42617b);opacity:1}
.trd-section .trd-size-btn:hover{border-color:var(--tr-accent,#4a99e7)}

/* Patch 04 - modelos visuais locais aos cards físicos. */
.trd-section .trd-channel .bench-channel-icon svg{width:var(--trd-icon-size,24px)!important;height:var(--trd-icon-size,24px)!important;max-width:none}
.trd-section .trd-channel .bench-channel-icon{width:max(30px, calc(var(--trd-icon-size,24px) + 8px));height:max(30px, calc(var(--trd-icon-size,24px) + 8px));display:inline-flex;align-items:center;justify-content:center}
.trd-section .trd-channel[data-visual-style="minimal"]{background:transparent!important;border-style:dashed!important;box-shadow:none!important}
.trd-section .trd-channel[data-visual-style="focus"]{min-height:175px;display:flex;flex-direction:column;align-items:center;justify-content:space-between;text-align:center}
.trd-section .trd-channel[data-visual-style="focus"] .bench-channel-top{width:100%;justify-content:space-between}
.trd-section .trd-channel[data-visual-style="focus"] .bench-channel-name{font-size:1.05rem;font-weight:800}
.trd-section .trd-channel[data-visual-style="focus"] .bench-channel-foot{width:100%}
.trd-section .trd-appearance-btn{position:absolute;left:8px;bottom:4px;border:1px solid var(--tr-border,#42617b);background:var(--tr-surface,#172c3f);color:var(--tr-text,#f2f7ff)!important;border-radius:5px;cursor:pointer;padding:3px 6px;font-size:11px;font-weight:700}
.trd-section .trd-appearance-btn[hidden]{display:none}
.trd-section .trd-grid .trd-channel.trd-layout-edit{padding-bottom:33px}
.trd-appearance-overlay{position:fixed;inset:0;background:rgba(0,0,0,.65);display:flex;align-items:center;justify-content:center;padding:16px;z-index:9999}
.trd-appearance-dialog{width:min(420px,100%);padding:23px;background:#162b3e;color:#eff7ff;border:1px solid #54718a;border-radius:14px;box-shadow:0 18px 70px #0008;display:grid;gap:16px}
.trd-appearance-dialog h3{margin:0;color:inherit;font-size:18px}
.trd-appearance-dialog label{display:grid;gap:7px;color:inherit;font-weight:600;font-size:13px}
.trd-appearance-select{width:100%;padding:10px;background:#203b53;color:#fff;border:1px solid #63829c;border-radius:8px}
.trd-appearance-actions{display:flex;justify-content:end;gap:10px}
.trd-appearance-actions button{padding:9px 12px;border:1px solid #63829c;border-radius:8px;color:#fff;background:#203b53;cursor:pointer}
.trd-appearance-actions .trd-appearance-save{background:#2878cf;border-color:#2878cf}

/* Patch 05: preservar ícones grandes sem recortes e sem interferir nos toggles MQTT. */
.trd-section .trd-channel{min-width:0;overflow:visible}
.trd-section .trd-channel .bench-channel-icon{flex-shrink:0}
.trd-section .trd-channel:has(.bench-channel-icon[style]){overflow:visible}
.trd-section .trd-channel[data-visual-style="focus"] .bench-channel-top{min-height:calc(var(--trd-icon-size,24px) + 12px)}
.trd-section .trd-channel[data-visual-style="focus"]{height:auto}

/* TechRib Patch 06 — modelos visuais. Somente CSS: preserva DOM,
   atributos de estado, controles de comando e eventos MQTT existentes. */
.trd-section .trd-grid .trd-channel[data-visual-style="round"]{
  min-height:190px;display:flex;flex-direction:column;align-items:center;
  justify-content:space-between;text-align:center;padding-top:14px;
}
.trd-section .trd-grid .trd-channel[data-visual-style="round"] .bench-channel-top{
  width:100%;display:flex;flex-direction:column;align-items:center;gap:7px;
}
.trd-section .trd-grid .trd-channel[data-visual-style="round"] .bench-channel-icon{
  border-radius:50%;width:max(66px,calc(var(--trd-icon-size,24px) + 18px));height:max(66px,calc(var(--trd-icon-size,24px) + 18px));
  box-shadow:0 0 0 3px color-mix(in srgb,var(--tile-accent) 24%,transparent);
}
.trd-section .trd-grid .trd-channel[data-visual-style="round"] .bench-channel-name{font-size:13px;font-weight:800;max-width:100%}
.trd-section .trd-grid .trd-channel[data-visual-style="round"] .bench-channel-foot{width:100%}
.trd-section .trd-grid .trd-channel[data-visual-style="horizontal"]{
  min-height:104px;display:grid;grid-template-columns:minmax(0,1fr) auto;align-content:center;align-items:center;
  gap:5px 8px;
}
.trd-section .trd-grid .trd-channel[data-visual-style="horizontal"] .bench-channel-top{grid-column:1 / 3;display:flex;justify-content:space-between;align-items:center}
.trd-section .trd-grid .trd-channel[data-visual-style="horizontal"] .bench-channel-name{grid-column:1;font-size:12px}
.trd-section .trd-grid .trd-channel[data-visual-style="horizontal"] .bench-channel-sub{grid-column:1}
.trd-section .trd-grid .trd-channel[data-visual-style="horizontal"] .bench-channel-foot{grid-column:2;grid-row:2 / span 2;justify-self:end}
.trd-section .trd-grid .trd-channel[data-visual-style="compact"]{
  min-height:88px;padding:7px;gap:3px;border-radius:8px;
}
.trd-section .trd-grid .trd-channel[data-visual-style="compact"] .bench-channel-icon{width:max(26px,calc(var(--trd-icon-size,24px) + 4px));height:max(26px,calc(var(--trd-icon-size,24px) + 4px))}
.trd-section .trd-grid .trd-channel[data-visual-style="compact"] .bench-channel-name{font-size:10px}
.trd-section .trd-grid .trd-channel[data-visual-style="compact"] .bench-channel-sub{display:none}
.trd-section .trd-grid .trd-channel[data-visual-style="industrial"]{
  background:color-mix(in srgb,var(--iot-card) 92%,#869caa)!important;
  border:2px solid var(--iot-border);border-radius:5px;
  box-shadow:inset 0 0 0 2px color-mix(in srgb,var(--iot-card) 65%,transparent);
}
.trd-section .trd-grid .trd-channel[data-visual-style="industrial"].on{
  border-color:var(--tile-accent);
}
.trd-section .trd-grid .trd-channel[data-visual-style="industrial"] .bench-channel-number{
  font-family:ui-monospace,SFMono-Regular,Consolas,monospace;letter-spacing:.05em;
}
.trd-section .trd-grid .trd-channel[data-visual-style="industrial"] .bench-channel-name{
  text-transform:uppercase;font-weight:850;letter-spacing:.035em;
}
.trd-section .trd-grid .trd-channel[data-visual-style="glass"]{
  background:linear-gradient(130deg,color-mix(in srgb,var(--iot-card) 93%,white) 0%,color-mix(in srgb,var(--iot-card) 84%,var(--tile-accent)) 100%)!important;
  border:1px solid color-mix(in srgb,var(--tile-accent) 32%,var(--iot-border));
  border-radius:18px;box-shadow:0 6px 18px rgba(0,0,0,.12),inset 0 1px 0 rgba(255,255,255,.12);
}
/* Edição continua acessível independentemente do modelo escolhido. */
.trd-section .trd-grid .trd-channel.trd-layout-edit{padding-bottom:37px;position:relative}
.trd-section .trd-grid .trd-channel.trd-layout-edit .trd-appearance-btn,
.trd-section .trd-grid .trd-channel.trd-layout-edit .trd-size-btn{z-index:4}
@media(max-width:550px){
  .trd-section .trd-grid .trd-channel[data-visual-style="horizontal"]{grid-template-columns:minmax(0,1fr) auto}
  .trd-section .trd-grid .trd-channel[data-visual-style="round"]{min-height:170px}
}

/* Patch 23C: acessibilidade para ícone acionável dos canais físicos */
.trd-channel .trd-icon-action{cursor:pointer;border:0;padding:0;display:flex;align-items:center;justify-content:center}
.trd-channel .trd-icon-action:disabled{cursor:not-allowed;opacity:.48}
.trd-channel .trd-icon-action:focus-visible{outline:2px solid var(--tr-accent,#39b98e);outline-offset:3px}
