/* Shared component contract, loaded after page CSS and legacy theme mappings.
   Aliases let existing screens adopt it without changing IDs or JS contracts. */
:root[data-theme] .main-content{padding:var(--space-8);}
:root[data-theme] .topbar{gap:var(--space-6);margin-bottom:var(--space-6);}
:root[data-theme] :is(.topbar-left h1,.mcp-consent-container h1){
    color:var(--theme-text);font-size:var(--font-page);font-weight:600;line-height:1.25;
}
:root[data-theme] .topbar-left p{font-size:14px;line-height:1.6;margin-top:var(--space-2);}
:root[data-theme] :is(.section-header,.profile-card-header,.activity-heading,.tool-card-header,.normalization-card-header,.client-activity-header){
    padding:var(--space-6);gap:var(--space-4);border-color:var(--theme-border-soft);
}
:root[data-theme] :is(.section-header h2,.profile-card-header h2,.activity-heading h2,.client-activity-header h2,.entity-header h2,.construction-panel h2,.version-card h2){
    color:var(--theme-text);font-size:var(--font-section);font-weight:600;line-height:1.4;
}
:root[data-theme] :is(.tool-card-header > strong,.normalization-card-header > strong){
    color:var(--theme-text);font-size:var(--font-section);font-weight:600;line-height:1.4;
}
:root[data-theme] :is(.title-yellow,.logo-yellow,.overview-value,.profile-usage-summary strong,.analysis-summary strong,.chart-summary-row strong,.policy-header strong,.normalizar-analysis-summary strong){color:var(--theme-highlight);}
:root[data-theme] :is(.overview-value,.profile-usage-summary strong,.analysis-summary strong){
    font-size:var(--font-metric);font-variant-numeric:tabular-nums;line-height:1.25;
}

:root[data-theme] :is(.ui-card,.activity-panel,.dashboard-status,.overview-card,.entity-card,.live-table-section,.client-activity-header,.analysis-filters,.analysis-summary,.analysis-insights,.analysis-chart-panel,.follow-form-panel,.follow-table-panel,.correcao-form-panel,.correcao-table-panel,.tool-card,.normalization-card,.script-card,.profile-card,.construction-panel,.ops-bar,.schedule-panel,.pipeline-panel,.terminal-panel,.login-panel,.version-card){
    background:var(--theme-panel);border:1px solid var(--theme-border);border-radius:var(--radius-card);box-shadow:var(--theme-shadow);
}
:root[data-theme] :is(.ui-card,.construction-panel){padding:var(--space-6);}
:root[data-theme] :is(.dashboard-status > div,.ops-metric,.ops-execution-key,.schedule-field,.schedule-metric,.login-brand){background:var(--theme-panel);}
:root[data-theme] :is(.overview-card,.profile-form,.profile-create-form,.profile-mcp-body){padding:var(--space-6);}
:root[data-theme] :is(.profile-grid,.overview-grid,.tools-board,.scripts-board){gap:var(--space-6);}
:root[data-theme] .client-card{background:var(--theme-panel);border-radius:var(--radius-card);}
:root[data-theme] .client-activity-section{
    --client-access-current:var(--theme-success);--client-access-warning:var(--theme-warning);--client-access-stale:var(--theme-danger);
}

/* Hidden/native proxy inputs, upload inputs, and RFID entry are intentionally excluded. */
:root[data-theme] :is(input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([hidden]):not(.rfid-hidden-input):not(.reference-date-native),select:not([hidden]),textarea:not([hidden])){
    background:var(--theme-input);border:1px solid var(--theme-control-border);border-radius:var(--radius-control);
    color:var(--theme-text);font:inherit;font-size:var(--font-body);height:var(--control-height);min-width:0;
    padding:10px 12px;line-height:1.4;transition:border-color var(--motion-fast),background-color var(--motion-fast);
}
:root[data-theme] :is(textarea:not([hidden]),select[multiple]:not([hidden])){height:auto;min-height:120px;}
:root[data-theme] textarea{resize:vertical;}
:root[data-theme] :is(input,textarea)::placeholder{color:var(--theme-muted);opacity:1;}
:root[data-theme] :is(input,select,textarea):focus{border-color:var(--theme-focus);}
:root[data-theme] :is(button,a,input,select,textarea,[tabindex]):focus-visible{
    outline:2px solid var(--theme-focus);outline-offset:3px;
}
:root[data-theme] :is(input,select,textarea):disabled{background:var(--theme-panel-2);color:var(--theme-muted);cursor:not-allowed;}
:root[data-theme] :is(input[type="checkbox"],input[type="radio"]){accent-color:var(--theme-accent);}
:root[data-theme] :is(.fragmentar-file-picker,.converter-file-picker,.normalizar-file-picker,.script-file-picker) > strong{
    background:var(--theme-input);border-color:var(--theme-control-border);border-radius:var(--radius-control);color:var(--theme-text);min-height:var(--control-height);
}
:root[data-theme] :is(.follow-form,.correcao-form,.profile-form,.profile-create-form,.follow-filters,.client-filters,.fragmentar-form,.converter-form,.normalizar-form,.script-form,.login-form) label > span:first-child{
    color:var(--theme-muted);font-size:var(--font-label);line-height:1.5;text-transform:none;
}

