/* ========== BASE ========== */
body {
    font-family: Inter, "Inter Placeholder", sans-serif !important;
    background: url("mera-background-alt.jpg") center/cover no-repeat fixed rgba(0, 0, 0, 0.8) !important;
    background-blend-mode: overlay !important;
    overflow-x: hidden;
}

/* ========== BRANDING ========== */
#branding {
    width: 3em;
}

.main::before {
    content: "";
    position: fixed;
    inset: 0;
    backdrop-filter: blur(5px);
    z-index: -1;
}

:root {
    /*
      Django always loads base.css that contains colors common to light and dark mode: https://github.com/django/django/blob/stable/5.1.x/django/contrib/admin/static/admin/css/base.css
      Django also loads dark_mode.css but it is not easy to force dark mode.
      That is why we need to copy the variables from dark_mode.css and use them here.

      https://github.com/django/django/blob/stable/5.1.x/django/contrib/admin/static/admin/css/dark_mode.css
      When upgrading Django, find a new link and copy and paste the variables below.
    */
    --primary: #264b5d;
    --primary-fg: #f7f7f7;

    --body-fg: #eeeeee;
    --body-bg: #121212;
    --body-quiet-color: #d0d0d0;
    --body-medium-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;
    --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;
    /* end */

    --mera-blue: #0447c2;

    /* Get rid of off-brand colors */
    --header-bg: #0a0a0acc;
    --button-bg: var(--close-button-bg);
    --button-hover-bg: var(--close-button-hover-bg);

    /* Copied from CTA button on https://mera.fit/ */
    --default-button-bg: #049ffc;
    --default-button-hover-bg: var(--mera-blue);

    --selected-row: var(--mera-blue);
}

/* ========== GLOBAL ========== */
.breadcrumbs,
.theme-toggle {
    display: none !important;
}

#nav-sidebar {
    background-color: transparent;
}

#toggle-nav-sidebar,
#nav-sidebar,
.form-row {
    border: none !important;
    box-shadow: none !important;
}

caption,
.fieldset-heading,
.inline-heading,
.collapse summary,
#changelist-filter-header {
    background-color: var(--header-bg) !important;
    border: 0 !important;
}

caption h1,
h2,
h3,
h4,
h5,
p,
a,
.collapse summary h1,
h2,
h3,
h4,
h5,
p,
a {
    color: var(--body-quiet-color) !important;
    border: none;
}

/* ========== BUTTONS ========== */
.submit-row .deletelink,
.submit-row input[type=submit],
.btn-save,
.btn-cancel {
    color: white !important;
    border: none !important;
    border-radius: 20px !important;
    padding: 0.5rem 1rem !important;
    cursor: pointer !important;
    font-size: 1rem !important;
}

.submit-row .deletelink {
    position: relative;
    color: transparent !important;
    padding: 12px 40px !important;
    border-radius: 24px !important;
    font-size: 18px !important;
}

.submit-row .deletelink::after {
    content: "Delete";
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* ========== LAYOUT ELEMENTS ========== */

fieldset.module {
    background-color: #0a0a0acc;
}

fieldset.module h1 {
    padding: 10px;
    margin-bottom: 20px;
    margin: 0;
}

#content {
    max-width: 1200px !important;
}

.mera-share-test-content fieldset.module {
    padding: 10px;
}

@media (min-width: 1024px) {
    .mera-toc {
        top: 83px !important;
    }
}

@media (min-width: 768px) {
    .mera-toc {
        position: fixed;
        left: 20px;
        top: 87px;
        width: 200px;
    }

    .mera-share-test-content {
        margin-left: 230px;
    }
}

@media (max-width: 768px) {
    .submit-row {
        flex-direction: column;
        gap: 12px;
        align-items: center;
        background-color: #00000000;
        border: none;
    }

    .mera-share {
        display: flex;
        justify-content: center;
        gap: 12px;
        flex-wrap: wrap;
        margin: 18px 0 4px;
    }

    textarea {
        max-width: 360px !important;
    }
}

