/* Shared native dialog surface. Feature-specific layout remains with its feature. */

body.portal-dialog-open {
  overflow: hidden;
}

dialog.modal {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  border: 0;
  color: inherit;
}

dialog.modal::backdrop,
dialog.support-console::backdrop,
dialog.billing-admin::backdrop {
  background: transparent;
}

dialog.support-console,
dialog.billing-admin {
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  border: 0;
  padding: 0;
  color: inherit;
}

dialog[open].hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  padding: 1rem;
  background: rgba(7, 16, 9, 0.45);
}

.modal.modal-centered {
  align-items: center;
}

.modal-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
  width: min(760px, 94vw);
  max-height: calc(100dvh - 2rem);
  overflow: hidden;
  border: 1px solid #c6d8e2;
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: 0 22px 52px rgba(11, 23, 13, 0.3);
  animation: fadeIn 120ms ease;
}

/* Portal dialogs use one typeface and exactly three reusable text-size roles. */
:is(dialog, .modal-card) {
  --dialog-type-heading: 1.08rem;
  --dialog-type-body: 0.9rem;
  --dialog-type-supporting: 0.8rem;
}

:is(dialog, .modal-card),
:is(dialog, .modal-card) :where(*) {
  font-family: var(--font-sans) !important;
  font-size: var(--dialog-type-body) !important;
  line-height: 1.45 !important;
}

:is(dialog, .modal-card) :where(h1, h2, h3, h4, h5, h6, legend, .dialog-type-heading) {
  font-size: var(--dialog-type-heading) !important;
  line-height: 1.25 !important;
}

:is(dialog, .modal-card) :where(small, .muted, .helper-text, .modal-status, .component-dialog-tab, .dialog-type-supporting) {
  font-size: var(--dialog-type-supporting) !important;
  line-height: 1.4 !important;
}

.modal-card.modal-medium { width: min(540px, 94vw); }
.modal-card.modal-large { width: min(760px, 94vw); height: min(720px, calc(100dvh - 2rem)); }
.modal-card.modal-xlarge { width: min(1100px, 96vw); height: min(820px, calc(100dvh - 1rem)); }