/* Primary actions: one geometry and a theme-aware fill. */
:root[data-theme] :is(.ui-button,.mcp-button,.profile-actions button,.pipeline-button,.login-form button[type="submit"],.follow-actions button,.follow-modal-actions button,.correcao-actions button,.correcao-modal-actions button,.fragmentar-actions button,.converter-actions button,.normalizar-actions button,.normalizar-rules-actions button,.normalizar-correction-actions button,.normalizar-encoding button,.script-date-picker button,.client-expand-label,.normalizar-analysis-actions button,.script-actions button,.script-download a,.script-google-actions a,.script-google-actions button,.activity-search button,.client-personalize-actions button.is-primary,.fragmentar-file-button,.converter-file-button,.normalizar-file-button,.script-file-button){
    align-items:center;display:inline-flex;justify-content:center;gap:var(--space-2);
    background:var(--theme-accent);border:1px solid var(--theme-highlight);border-radius:var(--radius-control);
    color:var(--theme-accent-text);cursor:pointer;font:inherit;font-size:var(--font-control);font-weight:600;
    height:auto;min-height:var(--control-height);line-height:1.4;padding:10px 16px;text-align:center;text-decoration:none;
    white-space:normal;filter:none;transition:background-color var(--motion-fast),border-color var(--motion-fast),color var(--motion-fast);
}
:root[data-theme] :is(.ui-button,.mcp-button,.profile-actions button,.pipeline-button,.login-form button[type="submit"],.follow-actions button,.follow-modal-actions button,.correcao-actions button,.correcao-modal-actions button,.fragmentar-actions button,.converter-actions button,.normalizar-actions button,.normalizar-rules-actions button,.normalizar-correction-actions button,.normalizar-encoding button,.script-date-picker button,.client-expand-label,.normalizar-analysis-actions button,.script-actions button,.script-download a,.script-google-actions a,.script-google-actions button,.activity-search button,.client-personalize-actions button.is-primary):hover:not(:disabled):not([aria-disabled="true"]){background:var(--button-hover-bg,var(--theme-accent-hover));filter:none;}

