/* ==========================================
   MASTER THEME VARIABLES
   ========================================== */
:root, [data-theme="light"], [data-theme="dark"] {
    --brand-bg: #f9fafb !important;
    --brand-text: #111827 !important;
    --brand-quiet: #4b5563 !important;
    --brand-muted: #6b7280 !important;
    --brand-border: #e5e7eb !important;

    --brand-header-bg: #6b7280 !important;
    --brand-header-text: #ffffff !important;
    --brand-header-hover: #d1d5db !important;

    --brand-primary: #374151 !important;
    --brand-primary-hover: #1f2937 !important;

    --brand-selected-bg: #e5e7eb !important;
    --font-family-primary: 'Inter', system-ui, sans-serif !important;

    --body-bg: var(--brand-bg) !important;
    --body-fg: var(--brand-text) !important;
    --body-quiet-color: var(--brand-quiet) !important;
    --selected-bg: var(--brand-selected-bg) !important;
    --selected-row: var(--brand-selected-bg) !important;
}

body, h1, h2, h3, h4, h5, h6 { font-family: var(--font-family-primary); }

/* ==========================================
   1. UNIFIED HEADER (Admin & Portal Sync)
   ========================================== */
/* Syncing the Main Header Backgrounds and Padding */
#header, .portal-header {
    background-color: var(--brand-header-bg) !important;
    border-bottom: none !important;
    padding: 10px 40px !important;
    color: var(--brand-header-text) !important;
}

/* Syncing Branding Links & Hover States */
#branding h1 a, #branding h1 a:link, #branding h1 a:visited,
.portal-branding a, .portal-branding a:link, .portal-branding a:visited {
    color: var(--brand-header-text) !important;
    text-decoration: none !important;
    transition: color 0.2s ease;
}
#branding h1 a:hover, .portal-branding a:hover {
    color: var(--brand-header-hover) !important;
    text-decoration: none !important;
}

/* Syncing Top-Right Menu Typography */
#user-tools, .portal-user-tools {
    display: block !important;
    font-size: 11px !important;
    font-weight: 400 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    text-align: right !important;
    color: var(--brand-header-text) !important;
}

/* Syncing Menu Links & Logout Buttons */
#user-tools a, #user-tools a:link, #user-tools a:visited, #user-tools button,
.portal-user-tools a, .portal-user-tools a:link, .portal-user-tools a:visited, .portal-user-tools button {
    color: var(--brand-header-text) !important;
    text-decoration: none !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 4px !important;
    font-family: inherit !important;
    font-size: 11px !important;
    text-transform: uppercase !important;
    cursor: pointer !important;
    outline: none !important;
    transition: color 0.2s ease;
}
#user-tools a:hover, #user-tools button:hover,
.portal-user-tools a:hover, .portal-user-tools button:hover {
    color: var(--brand-header-hover) !important;
    text-decoration: underline !important;
}
#user-tools strong, .portal-user-tools strong { font-weight: 600 !important; }

/* Admin Lists & Tables */
caption, div.module caption, .inline-group h2, div.breadcrumbs, thead th {
    background-color: var(--brand-primary) !important; color: var(--brand-header-text) !important;
    text-shadow: none !important; border: none !important;
}
caption a, caption a:link, caption a:visited, div.module caption a.section, div.module caption a.section:link, div.module caption a.section:visited, div.breadcrumbs a, div.breadcrumbs a:link, div.breadcrumbs a:visited, thead th a, thead th a:link, thead th a:visited {
    color: var(--brand-header-text) !important;
    text-decoration: none !important;
    transition: color 0.2s ease;
}

/* Hover states for Breadcrumbs and Main Content Area Headers */
caption a:hover, div.module caption a.section:hover, div.breadcrumbs a:hover {
    color: var(--brand-header-hover) !important;
    text-decoration: underline !important;
}

tr.selected, #nav-sidebar .current-app, #nav-sidebar .current-model, #nav-sidebar li.current > a, #nav-sidebar a[aria-current="page"] {
    background-color: var(--brand-selected-bg) !important; color: var(--brand-text) !important;
}

