/* Patient identifiers must never paint across the adjacent name column. */
#div_patient_results .patientresults {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.8fr) 18px 80px;
    grid-template-areas: "id name sex birth" "species breed neutered last";
    column-gap: 10px;
    row-gap: 4px;
    align-items: center;
}
#div_patient_results .patientresults > * {
    min-width: 0;
    width: auto;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#div_patient_results #ele_patientid { grid-area: id; overflow-wrap: anywhere; white-space: normal; }
#div_patient_results #ele_patient { grid-area: name; }
#div_patient_results #ele_species { grid-area: species; }
#div_patient_results #ele_breed { grid-area: breed; }
#div_patient_results #ele_patientsex { grid-area: sex; }
#div_patient_results #ele_birthdate { grid-area: birth; }
#div_patient_results #ele_castrated { grid-area: neutered; }
#div_patient_results #ele_lastdate { grid-area: last; }
@media (max-width: 600px) {
    #div_patient_results .patientresults {
        grid-template-columns: minmax(0, 1fr) 18px 80px;
        grid-template-areas: "name name name" "id sex birth" "species neutered last" "breed breed breed";
    }
}

/* Gallery headers and row alignment. Image tiles use the original viewer styles. */
#div_patient_data {
    --gallery-surface: #101f2a;
    --gallery-line: #2b414f;
    --gallery-text: #e3edf3;
    --gallery-muted: #abc0cd;
    --gallery-accent: #41bbd5;
    background: #0c1922;
    color: var(--gallery-text);
    scrollbar-color: #547481 #0c1922;
    color-scheme: dark;
}

#div_patient_data .patient_header,
#div_patient_data .study_header,
#div_patient_data .series_header {
    width: calc(100% - 24px);
    margin: 6px 12px;
    border: 1px solid var(--gallery-line);
    border-radius: 0 3px 3px 0;
    border-left: 4px solid var(--level-color);
    background: var(--gallery-surface);
    color: var(--gallery-text);
    box-shadow: none;
    transition: border-color .15s ease;
}
#div_patient_data .patient_header { --level-color: #4fb4e8; --gallery-surface: #102b3b; min-height: 64px; margin-bottom: 8px; }
#div_patient_data .study_header {
    --level-color: #8796ed;
    min-height: 36px;
    margin-top: 10px;
    background: #222b46;
}
#div_patient_data .series_header {
    width: calc(100% - 36px);
    --level-color: #be8be6;
    min-height: 32px;
    margin: 4px 12px 4px 24px;
    background: #30253f;
}
#div_patient_data .gallery-grid {
    padding-left: 24px;
    padding-right: 12px;
}
#div_patient_data .patient_header:hover,
#div_patient_data .study_header:hover,
#div_patient_data .series_header:hover {
    border-color: #466373;
    border-left-color: var(--level-color);
    color: var(--gallery-text);
    box-shadow: none;
}
#div_patient_data.is-patient-header-collapsed .patient_header { box-shadow: none; }
#div_patient_data .patient_header > .div_menuandcheck,
#div_patient_data .study_header > .div_menuandcheck,
#div_patient_data .series_header > .div_menuandcheck {
    flex: 0 0 auto;
    width: auto;
    align-self: center;
    align-items: center;
    flex-direction: row;
    gap: 2px;
    margin: 0 6px;
    padding: 0 6px 0 0;
    border-right: 1px solid var(--gallery-line);
}
#div_patient_data .study_header > div:not(.div_menuandcheck),
#div_patient_data .series_header > div:not(.div_menuandcheck) {
    padding: 4px 6px;
    gap: 6px 16px;
}
#div_patient_data .patient_header .patientresultselements,
#div_patient_data .study_header .patientresultselements,
#div_patient_data .series_header .patientresultselements {
    font-size: 12px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--gallery-muted);
    text-shadow: none;
}
#div_patient_data .study_header .patientresultselements:first-child,
#div_patient_data .series_header .patientresultselements:first-child {
    color: var(--gallery-text);
    font-weight: 700;
}
#div_patient_data .patient_header > div.patient-card-content {
    display: grid;
    grid-template-columns: minmax(0, max-content) 32px;
    grid-template-areas: "main search" "details details";
    gap: 6px 12px;
    padding: 7px 12px;
}
#div_patient_data .patient-card-main {
    grid-area: main;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
}
#div_patient_data .patient-card-kicker { display: none; }
#div_patient_data .patient_header .patient-card-name {
    max-width: 100%; font-size: 16px; font-weight: 700; color: var(--gallery-text); text-shadow: none;
}
#div_patient_data .patient-card-summary { gap: 6px 14px; }
#div_patient_data .patient_header .patient-card-id {
    padding: 0; background: none; border-radius: 0; box-shadow: none;
}
#div_patient_data .patient-card-details {
    grid-area: details;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 0;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
}
#div_patient_data .patient-card-detail {
    display: inline-flex;
    width: auto;
    max-width: 100%;
    min-height: 0;
    padding: 0 12px;
    gap: 5px;
    border: 0;
    border-left: 1px solid var(--gallery-line);
    font-size: 12px;
    line-height: 1.4;
}
#div_patient_data .patient-card-detail:first-child { padding-left: 0; border-left: 0; }
#div_patient_data .patient-card-detail .material-icons { display: none; }
#div_patient_data .patient-card-detail span { color: var(--gallery-muted); font-weight: 400; }
#div_patient_data .patient-card-detail strong { font-weight: 600; color: var(--gallery-text); }
#div_patient_data .patient_header .patient-card-search { grid-area: search; align-self: center; }
#div_patient_data .patient_header .vetera-lookup-btn,
#div_patient_data .study_header .vetera-lookup-btn {
    width: 30px; min-width: 30px; height: 30px;
    border: 1px solid var(--gallery-line); border-radius: 4px;
    color: var(--gallery-accent); background: transparent; box-shadow: none;
}
#div_patient_data .patient_header .vetera-lookup-btn .material-icons,
#div_patient_data .study_header .vetera-lookup-btn .material-icons { font-size: 18px; line-height: 28px; }
#div_patient_data .quick-preview-header-button { margin-left: 4px; color: var(--gallery-accent); }
#div_patient_data .patient_header .mdl-button,
#div_patient_data .study_header .mdl-button,
#div_patient_data .series_header .mdl-button,
#div_patient_data .patient_header .mdl-icon-toggle,
#div_patient_data .study_header .mdl-icon-toggle,
#div_patient_data .series_header .mdl-icon-toggle { width: 30px; min-width: 30px; height: 30px; }

