/*
 * Smallworld interaction foundation
 *
 * This layer standardizes behavior and geometry, not product identity. Runtimes
 * opt in with data-sw-ui on their body or application root and can override any
 * --sw-* token to preserve their palette and visual voice.
 */

:where([data-sw-ui]) {
  --sw-font-body: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sw-font-display: var(--sw-font-body);
  --sw-font-mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  --sw-control-height: 2.5rem;
  --sw-control-height-compact: 2rem;
  --sw-touch-target: 2.75rem;
  --sw-control-radius: 0.5rem;
  --sw-panel-radius: 0.75rem;
  --sw-focus-color: #2563eb;
  --sw-focus-width: 3px;
  --sw-motion-fast: 140ms;
  --sw-motion-standard: 180ms;
  --sw-disabled-opacity: 0.5;
  --sw-reading-width: 72ch;
  font-family: var(--sw-font-body);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* Opt-in work surface for browser runtimes with persistent navigation. */
.sw-desktop-runtime {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-width: 0;
  color: var(--sw-desktop-ink, #203347);
  background: var(--sw-desktop-background, #f4f6f9);
}

.sw-desktop-toolbar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.25rem;
  padding: 0.55rem 1.25rem;
  border-bottom: 1px solid var(--sw-desktop-border, #d8e1ea);
  background: var(--sw-desktop-toolbar, #fff);
}

.sw-desktop-toolbar-start,
.sw-desktop-tools,
.sw-desktop-body {
  display: flex;
  min-width: 0;
}

.sw-desktop-toolbar-start { flex: none; align-items: center; gap: 0.7rem; }
.sw-desktop-tools { flex: 1 1 24rem; align-items: center; }
.sw-desktop-menu {
  display: inline-grid;
  place-items: center;
  width: 2.75rem;
  min-width: 2.75rem;
  padding: 0;
  border: 1px solid var(--sw-desktop-border, #d8e1ea);
  border-radius: 999px;
  background: var(--sw-desktop-menu-background, #fff);
  color: var(--sw-desktop-menu-ink, currentColor);
  font-size: 1.2rem;
}
.sw-desktop-body { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.sw-desktop-navigation {
  flex: 0 0 var(--sw-desktop-navigation-width, 15rem);
  min-width: 0;
  overflow: auto;
  border-right: 1px solid var(--sw-desktop-border, #d8e1ea);
  background: var(--sw-desktop-navigation-background, #fff);
  transition: flex-basis var(--sw-motion-standard, 180ms), opacity var(--sw-motion-fast, 140ms);
}
.sw-desktop-runtime:not([data-navigation-open]) .sw-desktop-navigation { flex-basis: 0; opacity: 0; pointer-events: none; border-right: 0; padding: 0; margin: 0; }

.sw-desktop-brand,
.sw-desktop-actions,
.sw-desktop-workarea {
  min-width: 0;
}

.sw-desktop-brand {
  display: flex;
  align-items: center;
  flex: none;
}

.sw-desktop-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.sw-desktop-actions > :where(a, button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
}

.sw-desktop-workarea {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.sw-desktop-notices {
  position: relative;
  z-index: 20;
  display: flex;
  flex: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  min-height: 2.7rem;
  padding: 0.35rem 1.25rem;
  border-bottom: 1px solid var(--sw-desktop-border, #d8e1ea);
  background: #f5f9fc;
  font-size: 0.78rem;
}

/* One in-flow disclosure for header notices, independent of runtime utility CSS. */
.sw-runtime-notice-group { flex: none; border-bottom: 1px solid #e6cf91; background: #fff8df; color: #624713; font-size: 0.8rem; }
.sw-runtime-notice-group[hidden] { display: none; }
.sw-runtime-notice-group[data-notice-severity="critical"] { background: #fff0f0; border-color: #e7b4b5; color: #982f32; }
.sw-runtime-notice-group > summary { box-sizing: border-box; cursor: pointer; min-height: 2.5rem; padding: 0.5rem 1.25rem; font-weight: 650; }
.sw-desktop-notices[hidden] { display: none; }
.sw-runtime-notice-group > summary:focus-visible { outline: 2px solid currentColor; outline-offset: -3px; }
.sw-runtime-notice-content { max-height: min(60dvh, 32rem); overflow: auto; padding: 0.5rem 1rem; }
.sw-runtime-notice-content [data-sw-grouped-notices] { display: grid; gap: 0.5rem; }

.sw-desktop-notices-warning {
  border-bottom-color: #e6cf91;
  background: #fff8df;
}

.sw-desktop-notices-critical {
  border-bottom-color: #e7b4b5;
  background: #fff0f0;
}

.sw-desktop-notices-info {
  border-bottom-color: #bad5e8;
  background: #eef7fd;
}

.sw-desktop-notices-success {
  border-bottom-color: #b8dccd;
  background: #eef9f4;
}

.sw-desktop-notice-summaries {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
}

.sw-desktop-notice-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 650;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.sw-desktop-notice-warning,
.sw-desktop-notice-critical { color: #805517; }
.sw-desktop-notice-info { color: #29577b; }
.sw-desktop-notice-success { color: #176044; }
.sw-desktop-notice-critical { color: #982f32; }

.sw-desktop-notice-details { flex: none; }
.sw-desktop-notice-details > summary {
  display: flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid #cad6e1;
  border-radius: 0.4rem;
  background: #fff;
  color: #25445c;
  cursor: pointer;
  font-weight: 650;
  list-style: none;
}
.sw-desktop-notice-details > summary::-webkit-details-marker { display: none; }

.sw-desktop-notice-panel {
  /* Top-layer popover: opening notices must never resize the runtime header. */
  position: fixed;
  inset: auto;
  top: var(--sw-notice-top, 5rem);
  right: var(--sw-notice-right, 0.5rem);
  margin: 0;
  box-sizing: border-box;
  display: grid;
  gap: 0.5rem;
  width: min(36rem, calc(100vw - 1rem));
  max-height: min(65dvh, 35rem, calc(100dvh - var(--sw-notice-top, 5rem) - 0.5rem));
  overflow: auto;
  padding: 0.6rem;
  border: 1px solid #cbd6e1;
  border-radius: 0.6rem;
  background: #fff;
  box-shadow: 0 0.9rem 2.5rem #152b4026;
}
.sw-desktop-notice-panel:not(:popover-open) { display: none; }

.sw-desktop-notice-card {
  display: grid;
  gap: 0.35rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid #d8e1ea;
  border-radius: 0.5rem;
  background: #fff;
  line-height: 1.45;
}
.sw-desktop-notice-card h2 { margin: 0; font-size: 0.875rem; font-weight: 700; }
.sw-desktop-notice-heading { display: flex; align-items: flex-start; gap: 0.5rem; }
.sw-runtime-notice-icon { display: inline-flex; flex: none; width: 1.15rem; height: 1.15rem; align-items: center; justify-content: center; vertical-align: -0.2em; }
.sw-runtime-notice-icon svg { display: block; width: 100%; height: 100%; }
.sw-desktop-notice-card { overflow-wrap: anywhere; }
.sw-desktop-notice-card div { font-size: 0.82rem; }
.sw-desktop-notice-action { margin-top: 0.2rem; }

@media (min-width: 1024px) {
  .sw-desktop-runtime { height: 100dvh; overflow: hidden; }
}

@media (max-width: 1023px) {
  .sw-desktop-body { overflow: visible; }
  .sw-desktop-workarea { overflow: visible; }
}

@media (max-width: 760px) {
  .sw-desktop-toolbar { align-items: flex-start; flex-wrap: wrap; padding: 0.65rem 0.9rem; }
  .sw-desktop-tools { order: 3; flex-basis: 100%; }
  .sw-desktop-navigation { position: fixed; z-index: 40; top: 4.25rem; bottom: 0; left: 0; width: min(19rem, 88vw); box-shadow: 1rem 0 2.5rem #152b4030; }
  .sw-desktop-actions { justify-content: flex-start; }
  .sw-desktop-notices { padding: 0.45rem 0.9rem; }
  .sw-desktop-notice-summaries { flex-basis: 100%; }
  .sw-desktop-notice-details > summary { min-height: 2.75rem; }
}

:where([data-sw-ui]) *,
:where([data-sw-ui]) *::before,
:where([data-sw-ui]) *::after {
  box-sizing: border-box;
}

:where([data-sw-ui]) :where(button, input, select, textarea) {
  font: inherit;
}

:where([data-sw-ui]) :where(
    button,
    select,
    [role="button"],
    [role="tab"],
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"])
  ) {
  min-height: var(--sw-control-height);
}

:where([data-sw-ui]) :where(button, [role="button"], [role="tab"], summary) {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:where([data-sw-ui]) :where(
    a[href],
    button,
    input,
    select,
    textarea,
    summary,
    [tabindex]:not([tabindex="-1"]),
    [role="button"],
    [role="tab"]
  ):focus-visible {
  outline: var(--sw-focus-width) solid var(--sw-focus-color);
  outline-offset: 3px;
}

:where([data-sw-ui]) :where(button, [role="button"], [role="tab"]) {
  transition-duration: var(--sw-motion-fast);
  transition-property: color, background-color, border-color, box-shadow, opacity, transform;
  transition-timing-function: ease-out;
}

:where([data-sw-ui]) :where(button, input, select, textarea):disabled,
:where([data-sw-ui]) :where([role="button"], [role="tab"])[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: var(--sw-disabled-opacity);
}

:where([data-sw-ui]) :where(button, [role="button"]):not(:disabled):not([aria-disabled="true"]) {
  cursor: pointer;
}

:where([data-sw-ui]) :where([aria-busy="true"], [data-loading="true"]) {
  cursor: progress;
}

:where([data-sw-ui]) :where(h1, h2, h3) {
  font-family: var(--sw-font-display);
  text-wrap: balance;
}

:where([data-sw-ui]) :where(p, li, dd) {
  text-wrap: pretty;
}

:where([data-sw-ui]) :where(code, kbd, samp, pre) {
  font-family: var(--sw-font-mono);
}

:where([data-sw-ui]) :where([role="tablist"], [data-sw-tabs]) {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

:where([data-sw-ui]) :where([role="tab"], [data-sw-tab]) {
  min-height: var(--sw-control-height);
}

:where([data-sw-ui]) :where([data-sw-page-header]) {
  min-width: 0;
}

:where([data-sw-ui]) :where([data-sw-page-header]) h1 {
  margin-block: 0;
  overflow-wrap: anywhere;
}

:where([data-sw-ui]) :where([data-sw-actions]) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

:where([data-sw-ui]) :where([data-sw-control="button"], [data-sw-control="input"], [data-sw-control="select"]) {
  min-height: var(--sw-control-height);
  border-radius: var(--sw-control-radius);
}

:where([data-sw-ui]) :where([data-sw-control="compact"]) {
  min-height: var(--sw-control-height-compact);
}

@media (max-width: 48rem), (pointer: coarse) {
  :where([data-sw-ui]) :where(
      button,
      select,
      summary,
      [role="button"],
      [role="tab"],
      input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"])
    ) {
    min-height: var(--sw-touch-target);
  }

  :where([data-sw-ui]) :where(input, select, textarea) {
    font-size: max(1rem, 16px);
  }
}

@media (prefers-reduced-motion: reduce) {
  :where([data-sw-ui]),
  :where([data-sw-ui]) * {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.sw-message-deletion-notice { display:inline-flex; align-items:center; gap:8px; max-width:100%; color:#68746e; font-size:0.875rem; font-style:italic; line-height:1.5; }
.sw-message-deletion-notice > svg { flex:none; }
