/* =============================================================================
   GSCC Theme application layer
   Maps shared tokens onto layout chrome, cards, forms, tables, alerts, footer.
   Requires: gscc-design-tokens.css + data-gscc-theme on <html>
   ============================================================================= */

/* ----- Body / canvas ----- */
/* Admin/auth get canvas fill; public homepage keeps mystyle section backgrounds */
html[data-gscc-theme] body.admin-dash-page,
html[data-gscc-theme] body.main-body,
html[data-gscc-theme] body.GSCC-page {
  background-color: var(--gscc-color-bg) !important;
  color: var(--gscc-color-text);
}

html[data-gscc-theme] body.home-page {
  color: var(--gscc-color-text);
}

html[data-gscc-theme] .main-content,
html[data-gscc-theme] .app-content,
html[data-gscc-theme] .gscc-main {
  background-color: var(--gscc-color-bg);
  color: var(--gscc-color-text);
}

/* Do not paint #main-content / .custom-index / .page — public heroes and bands rely on transparent stacking */

/* ----- Cards / surfaces ----- */
/* Scoped: avoid flattening public counter/process/scheme cards styled in mystyle */
html[data-gscc-theme] .gscc-card,
html[data-gscc-theme] .al-card,
html[data-gscc-theme] .modal-content,
html[data-gscc-theme] .dropdown-menu,
html[data-gscc-theme] .popover,
html[data-gscc-theme] .select2-dropdown,
html[data-gscc-theme] .bank-list-card,
html[data-gscc-theme] .bank-list-item,
html[data-gscc-theme] .svn-card,
html[data-gscc-theme] .svn-filter-card,
html[data-gscc-theme] .admin-dash-page .card,
html[data-gscc-theme] .GSCC-page .card,
html[data-gscc-theme] .main-content > .card,
html[data-gscc-theme] .app-content .card {
  background-color: var(--gscc-color-surface) !important;
  color: var(--gscc-color-text);
  border-color: var(--gscc-color-border) !important;
}

html[data-gscc-theme] .card-header,
html[data-gscc-theme] .gscc-card-header,
html[data-gscc-theme] .modal-footer,
html[data-gscc-theme] .gp-bar {
  background-color: var(--gscc-color-bg-subtle) !important;
  border-color: var(--gscc-color-border-subtle) !important;
  color: var(--gscc-color-text);
}

/* ----- Forms ----- */
html[data-gscc-theme] .form-control,
html[data-gscc-theme] .form-select,
html[data-gscc-theme] select.form-control,
html[data-gscc-theme] textarea.form-control,
html[data-gscc-theme] .select2-container--default .select2-selection--single,
html[data-gscc-theme] .select2-container--default .select2-selection--multiple {
  background-color: var(--gscc-color-surface) !important;
  color: var(--gscc-color-text) !important;
  border-color: var(--gscc-color-border) !important;
}

html[data-gscc-theme] .form-control::placeholder {
  color: var(--gscc-color-muted);
  opacity: 1;
}

html[data-gscc-theme] .form-control:focus,
html[data-gscc-theme] .form-select:focus {
  border-color: var(--gscc-color-primary) !important;
  box-shadow: var(--gscc-shadow-focus) !important;
}

html[data-gscc-theme] .input-group-text {
  background: var(--gscc-color-bg-subtle) !important;
  color: var(--gscc-color-muted) !important;
  border-color: var(--gscc-color-border) !important;
}

html[data-gscc-theme] .invalid-feedback,
html[data-gscc-theme] .field-validation-error,
html[data-gscc-theme] .text-danger {
  color: var(--gscc-color-danger) !important;
}

html[data-gscc-theme] .text-muted,
html[data-gscc-theme] .gscc-muted {
  color: var(--gscc-color-muted) !important;
}

/* ----- Tables ----- */
html[data-gscc-theme] .table,
html[data-gscc-theme] .al-table,
html[data-gscc-theme] .institute-public-table {
  color: var(--gscc-color-text);
  background-color: var(--gscc-color-surface);
}

html[data-gscc-theme] .table > :not(caption) > * > * {
  border-color: var(--gscc-color-border-subtle);
  background-color: transparent;
  color: inherit;
}

html[data-gscc-theme] .al-table thead th,
html[data-gscc-theme] .table.gscc-table thead th,
html[data-gscc-theme] .institute-public-table tr.row0 th,
html[data-gscc-theme] .svn-table thead th {
  background: var(--gscc-color-secondary) !important;
  color: var(--gscc-color-text-inverse) !important;
}

html[data-gscc-theme="dark"] .al-table thead th,
html[data-gscc-theme="dark"] .svn-table thead th,
html[data-gscc-theme="dark"] .institute-public-table tr.row0 th {
  background: #0D1F18 !important;
  color: var(--gscc-color-text) !important;
}

html[data-gscc-theme] .table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: var(--gscc-color-bg-subtle);
  color: var(--gscc-color-text);
}

html[data-gscc-theme] .table-hover > tbody > tr:hover > * {
  background-color: var(--gscc-color-primary-soft) !important;
  color: var(--gscc-color-text);
}