#div_patient_data :is(.patient_header, .study_header, .series_header) button:focus-visible,
#div_patient_data :is(.patient_header, .study_header, .series_header) .mdl-icon-toggle.is-focused { outline: 2px solid var(--gallery-accent); outline-offset: 2px; }
#div_patient_data :is(.patient_header, .study_header) .vetera-lookup-btn:hover { color: #ecfaff; background: #284453; }

@media (max-width: 600px) {
    #div_patient_data .patient_header { align-items: flex-start; }
    #div_patient_data .patient_header > .div_menuandcheck,
    #div_patient_data .study_header > .div_menuandcheck,
    #div_patient_data .series_header > .div_menuandcheck { flex-direction: column; margin: 4px; padding-right: 4px; }
    #div_patient_data .patient_header > div.patient-card-content { grid-template-columns: minmax(0, 1fr) 36px; gap: 8px; padding: 10px 8px; }
    #div_patient_data .patient-card-main { gap: 6px 10px; }
    #div_patient_data .patient-card-detail { padding: 0; border: 0; flex-wrap: wrap; }
    #div_patient_data .patient-card-details { gap: 4px 12px; }
    #div_patient_data .patient_header .mdl-button,
    #div_patient_data .study_header .mdl-button,
    #div_patient_data .series_header .mdl-button,
    #div_patient_data .patient_header .mdl-icon-toggle,
    #div_patient_data .study_header .mdl-icon-toggle,
    #div_patient_data .series_header .mdl-icon-toggle { width: 36px; min-width: 36px; height: 36px; }
}
@media (forced-colors: active) {
    #div_patient_data { scrollbar-color: auto; }
    #div_patient_data .patient_header, #div_patient_data .study_header,
    #div_patient_data .series_header { border-color: CanvasText; }
}

/* One compact helper for all hierarchy levels; never clone controls or rows. */
.dicom-drag-preview {
    --drag-color: #4fb4e8;
    box-sizing: border-box; width: 280px; max-width: calc(100vw - 24px);
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border: 1px solid #526778; border-left: 5px solid var(--drag-color);
    border-radius: 0 4px 4px 0; background: #11232f; color: #ecf3f8;
    box-shadow: 0 5px 18px #0008; font: 12px system-ui, sans-serif;
    pointer-events: none; z-index: 2147482000;
}
.dicom-drag-preview[data-level="study"] { --drag-color: #8796ed; }
.dicom-drag-preview[data-level="series"] { --drag-color: #be8be6; }
.dicom-drag-preview[data-level="image"] { --drag-color: #b7c7d3; }
.dicom-drag-preview-icon { flex: none; color: var(--drag-color); font-size: 30px; }
.dicom-drag-preview-content { display: grid; min-width: 0; gap: 3px; }
.dicom-drag-preview-level { color: var(--drag-color); }
.dicom-drag-preview-label,.dicom-drag-preview-detail { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dicom-drag-preview-detail { color: #c1ced8; }