/* Sidebar */
#nav-sidebar { background-color: #ffffff !important; border-right: 1px solid var(--brand-border) !important; }
#nav-sidebar .caption, #nav-sidebar .app-filter { background-color: transparent !important; color: var(--brand-header-bg) !important; text-transform: uppercase; font-weight: 600 !important; }
.toggle-nav-sidebar {
    background-color: #f8f8f8 !important;
    color: var(--brand-primary) !important;
}
.toggle-nav-sidebar:hover {
    background-color: #f1f1f1 !important;
    color: var(--brand-primary-hover) !important;
}
.toggle-nav-sidebar:focus:not(:hover) {
    background-color: #f8f8f8 !important;
    color: var(--brand-primary) !important;
}

/* Standard Sidebar Links (Dark Text on Light Background) */
#nav-sidebar a, #nav-sidebar a:link, #nav-sidebar a:visited {
    color: var(--brand-primary) !important;
    text-decoration: none !important;
    transition: color 0.2s ease;
}
#nav-sidebar a:hover,
#nav-sidebar a[aria-current="page"]:hover,
#nav-sidebar li.current > a:hover {
    color: var(--brand-muted) !important;
    text-decoration: underline !important;
}

/* Sidebar Headers (White Text on Dark Background) */
#nav-sidebar caption a, #nav-sidebar caption a:link, #nav-sidebar caption a:visited, #nav-sidebar caption a.section {
    color: var(--brand-header-text) !important;
    text-decoration: none !important;
    transition: color 0.2s ease;
}
#nav-sidebar caption a:hover, #nav-sidebar caption a.section:hover {
    color: var(--brand-header-hover) !important;
    text-decoration: underline !important;
}

/* ==========================================
   2. INLINES & NESTED ADMIN (Modules & Lessons)
   ========================================== */
div.inline-group,
div.inline-related {
    border: 1px solid var(--brand-border) !important;
    box-shadow: none !important;
}

.inline-group details > summary,
.inline-related details > summary,
fieldset.collapse details > summary,
.inline-group .tabular thead th {
    background-color: var(--brand-selected-bg) !important;
    color: var(--brand-text) !important;
    border-bottom: 1px solid var(--brand-border) !important;
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
}

.inline-group details > summary::-webkit-details-marker,
.inline-related details > summary::-webkit-details-marker {
    color: var(--brand-text) !important;
}

/* Added fieldset h2 and .module h2 to force grey headers universally */
.inline-group details > summary > h2,
.inline-related details > summary > h3,
.inline-group > h2,
.inline-related > h3,
div.inline-group h2,
fieldset.collapse > summary > h2,
fieldset.collapse > h2,
fieldset h2,
.module h2 {
    background-color: var(--brand-primary) !important;
    color: var(--brand-header-text) !important;
    text-shadow: none !important;
    padding: 8px 12px !important;
    margin: 0 !important;
    display: block !important;
    border-radius: 4px 4px 0 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.inline-group details > summary > h2 a,
.inline-related details > summary > h3 a,
.inline-group > h2 a,
.inline-related > h3 a,
fieldset h2 a,
.module h2 a {
    color: var(--brand-header-text) !important;
    text-decoration: none !important;
}

/* Keep stacked inline delete labels readable inside the dark header bar. */
.inline-related > h3 span.delete,
.inline-related > h3 span.delete label,
.inline-related > h3 span.delete .vCheckboxLabel {
    color: var(--brand-header-text) !important;
}

/* ==========================================
   3. FORM SPECIFICS ("Add another", Buttons & Checkboxes)
   ========================================== */
/* Unified Buttons (Admin & Portal) */
.button, input[type=submit], input[type=button], .submit-row input, a.button, .btn-primary {
    background-color: var(--brand-primary) !important;
    color: var(--brand-header-text) !important;
    border: none !important;
    padding: 10px 15px; border-radius: 4px; cursor: pointer; text-decoration: none !important; display: inline-block; font-family: var(--font-family-primary);
}
.button:hover, input[type=submit]:hover, input[type=button]:hover, a.button:hover, .btn-primary:hover {
    background-color: var(--brand-primary-hover) !important;
    color: var(--brand-header-text) !important;
    text-decoration: none !important;
}

/* "Add another..." inline form links (Softer Grey) */
.add-row a,
.add-row a:link,
.add-row a:visited,
a.add-handler,
a.add-handler:link,
a.add-handler:visited,
.djn-add-handler,
.djn-add-handler:link,
.djn-add-handler:visited {
    color: var(--brand-muted) !important;
    font-weight: 500 !important;
    text-decoration: none !important;
}
.add-row a:hover,
a.add-handler:hover,
.djn-add-handler:hover {
    color: var(--brand-primary) !important;
    text-decoration: underline !important;
}

/* General Text Links: Add/Change Links, Recent Actions, and Dashboard Table Links */
a.addlink, a.addlink:link, a.addlink:visited,
a.changelink, a.changelink:link, a.changelink:visited,
a.viewlink, a.viewlink:link, a.viewlink:visited,
#content-related .actionlist a,
#content-related .actionlist a:link,
#content-related .actionlist a:visited,
#content-main table th a,
#content-main table th a:link,
#content-main table th a:visited,
#content-main table td a,
#content-main table td a:link,
#content-main table td a:visited {
    color: var(--brand-muted) !important;
    text-decoration: none !important;
    transition: color 0.2s ease;
}

