.sb-dialog, .ldg {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 24px);
  color: var(--ink);
}
.sb-dialog::backdrop, .ldg::backdrop {
  background: rgba(32, 33, 36, 0.4);
}
html[data-theme="dark"] .sb-dialog::backdrop,
html[data-theme="night"] .sb-dialog::backdrop,
html.night .sb-dialog::backdrop,
html[data-theme="dark"] .ldg::backdrop,
html.night .ldg::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.sb-dialog-sm, .ldg-sm { width: 360px; }
.sb-dialog-md, .ldg-md { width: 480px; }
.sb-dialog-lg, .ldg-lg { width: 640px; }
.sb-dialog-xl, .ldg-xl { width: 840px; }
.sb-dialog-sheet, .ldg-sheet {
  width: 420px;
  margin: 0 0 0 auto;
  height: 100vh;
  max-width: 100vw;
}
.sb-frame, .ldg-frame {
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 860px);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.sb-dialog-sheet .sb-frame,
.ldg-sheet .ldg-frame {
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  border-right: 0;
}
.sb-head, .ldg-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
}
.sb-head-text, .ldg-head-text { flex: 1; min-width: 0; }
.sb-title, .ldg-title {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.25;
  color: var(--ink);
}
.sb-lede, .ldg-lede {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}
.sb-x, .ldg-x {
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.sb-x:hover, .ldg-x:hover { background: var(--fill); color: var(--ink); }
.sb-body, .ldg-body {
  padding: 0 16px 16px;
  overflow: auto;
  flex: 1;
}
.sb-foot, .ldg-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
}
.sb-dialog-danger .sb-title, .ldg-danger .ldg-title { color: var(--red); }
.sb-alert, .ldg-alert {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 13px;
}
.sb-dialog[open], .ldg[open] { animation: sb-in 150ms ease; }
.sb-dialog[open]::backdrop, .ldg[open]::backdrop { animation: sb-fade 150ms ease; }
.sb-dialog.is-shake, .ldg.is-shake { animation: sb-shake 150ms ease; }
@keyframes sb-fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes sb-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes sb-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
html.sb-lock, html.ldg-lock { overflow: hidden; }

.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.fld-label {
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
  font-weight: 500;
}
.fld-input, .fld select, .fld textarea {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
.fld textarea { height: auto; min-height: 72px; padding: 8px 12px; }
.fld-input:focus, .fld select:focus, .fld textarea:focus {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-color: var(--blue);
}
.fld-input.is-invalid { border-color: var(--red); }
.fld-error { font-size: 12px; color: var(--red); }
.fld-help { font-size: 12px; color: var(--muted); }

.btn .spin {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: sb-spin .6s linear infinite;
}
@keyframes sb-spin { to { transform: rotate(360deg); } }
.btn:disabled, .btn.is-busy {
  opacity: 0.55;
  pointer-events: none;
}

.sb-toasts, .ldg-toasts {
  position: fixed;
  left: 16px;
  bottom: 16px;
  top: auto;
  transform: none;
  z-index: 80;
  width: 360px;
  max-width: calc(100vw - 24px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--toast-bg);
  color: var(--toast-ink);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
}
html[data-theme="dark"] .toast, html.night .toast {
  border-color: var(--line);
}
.toast-error { border-color: var(--red); }
.toast-ok { }
.toast-action { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.toast .btn { color: inherit; min-height: 32px; padding: 0 8px; }

.ctx {
  position: fixed;
  z-index: 70;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow);
}
.ctx button, .ctx a {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  border-radius: 8px;
  text-align: left;
}
.ctx button:hover, .ctx a:hover { background: var(--blue-soft); color: var(--blue); }
.ctx .is-off { opacity: 0.4; pointer-events: none; }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 0; }

.sb-split, .ldg-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.pick-list { max-height: 40vh; overflow: auto; }
.pick {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 8px;
  border-radius: 8px;
}
.pick:hover, .pick:has(input:checked) { background: var(--blue-soft); }
.codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--fill);
  border-radius: 8px;
  padding: 12px;
}
.palette { margin: 12vh auto auto !important; }
.search-grow { width: 280px; transition: width 150ms ease; }
.search-grow:focus-within { width: min(560px, 100%); }
.search-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  z-index: 30;
  max-height: 360px;
  overflow: auto;
  box-shadow: var(--shadow);
}

@media (max-width: 720px) {
  .sb-dialog:not(.sb-dialog-xl):not(.sb-dialog-sheet),
  .ldg:not(.ldg-xl):not(.ldg-sheet) {
    width: 100%;
    max-width: 100vw;
    margin: auto 0 0;
  }
  .sb-dialog:not(.sb-dialog-xl):not(.sb-dialog-sheet) .sb-frame,
  .ldg:not(.ldg-xl):not(.ldg-sheet) .ldg-frame {
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .sb-dialog:not(.sb-dialog-xl):not(.sb-dialog-sheet) .sb-head::before,
  .ldg:not(.ldg-xl):not(.ldg-sheet) .ldg-head::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    background: var(--line);
    border-radius: 2px;
    margin: 0 auto 8px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 6px;
  }
  .sb-split, .ldg-split { grid-template-columns: 1fr; }
  .sb-foot, .ldg-foot { flex-direction: column-reverse; }
  .sb-foot .btn, .ldg-foot .btn { width: 100%; }
  .sb-dialog-sheet, .ldg-sheet { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .sb-dialog[open], .sb-dialog[open]::backdrop,
  .ldg[open], .ldg[open]::backdrop { animation: none; }
}