/* ----- Public header / footer ----- */
/* Do not flatten branded chrome: keep mystyle middle-header / dark footer. */
html[data-gscc-theme] .top-header {
  background-color: var(--gscc-color-surface);
  color: var(--gscc-color-text);
  border-color: var(--gscc-color-border);
}

html[data-gscc-theme] .middle-header {
  /* Preserve white brand bar; only sync text tokens when needed */
  color: var(--gscc-color-text);
}

html[data-gscc-theme] .middle-header .logo-text .nav-link,
html[data-gscc-theme] .middle-header .government {
  color: var(--gscc-color-text) !important;
}
/* Keep brand green department title (mystyle #006F3A) */
html[data-gscc-theme] .middle-header .department,
html[data-gscc-theme] span.logo-text a.department {
  color: var(--gscc-color-primary) !important;
}

/* Public footer stays dark brand (mystyle). Only retint for dark/HC themes. */
html[data-gscc-theme] footer.footer-section {
  background: linear-gradient(135deg, #051a11 0%, #020b07 100%) !important;
  color: rgba(255, 255, 255, 0.75) !important;
  border-top: 4px solid #ea5e24 !important;
}

html[data-gscc-theme] footer.footer-section .footer-title,
html[data-gscc-theme] footer.footer-section .footer-links-list li a:hover {
  color: #ffffff !important;
}

html[data-gscc-theme] footer.footer-section .footer-links-list li a,
html[data-gscc-theme] footer.footer-section .footer-location-text,
html[data-gscc-theme] footer.footer-section .copyright-text,
html[data-gscc-theme] footer.footer-section .design-credit-text {
  color: #a3c4b5 !important;
}

html[data-gscc-theme] footer.footer-section .designer-link {
  color: #ea5e24 !important;
}

/* Admin / auth footers (not the public brand footer) */
html[data-gscc-theme] .admin-dash-page .main-footer,
html[data-gscc-theme] .admin-dash-page footer.footer {
  background: var(--gscc-color-bg) !important;
  color: var(--gscc-color-muted);
  border-top: 1px solid var(--gscc-color-border);
}

html[data-gscc-theme] .gscc-mobile-cta {
  background: var(--gscc-color-surface);
  border-bottom-color: var(--gscc-color-border);
}

/* Keep brand green nav bars as primary (inverse text) */
html[data-gscc-theme] .bg-green,
html[data-gscc-theme] .bottom-header,
html[data-gscc-theme] .mobile-sec.mobile-menu {
  background-color: var(--gscc-color-primary) !important;
  color: var(--gscc-color-text-inverse);
}

html[data-gscc-theme="dark"] .bg-green,
html[data-gscc-theme="dark"] .bottom-header,
html[data-gscc-theme="dark"] .mobile-sec.mobile-menu {
  background-color: #0D1F18 !important;
}

/* Inverse text only on green chrome / dark sidebars — not all side-menu labels */
html[data-gscc-theme] .bottom-header .nav-link,
html[data-gscc-theme] .bottom-header .side-menu__label,
html[data-gscc-theme] .bottom-header .side-menu__item,
html[data-gscc-theme] .mobile-menu .header-icons,
html[data-gscc-theme] .mobile-menu-sec .app-sidebar .side-menu__label,
html[data-gscc-theme] .mobile-menu-sec .app-sidebar .side-menu__item,
html[data-gscc-theme] .app-sidebar .side-menu__label,
html[data-gscc-theme] .app-sidebar .side-menu__item {
  color: var(--gscc-color-text-inverse) !important;
}

html[data-gscc-theme="dark"] .app-sidebar,
html[data-gscc-theme="dark"] .mobile-menu-sec .app-sidebar {
  background: #0D1F18 !important;
  border-color: var(--gscc-color-border);
}

/* Admin sticky header */
html[data-gscc-theme] .admin-dash-page .main-header.side-header {
  background: var(--gscc-color-surface) !important;
  border-bottom-color: var(--gscc-color-border) !important;
}

html[data-gscc-theme] .admin-dash-page .gov-brand-scheme,
html[data-gscc-theme] .admin-dash-page .gov-user-name {
  color: var(--gscc-color-text) !important;
}

html[data-gscc-theme] .admin-dash-page .gov-brand-dept,
html[data-gscc-theme] .admin-dash-page .gov-user-role {
  color: var(--gscc-color-muted) !important;
}

/* ----- Alerts / badges / tooltips ----- */
html[data-gscc-theme] .alert-success {
  background: var(--gscc-color-success-soft) !important;
  color: var(--gscc-color-success) !important;
  border-color: var(--gscc-color-success) !important;
}
html[data-gscc-theme] .alert-danger {
  background: var(--gscc-color-danger-soft) !important;
  color: var(--gscc-color-danger) !important;
  border-color: var(--gscc-color-danger) !important;
}
html[data-gscc-theme] .alert-warning {
  background: var(--gscc-color-warning-soft) !important;
  color: var(--gscc-color-warning) !important;
  border-color: var(--gscc-color-warning) !important;
}
html[data-gscc-theme] .alert-info {
  background: var(--gscc-color-info-soft) !important;
  color: var(--gscc-color-info) !important;
  border-color: var(--gscc-color-info) !important;
}

html[data-gscc-theme] .tooltip .tooltip-inner {
  background: var(--gscc-color-secondary);
  color: var(--gscc-color-text-inverse);
}

/* ----- Loader -----
   Keep a dim scrim and a solid card. A page-coloured overlay hid the spinner
   when a menu link started the next page. */
html[data-gscc-theme] #global-loader {
  background: rgba(15, 36, 28, 0.55) !important;
  color: #17212B;
}
html[data-gscc-theme] #global-loader .loader-content {
  background: #FFFFFF !important;
  border: 1px solid #DCE3E7 !important;
  box-shadow: 0 18px 48px rgba(15, 36, 28, 0.28) !important;
}
html[data-gscc-theme] .loader-title {
  color: var(--gscc-color-primary) !important;
  text-shadow: none !important;
}
html[data-gscc-theme] .loader-subtitle,
html[data-gscc-theme] .loader-text {
  color: #667085 !important;
  text-shadow: none !important;
}
html[data-gscc-theme] #global-loader .loader-spinner {
  border-color: rgba(var(--bs-primary-rgb),  0.18) !important;
  border-top-color: var(--gscc-color-primary) !important;
}
html[data-gscc-theme] #global-loader .loader-spinner-inner {
  border-top-color: var(--gscc-color-primary) !important;
}