.prompt-module {
    margin-left: 0;
    margin-right: 0;
    padding: 16px 18px;
    width: 100%;
    box-sizing: border-box;
}

.prompt-module h1 {
    margin-top: 0;
    margin-bottom: 1rem;
}

.prompt-card-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.prompt-card-header .mera-report-edit-btn {
    position: static;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #e6e9f4;
    background: #323443;
    border-color: #323443;
}

.prompt-card-header .mera-report-edit-btn:hover {
    background: #fcfdfe;
    color: #181818;
}

.prompt-wrap .mera-report {
    overflow-x: hidden;
}

.prompt-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.prompt-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0;
    list-style: none;
}

.prompt-tab {
    appearance: none;
    border: 0;
    background: #0c0c0c;
    color: #d4d7e4;
    padding: 0.45rem 0.9rem;
    border-radius: 10px;
    font-size: 0.92rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.prompt-tab:hover {
    background: #1b1b1b;
}

.prompt-tab--active {
    background: #323443;
    color: #e6e9f4;
}

.prompt-panes {
    position: relative;
}

.prompt-pane {
    display: none;
}

.prompt-pane.is-active {
    display: block;
}

.prompt-pane.is-editing .mera-report-edit-btn {
    display: none;
}

@media (max-width: 920px) {
    .mera-share-test main {
        padding-left: 0;
        width: 95vw;
    }
}

/* ========== MERA REPORT ========== */
.mera-report {
    background: #4a4b611a;
    border-radius: 10px;
    padding: 14px;
    margin-top: 12px;
    color: #fff;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mera-report :where(p, ul, ol) {
    margin: .45rem 5px;
}

.report-wrap {
    position: relative;
}

.mera-report {
    flex: 1 1 auto;
}

.mera-report-edit-btn {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 10;
    font-size: 14px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 8px;
    background: #323443;
    border: 1px solid #323443;
    cursor: pointer;
}

.mera-report-edit-btn:hover {
    background: #efefef;
    color: #000;
}

.report-wrap.editing .mera-report-edit-btn {
    display: none;
}

/* ========== MERA REPORT EDITOR ========== */
.mera-report-editor {
    --bg: #23242b;
    --bg-tab: #323443;
    --bg-toolbar: #23242b;
    --text: #e6edf3;
    --muted: #c9d1d9;
    --border: #30363d;
    --border-top: #23242b;
    --hover: #30363d;
    --brand: #566fe8;
    --link: #58a6ff;
    --reset: #b6341d;
}

.mera-report-editor .md-tabs {
    margin: 0;
    margin-bottom: -1px;
    padding: 0;
    display: flex;
    gap: 0px;
    border-bottom: none
}

.mera-report-editor .md-tab {
    background: var(--bg-tab);
    color: var(--muted);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    padding: 6px 10px;
    cursor: pointer;
}

.mera-report-editor .md-tab-active {
    background: var(--bg);
    color: #fff;
}

.mera-report-editor .btn-reset {
    margin-right: auto;
    color: white !important;
    background-color: var(--reset);
    border: none !important;
    padding: 0.5rem 1rem !important;
    border-radius: 15px;
    font-size: 1rem !important;
    line-height: 1;
}

.editor-toolbar {
    border: none !important;
}

.mera-report-editor .mera-editor-toolbar {
    background: var(--bg-toolbar);
    border-top-left-radius: 0px;
    border-top-right-radius: 8px;
    margin-top: -1px;
}

.mera-report-editor .mera-editor-toolbar :is(a, button) {
    background: transparent;
    color: var(--muted);
    border-radius: 8px;
    padding: 6px 8px;
    line-height: 1;
    box-shadow: none;
    outline: none;
}

.mera-report-editor .mera-editor-toolbar :is(a, button):hover,
.mera-report-editor .mera-editor-toolbar :is(a, button):focus {
    background: var(--hover);
    color: #fff;

}

.mera-report-editor .mera-editor-toolbar .active {
    background: var(--brand);

    color: #fff;
}

.mera-report-editor .cm-s-easymde.CodeMirror,
.mera-report-editor .cm-s-easymde .CodeMirror,
.mera-report-editor .cm-s-easymde .CodeMirror-scroll,
.mera-report-editor .cm-s-easymde .CodeMirror-sizer,
.mera-report-editor .cm-s-easymde .CodeMirror-lines,
.mera-report-editor .cm-s-easymde .CodeMirror-code,
.mera-report-editor .cm-s-easymde .CodeMirror-line,
.mera-report-editor .cm-s-easymde .CodeMirror-linebackground,
.mera-report-editor .cm-s-easymde .CodeMirror-gutters,
.mera-report-editor .cm-s-easymde .CodeMirror-linenumber,
.mera-report-editor .cm-s-easymde .CodeMirror pre {
    background: var(--bg) !important;
    color: var(--text) !important;
    border-color: var(--border);
}

.mera-report-editor .cm-s-easymde .CodeMirror {
    border: 1px solid var(--border);
}

.mera-report-editor .cm-s-easymde .CodeMirror-gutters {
    border-right: 1px solid var(--border);
}

.mera-report-editor .cm-s-easymde .CodeMirror-cursor {
    border-left: 2px solid var(--text);
}

.mera-report-editor .cm-s-easymde .CodeMirror-selected {
    background: #264568;
}

.mera-report-editor .CodeMirror,
.mera-report-editor .CodeMirror-scroll,
.mera-report-editor .editor-preview,
.mera-report-editor .editor-preview-side {
    max-height: 520px;
}

@media (max-height: 800px) {

    .mera-report-editor .CodeMirror,
    .mera-report-editor .CodeMirror-scroll,
    .mera-report-editor .editor-preview,
    .mera-report-editor .editor-preview-side {
        max-height: 60vh;
    }
}

.mera-report-editor .editor-preview,
.mera-report-editor .editor-preview-side {
    background: var(--bg);
    color: var(--text);
}

.mera-report-editor .editor-preview a,
.mera-report-editor .editor-preview-side a {
    color: var(--link);
}

/* ========== CHANGELIST INNER SCROLLBAR (hidden by default, visible on hover) ========== */
/* Make scrollbar translucent and visible on hover; fallback behavior across browsers */
#changelist-form .results {
    /* Firefox: hide by default */
    scrollbar-width: none;
    /* ensure overlays scroll smoothly */
    -webkit-overflow-scrolling: touch;
}