.modal-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.modal-scroll-body {
  min-height: 0;
  overflow-y: auto;
  padding: 0.86rem;
  display: grid;
  align-content: start;
  gap: 0.86rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.86rem;
  border-bottom: 1px solid var(--accent-strong);
  background: var(--accent);
  color: #fff;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.modal-card.is-dragging .modal-header { cursor: grabbing; }
.modal-header h3 { display: inline-flex; align-items: center; min-width: 0; gap: 0.5rem; color: #fff; }

.modal-close-button {
  position: relative;
  width: 1.92rem;
  height: 1.92rem;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #111;
  color: #fff;
}

.modal-close-button:hover { transform: none; }
.modal-close-button::before,
.modal-close-button::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.92rem;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}
.modal-close-button::before { transform: translate(-50%, -50%) rotate(45deg); }
.modal-close-button::after { transform: translate(-50%, -50%) rotate(-45deg); }

.modal-footer {
  display: grid;
  gap: 0.45rem;
  padding: 0.74rem 0.86rem 0.86rem;
  border-top: 1px solid #cfd8dc;
  background: #f1f4f6;
}
.modal-footer.hidden { display: none; }
.modal-footer .row { margin: 0; }
.modal-status { margin: 0; min-height: 1.2rem; overflow-wrap: anywhere; }
.modal-status:empty { display: none; min-height: 0; }

@media (max-width: 720px) {
  .modal.mobile-fullscreen-modal {
    align-items: stretch;
    padding: 0;
  }

  .mobile-fullscreen-modal,
  .mobile-fullscreen-modal > .modal-card {
    --dialog-type-heading: 1.125rem;
    --dialog-type-body: 1rem;
    --dialog-type-supporting: 0.875rem;
  }

  .mobile-fullscreen-modal > .modal-card,
  .mobile-fullscreen-modal > .modal-card.modal-medium,
  .mobile-fullscreen-modal > .modal-card.modal-large,
  .mobile-fullscreen-modal > .modal-card.modal-xlarge {
    width: 100%;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    transform: none !important;
  }

  .mobile-fullscreen-modal .modal-header {
    min-width: 0;
    padding-top: max(0.86rem, env(safe-area-inset-top));
    padding-right: max(0.86rem, env(safe-area-inset-right));
    padding-left: max(0.86rem, env(safe-area-inset-left));
    cursor: default;
    touch-action: auto;
  }

  .mobile-fullscreen-modal .modal-header > div,
  .mobile-fullscreen-modal .modal-header h3,
  .mobile-fullscreen-modal .modal-header p {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .mobile-fullscreen-modal .modal-close-button {
    width: 2.75rem;
    height: 2.75rem;
  }

  .mobile-fullscreen-modal .modal-scroll-body {
    padding-right: max(0.86rem, env(safe-area-inset-right));
    padding-bottom: max(0.86rem, env(safe-area-inset-bottom));
    padding-left: max(0.86rem, env(safe-area-inset-left));
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-fullscreen-modal .modal-footer {
    padding-right: max(0.86rem, env(safe-area-inset-right));
    padding-bottom: max(0.86rem, env(safe-area-inset-bottom));
    padding-left: max(0.86rem, env(safe-area-inset-left));
  }
}

/* The shared component form exposes one category per dialog opening. */
.component-category-card {
  width: min(820px, calc(100vw - 2rem));
  height: min(760px, calc(100dvh - 2rem));
  grid-template-rows: auto minmax(0, 1fr) auto;
}
/* A category whose content is a board needs room for several columns of
   categories, so on a large screen it takes as much of it as it can use. */
.component-category-card.is-wide { width: min(1800px, calc(100vw - 2rem)); height: calc(100dvh - 2rem); }
#node-modal-title { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
#node-modal-title > span:last-child { overflow-wrap: anywhere; }
.category-dialog-editor .modal-footer { display: none; }
.category-dialog-editor.modal-shell { min-height: 0; grid-template-rows: minmax(0, 1fr); }
.category-dialog-editor .node-editor-body { overflow-y: auto; overscroll-behavior: contain; }
.category-dialog-editor .component-dialog-layout { height: auto; }
/* A panel whose last field fills the dialog only fills it when every box above
   it stretches too. Content-sized boxes here left the field at its minimum
   height, scrolling inside itself while the dialog still had room below it. */
.category-dialog-editor .component-dialog-content { overflow: visible; display: flex; flex-direction: column; min-height: 100%; box-sizing: border-box; }
.category-dialog-editor .component-dialog-panel:has(> .component-dialog-panel-fill-last:not(.hidden)) { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.category-dialog-editor .component-dialog-panel > .component-dialog-panel-fill-last:not(.hidden) { flex: 1 1 auto; min-height: 0; }
.category-dialog-editor .component-dialog-panel { margin: 0; }
.category-dialog-editor .component-dialog-panel-body { padding: 0; }
.category-dialog-editor :is(input, select, textarea) { min-width: 0; max-width: 100%; }
.category-dialog-editor .component-dialog-fill-textarea { min-height: 18rem; resize: vertical; }
.component-editor-save-status { margin: 0; padding: 0.5rem 1rem; color: var(--muted); border-top: 1px solid var(--border); }
@media (max-width: 720px) {
  #node-modal { padding: 0; }
  #node-modal .component-category-card { width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .category-dialog-editor .inline-grid-2 { grid-template-columns: minmax(0, 1fr); }
}
.knowledge-block-placement { color: #b45309; font-size: var(--canvas-small, 11px); white-space: nowrap; }
/* The capacity line states a limit, so it carries the state of that limit. */
.knowledge-board .knowledge-capacity { margin: 0; padding: .45rem .65rem; border-left: 3px solid var(--capacity-ink, #667085); border-radius: 0 6px 6px 0; background: var(--capacity-tint, #f1f5f7); color: #33453a; }
.knowledge-board .knowledge-capacity.is-good { --capacity-ink: #2f9e59; --capacity-tint: #edf8f1; }
.knowledge-board .knowledge-capacity.is-warning { --capacity-ink: #b45309; --capacity-tint: #fdf4e7; }
.knowledge-board .knowledge-capacity.is-danger, .knowledge-board .knowledge-capacity.is-error { --capacity-ink: #b42318; --capacity-tint: #fdf0ef; }

/* Attached components open as one editor, with their categories beside the form. */
[data-node-editor-connection][hidden] { display: none; }
.component-category-card:has(.has-category-sidebar):not(.is-wide) { width: min(1040px, calc(100vw - 2rem)); }
/* Sidebar backgrounds meet the header, outer edge and footer. Content panes
   retain their own padding, including when navigation moves above them. */
.has-category-sidebar .node-editor-body,
.account-modal-body:has(> .account-tabbed-layout) {
  padding: 0;
  gap: 0;
  overflow: hidden;
  grid-template-rows: minmax(0, 1fr);
  align-content: stretch;
}
.has-category-sidebar .component-dialog-layout {
  display: grid;
  grid-template-columns: minmax(150px, 210px) minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}
.component-dialog-sidebar:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.75rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
}
.component-dialog-sidebar .component-dialog-section-toggle {
  flex-shrink: 0;
  overflow-wrap: anywhere;
}
.component-dialog-sidebar [aria-selected="true"] {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}
.has-category-sidebar .component-dialog-content { overflow-y: auto; min-height: 0; }
@media (max-width: 720px) {
  #node-modal .component-category-card:has(.has-category-sidebar) { width: 100%; }
  .has-category-sidebar .component-dialog-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .component-dialog-sidebar:not([hidden]) {
    flex-direction: row;
    padding: 0.4rem;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .component-dialog-sidebar .component-dialog-section-toggle { width: auto; white-space: nowrap; }

}
