/* Model management mapping of AI Workbench Tabs, Filter, ResourceCard,
   SideSheet, Form and Descriptions components. */
.model-page {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 32px 36px;
  background: var(--surface);
  scrollbar-gutter: stable;
}

.model-page svg,
.model-overlay svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.model-page h1 {
  color: var(--ink-strong);
  font-size: 20px;
  font-weight: 600;
  line-height: 28px;
}

.model-page h2,
.model-overlay h2 {
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  line-height: 24px;
}

.model-overlay h3 {
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

.m-page-head,
.m-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.m-page-head {
  margin-bottom: 24px;
}

.m-page-head p,
.m-detail-copy {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 20px;
}

.m-tabs {
  display: flex;
  min-height: 40px;
  align-items: flex-end;
  gap: 24px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 16px;
}

.m-tab {
  position: relative;
  align-self: stretch;
  border-bottom: 2px solid transparent;
  background: transparent;
  padding: 0 2px 11px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  transition: color 160ms ease, border-color 160ms ease;
}

.m-tab:hover {
  color: var(--ink);
}

.m-tab[aria-selected="true"] {
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 500;
}

.m-tab-count {
  margin-left: 5px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 400;
}

.m-toolbar {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.m-toolbar .s-search {
  width: 260px;
  border-radius: 999px;
}

.m-toolbar .s-select {
  width: 132px;
}

.m-toolbar .s-select select {
  border-radius: 999px;
  font-weight: 500;
}

.m-result {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.m-result b {
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.m-list-scroll {
  min-width: 0;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.m-grid {
  display: flex;
  min-width: 960px;
  flex-direction: column;
  gap: 8px;
}

.m-card {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  grid-template-columns: minmax(240px, 360px) 72px 190px 96px 120px;
  gap: 24px;
  border: 1px solid #e7e9f0;
  border-radius: 8px;
  background: #f7f8fb;
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.m-card[data-model-type="distilled"] {
  min-width: 1040px;
  grid-template-columns: minmax(230px, 290px) minmax(190px, 1fr) 68px 160px 80px 104px;
  gap: 20px;
}

.m-card:hover {
  border-color: var(--accent);
  background: #fafbff;
  box-shadow: 0 3px 12px rgba(13, 7, 34, 0.1);
}

.m-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.m-card-head {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.m-card-icon {
  display: flex;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid #e2e5ed;
  border-radius: 8px;
  background: var(--surface);
  color: #526ee8;
}

.m-card[data-model-type="distilled"] .m-card-icon {
  color: #258266;
}

.m-card-icon svg {
  width: 24px;
  height: 24px;
}

.m-card-title {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}

.m-card-title-row {
  display: flex;
  min-width: 0;
  height: 20px;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.m-card-title strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-card-base {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
}

.m-card-base svg {
  width: 14px;
  height: 14px;
  color: var(--faint);
}

.m-card-base span {
  flex: 0 0 auto;
  color: var(--muted);
}

.m-card-base b {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-version-tag {
  display: inline-flex;
  min-height: 20px;
  flex: 0 0 auto;
  align-items: center;
  border-radius: 6px;
  background: var(--accent-soft);
  padding: 1px 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  line-height: 18px;
}

.m-card-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.m-card-field > span,
.m-info-grid dt {
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
  white-space: nowrap;
}

.m-card-field > div {
  min-width: 0;
  min-height: 20px;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-agent-link {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.m-agent-link svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  color: var(--accent);
}

.m-agent-link span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-card-tags {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.m-card-tags .s-tag {
  min-height: 20px;
  border: 1px solid #e2e5ed;
  border-radius: 6px;
  background: var(--surface);
  padding: 1px 6px;
  overflow: hidden;
  color: var(--ink);
  font-size: 11px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-card-tags .s-tag svg {
  width: 12px;
  height: 12px;
}

.m-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}

.m-status::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  content: "";
}

.m-status.online {
  color: var(--success);
}

.m-status.online::before {
  background: var(--success);
}

.m-status.testing {
  color: var(--accent);
}

.m-status.testing::before {
  background: var(--accent);
}

.m-status.offline {
  color: var(--muted);
}

.m-card .m-status {
  width: max-content;
  min-height: 20px;
  border-radius: 6px;
  padding: 1px 6px;
  background: var(--surface-tint);
  color: var(--muted);
  font-size: 11px;
  line-height: 18px;
}

.m-card .m-status::before {
  display: none;
}

.m-card .m-status.online {
  background: var(--success-soft);
  color: var(--success);
}

.m-card .m-status.testing {
  background: var(--accent-soft);
  color: var(--accent);
}

.m-owner {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  align-items: center;
  gap: 5px;
  border: 1px solid #e2e5ed;
  border-radius: 999px;
  background: var(--surface);
  padding: 1px 6px 1px 2px;
}

.m-owner i {
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #d9cff6;
  color: #65519a;
  font-size: 9px;
  font-style: normal;
}

.m-owner b {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 11px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-empty {
  border: 1px solid var(--rule-soft);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 64px 20px;
  color: var(--muted);
  text-align: center;
}

.m-empty svg {
  width: 32px;
  height: 32px;
  margin: 0 auto 12px;
  color: var(--faint);
}

.m-empty strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink-soft);
  font-weight: 500;
}

.m-empty p {
  margin-bottom: 14px;
  font-size: 12px;
}

.m-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 12px;
}

.m-breadcrumb button {
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}

.m-breadcrumb button:hover {
  color: var(--accent);
}

.m-breadcrumb svg {
  width: 12px;
  height: 12px;
  color: var(--faint);
}

.m-detail-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.m-detail-title h1 {
  overflow-wrap: anywhere;
}

.m-detail-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.m-evaluate-link,
.m-preview-link {
  text-decoration: none;
}

.m-detail-band {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 0;
  margin: 24px 0 0;
  border: 1px solid var(--rule-soft);
  border-radius: 8px;
  background: var(--surface-soft);
}

.m-detail-band.has-related-agent {
  grid-template-columns: 1.2fr 0.85fr 1.4fr 1fr 0.9fr;
}

.m-detail-band > div {
  min-width: 0;
  padding: 16px 18px;
}

.m-detail-band > div + div {
  border-left: 1px solid var(--rule);
}

.m-detail-band span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.m-detail-band strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-detail-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}

.m-detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.m-detail-section-head small {
  color: var(--muted);
  font-size: 12px;
}

.m-info-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px 28px;
}

.m-info-grid > div {
  min-width: 0;
}

.m-info-grid dt {
  margin-bottom: 5px;
  white-space: normal;
}

.m-info-grid > .wide {
  grid-column: span 2;
}

.m-info-grid > .full {
  grid-column: 1 / -1;
}

.m-info-grid dd {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 22px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.m-info-grid dd.m-muted-value {
  color: var(--muted);
}

.model-overlay {
  position: fixed;
  inset: 0;
  z-index: 116;
  display: flex;
  justify-content: flex-end;
  background: rgba(9, 9, 11, 0.28);
  backdrop-filter: blur(2px);
}

.m-sheet {
  display: flex;
  width: min(680px, 100vw);
  height: 100dvh;
  min-height: 0;
  flex-direction: column;
  border-left: 1px solid var(--rule);
  background: var(--surface);
  box-shadow: var(--shadow-float);
  animation: m-sheet-enter 200ms ease-out;
}

.m-sheet-head {
  display: flex;
  min-height: 64px;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--rule);
  padding: 17px 20px 14px 24px;
}

.m-sheet-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
}

.m-sheet-close {
  display: inline-flex;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.m-sheet-close:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.m-sheet-body {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  overscroll-behavior: contain;
}

.m-sheet-foot {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--rule);
  padding: 16px 24px max(16px, env(safe-area-inset-bottom));
}

.m-sheet-note {
  margin-right: auto;
  color: var(--muted);
  font-size: 12px;
}

.m-form-section + .m-form-section {
  margin-top: 26px;
  padding-top: 24px;
  border-top: 1px solid var(--rule-soft);
}

.m-form-section > h3 {
  margin-bottom: 18px;
}

.m-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px 16px;
}

.m-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 7px;
}

.m-field.full {
  grid-column: 1 / -1;
}

.m-field > label {
  color: rgba(28, 31, 35, 0.8);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

.m-field em {
  margin-left: 2px;
  color: var(--danger);
  font-style: normal;
}

.m-field input,
.m-field textarea,
.m-field select {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 8px;
  outline: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.m-field input,
.m-field select {
  height: 36px;
  padding: 0 12px;
}

.m-field textarea {
  min-height: 96px;
  padding: 8px 12px;
  line-height: 22px;
  resize: vertical;
}

.m-field input:focus,
.m-field textarea:focus,
.m-field select:focus {
  border-color: var(--faint);
  box-shadow: 0 0 0 2px var(--surface-active);
}

.m-field input[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
}

.m-field input[aria-invalid="true"],
.m-field textarea[aria-invalid="true"],
.m-field select[aria-invalid="true"] {
  border-color: var(--danger);
}

.m-field small {
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
}

.m-error {
  color: var(--danger) !important;
}

.m-pull-state {
  display: flex;
  min-height: 116px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  margin-top: 22px;
  border: 1px dashed var(--rule);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.m-pull-state > svg {
  width: 24px;
  height: 24px;
  color: var(--faint);
}

.m-pull-state strong {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
}

.m-pull-state p {
  font-size: 12px;
  line-height: 18px;
}

.m-pull-state.loading svg {
  animation: m-spin 800ms linear infinite;
}

.m-pull-state.success {
  align-items: stretch;
  border-style: solid;
  border-color: #cce8da;
  background: #f5fbf8;
  color: var(--ink-soft);
  text-align: left;
}

.m-pull-success-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--success);
  font-size: 13px;
  font-weight: 500;
}

.m-pull-success-head svg {
  width: 18px;
  height: 18px;
}

.m-pull-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 6px;
}

.m-pull-grid span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
}

.m-pull-grid strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-edit-identity {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule-soft);
}

.m-edit-identity strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

.m-edit-identity span {
  color: var(--muted);
  font-size: 12px;
}

@keyframes m-sheet-enter {
  from {
    opacity: 0;
    transform: translateX(14px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes m-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1280px) {
  .model-page {
    padding: 24px;
  }
}

@media (max-width: 900px) {
  .m-info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .m-detail-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .m-detail-band > div:nth-child(3) {
    border-top: 1px solid var(--rule);
    border-left: 0;
  }

  .m-detail-band > div:nth-child(4) {
    border-top: 1px solid var(--rule);
  }

  .m-detail-band.has-related-agent > div:nth-child(5) {
    border-top: 1px solid var(--rule);
    border-left: 0;
  }
}

@media (max-width: 760px) {
  .model-page {
    height: calc(100dvh - 56px);
    padding: 20px 16px 32px;
  }

  .m-page-head,
  .m-detail-head {
    align-items: flex-start;
    gap: 12px;
  }

  .m-page-head .s-button,
  .m-detail-actions .s-button {
    height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }

  .m-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .m-toolbar .s-search {
    width: 100%;
    grid-column: 1 / -1;
  }

  .m-toolbar .s-select {
    width: 100%;
  }

  .m-toolbar > .s-button {
    justify-self: start;
  }

  .m-result {
    grid-column: 1 / -1;
    margin-left: 0;
  }

  .m-detail-head {
    flex-direction: column;
  }

  .m-detail-actions {
    width: 100%;
  }

  .m-detail-actions .s-button,
  .m-detail-actions .m-evaluate-link {
    flex: 1;
  }

  .m-info-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .m-info-grid > .wide,
  .m-info-grid > .full {
    grid-column: auto;
  }

  .m-sheet-head,
  .m-sheet-body,
  .m-sheet-foot {
    padding-right: 16px;
    padding-left: 16px;
  }

  .m-form-grid {
    grid-template-columns: 1fr;
  }

  .m-field.full {
    grid-column: auto;
  }

  .m-pull-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 460px) {
  .m-page-head {
    flex-direction: column;
  }

  .m-page-head .s-button {
    width: 100%;
  }

  .m-tabs {
    gap: 18px;
  }

  .m-detail-band {
    grid-template-columns: 1fr;
  }

  .m-detail-band > div + div,
  .m-detail-band > div:nth-child(3),
  .m-detail-band > div:nth-child(4) {
    border-top: 1px solid var(--rule);
    border-left: 0;
  }

  .m-detail-actions {
    flex-direction: column;
  }

  .m-detail-actions .s-button,
  .m-detail-actions .m-evaluate-link {
    width: 100%;
  }

  .m-pull-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .m-card,
  .m-sheet {
    animation: none;
    transition: none;
  }
}
