/*
 * Redes dark contrast layer.
 * Loaded after the legacy stylesheet so light-theme literals cannot win.
 */
:root[data-theme='dark'] {
  color-scheme: dark;
  --ink: #f5f7f6;
  --muted: #a8b0ab;
  --green: #78e6c1;
  --line: #3f4541;
  --paper: #171918;
  --redes-bg: #090a09;
  --redes-surface: #171918;
  --redes-surface-alt: #1e211f;
  --redes-surface-raised: #252a27;
  --redes-surface-emphasis: #303532;
  --redes-surface-hover: #353b37;
  --redes-text: #f5f7f6;
  --redes-text-secondary: #d2d7d4;
  --redes-muted: #a8b0ab;
  --redes-border: #3f4541;
  --redes-control-border: #6b746f;
  --redes-focus: #78e6c1;
  --redes-primary-surface: #1f745a;
}

:root[data-theme='dark'],
:root[data-theme='dark'] body,
:root[data-theme='dark'] #app {
  background-color: var(--redes-bg);
  color: var(--redes-text);
}

:root[data-theme='dark'] :is(
  .panel,.card,.stat,dialog,table,.modalhead,.auth-card,.hub-card,
  .publication-card,.studio-media-card,.schedule-card,.admin-kpi-card,
  .admin-table-card,.admin-user-card,.admin-detail-kpi,.admin-detail-card,
  .module-admin-card,.google-user-card,.google-menu-group,.google-drawer-sheet,
  .google-drawer-header,.filter-hub,.studio-access-panel,.pub-text-block,
  .stage-text-block,.upload-preview-area,.theme-choice,.publication-top-cover,
  .agency-delegation-card,.wa-status-card
) {
  background: var(--redes-surface);
  color: var(--redes-text);
  border-color: var(--redes-border);
}

:root[data-theme='dark'] :is(
  .auth-tabs,.settings-subnav,.empty,.note,.pre,.column,.weekday,.day,
  .datebox,.file-placeholder,.publication-cover-empty,.studio-media-preview,
  .google-menu-card,.art-card,.drop-zone,.qr-result,.pwa-banner
) {
  background: var(--redes-surface-alt);
  color: var(--redes-text-secondary);
  border-color: var(--redes-border);
}

:root[data-theme='dark'] :is(
  .card-body,.card-footer,.hub-card-body,.hub-card-footer,
  .publication-card-body,.publication-card-bottom,.studio-media-caption,
  .studio-media-actions,.module-admin-body,.module-admin-footer
) {
  background: transparent;
  border-color: var(--redes-border);
}

:root[data-theme='dark'] :is(h1,h2,h3,h4,h5,h6,strong,.admin-user-card-name,
  .admin-kpi-val,.admin-detail-card-title,.hub-card-title,.google-user-name) {
  color: var(--redes-text);
}

:root[data-theme='dark'] :is(p,small,.muted,.formhelp,.pagehead p,.card p,
  .admin-user-card-email,.admin-user-card-val,.admin-kpi-title,.admin-kpi-sub,
  .hub-card-desc,.hub-card-subtitle,.hub-card-meta,.google-user-email,
  .publication-card-body p,.publication-card-bottom) {
  color: var(--redes-text-secondary);
}

:root[data-theme='dark'] :is(label,.field,.eyebrow,.admin-user-card-lbl,
  .admin-detail-kpi-lbl,a) {
  color: var(--redes-focus);
}

:root[data-theme='dark'] :is(button:not(.primary),.button,.auth-tab,
  input,textarea,select,.button-label,.pub-editor-tab) {
  background: var(--redes-surface-raised);
  color: var(--redes-text);
  border-color: var(--redes-control-border);
}

:root[data-theme='dark'] :is(button:not(.primary),.button,.auth-tab,
  input,textarea,select,.button-label,.pub-editor-tab):hover {
  background: #2a302d;
  border-color: #626b66;
}

:root[data-theme='dark'] :is(input,textarea,select)::placeholder {
  color: #a1aaa5;
  opacity: 1;
}

:root[data-theme='dark'] :is(input,textarea,select):focus {
  border-color: var(--redes-focus);
  box-shadow: 0 0 0 3px rgba(124,232,197,.17);
}

:root[data-theme='dark'] input:-webkit-autofill,
:root[data-theme='dark'] input:-webkit-autofill:hover,
:root[data-theme='dark'] input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--redes-text);
  caret-color: var(--redes-text);
  -webkit-box-shadow: 0 0 0 1000px var(--redes-surface-raised) inset;
  border-color: var(--redes-focus);
}

:root[data-theme='dark'] .auth-tab.active,
:root[data-theme='dark'] .settings-subnav .tab-btn.active {
  background: #303632;
  color: #ffffff;
  border-color: #626b66;
  box-shadow: inset 0 0 0 1px rgba(124,232,197,.16);
}

