@use "cisa_colors" as *;
@use "uswds-core" as *;

// We'll use Django's CSS vars: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#theming-support 
// and assign USWDS theme vars whenever possible
// If needed (see below), we'll use the USWDS hex value
// As a last resort, we'll use CISA colors to supplement the palette
:root,
html[data-theme="light"] {
    --primary: #{$theme-color-primary};
    --secondary: #{$theme-color-primary-darkest};
    --accent: #{$theme-color-accent-cool};
    // --primary-fg: #fff;

    // USWDS theme vars that are set to a token, such as #{$theme-color-base-darker}
    // would interpolate to 'gray-cool-70' and output invalid CSS, so we use the hex
    // source value instead: https://designsystem.digital.gov/design-tokens/color/system-tokens/
    --body-fg: #3d4551;
    // --body-bg: #fff;
    --body-quiet-color: #{$theme-color-base-dark};
    // --body-loud-color: #000;

    --header-color: var( --primary-fg);
    --header-branding-color:  var( --primary-fg);
    // --header-bg: var(--secondary);
    // --header-link-color: var(--primary-fg);

    --breadcrumbs-fg: #{$theme-color-accent-cool-lightest};
    // --breadcrumbs-link-fg: var(--body-bg);
    --breadcrumbs-bg: #{$theme-color-primary-dark};

    // #{$theme-link-color} would interpolate to 'primary', so we use the source value instead
    --link-fg: #{$theme-color-primary};
    --link-hover-color: #{$theme-color-primary};
    // $theme-link-visited-color - violet-70v
    --link-selected-fg: #54278f;

    --hairline-color: #{$dhs-gray-15};
    // $theme-color-base-lightest - gray-5
    --border-color: #f0f0f0;

    --error-fg: #{$theme-color-error};

    --message-success-bg: #{$theme-color-success-lighter};
    --checkbox-green: #{$theme-color-success-light};
    // $theme-color-warning-lighter - yellow-5
    --message-warning-bg: #faf3d1;
    --message-error-bg: #{$theme-color-error-lighter};

    --darkened-bg: #{$dhs-gray-15}; /* A bit darker than --body-bg */
    --selected-bg: var(--border-color); /* E.g. selected table cells */
    --selected-row: var(--message-warning-bg);

    // --button-fg: #fff;
    // --button-bg: var(--secondary);
    --button-hover-bg: #{$theme-color-primary-darker};
    --default-button-bg: #{$theme-color-primary-dark};
    --default-button-hover-bg: #{$theme-color-primary-darkest};
    // #{$theme-color-base} - 'gray-cool-50'
    --close-button-bg: #71767a;
    // #{$theme-color-base-darker} - 'gray-cool-70'
    --close-button-hover-bg: #3d4551;
    --delete-button-bg: #{$theme-color-error};
    --delete-button-hover-bg: #{$theme-color-error-dark};

    // --object-tools-fg: var(--button-fg);
    // --object-tools-bg: var(--close-button-bg);
    // --object-tools-hover-bg: var(--close-button-hover-bg);

    --summary-box-bg: #f1f1f1;
    --summary-box-border: #d1d2d2;
}