#changelist-form .results:hover {
    /* Firefox: show default thickness on hover */
    scrollbar-width: auto;
    /* thumb + track color for Firefox (thumb then track) */
    scrollbar-color: rgba(242, 242, 242, 0.237) transparent;
}

/* WebKit-based browsers */
#changelist-form .results::-webkit-scrollbar {
    width: 0px;
    height: 0px;
}

#changelist-form .results:hover::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

#changelist-form .results:hover::-webkit-scrollbar-track {
    background: transparent;
}

#changelist-form .results:hover::-webkit-scrollbar-thumb {
    background-color: rgba(13, 13, 13, 0.16);
    border-radius: 6px;
    border: 2px solid transparent;
    /* create spacing effect */
    background-clip: padding-box;
}

/* Add a subtle transition for hover appearance */
#changelist-form .results:hover::-webkit-scrollbar-thumb {
    transition: background-color 160ms linear;
}


.mera-report-editor .editor-preview table,
.mera-report-editor .editor-preview-side table {
    border-color: var(--border);
}

.mera-report-editor .editor-preview th,
.mera-report-editor .editor-preview td,
.mera-report-editor .editor-preview-side th,
.mera-report-editor .editor-preview-side td {
    border-color: var(--border);
}

.mera-report-editor .editor-preview tr:nth-child(2n),
.mera-report-editor .editor-preview-side tr:nth-child(2n) {
    background: var(--bg-2);
}

