/* Light uses the original palette and explicitly resets native browser controls. */
@media screen {
  html[data-theme="light"] {
    color-scheme: light;
    color-scheme: only light;
    --cv-bg: #fff; --cv-panel: #fff; --cv-raised: #f5f5f5;
    --cv-text: #333; --cv-muted: #777; --cv-border: #ddd;
    color: #333;
    background: url('../img/mybg.png') #fff;
  }
  html[data-theme="light"] body,
  html[data-theme="light"] #extr-page,
  html[data-theme="light"] .page-ns { background-color: #fff; color: #333; }
  html[data-theme="light"] #extr-page #main { background-color: #fff; color: #333; }
  html[data-theme="light"] .panel,
  html[data-theme="light"] .modal-content,
  html[data-theme="light"] .dropdown-menu,
  html[data-theme="light"] .popover,
  html[data-theme="light"] .jarviswidget > div,
  html[data-theme="light"] .smart-form fieldset {
    background-color: #fff; color: #333;
  }
  html[data-theme="light"] .well { background-color: #fbfbfb; color: #333; }
  html[data-theme="light"] .form-control {
    background-color: #fff; color: #555; border-color: #ccc;
  }
  html[data-theme="light"] .smart-form .input input,
  html[data-theme="light"] .smart-form .select select,
  html[data-theme="light"] .smart-form .textarea textarea {
    background-color: #fff; color: #404040; border-color: #bdbdbd;
  }
  html[data-theme="light"] .form-control[disabled],
  html[data-theme="light"] .form-control[readonly],
  html[data-theme="light"] fieldset[disabled] .form-control { background-color: #eee; }
  html[data-theme="light"] .form-control:focus { border-color: #66afe9; }
  html[data-theme="light"] .smart-form .input input:focus,
  html[data-theme="light"] .smart-form .select select:focus,
  html[data-theme="light"] .smart-form .textarea textarea:focus { border-color: #3276b1; }
  html[data-theme="light"] .smart-form .state-error input,
  html[data-theme="light"] .smart-form .state-error select,
  html[data-theme="light"] .smart-form .state-error textarea { background-color: #fff0f0; border-color: #a90329; }
  html[data-theme="light"] .smart-form .state-success input,
  html[data-theme="light"] .smart-form .state-success select,
  html[data-theme="light"] .smart-form .state-success textarea { background-color: #f0fff0; border-color: #7dc27d; }
}
.cv-theme-toggle {
  position: fixed; bottom: 12px; left: 12px; z-index: 1040;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 8px 12px;
  border: 1px solid #aaa; border-radius: 20px;
  background: #fff; color: #333; box-shadow: 0 2px 8px rgba(0,0,0,.2);
  font: inherit; cursor: pointer;
}
.cv-theme-toggle:focus { outline: 3px solid #3276b1; outline-offset: 3px; }
@media screen and (max-width: 600px) {
  .cv-theme-toggle span { display: none; }
  .cv-theme-toggle { justify-content: center; width: 40px; padding: 8px; }
}
@media screen {
  html[data-theme="dark"] {
    color-scheme: dark;
    --cv-bg: #151b24; --cv-panel: #202936; --cv-raised: #2a3545;
    --cv-text: #e4eaf2; --cv-muted: #b5c1d1; --cv-border: #526176;
    background: var(--cv-bg); color: var(--cv-text);
  }
  html[data-theme="dark"] body,
  html[data-theme="dark"] #extr-page,
  html[data-theme="dark"] #main,
  html[data-theme="dark"] .page-ns,
  html[data-theme="dark"] .bg-container {
    background: var(--cv-bg); color: var(--cv-text);
  }
  html[data-theme="dark"] .bg_custom,
  html[data-theme="dark"] .bg_custom2 { background: var(--cv-bg) !important; }
  html[data-theme="dark"] #header,
  html[data-theme="dark"] #ribbon,
  html[data-theme="dark"] .page-footer,
  html[data-theme="dark"] .panel,
  html[data-theme="dark"] .panel-heading,
  html[data-theme="dark"] .well,
  html[data-theme="dark"] .modal-content,
  html[data-theme="dark"] .modal-header,
  html[data-theme="dark"] .modal-footer,
  html[data-theme="dark"] .dropdown-menu,
  html[data-theme="dark"] .popover,
  html[data-theme="dark"] .popover-title,
  html[data-theme="dark"] .jarviswidget > div,
  html[data-theme="dark"] .smart-form header,
  html[data-theme="dark"] .smart-form fieldset,
  html[data-theme="dark"] .smart-form footer {
    background: var(--cv-panel); color: var(--cv-text); border-color: var(--cv-border);
  }
  html[data-theme="dark"] .jarviswidget > header:not([style]),
  html[data-theme="dark"] .nav-tabs > li.active > a,
  html[data-theme="dark"] .nav-tabs > li > a:hover,
  html[data-theme="dark"] .btn-default,
  html[data-theme="dark"] .cv-theme-toggle {
    background: var(--cv-raised); color: var(--cv-text); border-color: var(--cv-border);
  }
  html[data-theme="dark"] .form-control,
  html[data-theme="dark"] .smart-form .input input,
  html[data-theme="dark"] .smart-form .select select,
  html[data-theme="dark"] .smart-form .textarea textarea,
  html[data-theme="dark"] .input-group-addon,
  html[data-theme="dark"] .smart-form .checkbox i,
  html[data-theme="dark"] .smart-form .radio i {
    background: var(--cv-bg); color: var(--cv-text); border-color: var(--cv-border);
  }
  html[data-theme="dark"] input::placeholder,
  html[data-theme="dark"] textarea::placeholder { color: var(--cv-muted); opacity: 1; }
  html[data-theme="dark"] .form-control:focus,
  html[data-theme="dark"] .smart-form input:focus,
  html[data-theme="dark"] .smart-form textarea:focus,
  html[data-theme="dark"] .smart-form select:focus { border-color: #75baff; }
  html[data-theme="dark"] .form-control[disabled],
  html[data-theme="dark"] .form-control[readonly] { background: var(--cv-raised); color: var(--cv-muted); }
  html[data-theme="dark"] .smart-form,
  html[data-theme="dark"] .smart-form .label,
  html[data-theme="dark"] .smart-form .checkbox,
  html[data-theme="dark"] .smart-form .radio,
  html[data-theme="dark"] .smart-form legend,
  html[data-theme="dark"] legend,
  html[data-theme="dark"] .close { color: var(--cv-text); text-shadow: none; }
  html[data-theme="dark"] .note,
  html[data-theme="dark"] .help-block,
  html[data-theme="dark"] .text-muted,
  html[data-theme="dark"] .smart-form .note { color: var(--cv-muted); }
  html[data-theme="dark"] a:not(.btn):not(.label):not(.badge) { color: #8bc5ff; }
  html[data-theme="dark"] .dropdown-menu > li > a:hover { background: var(--cv-raised); }
  html[data-theme="dark"] .table,
  html[data-theme="dark"] .table > thead > tr > th,
  html[data-theme="dark"] .table > tbody > tr > td,
  html[data-theme="dark"] .table > tbody > tr > th,
  html[data-theme="dark"] .table-bordered { border-color: var(--cv-border); color: var(--cv-text); }
  html[data-theme="dark"] .table > thead > tr,
  html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd),
  html[data-theme="dark"] .pagination > li > a,
  html[data-theme="dark"] .pagination > li > span { background: var(--cv-raised); color: var(--cv-text); }
  html[data-theme="dark"] .table > tbody > tr { background: var(--cv-panel); }
  html[data-theme="dark"] .table-hover > tbody > tr:hover { background: #34465c; }
  html[data-theme="dark"] .nav-tabs,
  html[data-theme="dark"] hr,
  html[data-theme="dark"] .panel-default,
  html[data-theme="dark"] .border-trl { border-color: var(--cv-border); }
  html[data-theme="dark"] .select2-dropdown,
  html[data-theme="dark"] .select2-container--default .select2-selection--single,
  html[data-theme="dark"] .select2-container--default .select2-selection--multiple,
  html[data-theme="dark"] .select2-search__field,
  html[data-theme="dark"] .ui-datepicker {
    background: var(--cv-panel); color: var(--cv-text); border-color: var(--cv-border);
  }
  html[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered { color: var(--cv-text); }
  html[data-theme="dark"] .select2-container--default .select2-results__option[aria-selected=true] { background: var(--cv-raised); }
  html[data-theme="dark"] .imageUploadForm .pickFile { background: var(--cv-panel); }
}
@media print { .cv-theme-toggle { display: none !important; } }
@media screen {
  html[data-theme="dark"] #extr-page #header {
    background: var(--cv-panel) !important; border-bottom-color: var(--cv-border) !important;
  }
  html[data-theme="dark"] #extr-page #main { background: var(--cv-bg); }
  html[data-theme="dark"] .txt-color-darken { color: var(--cv-text) !important; }
  html[data-theme="dark"] .smart-form .icon-append,
  html[data-theme="dark"] .smart-form .icon-prepend { color: var(--cv-muted); border-color: var(--cv-border); }
  html[data-theme="dark"] .smart-form .input input[disabled],
  html[data-theme="dark"] .smart-form .select select[disabled],
  html[data-theme="dark"] .smart-form .textarea textarea[disabled] { background: var(--cv-raised); color: var(--cv-muted); }
  html[data-theme="dark"] .pagination > .active > a,
  html[data-theme="dark"] .pagination > .active > span { background: #3276b1; color: #fff; }
}


/* Shared page backgrounds override the original light !important declarations. */
@media screen {
  html[data-theme="dark"] #extr-page.bg-container {
    background-color: #151b24 !important;
    background-image: none !important;
    color: #e4eaf2;
  }
  html[data-theme="dark"] #extr-page.bg-container > router-outlet + * {
    display: block;
    min-height: 100vh;
    background-color: #151b24;
    color: #e4eaf2;
  }
  html[data-theme="dark"] #content {
    background-color: #151b24;
    color: #e4eaf2;
  }
  html[data-theme="dark"] .jarviswidget > div,
  html[data-theme="dark"] .widget-body {
    background-color: #202936;
    color: #e4eaf2;
    border-color: #526176;
  }
  html[data-theme="dark"] .jarviswidget > header:not([style]),
  html[data-theme="dark"] .form-actions {
    background-color: #2a3545;
    color: #e4eaf2;
    border-color: #526176;
  }
  html[data-theme="dark"] .jarviswidget > header[style] { color: #fff; }
  html[data-theme="dark"] #frm-buttom-top { border-bottom-color: #526176 !important; }
  html[data-theme="dark"] legend,
  html[data-theme="dark"] fieldset { color: #e4eaf2; border-color: #526176; }
}


/* SmartAdmin's outer widget frame declares these colors as !important. */
@media screen {
  html[data-theme="dark"] .jarviswidget > div {
    background-color: #202936 !important;
    border-right-color: #526176 !important;
    border-bottom-color: #526176 !important;
    border-left-color: #526176 !important;
  }
  html[data-theme="dark"] .dataTables_wrapper,
  html[data-theme="dark"] .dataTables_scroll,
  html[data-theme="dark"] .dataTables_scrollHead,
  html[data-theme="dark"] .dataTables_scrollBody,
  html[data-theme="dark"] .dataTables_scrollFoot {
    background-color: #202936;
    color: #e4eaf2;
    border-color: #526176;
  }
  html[data-theme="dark"] .dt-toolbar,
  html[data-theme="dark"] .dt-toolbar-footer {
    background: #2a3545;
    color: #e4eaf2;
    border-color: #526176;
    -webkit-box-shadow: none;
    -moz-box-shadow: none;
    box-shadow: none;
  }
  html[data-theme="dark"] .table-responsive { border-color: #526176; }
}
.cv-company-switch {
  position: fixed; bottom: 12px; right: 12px; z-index: 1040;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 8px 12px;
  border: 1px solid #aaa; border-radius: 20px;
  background: #fff; color: #333;
  box-shadow: 0 2px 8px rgba(0,0,0,.2); font: inherit; cursor: pointer;
}
.cv-company-switch:focus { outline: 3px solid #3276b1; outline-offset: 3px; }
@media screen {
  html[data-theme="dark"] .cv-company-switch { background: #2a3545; color: #e4eaf2; border-color: #526176; }
}
@media print { .cv-company-switch { display: none !important; } }
#header #logo-group.cv-brand {
  display: flex; align-items: center; gap: 12px;
  width: auto; max-width: calc(100% - 140px); height: 100%;
}
#header #logo-group.cv-brand > a { flex: 0 0 auto; }
#header #logo-group.cv-brand #logo { width: auto; margin: 0; }
#header #logo-group.cv-brand #logo img { max-height: 36px; object-fit: contain; }
#header sa-company-name { display: block; flex: 1 1 auto; min-width: 0; }
#header sa-company-name.cv-company-name-empty { display: none; }
.cv-company-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 600; color: #333; }
@media screen {
  html[data-theme="dark"] .cv-company-name { color: #e4eaf2; }
}
@media screen and (max-width: 600px) {
  #header #logo-group.cv-brand { gap: 8px; max-width: calc(100% - 100px); }
  #header #logo-group.cv-brand #logo img { max-width: 85px; }
  .cv-company-name { font-size: 12px; }
}