// Fold dark theme settings into our main CSS
// https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#theming-support > dark theme note
@media (prefers-color-scheme: dark) {
    :root,
    html[data-theme="dark"] {
      // Edit the primary to meet accessibility requ.  
      --primary: #23485a;
      --primary-fg: #f7f7f7;
  
      --body-fg: #eeeeee;
      --body-bg: #121212;
      --body-quiet-color: #e0e0e0;
      --body-loud-color: #ffffff;
  
      --breadcrumbs-link-fg: #e0e0e0;
      --breadcrumbs-bg: var(--primary);
  
      --link-fg: #81d4fa;
      --link-hover-color: #4ac1f7;
      --link-selected-fg: #6f94c6;
  
      --hairline-color: #272727;
      --border-color: #353535;
  
      --error-fg: #e35f5f;
      --message-success-bg: #006b1b;
      --checkbox-green: #006b1b;
      --message-warning-bg: #583305;
      --message-error-bg: #570808;
  
      --darkened-bg: #212121;
      --selected-bg: #1b1b1b;
      --selected-row: #00363a;
  
      --close-button-bg: #333333;
      --close-button-hover-bg: #666666;

      --summary-box-bg:  #121212;
      --summary-box-border: #666666;
    }

    // Dark mode django (bug due to scss cascade) and USWDS tables
    .change-list .usa-table,
    .change-list .usa-table--striped tbody tr:nth-child(odd) td,
    .change-list .usa-table--borderless thead th,
    .change-list .usa-table thead td, 
    .change-list .usa-table thead th,
    .change-form .usa-table,
    .change-form .usa-table--striped tbody tr:nth-child(odd) td,
    .change-form .usa-table--borderless thead th,
    .change-form .usa-table thead td, 
    .change-form .usa-table thead th,
    body.dashboard,
    body.change-list,
    body.change-form,
    .custom-admin-template,
    .dl-dja dt {
        color: var(--body-fg);
    }
    .usa-table td {
        background-color: transparent;
    }

    // Sets darker color on delete page links.
    // Remove when dark mode successfully applies to Django delete page.
    .delete-confirmation .content a:not(.button)  {
        color: color('primary');
    }
}

// Firefox needs this to be specifically set
html[data-theme="dark"] {
    .change-list .usa-table,
    .change-list .usa-table--striped tbody tr:nth-child(odd) td,
    .change-list .usa-table--borderless thead th,
    .change-list .usa-table thead td, 
    .change-list .usa-table thead th,
    .change-form .usa-table,
    .change-form .usa-table--striped tbody tr:nth-child(odd) td,
    .change-form .usa-table--borderless thead th,
    .change-form .usa-table thead td, 
    .change-form .usa-table thead th,
    body.dashboard,
    body.change-list,
    body.change-form,
    .custom-admin-template,
    .dl-dja dt {
        color: var(--body-fg);
    }
    .usa-table td {
        background-color: transparent;
    }

    // Sets darker color on delete page links.
    // Remove when dark mode successfully applies to Django delete page.
    .delete-confirmation .content a:not(.button)  {
        color: color('primary');
    } 
}


#branding h1 a:link, #branding h1 a:visited {
    color: var(--primary-fg);
}

// Reset the USWDS styles for alerts
@include at-media(desktop) {
    .dashboard .usa-alert__body--widescreen {
        padding-left: 4rem !important;
    }

    .dashboard .usa-alert__body--widescreen::before {
        left: 1.5rem !important;
    }
}

#branding h1,
.dashboard h1, .dashboard h2, .dashboard h3,
.module h2 {
    font-weight: font-weight('bold');
}

div#content > h2 {
    font-size: 1.3rem;
}

.module h3 {
    padding: 0;
    color: var(--link-fg);
    margin: units(2) 0 units(1) 0;
}

.module ul.padding-0 {
    padding: 0 !important;
}

.module ul.margin-0 {
    margin: 0 !important;
}

.change-list {
    .usa-table--striped tbody tr:nth-child(odd) td,
    .usa-table--striped tbody tr:nth-child(odd) th,
    .usa-table td,
    .usa-table th {
        background-color: transparent;
    }
}

.change-form {
    .usa-table--striped tbody tr:nth-child(odd) td,
    .usa-table--striped tbody tr:nth-child(odd) th,
    .usa-table td,
    .usa-table th {
        background-color: transparent;
    }
    .usa-table td {
        border-bottom: 1px solid var(--hairline-color);
    }
}

#nav-sidebar {
    padding-top: 20px;
}

// Fix django admin button height bugs
.submit-row a.deletelink,
.delete-confirmation form .cancel-link,
.submit-row a.closelink {
    height: auto!important;
    font-size: 14px;
}