/* Secondary actions are neutral; links and supporting information use the secondary color. */
:root[data-theme] :is(.ui-button--secondary,.profile-secondary,.pipeline-button.secondary,.follow-actions button.secondary,.follow-modal-actions button.secondary,.correcao-actions button.secondary,.correcao-modal-actions button.secondary,.fragmentar-actions button.secondary,.converter-actions button.secondary,.normalizar-actions button.secondary,.normalizar-rules-actions button.secondary,.normalizar-correction-actions button.secondary,.normalizar-analysis-actions button.secondary,.script-actions button.secondary,.script-download a.secondary,.mcp-button[data-mcp-copy],.follow-filter-actions button,.follow-continuation-button,.datetime-field button,.script-copy-row button,.cba-analysis-row button,.activity-search a,.client-personalize-toggle,.client-personalize-actions button:not(.is-primary),.correcao-pagination button,.analysis-nav-button,.toggle-button,.sidebar-logout button){
    align-items:center;display:inline-flex;justify-content:center;gap:var(--space-2);
    background:var(--theme-panel-2);border:1px solid var(--theme-control-border);border-radius:var(--radius-control);
    color:var(--theme-text);cursor:pointer;font:inherit;font-size:var(--font-control);font-weight:500;
    height:auto;min-height:var(--control-height);line-height:1.4;padding:10px 16px;text-decoration:none;white-space:normal;filter:none;
    --button-hover-bg:var(--theme-secondary-soft);
    transition:background-color var(--motion-fast),border-color var(--motion-fast),color var(--motion-fast);
}
:root[data-theme] :is(.ui-button--secondary,.profile-secondary,.pipeline-button.secondary,button.secondary,.mcp-button[data-mcp-copy],.follow-filter-actions button,.follow-continuation-button,.datetime-field button,.script-copy-row button,.cba-analysis-row button,.activity-search a,.client-personalize-toggle,.client-personalize-actions button:not(.is-primary),.correcao-pagination button,.analysis-nav-button,.toggle-button,.sidebar-logout button):hover:not(:disabled):not([aria-disabled="true"]){
    background:var(--theme-secondary-soft);border-color:var(--theme-secondary);color:var(--theme-text);filter:none;
}
:root[data-theme] :is(.quick-user-button,.analysis-search-clear){
    background:var(--theme-secondary-soft);border:1px solid var(--theme-secondary);border-radius:var(--radius-control);
    color:var(--theme-secondary);font-size:var(--font-label);height:auto;min-height:28px;padding:4px 8px;filter:none;
}
:root[data-theme] :is(.ui-link,.profile-mcp-guide a,.profile-mcp-notice a,.profile-mcp-copy-message,.chart-label-previous){color:var(--theme-secondary);}
:root[data-theme] :is(.ui-button--danger,.mcp-revoke-button,.follow-remove-button,.correcao-remove-button,.follow-modal-actions button.danger,.correcao-modal-actions button.danger){
    background:var(--theme-danger-soft);border:1px solid var(--theme-danger);border-radius:var(--radius-control);
    color:var(--theme-danger);font-size:var(--font-control);min-height:var(--control-height);padding:10px 16px;
    --button-hover-bg:var(--theme-danger-soft);
}
:root[data-theme] :is(.ui-button--danger,.mcp-revoke-button,.follow-remove-button,.correcao-remove-button,button.danger):hover:not(:disabled){
    background:var(--theme-danger-soft);border-color:var(--theme-danger);color:var(--theme-danger);filter:none;
}
:root[data-theme] :is(button:disabled,.ui-button[aria-disabled="true"],.script-download a[aria-disabled="true"],.script-download a.disabled){opacity:.55;cursor:not-allowed;filter:none;}
:root[data-theme] :is(.toggle-button.active,.analysis-values-button.active,.mcp-button[aria-pressed="true"]){--button-hover-bg:var(--theme-accent-soft);background:var(--theme-accent-soft);border-color:var(--theme-highlight);color:var(--theme-highlight);}

/* Hidden panels/buttons must remain hidden even when a component uses flex/grid. */
:root[data-theme] [hidden]{display:none !important;}

/* Sidebar geometry is preserved; only its shared visual contract changes. */
:root[data-theme] .sidebar{background:var(--theme-panel);border-color:var(--theme-border);}
:root[data-theme="dark"] .sidebar{background:var(--theme-bg);}
:root[data-theme] :is(.sidebar-logo,.sidebar-user-name){color:var(--theme-text);}
:root[data-theme] :is(.sidebar-user-role,.sidebar-version){color:var(--theme-muted);}
:root[data-theme] .sidebar-user{border-color:var(--theme-border-soft);}
:root[data-theme] .sidebar-link{color:var(--theme-text);border-radius:var(--radius-control);font-size:14px;min-height:var(--control-height);}
:root[data-theme] .sidebar-link:hover{background:var(--theme-panel-2);border-color:var(--theme-border);color:var(--theme-text);}
:root[data-theme] .sidebar-link.active{background:var(--theme-accent);border-color:var(--theme-highlight);color:var(--theme-accent-text);}
:root[data-theme] .sidebar-version:hover{border-color:var(--theme-secondary);color:var(--theme-secondary);}

/* Operational states are independent of the selected brand palette. */
:root[data-theme] :is(.ui-message,.profile-message,.schedule-message,.login-error,.follow-modal-warning,.correcao-modal-warning){
    background:var(--theme-secondary-soft);border:1px solid var(--theme-secondary);border-radius:var(--radius-control);
    color:var(--theme-secondary);font-size:14px;line-height:1.6;padding:12px 16px;overflow-wrap:anywhere;
}
:root[data-theme] :is(.ui-message--success,.profile-message.success,.status-ok){background:var(--theme-success-soft);border-color:var(--theme-success);color:var(--theme-success);}
:root[data-theme] :is(.follow-status-ok,.correcao-status-ok,.normalizar-status-ok,.trend-value.trend-up){color:var(--theme-success);}
:root[data-theme] :is(.ui-message--error,.profile-message.error,.login-error,.status-error,.follow-modal-warning,.correcao-modal-warning){background:var(--theme-danger-soft);border-color:var(--theme-danger);color:var(--theme-danger);}
:root[data-theme] :is(.follow-status-error,.correcao-status-error,.normalizar-status-error,.trend-value.trend-down){color:var(--theme-danger);}
:root[data-theme] .ui-message--warning{background:var(--theme-warning-soft);border-color:var(--theme-warning);color:var(--theme-warning);}
:root[data-theme] :is(.status-pending,.profile-mcp-status){background:var(--theme-panel-2);border-color:var(--theme-control-border);color:var(--theme-muted);}
:root[data-theme] .profile-mcp-status.is-ready{background:var(--theme-success-soft);border-color:var(--theme-success);color:var(--theme-success);}
:root[data-theme] .profile-mcp-notice{background:var(--theme-secondary-soft);border-color:var(--theme-secondary);color:var(--theme-text);}
:root[data-theme] :is(.profile-mcp-details div,.profile-mcp-guide,.mcp-connection-item){background:var(--theme-panel-3);border-color:var(--theme-border);border-radius:var(--radius-card);}
:root[data-theme] :is(.profile-mcp-code,.profile-mcp-prompt){background:var(--theme-input);border-color:var(--theme-control-border);color:var(--theme-text);}
:root[data-theme] .profile-mcp-copy-row{align-items:flex-start;}
:root[data-theme] .profile-mcp-body p{font-size:14px;}