:root[data-theme='dark'] .primary {
  background: #1f745a;
  border-color: #65d9b5;
  color: #ffffff;
}

:root[data-theme='dark'] .primary:hover {background:#278164}

:root[data-theme='dark'] :is(.topbar,.list-row,td,th,.modalhead,
  .admin-user-card-divider,.google-drawer-header) {
  border-color: var(--redes-border);
}

:root[data-theme='dark'] th {
  background: var(--redes-surface-alt);
  color: #bdc5c1;
}

:root[data-theme='dark'] tr:hover td,
:root[data-theme='dark'] .admin-user-card:hover,
:root[data-theme='dark'] .hub-card:hover,
:root[data-theme='dark'] .google-user-card:hover {
  background: #1b1e1c;
}

:root[data-theme='dark'] :is(.publication-status,.tag,.badge,.event) {
  background: #25302c;
  color: #baf3df;
  border-color: #42665a;
}

:root[data-theme='dark'] option {
  background: var(--redes-surface-raised);
  color: var(--redes-text);
}

/* Ficha completa: neutraliza a paleta clara local deste componente. */
:root[data-theme='dark'] .admin-detail-sheet {
  color: var(--redes-text);
}

:root[data-theme='dark'] .admin-detail-header-card {
  background: #303532;
  color: #ffffff;
  border-color: #68716c;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 12px 30px rgba(0,0,0,.24);
}

:root[data-theme='dark'] .admin-detail-name,
:root[data-theme='dark'] .admin-detail-header-meta,
:root[data-theme='dark'] .admin-detail-header-meta code {
  color: #ffffff;
}

:root[data-theme='dark'] .admin-id-pill {
  background: #232724;
  color: #ffffff;
  border-color: #7b8580;
}

:root[data-theme='dark'] .admin-id-pill:hover { background: #3a403c; }

:root[data-theme='dark'] .admin-detail-kpi,
:root[data-theme='dark'] .admin-detail-card {
  background: #242826;
  color: #ffffff;
  border-color: #565e59;
}

:root[data-theme='dark'] .admin-detail-kpi-val,
:root[data-theme='dark'] .admin-detail-card-title,
:root[data-theme='dark'] .admin-detail-item .val,
:root[data-theme='dark'] .admin-detail-item .val :is(b,strong,code),
:root[data-theme='dark'] .admin-detail-linked-agency,
:root[data-theme='dark'] .admin-detail-phone {
  color: #ffffff;
}

:root[data-theme='dark'] .admin-detail-kpi-lbl,
:root[data-theme='dark'] .admin-detail-item .lbl,
:root[data-theme='dark'] .admin-detail-item .val .muted {
  color: #c8cfcb;
}

:root[data-theme='dark'] .admin-detail-card-title,
:root[data-theme='dark'] .admin-detail-footer-actions {
  border-color: #565e59;
}

/* Neutralize legacy inline light surfaces and dark text literals. */
:root[data-theme='dark'] [style*='background: #fff'],
:root[data-theme='dark'] [style*='background:#fff'],
:root[data-theme='dark'] [style*='background: white'],
:root[data-theme='dark'] [style*='background:white'] {
  background: var(--redes-surface) !important;
  color: var(--redes-text) !important;
  border-color: var(--redes-border) !important;
}

:root[data-theme='dark'] [style*='color:#0f172a'],
:root[data-theme='dark'] [style*='color:#13332a'],
:root[data-theme='dark'] [style*='color:#173f37'],
:root[data-theme='dark'] [style*='color:#1f362b'],
:root[data-theme='dark'] [style*='color:#233d37'],
:root[data-theme='dark'] [style*='color:#334155'] {
  color: var(--redes-text) !important;
}

:root[data-theme='dark'] [style*='color:#495e54'],
:root[data-theme='dark'] [style*='color:#50655a'],
:root[data-theme='dark'] [style*='color:#556c5e'],
:root[data-theme='dark'] [style*='color:#627362'],
:root[data-theme='dark'] [style*='color:#627568'],
:root[data-theme='dark'] [style*='color:#7a8b7e'],
:root[data-theme='dark'] [style*='color:#7e8a78'] {
  color: var(--redes-text-secondary) !important;
}

/* Technical exception: QR contrast requires a solid white quiet zone. */
:root[data-theme='dark'] :is(.wa-qr-img,.qr-code,.qr-result img,.qr-result canvas) {
  background: #ffffff !important;
}

:root[data-theme='dark'] {
  scrollbar-color: #656b68 #171918;
}

/*
 * Canonical graphite pass.
 * The legacy application still contains light-theme literals and inline styles.
 * This final layer is intentionally loaded last and owns every structural surface
 * whenever the resolved theme is dark.
 */
:root[data-theme='dark'] :is(
  .workspace,.auth-page,.auth-form,.modalbody,.modalfoot,.tablewrap,
  .studio-writing,.studio-materials,.admin-page,.agency-page
) {
  color: var(--redes-text);
}

:root[data-theme='dark'] :is(
  .studio-bar,.pub-editor-tabs-bar,.publication-top-cover,.filter-hub,
  .access-history-wrap,.google-drawer-sheet,.google-drawer-header,
  .upload-dialog-box,.upload-preview-area,.stage-text-block,.pub-text-block,
  .schedule-card,.schedule-notes,.pre,.pwa-banner,footer
) {
  background: var(--redes-surface-alt) !important;
  color: var(--redes-text-secondary) !important;
  border-color: var(--redes-border) !important;
}

:root[data-theme='dark'] .studio-bar {
  background: rgba(30,33,31,.97) !important;
  box-shadow: 0 10px 24px rgba(0,0,0,.2);
}

:root[data-theme='dark'] :is(
  .kpi-card,.datebox,.day,.weekday,.column,.pub-text-menu-item,
  .schedule-date-badge,.schedule-network-chip,.day-count,.google-menu-icon,
  .admin-kpi-icon,.theme-preview,.filter-total-count,.card-date-badge
) {
  background: var(--redes-surface-raised) !important;
  color: var(--redes-text) !important;
  border-color: var(--redes-control-border) !important;
}

:root[data-theme='dark'] :is(
  .kpi-label,.access-history-table th,.pub-date-note,.schedule-notes,
  .upload-dialog-prompt small,.filter-total-count
) {
  color: var(--redes-text-secondary) !important;
}

:root[data-theme='dark'] :is(.kpi-value,.access-history-table td,.upload-dialog-prompt strong) {
  color: var(--redes-text) !important;
}

:root[data-theme='dark'] .access-history-table th {
  background: var(--redes-surface-emphasis) !important;
}

:root[data-theme='dark'] .access-history-table td {
  background: var(--redes-surface) !important;
  border-color: var(--redes-border) !important;
}

:root[data-theme='dark'] :is(
  .pub-meta-badge,.pub-ext-link,.pub-meta-views,.pub-meta-date,
  .filter-chip,.pub-text-badge,.publication-status,.badge,.tag,.tab-badge,
  .hub-suite-tag,.theme-current-badge
) {
  background: rgba(120,230,193,.11) !important;
  color: #b9f4df !important;
  border-color: rgba(120,230,193,.4) !important;
}

:root[data-theme='dark'] :is(
  .publication-open,.studio-media-preview,.publication-card-cover,
  .publication-cover-empty,.file-placeholder,.thumb-grid img
) {
  background-color: var(--redes-surface-raised) !important;
  color: var(--redes-text-secondary) !important;
  border-color: var(--redes-border) !important;
}

:root[data-theme='dark'] :is(.event,.event.event-publication,.event.event-pub-active) {
  background: var(--redes-surface-raised) !important;
  color: var(--redes-text) !important;
  border-color: var(--redes-control-border) !important;
}

:root[data-theme='dark'] :is(.error,.badge.rose,[style*='background:#fee2e2'],[style*='background: #fee2e2']) {
  background: rgba(239,68,68,.14) !important;
  color: #fca5a5 !important;
  border-color: rgba(252,165,165,.42) !important;
}

:root[data-theme='dark'] :is(.badge.warn,[style*='background:#fef3c7'],[style*='background: #fef3c7'],[style*='background:#fef9c3']) {
  background: rgba(245,158,11,.14) !important;
  color: #fcd34d !important;
  border-color: rgba(252,211,77,.4) !important;
}

:root[data-theme='dark'] :is(
  [style*='background:#dcfce7'],[style*='background: #dcfce7'],
  [style*='background:#ecfdf5'],[style*='background: #ecfdf5'],
  [style*='background:#f0fdf4'],[style*='background: #f0fdf4'],
  [style*='background:#d1fae5'],[style*='background:#d4edd7'],
  [style*='background:#eaf5ea'],[style*='background:#e9f2e7']
) {
  background: rgba(34,197,94,.14) !important;
  color: #86efac !important;
  border-color: rgba(134,239,172,.4) !important;
}

:root[data-theme='dark'] :is(
  [style*='background:#eff6ff'],[style*='background: #eff6ff'],
  [style*='background:#dbeafe'],[style*='background:#e0f2fe'],
  [style*='background:#eef2ff'],[style*='background:#e0e7ff'],
  [style*='background:#f3e8ff'],[style*='background:#f5f3ff']
) {
  background: rgba(96,165,250,.14) !important;
  color: #bfdbfe !important;
  border-color: rgba(147,197,253,.4) !important;
}

:root[data-theme='dark'] :is(
  [style*='background:#fff'],[style*='background: #fff'],
  [style*='background:white'],[style*='background: white'],
  [style*='background:#f8fafc'],[style*='background: #f8fafc'],
  [style*='background:#f8faf7'],[style*='background: #f8faf7'],
  [style*='background:#fafcf8'],[style*='background: #fafcf8'],
  [style*='background:#f9fafb'],[style*='background: #f9fafb'],
  [style*='background:#f1f5f9'],[style*='background: #f1f5f9']
) {
  background: var(--redes-surface-raised) !important;
  color: var(--redes-text) !important;
  border-color: var(--redes-control-border) !important;
}

:root[data-theme='dark'] dialog::backdrop {
  background: rgba(0,0,0,.76);
}

/* Superadmin: semantic pills must remain dark graphite in the dark theme. */
:root[data-theme='dark'] .admin-user-tip {
  background: var(--redes-surface-raised) !important;
  color: var(--redes-text-secondary) !important;
  border-color: var(--redes-control-border) !important;
}

:root[data-theme='dark'] .admin-user-count { color: var(--redes-text) !important; }

:root[data-theme='dark'] .admin-org-slug {
  background: var(--redes-surface-emphasis) !important;
  color: var(--redes-text-secondary) !important;
  border-color: var(--redes-control-border) !important;
}

:root[data-theme='dark'] :is(.plan-pill, .badge-client, .status-pill.status-active, .wa-badge.working) {
  background: rgba(34,197,94,.14) !important;
  color: #a7f3d0 !important;
  border-color: rgba(134,239,172,.45) !important;
}

:root[data-theme='dark'] .plan-free {
  background: var(--redes-surface-emphasis) !important;
  color: var(--redes-text-secondary) !important;
  border-color: var(--redes-control-border) !important;
}

:root[data-theme='dark'] :is(.plan-plus, .plan-starter, .badge-admin, .badge-agency) {
  background: rgba(59,130,246,.14) !important;
  color: #bfdbfe !important;
  border-color: rgba(147,197,253,.45) !important;
}

:root[data-theme='dark'] :is(.plan-enterprise, .wa-badge.qr-pending, .wa-badge.starting) {
  background: rgba(245,158,11,.14) !important;
  color: #fde68a !important;
  border-color: rgba(252,211,77,.45) !important;
}

:root[data-theme='dark'] :is(.status-pill.status-suspended, .wa-badge.stopped, .wa-badge.failed) {
  background: rgba(239,68,68,.14) !important;
  color: #fecaca !important;
  border-color: rgba(252,165,165,.45) !important;
}

:root[data-theme='dark'] .badge-superadmin {
  background: rgba(168,85,247,.14) !important;
  color: #e9d5ff !important;
  border-color: rgba(216,180,254,.45) !important;
}

:root[data-theme='dark'] :is(.admin-btn-action, .admin-btn-view, .admin-btn-plan, .admin-btn-role, .admin-btn-suspend, .admin-btn-activate) {
  background: var(--redes-surface-raised) !important;
  color: var(--redes-text) !important;
  border-color: var(--redes-control-border) !important;
}

:root[data-theme='dark'] :is(.admin-btn-action, .admin-btn-view, .admin-btn-plan, .admin-btn-role, .admin-btn-suspend, .admin-btn-activate):hover {
  background: var(--redes-surface-hover) !important;
  border-color: var(--redes-focus) !important;
}

/* Account avatar: explicit high-contrast pair for each resolved theme. */
.account-profile-avatar {
  width: 46px;
  height: 46px;
  font-size: 18px;
  font-weight: 800;
  border: 1px solid transparent;
}

:root:not([data-theme='dark']) .account-profile-avatar-superadmin,
:root[data-theme='light'] .account-profile-avatar-superadmin {
  background: #5b21b6;
  color: #ffffff;
  border-color: #4c1d95;
  box-shadow: 0 0 0 3px #ede9fe;
}

:root:not([data-theme='dark']) .account-profile-avatar-user,
:root[data-theme='light'] .account-profile-avatar-user {
  background: #16634f;
  color: #ffffff;
  border-color: #104b3c;
  box-shadow: 0 0 0 3px #d9eee7;
}

:root[data-theme='dark'] .account-profile-avatar-superadmin {
  background: #c4b5fd;
  color: #20113a;
  border-color: #ddd6fe;
  box-shadow: 0 0 0 3px rgba(196,181,253,.20);
}

:root[data-theme='dark'] .account-profile-avatar-user {
  background: #6ee7c0;
  color: #052e22;
  border-color: #a7f3d0;
  box-shadow: 0 0 0 3px rgba(110,231,192,.18);
}
