/*
 * Dark-mode rules for HWI's own app-wide components (as opposed to Bootstrap/plugins, see theme-bootstrap3.css).
 * Scoped to :root[data-theme="dark"], so light mode is untouched. Fold these into the components' own stylesheets
 * (using the --ws-* tokens) as those stylesheets get migrated, and delete the rule from here.
 */

/* ---------- Toast messages (messagemanager.css) ---------- */
:root[data-theme="dark"] .message-container .message {
  background: var(--ws-surface-raised, var(--ws-surface));
  color: var(--ws-text);
  box-shadow: var(--ws-shadow-lg);
}
:root[data-theme="dark"] .message-container .message.success_message { background: #12301f; color: #c3f3d3; }
:root[data-theme="dark"] .message-container .message.info_message    { background: #12293f; color: #c6e1fa; }
:root[data-theme="dark"] .message-container .message.warning_message { background: #3a2c0d; color: #fae6b3; }
:root[data-theme="dark"] .message-container .message.error_message   { background: #3d1717; color: #fbc9c9; }
:root[data-theme="dark"] .message-container .message .msg-close { color: inherit; }

/* ---------- Handsontable (data grids) ---------- */
:root[data-theme="dark"] .handsontable { color: var(--ws-text); }
:root[data-theme="dark"] .handsontable tr,
:root[data-theme="dark"] .handsontable tbody tr { background-color: var(--ws-surface); }
:root[data-theme="dark"] .handsontable td,
:root[data-theme="dark"] .handsontable .htCore td { background-color: var(--ws-surface); color: var(--ws-text); border-color: var(--ws-border); }
:root[data-theme="dark"] .handsontable th,
:root[data-theme="dark"] .handsontable .htCore th { background-color: var(--ws-surface-2); color: var(--ws-text-muted); border-color: var(--ws-border); }
:root[data-theme="dark"] .handsontable td.htDimmed { color: var(--ws-text-muted); }
:root[data-theme="dark"] .handsontable tr:first-child th,
:root[data-theme="dark"] .handsontable tr:first-child td { border-top-color: var(--ws-border); }
:root[data-theme="dark"] .handsontable .wtBorder.current { background-color: var(--ws-primary) !important; }
:root[data-theme="dark"] .handsontable td.area:before { background: var(--ws-primary); }
:root[data-theme="dark"] .handsontableInput { background: var(--ws-surface-2); color: var(--ws-text); box-shadow: 0 0 0 2px var(--ws-primary) inset; }
:root[data-theme="dark"] .handsontable .htDropdownMenu,
:root[data-theme="dark"] .htContextMenu .ht_master .wtHolder,
:root[data-theme="dark"] .htContextMenu table.htCore { background: var(--ws-surface-raised, var(--ws-surface)); }

/* ---------- Ace code editor (default "textmate" theme classes) ---------- */
:root[data-theme="dark"] .ace_editor,
:root[data-theme="dark"] .ace-tm { background-color: #0f1722; color: #d4dde8; }
:root[data-theme="dark"] .ace-tm .ace_gutter { background: var(--ws-surface); color: var(--ws-text-muted); }
:root[data-theme="dark"] .ace-tm .ace_gutter-active-line { background-color: var(--ws-hover); }
:root[data-theme="dark"] .ace-tm .ace_print-margin { width: 1px; background: var(--ws-border); }
:root[data-theme="dark"] .ace-tm .ace_cursor { color: var(--ws-text); }
:root[data-theme="dark"] .ace-tm .ace_marker-layer .ace_selection { background: #26456b; }
:root[data-theme="dark"] .ace-tm .ace_marker-layer .ace_active-line { background: var(--ws-surface); }
:root[data-theme="dark"] .ace-tm .ace_marker-layer .ace_selected-word { border: 1px solid #3a5f8c; background: transparent; }
:root[data-theme="dark"] .ace-tm .ace_invisible { color: var(--ws-border-strong); }
:root[data-theme="dark"] .ace-tm .ace_keyword,
:root[data-theme="dark"] .ace-tm .ace_storage { color: #c792ea; }
:root[data-theme="dark"] .ace-tm .ace_string { color: #9ece6a; }
:root[data-theme="dark"] .ace-tm .ace_constant,
:root[data-theme="dark"] .ace-tm .ace_constant.ace_numeric,
:root[data-theme="dark"] .ace-tm .ace_constant.ace_language { color: #ff9e64; }
:root[data-theme="dark"] .ace-tm .ace_comment { color: var(--ws-text-subtle); font-style: italic; }
:root[data-theme="dark"] .ace-tm .ace_variable,
:root[data-theme="dark"] .ace-tm .ace_identifier { color: #7dcfff; }
:root[data-theme="dark"] .ace-tm .ace_support.ace_function,
:root[data-theme="dark"] .ace-tm .ace_entity.ace_name.ace_function { color: #7aa2f7; }
:root[data-theme="dark"] .ace_tooltip,
:root[data-theme="dark"] .ace_autocomplete { background: var(--ws-surface-raised, var(--ws-surface)); color: var(--ws-text); border-color: var(--ws-border-strong); }

/* ---------- Login, registration and other .login-container pages (style.css) ---------- */
:root[data-theme="dark"] .login-container {
  background: var(--ws-surface);
  color: var(--ws-text);
  border: 1px solid var(--ws-border);
  box-shadow: var(--ws-shadow-lg);
}
:root[data-theme="dark"] .login-container h1,
:root[data-theme="dark"] .login-container h2,
:root[data-theme="dark"] .login-container h3,
:root[data-theme="dark"] .login-container label { color: var(--ws-text); }
:root[data-theme="dark"] .login-container input[type="text"],
:root[data-theme="dark"] .login-container input[type="password"],
:root[data-theme="dark"] .login-container input[type="email"],
:root[data-theme="dark"] .login-container select {
  background: var(--ws-surface-2);
  color: var(--ws-text);
  border: 1px solid var(--ws-border);
}
:root[data-theme="dark"] .login-container input::placeholder { color: var(--ws-text-subtle); }
:root[data-theme="dark"] .login-container .message,
:root[data-theme="dark"] .login-container .form .message { color: var(--ws-text-muted); }
:root[data-theme="dark"] .login-container .form .message a { color: var(--ws-primary); }

/* ---------- Project tiles (projects page, favourites and recent) and the list view (project.css) ---------- */
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .big-box-button {
  background: var(--ws-surface);
  color: var(--ws-text);
  border-color: var(--ws-border);
  box-shadow: var(--ws-shadow);
}
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .big-box-button:hover,
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .big-box-button:focus-visible,
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .big-box-button:has(:focus-visible) {
  background: var(--ws-surface-raised, var(--ws-surface));
  border-color: var(--ws-primary);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .5);
}
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .head,
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .head .grid-item-name { color: var(--ws-text); }
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .summary { color: var(--ws-text-muted); }
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .summary.contents-count { background: var(--ws-surface-2); color: var(--ws-text-muted); }
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .card-icon-row .fa,
:root[data-theme="dark"] :is(#projectgrid, .project-card-grid) .prj-header-col .fa { color: var(--ws-text-muted); }
:root[data-theme="dark"] .project-card-grid .far.fa-star { color: var(--ws-text-subtle); }

:root[data-theme="dark"] #projectstable-list { border-color: var(--ws-border); }
:root[data-theme="dark"] #projectstable-list thead th { background: var(--ws-surface-2); color: var(--ws-text-muted); border-bottom-color: var(--ws-border-strong); }
:root[data-theme="dark"] #projectstable-list tbody tr:hover { background-color: var(--ws-hover); }
:root[data-theme="dark"] #projectstable-list td.description-cell.empty { color: var(--ws-text-subtle); }

/* ---------- Projects toolbar: grid/list switch, sort label ---------- */
/* project.css styles these with :is(#project-grid, #project-list) (an ID), so the selector must mirror it */
:root[data-theme="dark"] :is(#project-grid, #project-list) .btn-default.active,
:root[data-theme="dark"] :is(#project-grid, #project-list) .btn-default.active:hover,
:root[data-theme="dark"] :is(#project-grid, #project-list) .btn-default.active:focus {
  background-color: var(--ws-primary-soft);
  background-image: none;
  border-color: var(--ws-primary);
  color: var(--ws-primary);
}
:root[data-theme="dark"] .toolbar-sort-label { color: var(--ws-text-muted); }

/* ---------- Jobs page: the "auto refresh"-style toggle ---------- */
:root[data-theme="dark"] .jl-toggle-slider { background: var(--ws-border-strong); }
:root[data-theme="dark"] .jl-toggle-label input:checked + .jl-toggle-slider { background: #3d9a41; }
:root[data-theme="dark"] .jl-toggle-text { color: var(--ws-text-muted); }

/* ---------- Template editor: ghost icon buttons ---------- */
:root[data-theme="dark"] .btn.edit,
:root[data-theme="dark"] .type-actions .btn,
:root[data-theme="dark"] .toggle-type-attrs { color: var(--ws-text-muted); }
:root[data-theme="dark"] .typeattr-list-item .btn.edit:hover { background: var(--ws-hover); }

/* ---------- Admin index (templates/admin/index.html) ---------- */
:root[data-theme="dark"] table.datatable tr.even { background: var(--ws-surface-2); }
:root[data-theme="dark"] table.datatable tr.odd { background: var(--ws-surface); }
:root[data-theme="dark"] .tablerow li:nth-child(even) { background: var(--ws-surface-2); }
:root[data-theme="dark"] .tablerow li:nth-child(odd) { background: var(--ws-surface); }
:root[data-theme="dark"] table.datatable thead { background: var(--ws-surface-2); color: var(--ws-text-muted); }
:root[data-theme="dark"] table.datatable td { border-color: var(--ws-border); color: var(--ws-text); }
:root[data-theme="dark"] table.datatable th { color: var(--ws-text-muted); }

/* ---------- Main navbar on the template editor pages: their stylesheet forces a translucent white with !important ---------- */
:root[data-theme="dark"] #main_menu.navbar {
  background: rgba(22, 32, 46, .85) !important;
  border-color: var(--ws-border) !important;
}

/* ---------- Interactive states (hover, focus, active, selected, open) that were painted with a light background ----------
   Derived mechanically from the light rules they override (same selector, so the specificity matches; !important where
   the original has it). Fold each into its own stylesheet as that stylesheet moves onto the --ws-* tokens. */
/* dashboards/static/dashboards/css/dashboard.css */
:root[data-theme="dark"] .dash-filter-btn:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .dash-action-btn:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .dash-kill-btn:hover { background: rgba(248, 113, 113, .16); }
:root[data-theme="dark"] .dash-table tbody tr:hover { background: var(--ws-hover); }
/* job_manager/static/job_manager/css/job.css */
:root[data-theme="dark"] .jd-action-btn:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .jd-action-btn.jd-kill-btn:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .jd-action-btn.jd-delete-btn:hover { background: rgba(248, 113, 113, .16); }
/* job_manager/static/job_manager/css/jobs.css */
:root[data-theme="dark"] #jobtable tbody tr:hover td { background: var(--ws-hover) !important; }
:root[data-theme="dark"] .jl-action-btn:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .jl-stop-btn:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .jl-delete-btn:hover { background: rgba(248, 113, 113, .16); }
/* rule_manager/static/rule_manager/css/rules-modern.css */
:root[data-theme="dark"] #rule-manager .rule-delete:hover { background: rgba(248, 113, 113, .16); }
/* template_manager/static/template_manager/css/template-modern.css */
:root[data-theme="dark"] .dropdown-menu > li > a.text-danger:hover { background: rgba(248, 113, 113, .16) !important; }
:root[data-theme="dark"] .typeattr-list-item .btn.edit:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .typeattr-list-item .btn.delete:hover { background: rgba(248, 113, 113, .16); }
/* attributes.css */
:root[data-theme="dark"] .section-heading {
  background: var(--ws-surface-2);
  color: var(--ws-text);
  border-bottom-color: var(--ws-border);
}
:root[data-theme="dark"] .subsection-heading {
  background: var(--ws-surface);
  color: var(--ws-text-muted);
  border-bottom-color: var(--ws-border);
}
:root[data-theme="dark"] .attr-label { color: var(--ws-text); }
:root[data-theme="dark"] .attribute .novalue { color: var(--ws-text-muted); }
:root[data-theme="dark"] .section-heading:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .subsection-heading:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .ra-icon-btn:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .ra-icon-btn:focus { background: var(--ws-hover); }
/* bookmarks.css */
:root[data-theme="dark"] #bookmark-list .bookmark-link:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #bookmark-list .bookmark-link:focus { background: var(--ws-hover); }
:root[data-theme="dark"] #recently-accessed-list .recent-link:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #recently-accessed-list .recent-link:focus { background: var(--ws-hover); }
:root[data-theme="dark"] #recently-modified-list .recent-link:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #recently-modified-list .recent-link:focus { background: var(--ws-hover); }
/* network/contextmenu.css */
:root[data-theme="dark"] #context-group-add-list li:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #context-group-rem-list li:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .context-menu li:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #context-menu li:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .context-menu li.divider:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #context-menu li.divider:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .context-menu li.context-menu-item-disabled:hover { background: var(--ws-surface); }
:root[data-theme="dark"] #context-menu li.context-menu-item-disabled:hover { background: var(--ws-surface); }
:root[data-theme="dark"] .context-menu li.context-menu-item-danger.context-menu-item-disabled:hover { background: var(--ws-surface); }
:root[data-theme="dark"] #context-menu li.context-menu-item-danger.context-menu-item-disabled:hover { background: var(--ws-surface); }
/* network/network.css */
:root[data-theme="dark"] .conditional-style-legend .legend-settings-btn:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .conditional-style-legend .legend-refresh-btn:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .conditional-style-legend .legend-toggle-styling-btn:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] #network-tabs > li.active > a { background: var(--ws-surface); }
:root[data-theme="dark"] #network-tabs > li.active > a:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #network-tabs > li.active > a:focus { background: var(--ws-surface); }
:root[data-theme="dark"] tbody tr:hover { background: var(--ws-hover) !important; }
:root[data-theme="dark"] .fix-dataframe-headers-menu li:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .dataframe-data-menu li:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .leaflet-bar a:not(.leaflet-disabled) { background: var(--ws-surface) !important; }
:root[data-theme="dark"] .leaflet-bar a:not(.leaflet-disabled):hover { background: var(--ws-hover) !important; }
:root[data-theme="dark"] .map-controls-group .map-layers-icon-btn:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .hwi-control-bar .map-controls-toggle:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #view-toggle .view-toggle-option:hover { background: var(--ws-hover); }
/* network/right-sidebar.css */
:root[data-theme="dark"] #right_sidebar_icons a:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #right_sidebar_icons a.active { background: var(--ws-primary-soft); }
/* network/scenario.css */
:root[data-theme="dark"] #comparison-content .header:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #scenario-options .scenario-menu-item:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .hydra-tree-node-row:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .hydra-tree-add-child:hover { background: var(--ws-primary-soft); }
/* network/sidebar.css */
:root[data-theme="dark"] .options .filterheading.toggle:hover { background: var(--ws-hover); }
:root[data-theme="dark"] .linkbutton.active { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .linkbutton.active:hover { background: var(--ws-primary-soft); }
:root[data-theme="dark"] .linkbutton.active:focus { background: var(--ws-primary-soft); }
/* project-explorer.css */
:root[data-theme="dark"] .pe-selectable:hover { background: var(--ws-primary-soft); }
/* project.css */
:root[data-theme="dark"] .ownership-filter-option:hover { background: var(--ws-hover); }
:root[data-theme="dark"] #projectstable-list tbody tr:hover { background: var(--ws-hover); }
:root[data-theme="dark"] :is(#project-grid { background: var(--ws-primary-soft); }
:root[data-theme="dark"] #project-list) .btn-default.active { background: var(--ws-primary-soft); }
:root[data-theme="dark"] #project-list) .btn-default:active { background: var(--ws-primary-soft); }
/* style.css */
:root[data-theme="dark"] .tabs .tab.selected { background: var(--ws-hover); }

/* ---------- Attribute name hover tooltips (attributes.css, ResourceAttributeManager.js) ---------- */
/* .ra-tooltip is the info table; #hover-attr-description is the template description. */
:root[data-theme="dark"] .ra-tooltip,
:root[data-theme="dark"] #hover-attr-description,
:root[data-theme="dark"] #hover-unit-description {
  background: var(--ws-surface-raised, var(--ws-surface-2));
  color: var(--ws-text);
  border: 1px solid var(--ws-border-strong);
  box-shadow: var(--ws-shadow-lg);
}
:root[data-theme="dark"] .ra-tooltip table,
:root[data-theme="dark"] .ra-tooltip table td { background: transparent; color: var(--ws-text); border-color: var(--ws-border); }