// right justify custom buttons and display as links
.submit-row input.custom-link-button,
.submit-row input.custom-link-button:hover {
    background: none;
    border: none;
    color: var(--link-fg);
    cursor: pointer;
    text-decoration: none;
    padding: 0;
    font-size: inherit;
    margin-left: auto;
}
.submit-row div.spacer {
    flex-grow: 1;
}
.submit-row .mini-spacer{
    margin-left: 2px;
    margin-right: 2px;
}
.submit-row span {
    margin-top: units(1);
}

// Customize 
// Keep th from collapsing 
.min-width-25 {
    min-width: 25px;
}
.min-width-81 {
    min-width: 81px;
}

.primary-th {
    padding-top: 8px;
    padding-bottom: 8px;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    text-transform: none;
    font-weight: font-weight('bold');
    text-align: left;
    background: var(--primary);
    color: var(--header-link-color);
}

// Font mismatch issue due to conflicts between django and uswds,
// rough overrides for consistency and readability. May want to revise
// in the future
.object-tools li a,
.object-tools p a {
    font-family: family('sans');
    text-transform: none!important;
    font-size: 14px!important;
}

// For consistency, make the overrided p a
// object tool buttons the same size as the ul li a
.object-tools p {
    line-height: 1.25rem;
}

// Fix margins in mobile view
@media (max-width: 767px) {
    .object-tools li {
        // our CSS is read before django's, so need !important
        // to override
        margin-left: 0!important;
        margin-right: 15px;
    }
}

// Fix height of buttons
.object-tools li {
    height: auto;
}

// Fixing height of buttons breaks layout because
// object-tools and changelist are siblings with
// flexbox positioning
#changelist {
    clear: both;
}

// Account for the h2, roughly 90px
@include at-media(tablet) {
    .object-tools {
        padding-left: 90px;
    }
}

// Combo box
#select2-id_domain-results,
#select2-id_user-results {
    width: 100%;
}

// Content list inside of a DjA alert, unstyled
.messagelist_content-list--unstyled {
    padding-left: 0;
    li {
        font-family: family('sans');
        font-size: 13.92px!important;
        background: none!important;
        padding: 0!important;
        margin: 0!important;
    }
}

.module {
    .margin-left-0 {
        margin-left: 0;
    }
    .margin-top-0 {
        margin-top: 0;
    }
    .padding-left-0 {
        padding-left: 0;
    }
}

.admin-list-inline {
    li {
        float: left;
        padding-top: 0;
        margin-right: 4px;
    }
    li:not(:last-child)::after {
        content: ",";
    }
}

.form-row {
    .margin-y-0 {
        margin-top: 0;
        margin-bottom: 0;
    }
    .padding-y-0 {
        padding-top: 0;
        padding-bottom: 0;
    }
}

// Fixes a display issue where the list was entirely white, or had too much whitespace
.select2-dropdown {
    display: inline-grid !important;
}

input.admin-confirm-button {
    text-transform: none;
}

// Button groups in /admin incorrectly have bullets.
// Remove that!
.usa-modal__footer .usa-button-group__item {
    list-style-type: none;
}

// USWDS media checks are overzealous in this situation,
// we should manually define this behaviour.
@media (max-width: 768px) {
    .button-list-mobile {
        display: contents !important;
    }
}

.usa-button-group {
    margin-left: -0.25rem!important;
    padding-left: 0!important;
    .usa-button-group__item {
        list-style-type: none;
        line-height: normal;
    }
}