/* Compact table typography; column layout remains controlled by each screen. */
:root[data-theme] :is(.activity-table,.profile-usage-table,.follow-table,.correcao-table,.live-table,.pipeline-table) th{font-size:var(--font-label);color:var(--theme-muted);}
:root[data-theme] :is(.activity-table,.profile-usage-table,.follow-table,.correcao-table,.live-table,.pipeline-table) td{font-size:14px;}
:root[data-theme] :is(.activity-table,.profile-usage-table,.follow-table,.correcao-table,.live-table,.pipeline-table) tbody tr:hover > td{background:var(--theme-panel-2);}
:root[data-theme] .activity-table :is(th,td){padding:var(--space-4);}

/* Theme previews use their own scoped palette, independent of the current theme. */
:root[data-theme] .theme-options label{position:relative;}
:root[data-theme] .theme-options input[type="radio"]{
    position:absolute;top:0;left:0;width:1px;height:1px;margin:0;padding:0;border:0;opacity:0;
}
:root[data-theme] .theme-options input + span{background:var(--theme-panel);border-color:var(--theme-border);color:var(--theme-text);}
:root[data-theme] .theme-options input + span strong{color:var(--theme-text);}
:root[data-theme] .theme-options input + span small{color:var(--theme-muted);font-size:var(--font-label);text-transform:none;}
:root[data-theme] .theme-options input:checked + span{border-color:var(--theme-focus);box-shadow:0 0 0 1px var(--theme-focus) inset;}
:root[data-theme] .theme-options input:focus-visible + span{outline:2px solid var(--theme-focus);outline-offset:3px;}
:root[data-theme] .theme-preview{background:var(--theme-bg);border-color:var(--theme-border);}
:root[data-theme] .theme-preview::before{background:var(--theme-panel);border-color:var(--theme-border);}
:root[data-theme] .theme-preview::after{background:var(--theme-highlight);}
:root[data-theme] .theme-preview b{background:var(--theme-secondary);}
:root[data-theme] .theme-preview em{background:var(--theme-accent);}
:root[data-theme] .mcp-consent-container .profile-card{padding:var(--space-6);}
:root[data-theme] .mcp-consent-container :is(p,ul){margin-top:var(--space-4);}
:root[data-theme] .mcp-consent-container ul{padding-left:var(--space-6);}
:root[data-theme] .mcp-consent-container .profile-form{padding:var(--space-6) 0 0;}

@media(max-width:768px){
    :root[data-theme] .main-content{padding:var(--space-4);}
    :root[data-theme] :is(.topbar-left h1,.mcp-consent-container h1){font-size:26px;}
    :root[data-theme] :is(.section-header,.profile-card-header,.activity-heading,.tool-card-header,.normalization-card-header,.client-activity-header,.overview-card,.profile-form,.profile-create-form,.profile-mcp-body){padding:var(--space-4);}
    :root[data-theme] :is(.section-header,.profile-actions,.follow-actions,.correcao-actions){flex-wrap:wrap;}
    :root[data-theme] .profile-mcp-copy-row{flex-wrap:wrap;}
    :root[data-theme] .profile-mcp-copy-row :is(input,textarea){flex:1 1 100%;}
    :root[data-theme] .profile-mcp-copy-row .mcp-button{width:auto;max-width:100%;}
}
@media(prefers-reduced-motion:reduce){
    :root[data-theme]{--motion-fast:0ms;}
    :root[data-theme] :is(.client-card,.sidebar-link,.rfid-block,.rfid-chip,.rfid-coils){transition:none;animation:none;}
}
