/* model manager */
.model-manager {
    background-color: var(--comfy-menu-bg);
    box-sizing: border-box;
    color: var(--bg-color);
    font-family: monospace;
    font-size: 15px;
    height: 100%;
    padding: 8px;
    position: fixed;
    overflow: hidden;
    width: 100%;
    z-index: 2000;
    
    /*override comfy-modal settings*/
    border-radius: 0;
    box-shadow: none;
    justify-content: unset;
    max-height: 100vh;
    max-width: 100vw;
    transform: none;
    /*disable double-tap zoom on model manager*/
    touch-action: manipulation;
}

.model-manager .comfy-modal-content {
    width: 100%;
    gap: 16px;
}

.model-manager .no-highlight {
    user-select: none;
    -moz-user-select: none;
    -webkit-text-select: none;
    -webkit-user-select: none;
}

.model-manager label:has(> *){
    pointer-events: none;
}

.model-manager label > * {
    pointer-events: auto;
}

/* sidebar */

.model-manager {
    --model-manager-sidebar-width-left: 50vw;
    --model-manager-sidebar-width-right: 50vw;
    --model-manager-sidebar-height-top: 50vh;
    --model-manager-sidebar-height-bottom: 50vh;
    
    --model-manager-left: 0;
    --model-manager-right: 0;
    --model-manager-top: 0;
    --model-manager-bottom: 0;
    
    left: var(--model-manager-left);
    top: var(--model-manager-right);
    right: var(--model-manager-top);
    bottom: var(--model-manager-bottom);
}

.model-manager.cursor-drag-left,
.model-manager.cursor-drag-right {
    cursor: ew-resize;
}

.model-manager.cursor-drag-top,
.model-manager.cursor-drag-bottom {
    cursor: ns-resize;
}

.model-manager.cursor-drag-top.cursor-drag-left,
.model-manager.cursor-drag-bottom.cursor-drag-right {
    cursor: nwse-resize;
}

.model-manager.cursor-drag-top.cursor-drag-right,
.model-manager.cursor-drag-bottom.cursor-drag-left {
    cursor: nesw-resize;
}

/* sidebar buttons */
.model-manager .sidebar-buttons {
    overflow: hidden;
    color: var(--input-text);
    display: flex;
    flex-direction: row-reverse;
    flex-wrap: wrap;
}

.model-manager .sidebar-buttons .radio-button-group-active {
    border-color: var(--fg-color);
    color: var(--fg-color);
    overflow: hidden;
}

.model-manager[data-sidebar-state="left"] {
    width: var(--model-manager-sidebar-width-left);
    max-width: 95vw;
    min-width: 22vw;
    right: auto;
    border-right: solid var(--border-color) 2px;
}

.model-manager[data-sidebar-state="top"] {
    height: var(--model-manager-sidebar-height-top);
    max-height: 95vh;
    min-height: 22vh;
    bottom: auto;
    border-bottom: solid var(--border-color) 2px;
}

.model-manager[data-sidebar-state="bottom"] {
    height: var(--model-manager-sidebar-height-bottom);
    max-height: 95vh;
    min-height: 22vh;
    top: auto;
    border-top: solid var(--border-color) 2px;
}

.model-manager[data-sidebar-state="right"] {
    width: var(--model-manager-sidebar-width-right);
    max-width: 95vw;
    min-width: 22vw;
    left: auto;
    border-left: solid var(--border-color) 2px;
}

/* common */
.model-manager h1 {
    min-width: 0;
    overflow-wrap: break-word;
}

.model-manager textarea {
    border: solid 2px var(--border-color);
    border-radius: 8px;
    font-size: 1.2em;
    resize: vertical;
    width: 100%;
    height: 100%;
}

.model-manager input[type="file"] {
    width: 100%;
}

.model-manager button {
    margin: 0;
	border: 2px solid var(--border-color);
}

.model-manager button:not(.icon-button),
.model-manager select,
.model-manager input {
    padding: 4px 8px;
    margin: 0;
}

.model-manager button:disabled,
.model-manager select:disabled,
.model-manager input:disabled {
    background-color: var(--comfy-menu-bg);
    filter: brightness(1.2);
    cursor: not-allowed;
}

.model-manager button.block {
    width: 100%;
}

.model-manager ::-webkit-scrollbar {
    width: 16px;
}