// This block resolves some of the issues we're seeing on buttons due to css
// conflicts between DJ and USWDS
a.button,
.usa-button--dja {
    display: inline-block;
    padding: 10px 15px;
    font-size: 14px;
    line-height: 16.1px;
    font-kerning: auto;
    font-family: inherit;
    font-weight: normal;
    text-decoration: none !important;
}
.button svg,
.button span,
.usa-button--dja svg,
.usa-button--dja span {
    vertical-align: middle;
}
.usa-button--dja.usa-button--unstyled {
    color: var(--link-fg);
}
.usa-button--dja:not(.usa-button--unstyled, .usa-button--outline, .usa-modal__close, .usa-button--secondary) {
    background: var(--button-bg);
}
.usa-button--dja span {
    font-size: 14px;
}
.usa-button--dja:not(.usa-button--unstyled, .usa-button--outline, .usa-modal__close, .usa-button--secondary):hover {
    background: var(--button-hover-bg);
}
a.button:active, a.button:focus {
    text-decoration: none;
}
.usa-modal {
    font-family: inherit;
}
input[type=submit].button--dja-toolbar {
    border: 1px solid var(--border-color);
    font-size: 0.8125rem;
    padding: 4px 8px;
    margin: 0;
    vertical-align: middle;
    background: var(--body-bg);
    box-shadow: 0 -15px 20px -10px rgba(0, 0, 0, 0.15) inset;
    cursor: pointer;
    color: var(--body-fg);
}
input[type=submit].button--dja-toolbar:focus, input[type=submit].button--dja-toolbar:hover {
    border-color: var(--body-quiet-color);
}
.admin-icon-group {
    position: relative;
    display: inline;
    align-items: center;

    input {
        // Allow for padding around the copy button
        padding-right: 35px !important;
    }

    button {
        width: max-content;
    }

    @media (max-width: 1000px) {
        button {
            display: block;
        }
    }

    span {
        padding-left: 0.05rem;
    }

}
.usa-button__small-text,
.usa-button__small-text span {
    font-size: 13px;
}

.object-tools li button, button.addlink {
    font-family: Source Sans Pro Web, Helvetica Neue, Helvetica, Roboto, Arial, sans-serif;
    text-transform: none !important;
    font-size: 14px !important;
    display: block;
    float: left;
    padding: 3px 12px;
    background: var(--object-tools-bg) !important;
    color: var(--object-tools-fg);
    font-weight: 400;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 15px;
    cursor: pointer;
    border: none;
    line-height: 20px;
    &:focus, &:hover{
        background: var(--object-tools-hover-bg) !important;
    }
}

// Mimic the style for <a>
.object-tools > p > button.addlink {
    background-image: url(../admin/img/tooltag-add.svg) !important;
    background-repeat: no-repeat !important;
    background-position: right 7px center !important;
    padding-right: 25px;
}

.usa-modal--django-admin .usa-prose ul > li {
    list-style-type: inherit;
    // Styling based off of the <p> styling in django admin
    line-height: 1.5;
    margin-bottom: 0;
    margin-top: 0;
    max-width: 68ex;
}

details.dja-detail-table {
    display: inline-table;
    background-color: var(--body-bg);
    .dja-details-summary {
        cursor: pointer;
        color: var(--link-fg);
        text-decoration: underline;
    }

    @media (max-width: 1024px){
        .dja-detail-contents {
            max-width: 400px !important;
            overflow-x: scroll !important;
        }
    }

    tr {
        background-color: transparent;
    }

    thead tr {
        background-color: var(--darkened-bg);
    }

    td, th {
        padding-left: 12px;
        border: none;
        background-color: var(--darkened-bg);
        color: var(--body-quiet-color);
    }

    thead > tr > th {
        border-top: none;
        border-bottom: none;
    }
}


address.margin-top-neg-1__detail-list {
    margin-top: -8px !important;
}

.dja-detail-list {
    dl {
        padding-left: 0px !important;
        margin-top: 5px !important;
    }
    // Mimic the normal label size
    address, dt {
        font-size: 0.8125rem;
        color: var(--body-quiet-color);
    }
}

address.dja-address-contact-list {
    font-size: unset;
}

address.dja-address-contact-list {
    color: var(--body-quiet-color);
}

// Mimic the normal label size
@media (max-width: 1024px){
    .dja-detail-list dt, .dja-detail-list address {
        font-size: 0.875rem;
        color: var(--body-quiet-color);
    }
}

// Targets the unstyled buttons in the form
.button--clipboard {
    color: var(--link-fg);
}

.errors span.select2-selection {
    border: 1px solid var(--error-fg) !important;
}

.choice-filter {
    position: relative;
    padding-left: 20px;
    svg {
        top: 4px;
    }
}