a.addlink:hover,
a.changelink:hover,
a.viewlink:hover,
#content-related .actionlist a:hover,
#content-main table th a:hover,
#content-main table td a:hover {
    color: var(--brand-primary) !important;
    text-decoration: underline !important;
}

/* ABSOLUTE OVERRIDE: Protect Top-Right "Add" Buttons */
/* Placed after general links to guarantee it wins the CSS cascade */
ul.object-tools li a,
ul.object-tools li a:link,
ul.object-tools li a:visited,
ul.object-tools li a.addlink,
ul.object-tools li a.changelink,
ul.object-tools li a.viewlink {
    background-color: var(--brand-primary) !important;
    color: var(--brand-header-text) !important; /* Force White Text */
    text-decoration: none !important;
}
ul.object-tools li a:hover,
ul.object-tools li a.addlink:hover,
ul.object-tools li a.changelink:hover,
ul.object-tools li a.viewlink:hover {
    background-color: var(--brand-primary-hover) !important;
    color: var(--brand-header-text) !important; /* Force White Text */
    text-decoration: none !important;
}

/* ABSOLUTE OVERRIDE: Protect Changelist Column Headers (White Text on Dark Background) */
thead th a,
thead th a:link,
thead th a:visited,
#result_list thead th a,
#result_list thead th a:link,
#result_list thead th a:visited {
    color: var(--brand-header-text) !important; /* Force White Text */
    text-decoration: none !important;
    background: transparent !important; /* Prevents <a> from carrying a background */
}
thead th a:hover,
#result_list thead th a:hover {
    color: var(--brand-header-hover) !important;
    text-decoration: underline !important;
    background: transparent !important;
}

/* Kill the Django default background hover effect on the table headers (Globally) */
thead th:hover,
thead th.sorted:hover,
thead th.sortable:hover,
thead th:focus-within,
#result_list thead th:hover,
#result_list thead th.sorted:hover,
#result_list thead th.sortable:hover,
#result_list thead th.sortable:focus-within,
#changelist table thead th:hover,
#changelist table thead th.sortable:hover,
#changelist table thead th.sorted:hover {
    background: var(--brand-primary) !important;
    background-color: var(--brand-primary) !important;
}

/* Custom Checkbox */
#content input[type="checkbox"][id*="correct"] {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    width: 18px !important;
    height: 18px !important;
    border: 2px solid var(--brand-muted) !important;
    border-radius: 50% !important;
    background-color: #fff !important;
    cursor: pointer !important;
    position: relative !important;
    display: inline-block !important;
    vertical-align: middle !important;
    margin: 0 !important;
}

#content input[type="checkbox"][id*="correct"]:checked::after {
    content: '' !important;
    position: absolute !important;
    top: 3px !important;
    left: 3px !important;
    width: 8px !important;
    height: 8px !important;
    background-color: var(--brand-primary) !important;
    border-radius: 50% !important;
}

#content input[type="checkbox"][id*="correct"]:hover {
    border-color: var(--brand-primary) !important;
}