.model-manager ::-webkit-scrollbar-track {
    background-color: var(--comfy-input-bg);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.model-manager ::-webkit-scrollbar-thumb {
    background-color: var(--fg-color);
    border-radius: 3px;
}

.model-manager .search-text-area::-webkit-input-placeholder {
   font-style: italic;
}
.model-manager .search-text-area:-moz-placeholder {
   font-style: italic;  
}
.model-manager .search-text-area::-moz-placeholder {
   font-style: italic;  
}
.model-manager .search-text-area:-ms-input-placeholder {  
   font-style: italic; 
}

.model-manager .icon-button {
    height: 40px;
    width: 40px;
    line-height: 1.15;
}

.model-manager .row {
    display: flex;
    min-width: 0;
    gap: 8px;
}

.model-manager .tab-header {
    display: flex;
    padding: 8px 0px;
    flex-direction: column;
    background-color: var(--bg-color);
}

.model-manager .tab-header-flex-block {
	width: 100%;
    min-width: 0;
}

.model-manager .comfy-button-success {
    color: green;
    border-color: green;
}

.model-manager .comfy-button-failure {
    color: darkred;
    border-color: darkred;
}

.model-manager .no-select {
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* main content */
.model-manager .model-manager-panel {
    color: var(--fg-color);
}

.model-manager .model-tab-group {
    display: flex;
    gap: 4px;
    height: 40px;
}

.model-manager .model-tab-group .tab-button {
    background-color: var(--comfy-menu-bg);
    border: 2px solid var(--border-color);
    border-bottom: none;
    border-radius: 8px 8px 0px 0px;
    cursor: pointer;
    padding: 8px 12px;
    margin-bottom: 0px;
    z-index: 1;
}

.model-manager .model-tab-group .tab-button.active {
    background-color: var(--bg-color);
    cursor: default;
    position: relative;
    z-index: 1;
    pointer-events: none;
}

.model-manager .model-manager-body {
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
}

.model-manager .model-manager-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.model-manager .model-manager-body {
    flex: 1;
    overflow: hidden;
    padding: 8px 0px 8px 16px;
}

.model-manager .model-manager-body .tab-contents {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    width: auto;
    overflow-x: auto;
    overflow-y: hidden;
}

.model-manager .model-manager-body .tab-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    padding-right: 16px;
}

/* model info view */
.model-manager .model-info-container {
    background-color: var(--bg-color);
    border-radius: 16px;
    color: var(--fg-color);
    width: auto;
}

.model-manager .model-metadata {
    table-layout: fixed;
    text-align: left;
    width: 100%;
}

.model-manager .model-metadata-key {
    overflow-wrap: break-word;
    width: 20%;
}

.model-manager .model-metadata-value {
    overflow-wrap: anywhere;
    width: 80%;
}

.model-manager table {
    border-collapse: collapse;
}

.model-manager th {
    border: 1px solid;
    padding: 4px 8px;
}

/* download tab */

.model-manager .download-model-infos {
    display: flex;
    flex-direction: column;
    padding: 0;
    row-gap: 10px;
}

.model-manager .download-details summary {
    background-color: var(--comfy-menu-bg);
    border-radius: 16px;
    padding: 16px;
    word-wrap: break-word;
}

.model-manager .download-details[open] summary {
    background-color: var(--border-color);
}

.model-manager .download-details > div {
    column-gap: 8px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px;
    row-gap: 16px;
}

.model-manager [data-name="Download"] .download-settings-wrapper {
    flex: 1;
}

.model-manager [data-name="Download"] .download-settings {
    display: flex;
    flex-direction: column;
    row-gap: 16px;
}

.model-manager .download-button {
    max-width: fit-content;
}

/* models tab */
.model-manager [data-name="Models"] .row {
    position: sticky;
    z-index: 1;
    top: 0;
}

/* preview image */
.model-manager .item {
    position: relative;
    width: 240px;
    height: 360px;
    text-align: center;
    overflow: hidden;
	border-radius: 8px;
}

.model-manager .item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

.model-manager .model-info-container .item {
    width: auto;
    height: auto;
}
.model-manager .model-info-container .item img {
    height: auto;
    width: auto;
    max-width: 100%;
    max-height: 50vh;
}

.model-manager .model-preview-button-left,
.model-manager .model-preview-button-right {
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto;
    border-radius: 20px;
}

.model-manager .model-preview-button-right {
    right: 4px;
}

.model-manager .model-preview-button-left {
    left: 4px;
}

.model-manager .item .model-preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background-color: rgba(0, 0, 0, 0);
}

/* grid */
.model-manager .comfy-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.model-manager .comfy-grid .model-label {
	background-color: rgb(from var(--content-hover-bg) r g b / 0.5);
	width: 100%;
	height: 2.2rem;
	position: absolute;
	bottom: 0;
	text-align: center;
	line-height: 2.2rem;
}

.model-manager .comfy-grid .model-label > p {
	width: calc(100% - 2rem);
	overflow-x: scroll;
	white-space: nowrap;
	display: inline-block;
	vertical-align: middle;
	margin: 0;
}