.mera-report-editor .editor-preview pre,
.mera-report-editor .editor-preview code,
.mera-report-editor .editor-preview-side pre,
.mera-report-editor .editor-preview-side code {
    background: var(--bg-2);
    color: var(--text);
}

.mera-report-editor .editor-preview blockquote,
.mera-report-editor .editor-preview-side blockquote {
    border-left: 4px solid var(--border);
    color: var(--muted);
}

.mera-report-editor .btn-save {
    background: var(--brand);
    color: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
}

.mera-report-editor .btn-save:hover {
    background: #2a7df0;
    border-color: #2a7df0;
}

.mera-report-editor .btn-cancel {
    background: #323443;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
}

.mera-report-editor .btn-cancel:hover {
    background: var(--hover);
}

.mera-report-editor .md-tab,
.mera-report-editor .mera-editor-toolbar :is(a, button),
.mera-report-editor .btn-save,
.mera-report-editor .btn-cancel {
    outline: none;
    box-shadow: none;
}

.mera-report-edit-btn--text {
    width: auto;
    height: 32px;
    padding: 0 10px;
    gap: 6px;
    border-radius: 8px;
}

.mera-report-edit-btn svg {
    width: 14px;
    height: 14px;
    display: inline-block;
    vertical-align: middle;
    fill: currentColor;
    pointer-events: none;
}

/* Too broad */
span {
    max-width: 250px;
}

.mera-report-edit-btn--text span {
    font-size: 13px;
    line-height: 1;
}

.mera-share {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-left: 17% !important;
    margin: 18px 0 4px;
}

.mera-share a {
    color: #fff;
    padding: 10px 18px;
    border-radius: 30px;
    box-shadow: 0 10px 10px rgba(0, 0, 0, 0.5);
    text-transform: uppercase;
    letter-spacing: .4px;
    font-size: .95rem;
}

.mera-share a:hover {
    opacity: .9
}

.mera-share-test .mera-report-editor {
    --bg: #23242b;
    --bg-tab: #535977;
    --bg-toolbar: #23242b;
}

.mera-share-test .mera-report-edit-form {
    margin: 0;
}

.mera-share-test .md-tabs {
    display: inline-flex;
    gap: 4px;
    background: transparent;
    position: relative;
    z-index: 2;
}

.mera-share-test .md-tab {
    appearance: none;
    border: 0;
    border-radius: 10px 10px 0 0;
    padding: 6px 12px;
    font-weight: 400;
    background: #3e4257;
    color: #d3d7e3;
    cursor: pointer;
}

.mera-share-test .md-tab:hover {
    filter: brightness(1.05);
}

.mera-share-test .md-tab-active {
    background: #2f3347;
    color: #fff;
    font-weight: 700;
}

.mera-share-test .EasyMDEContainer {
    background: #2f3347;
    border-radius: 0 12px 12px 12px;
    padding: 10px;
    margin-top: 1px;
}

.mera-share-test .EasyMDEContainer .CodeMirror {
    background: #2f3347;
    color: #fff;
    min-height: 260px;
}

.mera-share-test .EasyMDEContainer .mera-editor-toolbar {
    background: var(--bg-toolbar);
    border: 1px solid #3b3f55;
    border-radius: 8px 8px 0 0;
}

.mera-share-test .EasyMDEContainer .mera-editor-toolbar a {
    color: #cfd5e6;
}

.mera-share-test .EasyMDEContainer .mera-editor-toolbar a:hover {
    color: #fff;
}

.mera-share-test .EasyMDEContainer .mera-editor-preview {
    background: #2f3347;
    color: #e6e9f4;
    border: 1px solid #3b3f55;
    padding: 12px;
}

.mera-share-test .btn-row {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 10px;
}