.choice-filter--checked {
    svg:nth-child(1) {
        background: var(--checkbox-green);
        fill: var(--checkbox-green);
    }
    svg:nth-child(2) {
        color: var(--body-loud-color);
    }
}

// Let's define this block of code once and use it for analysts over a certain screen size,
// superusers over another screen size.
@mixin submit-row-wrapper--collapsed-one-line(){
    &.submit-row-wrapper--collapsed {
     transform: translate3d(0, 42px, 0);
    }
    .submit-row {
        clear: none;
    }
  }

// Sticky submit bar for domain requests on desktop
@media screen and (min-width:768px) {
    .submit-row-wrapper {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 338px;
        background: var(--darkened-bg);
        border-top-left-radius: 6px;
        transition: transform .2s ease-out;
        .submit-row {
            margin-bottom: 0;
        }
    }
    .submit-row-wrapper--collapsed {
        // translate3d is more performant than translateY
        // https://stackoverflow.com/questions/22111256/translate3d-vs-translate-performance
        transform: translate3d(0, 88px, 0);
    }
    .submit-row-wrapper--collapsed-one-line {
        @include submit-row-wrapper--collapsed-one-line();
    }
    .submit-row {
        clear: both;
    }
    .submit-row-toggle{
        display: inline-block;
        position: absolute;
        top: -30px;
        right: 0;
        background: var(--darkened-bg);
    }
    #submitRowToggle {
        color: var(--body-fg);
    }
    .submit-row-sticky {
        max-width: 325px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: medium;
        padding-top: 3px !important;
    }
}

.visible-768 {
    display: none;
}

@media screen and (min-width:768px) {
    .visible-768 {
        display: block;
        padding-top: 0;
    }
}

@media screen and (min-width:935px) {
    // Analyst only class
    .submit-row-wrapper--analyst-view {
        @include submit-row-wrapper--collapsed-one-line();
    }
}

@media screen and (min-width:1256px) {
    .submit-row-wrapper {
        @include submit-row-wrapper--collapsed-one-line();
    }
}

// Collapse button styles for fieldsets
.module.collapse--dgfieldset {
    margin-top: -35px;
    padding-top: 0;
    border: none;
}
.collapse-toggle--dgsimple,
.module.collapse--dgfieldset button {
    background: none;
    text-transform: none;
    color: var(--link-fg);
    margin-top: 8px;
    margin-left: 10px;
    span {
        text-decoration: underline;
        font-size: 13px;
        font-feature-settings: "kern";
        font-kerning: normal;
        line-height: 13px;
        font-family: family('sans');
    }
    &:hover {
        color: var(--link-fg);
        svg {
            color: var(--link-fg);
        }
    }
}
.collapse--dgfieldset.collapsed .collapse-toggle--dgfieldset  {
    display: inline-block!important;
    * {
        display: inline-block;
    }
}
.collapse--dgsimple.collapsed {
    display: none;
}

.dja-status-list {
    border-top: solid 1px var(--border-color);
    margin-left: 0 !important;
    padding-left: 0 !important;
    padding-top: 10px;
    li {
        line-height: 1.5;
        font-family: family('sans');
        padding-top: 0;
        padding-bottom: 0;
    }
}

.no-outline-on-click:focus {
    outline: none !important;
}

// Get rid of padding on all help texts
form .aligned p.help, form .aligned div.help {
    padding-left: 0px !important;
}

// We override the DJA header on multi list selects from h2 to h3
// The following block of code styles our generated h3s to match the old h2s
.selector .selector-available h3 {
    background: var(--darkened-bg);
    color: var(--body-quiet-color);
}

.selector-available h3, .selector-chosen h3 {
    border: 1px solid var(--border-color);
    border-radius: 4px 4px 0 0;
    margin: 0;
    padding: 8px;
    font-size: 0.8125rem;
    text-align: left;
    margin: 0;
    padding: 8px;
    line-height: 1.3;
}