/* ----- Empty / placeholder states ----- */
html[data-gscc-theme] .empty-state,
html[data-gscc-theme] .no-data,
html[data-gscc-theme] .text-center.text-muted {
  color: var(--gscc-color-muted) !important;
}

/* ----- Theme control UI ----- */
.gscc-theme-control {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0.25rem;
  position: relative;
}
.gscc-theme-control label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.gscc-theme-control select {
  min-height: 32px;
  max-width: 9.5rem;
  padding: 0.2rem 1.6rem 0.2rem 0.45rem;
  font-size: var(--gscc-fs-xs, 11px);
  font-weight: var(--gscc-fw-semibold, 600);
  color: var(--gscc-color-text);
  background-color: var(--gscc-color-surface);
  border: 1px solid var(--gscc-color-border);
  border-radius: var(--gscc-radius-sm, 4px);
  cursor: pointer;
}
.gscc-theme-control select:focus-visible {
  outline: 2px solid var(--gscc-color-accent);
  outline-offset: 2px;
}

.gscc-theme-control--compact select {
  max-width: 7.5rem;
  font-size: 10px;
}

.home-page .top-header .gscc-theme-control select,
.home-page .main-nav .gscc-theme-control select {
  border-color: var(--gscc-color-border);
}

.admin-dash-page .gscc-theme-control {
  margin-right: 0.5rem;
}

/* High contrast: stronger borders & focus everywhere */
html[data-gscc-theme="high-contrast"] .card,
html[data-gscc-theme="high-contrast"] .form-control,
html[data-gscc-theme="high-contrast"] .form-select,
html[data-gscc-theme="high-contrast"] .btn,
html[data-gscc-theme="high-contrast"] .table,
html[data-gscc-theme="high-contrast"] .modal-content {
  border-width: 2px !important;
  border-color: #000 !important;
}

html[data-gscc-theme="high-contrast"] a:focus-visible,
html[data-gscc-theme="high-contrast"] button:focus-visible,
html[data-gscc-theme="high-contrast"] .form-control:focus-visible,
html[data-gscc-theme="high-contrast"] .btn:focus-visible {
  outline: 3px solid #000 !important;
  outline-offset: 2px !important;
  box-shadow: none !important;
}

html[data-gscc-theme="high-contrast"] .btn-primary {
  background: #003D26 !important;
  color: #fff !important;
  border-color: #000 !important;
}

/* Auth shells */
.gscc-auth-theme-bar {
  position: relative;
  z-index: 5;
  background: transparent;
}
html[data-gscc-theme] .main-signin-wrapper,
html[data-gscc-theme] .container-login100,
html[data-gscc-theme] .wrap-login100,
html[data-gscc-theme] .card-login,
html[data-gscc-theme] .page-login .card,
html[data-gscc-theme] .sign-up-body.card {
  background-color: var(--gscc-color-surface) !important;
  color: var(--gscc-color-text);
  border-color: var(--gscc-color-border);
}
html[data-gscc-theme] .page-login,
html[data-gscc-theme] body.login-img {
  background-color: var(--gscc-color-bg) !important;
  color: var(--gscc-color-text);
}
html[data-gscc-theme] .main-heading,
html[data-gscc-theme] .main-signin-header h2 {
  color: var(--gscc-color-text) !important;
}

/* Charts: leave canvas as-is; container surfaces follow theme */
html[data-gscc-theme] .chart-container,
html[data-gscc-theme] .cw {
  background: var(--gscc-color-surface);
  border-radius: var(--gscc-radius-md);
}

/* Prefer system without flash when preference is system — handled in JS */
@media (prefers-reduced-motion: reduce) {
  html[data-gscc-theme] * {
    transition: none !important;
  }
}