.mera-share-test .btn-cancel,
.mera-share-test .btn-save {
    appearance: none;
    border: 0;
    border-radius: 12px;
    padding: 8px 14px;
    font-weight: 600;
}

.mera-share-test .btn-cancel {
    background: #2c2f3e;
    color: #e6e9f4;
    font-weight: 400;
}

.mera-share-test .btn-save {
    background: #5b6cff;
    color: #fff;
}

.mera-share-test .btn-cancel:hover {
    filter: brightness(1.08);
}

.mera-share-test .btn-save:hover {
    filter: brightness(1.06);
}

.EasyMDEContainer .mera-editor-toolbar a:before,
.EasyMDEContainer .mera-editor-toolbar i.fa {
    font-family: "FontAwesome" !important;
    font-style: normal;
    font-weight: normal;
}

/* ========== GRAPHS ========== */
.mera-graph {
    break-inside: avoid;
    page-break-inside: avoid;
    margin: 12px 0 6px;
    max-width: 100%;
}

.mera-graph .plotly-graph-div {
    width: 100% !important;
    min-height: clamp(360px, 44vw, 560px) !important;
}

.mera-graph svg,
.mera-graph img {
    display: block;
    max-width: 100% !important;
    height: auto !important;
    margin: 0 auto;
}

/* ========== PROGRESS GRID ========== */
.mera-progress-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

@media (max-width: 1000px) {
    .mera-share {
        margin-left: auto !important;
    }

    .mera-progress-grid {
        grid-template-columns: 1fr;
    }
}

/* ========== PRINT ========== */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
        font-family: Georgia, serif;
    }

    * {
        color: #000 !important;
        text-shadow: none !important;
        box-shadow: none !important;
    }

    p,
    a,
    h1,
    h2,
    h3,
    h4,
    h5 {
        color: #000 !important;
    }

    .toc-desktop,
    .toc-mobile,
    .share {
        display: none !important;
    }

    .report,
    pre {
        background: #fff !important;
        border: none;
        border-radius: 0;
    }

    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 90%;
    }

    .graph {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    @page {
        margin: 18mm;
    }
}

/* ========== INTAKE FORM ========== */
.mera-intake-skin {
    --radius: 14px;
    --surface-2: #2e3142;
    --text: #eef0f4;
    --text-muted: #c7cad4;
    --accent: #4fd6a8;
    --accent-2: #35b79b;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    color: var(--text);
}

.mera-intake-skin.mera-intake-form {
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: 0 10px 22px rgba(0, 0, 0, .3);
    max-width: 860px;
    margin: 18px auto;
}

.mera-intake-skin .mera-section-title {
    color: var(--accent);
    border-bottom: 2px solid var(--accent-2);
    padding-bottom: 10px;
    margin-bottom: 12px;
    font-weight: 600;
}

.mera-intake-skin .mera-form-table {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 14px 18px;
    align-items: center;
}

@media (max-width: 390px) {

    #id_health_goals,
    #id_notes {
        max-width: 250px !important;
    }

    .form-row textarea,
    .mera-intake-skin textarea {
        max-width: min(90vw, 320px);
    }
}

@media (max-width: 720px) {
    .mera-intake-skin .mera-form-table {
        grid-template-columns: 1fr;
    }

    .related-widget-wrapper,
    .form-row {
        padding: 10px !important;
    }
}

.mera-intake-skin .mera-row-field :is(input, select, textarea) {
    padding: 10px 12px;
    border: 1px solid #3f4660;
    border-radius: 8px;
    background: #2f3347;
    color: #fff;
}

.mera-intake-skin .mera-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 4px;
}

.mera-intake-skin .mera-actions {
    margin-top: 18px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.mera-intake-skin .mera-actions .btn.primary {
    background: #6b79c7;
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-weight: 700;
    cursor: pointer;
}

.mera-intake-skin .mera-actions .btn.primary:hover {
    filter: brightness(1.06);
}