.selector .selector-chosen h3 {
    background: var(--primary);
    color: var(--header-link-color);
}

div.dja__model-description{
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;  
    overflow: hidden;

    p, li {
        font-size: medium;
        color: var(--secondary);
    }

    li {
        list-style-type: disc;
        font-family: family('sans');
    }

    a, a:link, a:visited {
        font-size: medium;
        color: color('primary') !important;
    }

    &.dja__model-description--no-overflow {
        display: block;
        overflow: auto;
    }

}

.import_export_text {
    color: var(--secondary);
}

.text-underline {
    text-decoration: underline !important;
}

.module caption, .inline-group h2 {
    text-transform: capitalize;
}

.module caption {
    // Match the old <h2> size for django admin
    font-size: 0.8125rem;
}

// text-bold doesn't work here due to style overrides, unfortunately.
// This is a workaround.
caption.text-bold {
    font-weight: font-weight('bold');
}

.wrapped-button-group {
    // This button group has too many items
    flex-wrap: wrap;
    // Fix a weird spacing issue with USWDS a buttons in DJA
    a.button {
        padding: 6px 8px 10px 8px;
    }
}

.usa-button--dja-link-color {
    color: var(--link-fg);
}

.textarea-wrapper {
    width: 100%;
    max-width: 610px;
}

.dja-readonly-textarea-container {
    width: 100%;
    textarea {
        width: 100%;
        max-width: 610px;
        resize: none;
        cursor: auto;

        &::-webkit-scrollbar {
            background-color: transparent;
            border: none;
            width: 12px;
        }

        // Style the scroll bar handle
        &::-webkit-scrollbar-thumb {
            background-color: var(--body-fg);
            border-radius: 99px;
            background-clip: content-box;
            border: 3px solid transparent;
        }
    }
}

.max-full {
    width: 100% !important;
}

.thin-border {
    background-color: var(--selected-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    label {
        padding-top: 0 !important;
    }
}

.display-none {
    // Many elements in django admin try to override this, so we need !important.
    display: none !important;
}

.margin-top-0 {
    margin-top: 0 !important;
}

.padding-top-0 {
    padding-top: 0 !important;
}

.padding-bottom-0 {
    padding-bottom: 0 !important;
}

.flex-container {
    @media screen and (min-width: 700px) and (max-width: 1150px) {
        &.flex-container--mobile-inline {
            display: inline !important;
        }
    }
}

.text-faded {
    color: #{$dhs-gray-60};
}
ul.add-list-reset {
    padding: 0 !important;
    margin: 0 !important;
}

// Fix the combobox when deployed outside admin (eg user transfer)
.submit-row .select2,
.submit-row .select2 span {
    margin-top: 0;
}
.transfer-user-selector .select2-selection__placeholder {
    color: #3d4551!important;
}

.dl-dja dt {
    font-size: 14px;
}

.organization-admin-label {
    font-weight: 600;
    font-size: .8125rem;
}

.change-form .usa-table {
    td {
    color: inherit !important; 
    background-color: transparent !important; 
    }
}

@media (min-width: 1080px) {
    .analytics-dashboard-charts {
        // Desktop layout - charts in top row, details in bottom row
        display: grid;
        gap: 2rem;
        // Equal columns each gets 1/2 of the space
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas:
            "chart1 chart2"
            "details1 details2"
            "chart3 chart4"
            "details3 details4"
            "chart5 chart6"
            "details5 details6";

        .chart-1 { grid-area: chart1; }
        .chart-2 { grid-area: chart2; }
        .chart-3 { grid-area: chart3; }
        .chart-4 { grid-area: chart4; }
        .chart-5 { grid-area: chart5; }
        .chart-6 { grid-area: chart6; }
        .details-1 { grid-area: details1; }
        .details-2 { grid-area: details2; }
        .details-3 { grid-area: details3; }
        .details-4 { grid-area: details4; }
        .details-5 { grid-area: details5; }
        .details-6 { grid-area: details6; }
    }

}

#result_list > tbody tr > th > a {
    text-decoration: underline;
}
