/* Shared workspace controls; inherit the site's public/admin design tokens. */
.ml-shell, .ml-dialog, .ml-selection, .ml-preview {
    --ml-primary: var(--admin-primary, var(--primary-color, #6366f1));
    --ml-text: var(--admin-text, var(--text-main, #111827));
    --ml-muted: var(--admin-text-secondary, var(--text-secondary, #6b7280));
    --ml-border: var(--admin-border, var(--border-color, #e5e7eb));
    --ml-surface: var(--admin-surface, var(--bg-surface, #fff));
    color: var(--ml-text);
    font-family: inherit;
    box-sizing: border-box;
}
.ml-shell { width: 100%; padding: 24px; margin: 0 auto; }
.ml-shell *, .ml-dialog *, .ml-selection * { box-sizing: border-box; }
.ml-workspace { flex: 1; min-height: 0; overflow: auto; background: var(--bg-light); }
.ml-page-title, .ml-header, .ml-toolbar, .ml-actions { display: flex; align-items: center; gap: 12px; }
.ml-header { justify-content: space-between; margin-bottom: 20px; }
.ml-header h1, .ml-header h2 { margin: 0; font-size: 18px; font-weight: 600; }
.ml-muted { color: var(--ml-muted); font-size: 12px; line-height: 1.5; }
.ml-shell button:where(:not(.lp-modal-close)), .ml-shell input, .ml-shell select, .ml-editor input, .ml-editor select, .ml-selection button:where(:not(.btn)) {
    font: inherit; font-size: 13px; color: var(--ml-text); border: 1px solid var(--ml-border);
    background: var(--ml-surface); border-radius: 8px; padding: 8px 12px; line-height: 20px;
}
.ml-shell button:where(:not(.lp-modal-close)), .ml-selection button:where(:not(.btn)) { cursor: pointer; transition: background .16s, border-color .16s, color .16s; }
.ml-shell button:where(:not(.lp-modal-close)):hover, .ml-selection button:where(:not(.btn)):hover { border-color: #c7cbd3; background: #f9fafb; }
.ml-shell button:disabled, .ml-selection button:disabled { opacity: .5; cursor: default; }
.ml-shell button:focus-visible, .ml-shell input:focus-visible, .ml-filters summary:focus-visible, .ml-selection button:focus-visible {
    outline: 2px solid var(--ml-primary); outline-offset: 3px;
}
.ml-primary { background: var(--ml-primary) !important; border-color: var(--ml-primary) !important; color: #fff !important; font-weight: 600 !important; }
.ml-toolbar { justify-content: space-between; gap: 20px; margin: 0 0 20px; }
.ml-tabs { display: flex; gap: 24px; align-self: stretch; }
.ml-shell .ml-tabs button { position: relative; border: 0; background: none; border-radius: 0; padding: 9px 0 13px; color: var(--ml-muted); font-size: 14px; white-space: nowrap; }
.ml-shell .ml-tabs button[aria-pressed=true] { color: var(--ml-text); font-weight: 600; }
.ml-tabs button[aria-pressed=true]::after { content: ''; height: 2px; background: var(--ml-primary); border-radius: 2px; position: absolute; bottom: 0; left: 0; right: 0; }
.ml-search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--ml-border); border-radius: 8px; padding: 0 12px; background: var(--ml-surface); width: 240px; }
.ml-search svg { width: 16px; height: 16px; color: #9ca3af; flex-shrink: 0; }
.ml-shell .ml-search input { border: 0; padding: 8px 0; outline: none; width: 100%; min-width: 0; background: transparent; }
.ml-filterbar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; padding-bottom: 20px; border-bottom: 1px solid var(--ml-border); }
.ml-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.ml-filters details { position: relative; min-width: 100px; }
.ml-filters summary { list-style: none; cursor: pointer; border: 1px solid var(--ml-border); border-radius: 8px; padding: 7px 12px; font-size: 13px; background: var(--ml-surface); display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.ml-filters summary::-webkit-details-marker { display: none; }
.ml-filters summary::after { content: ''; width: 6px; height: 6px; border-right: 1.5px solid #9ca3af; border-bottom: 1.5px solid #9ca3af; transform: rotate(45deg) translateY(-2px); }
.ml-filters details[open] summary, .ml-filters details:has(input:checked) summary { border-color: var(--ml-primary); color: var(--ml-primary); }
.ml-options { position: absolute; z-index: 5; left: 0; top: calc(100% + 6px); min-width: 190px; max-height: 260px; overflow: auto; padding: 6px; background: var(--ml-surface); border: 1px solid var(--ml-border); box-shadow: var(--shadow-lg, 0 8px 25px #11182714); border-radius: 10px; }
.ml-options label { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 5px; white-space: nowrap; font-size: 13px; cursor: pointer; }
.ml-options label:hover { background: #f3f4f6; }
.ml-options input { accent-color: var(--ml-primary); }
.ml-shell [data-reset] { border: 0; background: none; color: var(--ml-muted); padding: 4px; font-size: 12px; }
.ml-shell [data-count] { margin-left: auto; white-space: nowrap; font-size: 12px; color: #9ca3af; }
.ml-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 20px 16px; margin-top: 20px; }
.ml-card { min-width: 0; position: relative; border: 1px solid var(--ml-border); border-radius: 10px; background: var(--ml-surface); overflow: hidden; transition: border-color .16s; }
.ml-card:hover { border-color: #cbd0db; }
.ml-card.is-selected { border-color: var(--ml-primary); box-shadow: 0 0 0 1px var(--ml-primary); }
.ml-photo { position: relative; overflow: hidden; background: #f0f1f3; }
.ml-shell .ml-image { display: block; border: 0; padding: 0; width: 100%; border-radius: 0; background: transparent; }
.ml-image img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.ml-unavailable { aspect-ratio: 1; display: grid; place-items: center; color: #9ca3af; font-size: 13px; }
.ml-shell .ml-icon-button { position: absolute; display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid #ffffff80; border-radius: 50%; padding: 0; background: #fffffff0; color: #4b5563; box-shadow: 0 1px 4px #1118270d; }
.ml-icon-button svg { width: 16px; height: 16px; }
.ml-shell .ml-favorite { top: 10px; right: 10px; }
.ml-shell .ml-favorite[aria-pressed=true] { color: var(--ml-primary); }
.ml-favorite[aria-pressed=true] svg { fill: currentColor; }
.ml-shell .ml-preview-action { bottom: 10px; right: 10px; opacity: 0; transform: translateY(3px); transition: opacity .16s, transform .16s; }
.ml-card:hover .ml-preview-action, .ml-card:focus-within .ml-preview-action { opacity: 1; transform: none; }
.ml-selected-badge { position: absolute; bottom: 10px; left: 10px; display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; padding: 4px 8px; border-radius: 5px; color: #fff; background: var(--ml-primary); }
.ml-selected-badge svg { width: 12px; height: 12px; }
.ml-info { padding: 10px 12px 12px; }
.ml-card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ml-card-title strong { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ml-card-title span { font-size: 11px; color: #9ca3af; white-space: nowrap; }
.ml-tags { display: flex; gap: 5px; margin-top: 7px; overflow: hidden; }
.ml-tags span { font-size: 10px; line-height: 17px; color: #6b7280; background: #f5f6f8; padding: 1px 5px; border-radius: 3px; white-space: nowrap; }
.ml-sentinel { text-align: center; padding: 28px 12px; min-height: 70px; color: #9ca3af; font-size: 12px; }
.ml-dialog { border: 1px solid var(--ml-border); padding: 0; border-radius: 12px; width: min(1080px, 94vw); max-height: 90vh; box-shadow: var(--shadow-lg); margin: auto; background: var(--ml-surface); }
.ml-dialog::backdrop { background: #0f172a66; }
.ml-dialog .ml-shell { padding: 24px; }
.ml-scroll { overflow: auto; height: 62vh; padding: 2px 4px; }
.ml-footer { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--ml-border); padding-top: 16px; margin-top: 16px; }
.ml-footer .ml-primary { padding: 8px 24px; }
.ml-dialog .lp-modal-close, .ml-preview .lp-modal-close { padding: 0; flex-shrink: 0; }
.ml-dialog .lp-modal-close svg, .ml-preview .lp-modal-close svg { width: 20px; height: 20px; }
.ml-preview { border: 0; border-radius: 12px; padding: 12px; max-width: 90vw; max-height: 92vh; margin: auto; }
.ml-preview::backdrop { background: #0f172aa6; }
.ml-preview img { display: block; max-width: 80vw; max-height: 78vh; object-fit: contain; }
.ml-selection { border: 1px solid var(--ml-border); border-radius: 8px; padding: 14px; margin: 12px 0; background: var(--ml-surface); }
.ml-selection strong { font-size: 13px; font-weight: 600; }
.ml-selection .ml-muted { margin-top: 8px; font-size: 11px; }
.ml-selected { display: flex; gap: 10px; align-items: center; margin-top: 10px; font-size: 12px; }
.ml-selected:empty { display: none; }
.ml-selected img { width: 64px; height: 64px; border: 1px solid var(--ml-border); border-radius: 6px; object-fit: cover; }
.ml-editor { display: grid; gap: 14px; padding: 8px 0; min-width: min(540px, 76vw); }
.ml-editor label { display: grid; gap: 6px; font-size: 13px; }
.ml-editor input, .ml-editor select { width: 100%; }
.ml-editor input[type=checkbox] { width: auto; }
.ml-editor .ml-actions { flex-wrap: wrap; }
.ml-error { color: #b42336; font-size: 13px; }
.ml-admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ml-admin-table td, .ml-admin-table th { text-align: left; padding: 12px; border-bottom: 1px solid var(--ml-border); }
.ml-admin-table th { background: var(--admin-bg, #f8fafc); color: var(--ml-muted); font-weight: 500; }
.ml-admin-table img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; }
.ml-admin-table .ml-actions { flex-wrap: wrap; }
.ml-results { max-height: 300px; overflow: auto; white-space: pre-wrap; font-size: 13px; }
.ml-admin-wrap { overflow: auto; }
[data-admin-models] .ml-shell { padding: 0; }
[data-admin-models] .ml-header { flex-wrap: wrap; }
[data-admin-models] .ml-actions { flex-wrap: wrap; }
.ml-nav-toggle { display: none; border: 0; background: none; padding: 4px; color: var(--text-secondary); cursor: pointer; }
body[data-page=models] .menu-link-item.active a { color: var(--primary-color); background: #eef2ff; border-right: 3px solid var(--primary-color); }
@media (max-width: 1024px) { .ml-nav-toggle { display: block; } }
@media (max-width: 600px) {
    .ml-shell, .ml-dialog .ml-shell { padding: 16px; }
    .ml-toolbar { gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
    .ml-search { width: 100%; }
    .ml-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 10px; }
    .ml-filterbar { gap: 8px; }
    .ml-filters { width: 100%; gap: 6px; }
    .ml-filters details { min-width: 0; flex: 1 1 auto; }
    .ml-filters summary { gap: 12px; padding: 6px 10px; font-size: 12px; }
    .ml-filters details:last-child .ml-options { left: auto; right: 0; }
    .ml-card-title { align-items: flex-start; flex-direction: column; gap: 2px; }
    .ml-info { padding: 8px 9px 10px; }
    .ml-scroll { height: 60vh; }
    .ml-shell .ml-preview-action { opacity: 1; transform: none; }
    body[data-page=models] .app-topbar { padding: 0 16px; }
}

/* Compact reference control, aligned with the generation settings panel. */
.ml-selection { padding: 0; border: 0; border-radius: 0; background: none; margin: 16px 0 12px; }
.ml-selection-heading { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.ml-selection-heading strong { font-size: 13px; }
.ml-selection-heading > span { font-size: 11px; color: var(--text-muted, #9ca3af); font-weight: 400; }
.ml-choice { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--ml-border); border-radius: 8px; background: var(--ml-surface); }
.ml-choice .ml-selected { position: relative; flex: 0 0 56px; width: 56px; height: 56px; margin: 0; border-radius: 6px; display: grid; place-items: center; background: var(--bg-light, #f9fafb); color: #9ca3af; }
.ml-choice .ml-selected img { width: 56px; height: 56px; border: 0; }
.ml-selection .ml-remove-model { position: absolute; top: -5px; right: -5px; padding: 0; display: grid; place-items: center; width: 18px; height: 18px; border: 1px solid #e5e7eb; border-radius: 50%; background: #fff; color: #6b7280; line-height: 16px; font-size: 15px; }
.ml-choice-controls { min-width: 0; flex: 1; }
.ml-choice-controls [data-model-title] { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 6px; }
.ml-choice-controls .ml-actions { gap: 8px; flex-wrap: wrap; }
.ml-selection .ml-actions .btn { padding: 6px 10px; font-size: 12px; line-height: 18px; white-space: nowrap; }
.ml-selection .ml-muted { margin: 6px 0 0; font-size: 11px; color: var(--text-muted, #9ca3af); }
.reference-preference-options:has(#reference-model-toggle) { grid-template-columns: minmax(0, 1fr); }
.reference-preference-options:has(#reference-model-toggle) .reference-preference-option { align-items: center; padding: 10px 12px; }
.reference-preference-options:has(#reference-model-toggle) .reference-preference-option small { font-size: 11px; }

.ml-selection [data-note]:empty { display: none; }

.ml-dialog:focus, .ml-preview:focus { outline: none; }