/* ==========================================
   4. FRONTEND PORTAL (Layout Specifics)
   ========================================== */
/* The colors and typography are now fully synced in Section 1 and 3.
   These remaining classes handle specific frontend layout containers. */
.portal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.portal-branding h1 {
    margin: 0;
    padding: 0;
    font-weight: 300;
    font-size: 1.5rem;
}

.portal-branding a {
    display: flex;
    align-items: center;
}

.portal-branding img {
    height: 35px; width: 35px; object-fit: contain; margin-right: 12px; border-radius: 4px;
}

.portal-body { background-color: var(--brand-bg); color: var(--brand-text); margin: 0; padding: 0; line-height: 1.6; }
.portal-container { padding: 20px; max-width: 1400px; margin: 30px auto; background: #ffffff; min-height: 80vh; border: 1px solid var(--brand-border); border-radius: 8px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05); }
.portal-card { border: 1px solid var(--brand-border); padding: 20px; margin-bottom: 30px; border-radius: 8px; background: var(--brand-bg); }

.admin-link, .admin-link:link, .admin-link:visited { color: #ffca28 !important; font-weight: bold !important; text-decoration: none !important; }
.admin-link:hover { text-decoration: underline !important; }

.alert { padding: 10px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; }
.alert-error, .alert-danger { color: #a94442; background-color: #f2dede; border-color: #ebccd1; }
.alert-info { color: #31708f; background-color: #d9edf7; border-color: #bce8f1; }
.alert-success { color: #3c763d; background-color: #dff0d8; border-color: #d6e9c6; }

/* ==========================================
   5. TINYMCE OVERRIDES
   ========================================== */
/* Forces the rich text editor to be roughly half its default height */
.tox-tinymce, .mce-tinymce {
    height: 250px !important;
    min-height: 250px !important;
}

/* Kills the "Powered by TinyMCE" branding in the bottom right corner */
.tox .tox-statusbar__branding {
    display: none !important;
}

/* ==========================================
   6. USER ADMIN - COURSE ASSIGNMENTS INLINE
   ========================================== */
/* Creates a strong visual "HR" separator above the inline module */
#assignments-group {
    margin-top: 50px !important;
    border-top: 4px solid var(--brand-primary) !important;
    padding-top: 20px !important;
    clear: both !important; /* Ensures it drops below the user fields cleanly */
}

/* ==========================================
   7. DUAL-BOX SELECTORS (Groups & Permissions)
   ========================================== */
/* 1. Header backgrounds and the specific Helptext paragraphs.
      Using #content guarantees absolute specificity dominance over Django. */
#content .selector h2,
#content .selector h2 label,
#content .selector p.helptext,
#content .selector p[id*="_helptext"],
#content .selector .selector-available-title,
#content .selector .selector-chosen-title,
#content .selector .selector-available-title label,
#content .selector .selector-chosen-title label {
    background-color: var(--brand-primary) !important;
    color: var(--brand-header-text) !important;
    margin: 0 !important;
}

#content .selector h2 {
    padding: 8px 12px !important;
    border-radius: 4px 4px 0 0 !important;
}

#content .selector p.helptext,
#content .selector p[id*="_helptext"] {
    padding: 4px 12px 8px 12px !important;
    border-radius: 0 !important;
}

/* 2. Target the Choose All / Remove All Buttons */
#content button.selector-chooseall,
#content button.selector-clearall {
    background-color: var(--brand-primary) !important;
    color: var(--brand-header-text) !important;
    border: none !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    padding: 6px 10px !important;
    margin: 5px auto 0 auto !important; /* Centered with a gap above */
    display: block !important;          /* Required for margin: auto to work */
    width: auto !important;             /* Content-width only */
}

#content button.selector-chooseall:hover,
#content button.selector-clearall:hover {
    background-color: var(--brand-primary-hover) !important;
}

/* 3. Target the middle Arrow Buttons (Add/Remove) */
#content .selector-chooser button {
    background-color: var(--brand-muted) !important;
    border: none !important;
    color: var(--brand-header-text) !important;
}

#content .selector-chooser button:hover {
    background-color: var(--brand-primary) !important;
}