.model-manager .comfy-grid .model-label {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.model-manager .comfy-grid .model-label ::-webkit-scrollbar { 
    width: 0;
    height: 0;
}

.model-manager .comfy-grid .model-preview-top-right,
.model-manager .comfy-grid .model-preview-top-left {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 8px;
    top: 8px;
}

.model-manager .comfy-grid .model-preview-top-right {
    right: 8px;
}

.model-manager .comfy-grid .model-preview-top-left {
    left: 8px;
}

.model-manager .comfy-grid .model-button {
    opacity: 0.65;
}

.model-manager .comfy-grid .model-button:hover {
    opacity: 1;
}

.model-manager .comfy-grid .model-label {
    user-select: text;
}

/* radio */
.model-manager .comfy-radio-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.model-manager .comfy-radio {
    display: flex;
    gap: 4px;
    padding: 4px 16px;
    color: var(--input-text);
	border: 2px solid var(--border-color);
    border-radius: 16px;
    background-color: var(--comfy-input-bg);
    font-size: 18px;
}

.model-manager .comfy-radio:has(> input[type="radio"]:checked) {
	border-color: var(--border-color);
	background-color: var(--comfy-menu-bg);
}

.model-manager .comfy-radio input[type="radio"]:checked + label {
	color: var(--fg-color);
}

.model-manager .radio-input {
	opacity: 0;
	position: absolute;
}

/* model preview select */
.model-manager .model-preview-select-radio-container {
    min-width: 0;
    flex: 1;
}

.model-manager .model-preview-select-radio-inputs > div {
    padding: 16px 0 8px 0;
}

.model-manager .model-preview-select-radio-container img {
    position: relative;
    width: 230px;
    height: 345px;
    text-align: center;
    overflow: hidden;
	border-radius: 8px;
    object-fit: cover;
}

/* topbar */
.model-manager .topbar-buttons {
    display: flex;
    float: right;
}

.model-manager .topbar-buttons button {
    height: 33px;
    padding: 1px 6px;
    width: 33px;
}

.model-manager .model-manager-head .topbar-left {
    display: flex;
    float: left;
}

.model-manager .model-manager-head .topbar-right {
    column-gap: 4px;
    display: flex;
    flex-direction: row-reverse;
    float: right;
}

.model-manager .model-manager-head .topbar-right select {
    position: relative;
    top: 0;
    bottom: 0;
    font-size: 24px;
    -o-appearance: none;
    -ms-appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* search dropdown */
.model-manager .input-dropdown-container {
    position: relative;
}

.model-manager .search-models {
    display: flex;
    flex: 1;
    flex-direction: row;
    min-width: 0;
}

.model-manager .model-select-dropdown {
    min-width: 0;
    overflow: auto;
}

.model-manager .search-text-area,
.model-manager .plain-text-area,
.model-manager .model-select-dropdown {
	flex: 1;
    min-height: 36px;
    padding-block: 0;
    min-width: 36px;
}

.model-manager .model-select-dropdown {
    min-height: 40px;
}

.model-manager .search-directory-dropdown {
    background-color: var(--bg-color);
    border: 2px var(--border-color) solid;
    border-radius: 10px;
    color: var(--fg-color);
    max-height: 40vh;
    overflow: auto;
    position: absolute;
    z-index: 1;
}

@media (pointer:none), (pointer:coarse) {
    .model-manager .search-directory-dropdown {
        max-height: 17.5vh;
    }
}

.model-manager .search-directory-dropdown:empty {
    display: none;
}

.model-manager .search-directory-dropdown > p {
    margin: 0;
    padding: 0.85em 20px;
    min-width: 0;
}
.model-manager .search-directory-dropdown > p {
    -ms-overflow-style: none;  /* Internet Explorer 10+ */
    scrollbar-width: none;  /* Firefox */
}
.model-manager .search-directory-dropdown > p::-webkit-scrollbar { 
    display: none;  /* Safari and Chrome */
}

.model-manager .search-directory-dropdown > p.search-directory-dropdown-key-selected,
.model-manager .search-directory-dropdown > p.search-directory-dropdown-mouse-selected {
    background-color: var(--border-color);
}

.model-manager .search-directory-dropdown > p.search-directory-dropdown-key-selected {
    border-left: 1mm solid var(--input-text);
}

/* model manager settings */
.model-manager .model-manager-settings > div,
.model-manager .model-manager-settings > label,
.model-manager .tag-generator-settings > label,
.model-manager .tag-generator-settings > div {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 16px 0;
}

.model-manager .model-manager-settings button {
    height: 40px;
    min-width: 120px;
    justify-content: center;
}

.model-manager .model-manager-settings input[type="number"],
.model-manager .tag-generator-settings input[type="number"]{
    width: 50px;
}

.model-manager .search-settings-text {
    width: 100%;
}
