/* Scoped to #sb. No :root. No z-index above 100. No bare header/aside/main/#panel. */

#sb {
  --bg: var(--dr-surface, #E5E7EB);
  --panel: var(--dr-panel, #FFFFFF);
  --ink: var(--dr-ink, #111111);
  --sb-band-line: 1px;
  --sb-ctrl: 11px;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--bg);
  min-width: 0;
}

#sb-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 0 12px;
  background: var(--bg);
}

.sb-idrow {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.sb-id {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#sb-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

#sb-status {
  font-size: var(--dr-text-meta, 13px);
  color: var(--dr-ink-faint, #6B7280);
  line-height: 1.35;
  min-width: 0;
}

.sb-id-links {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  font-size: var(--dr-text-meta, 13px);
}

.sb-id-links a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sb-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sb-views {
  display: flex;
  flex: none;
  gap: 4px;
}

.sb-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  min-width: 0;
}

/* Browse #controls: 11px, 0.2rem radius, blue fill. dr-btn is a 44px pill. */
#sb .sb-toolbar .dr-btn {
  min-height: 0;
  height: 1.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 0.2rem;
  border: 1px solid #374151;
  background: #3b82f6;
  color: #fff;
  font-size: var(--sb-ctrl);
  font-weight: 500;
  line-height: 1rem;
  gap: 0;
}

#sb .sb-toolbar .dr-btn:hover {
  background: #2563eb;
  color: #fff;
}

#sb .sb-views .dr-btn {
  background: #fff;
  color: #111;
  border-color: #111;
}

#sb .sb-views .dr-btn:hover {
  background: #e5e7eb;
  color: #111;
}

#sb .sb-views .dr-btn[aria-pressed="true"] {
  background: #111;
  border-color: #111;
  color: #fff;
}

#sb .sb-views .dr-btn[aria-pressed="true"]:hover {
  background: #111;
  color: #fff;
}

#sb .sb-views #sb-view-editor,
#sb .sb-views #sb-view-editor[aria-pressed="true"],
#sb .sb-views #sb-view-editor[aria-pressed="false"],
#sb .sb-views #sb-view-controls,
#sb .sb-views #sb-view-controls[aria-pressed="true"],
#sb .sb-views #sb-view-controls[aria-pressed="false"] {
  background: #10b981;
  border-color: #059669;
  color: #fff;
}

#sb .sb-views #sb-view-editor:hover,
#sb .sb-views #sb-view-controls:hover {
  background: #059669;
  color: #fff;
}

#sb-post-url {
  min-width: 0;
  flex: 1 1 14rem;
  height: 1.75rem;
  padding: 0 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.2rem;
  font-size: var(--sb-ctrl);
  line-height: 1.75rem;
  background: var(--panel);
}

#sb-error:not([hidden]) {
  color: var(--dr-ink, #111);
  background: var(--panel);
  border: 1px solid var(--dr-line, #D3D7DE);
  border-radius: var(--dr-radius-control, 0.625rem);
  padding: 8px 12px;
  font-size: var(--dr-text-dense, 14px);
}

#sb-paste,
#sb-load {
  width: min(42rem, calc(100vw - 2.5rem));
}

#sb-paste-form,
#sb-load-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

#sb-load-form #sb-url {
  width: 100%;
  min-width: 0;
  height: 2.75rem;
  padding: 0 12px;
  border: 1px solid var(--dr-line, #D3D7DE);
  border-radius: var(--dr-radius-control, 0.625rem);
  font-size: 16px;
  background: var(--panel);
}

#sb-paste-text {
  width: 100%;
  min-width: 0;
  min-height: 16rem;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--dr-text-dense, 14px);
  line-height: 1.4;
  padding: 10px 12px;
  border: 1px solid var(--dr-line, #D3D7DE);
  border-radius: var(--dr-radius-control, 0.625rem);
  background: var(--dr-panel, #fff);
  color: var(--dr-ink, #111);
}

#sb-paste-error:not([hidden]) {
  margin: 0;
  font-size: var(--dr-text-dense, 14px);
  color: var(--dr-ink, #111);
}

#sb[data-view="diagram"] #sb-table {
  display: none;
}

#sb[data-view="table"] #sb-canvas {
  display: none;
}

#sb[data-editor="off"] #sb-panel {
  display: none;
}

#sb[data-controls="off"] #sb-controls {
  display: none;
}

#sb-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 26rem;
  height: calc(100dvh - var(--sb-stage-top, 7rem) - var(--nav-clearance, 0px) - var(--sb-band-line) * 2);
  border: var(--sb-band-line) solid var(--dr-line, #D3D7DE);
  border-radius: var(--dr-radius-lg, 0.75rem);
  overflow: hidden;
  background: var(--panel);
}

#sb-canvas {
  position: relative;
  isolation: isolate;
  min-width: 0;
  min-height: 0;
  background: radial-gradient(circle at 50% 42%, #FFFFFF 0%, #F2F2EE 70%);
}

#sb-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* On body: #sb-canvas is isolation:isolate, so a tip inside it clips. */
.sb-graph-tip {
  position: fixed;
  z-index: var(--dr-z-popover, 70);
  max-width: 17rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--dr-radius-sm, 6px);
  background: var(--dr-accent, #252739);
  color: #fff;
  font-size: var(--dr-text-meta, 13px);
  line-height: 1.4;
  white-space: pre-wrap;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.26);
}

.sb-graph-tip[hidden] {
  display: none;
}

#sb-controls {
  position: absolute;
  top: 8px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  z-index: var(--dr-z-canvas-ui, 20);
  background: #f3f4f6;
  padding: 1rem;
  border-radius: 0.375rem;
}

#sb-controls .sb-ctrl-row {
  display: flex;
  gap: 0.5rem;
}

#sb-controls .sb-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  min-height: 2rem;
  margin: 0;
  padding: 0;
  border: 1px solid #374151;
  border-radius: 0.25rem;
  background: #111;
  color: #fff;
  box-shadow: none;
  cursor: pointer;
}

#sb-controls .sb-tool:hover {
  background: #374151;
}

#sb-controls .sb-tool svg {
  width: 14px;
  height: 14px;
}

#sb-controls .sb-tool--mode {
  background: #fff;
  color: #111;
  border-color: #111;
}

#sb-controls .sb-tool--mode:hover {
  background: #e5e7eb;
}

#sb-controls .sb-tool--mode[aria-pressed="true"] {
  background: #111;
  color: #fff;
}

#sb-controls .sb-tool--mode[aria-pressed="true"]:hover {
  background: #111;
  color: #fff;
}

#sb-controls .sb-circular {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

#sb-controls .sb-circular-label {
  font-size: 10px;
  line-height: 1.15;
  color: #111;
}

#sb-controls .sb-switch {
  position: relative;
  display: inline-block;
  width: 2rem;
  height: 1rem;
  flex: none;
}

#sb-controls .sb-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

#sb-controls .sb-switch label {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #ccc;
  border-radius: 1rem;
}

#sb-controls .sb-switch label::before {
  position: absolute;
  content: "";
  height: 0.75rem;
  width: 0.75rem;
  left: 0.125rem;
  bottom: 0.125rem;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

#sb-controls .sb-switch input:checked + label {
  background: #22c55e;
}

#sb-controls .sb-switch input:checked + label::before {
  transform: translateX(1rem);
}

#sb-empty:not([hidden]) {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: var(--dr-ink-faint, #6B7280);
  font-size: var(--dr-text-dense, 14px);
  padding: 24px;
  text-align: center;
}

#sb-panel {
  position: relative;
  background: #f8fafc;
  color: #111;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: system-ui, sans-serif;
  --dr-sheet-surface: #f8fafc;
}

#sb-panel .insp-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: #111;
  padding: 0;
}

#sb-panel .insp-head h3 {
  margin: 0.2rem 0 0.35rem;
  font-size: 0.95rem;
  line-height: 1.25;
  font-weight: 700;
}

#sb-panel .insp-kind {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4b5563;
  margin: 0;
}

#sb-panel .insp-id {
  color: #4b5563;
  font-size: 0.75rem;
  margin: 0.25rem 0;
}

#sb-panel .insp-body p,
#sb-panel .sb-hits,
#sb-panel .sb-lede {
  margin: 0.25rem 0;
  font-size: 0.75rem;
  color: #4b5563;
}

#sb-panel .insp-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}

#sb-panel .insp-primary {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.45rem 0.6rem;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

#sb-panel .insp-primary:hover {
  background: #2563eb;
}

#sb-panel .insp-links {
  font-size: 11px;
  line-height: 1.5;
  margin-top: 0.75rem;
}

#sb-panel .insp-links a {
  text-decoration: underline;
  color: #111;
}

#sb-panel .insp-note {
  font-size: 10px;
  color: #6b7280;
}

#sb-panel .insp-k {
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  margin-top: 0.6rem;
  color: #4b5563;
}

#sb-panel .insp-neighbors ul {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
}

#sb-panel .insp-neighbors li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 11px;
  margin: 0.15rem 0;
}

#sb-panel .insp-neighbor {
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
  font-size: 11px;
  color: #111;
}

#sb-panel .insp-grant {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 12px;
}

#sb-panel .sb-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 12px;
}

#sb-panel label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: #4b5563;
}

#sb-panel label.sb-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

#sb-panel input,
#sb-panel select,
#sb-panel textarea {
  font: inherit;
  font-size: var(--sb-ctrl);
  padding: 0.3rem 0.4rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  min-width: 0;
  color: #111;
}

#sb-panel fieldset {
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 6px 8px;
  margin: 0;
}

#sb-panel legend {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#sb-table {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  background: var(--panel);
}

#sb-table h2 {
  font-size: var(--dr-text-dense, 14px);
  margin: 16px 0 8px;
}

#sb-table .sb-sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 16px 0 8px;
}

#sb-table .sb-sheet-head h2 {
  margin: 0;
}

#sb-table .sb-lede {
  font-size: var(--dr-text-meta, 13px);
  color: var(--dr-ink-faint, #6B7280);
  margin: 0 0 10px;
}

#sb-table .sb-table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#sb-table .dr-btn {
  min-height: 0;
  height: 1.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 0.2rem;
  font-size: var(--sb-ctrl);
  line-height: 1rem;
}

#sb-table .sb-table-wrap {
  overflow-x: auto;
  min-width: 0;
}

#sb-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--sb-ctrl);
}

#sb-table th,
#sb-table td {
  border-bottom: 1px solid var(--dr-line, #D3D7DE);
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
}

#sb-table th {
  cursor: pointer;
  position: sticky;
  top: 0;
  background: var(--panel);
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
}

#sb-table .sb-sort-ind {
  color: var(--dr-ink-faint, #6B7280);
  font-size: 0.75rem;
  margin-left: 0.25rem;
}

#sb-table tr[aria-selected="true"] {
  background: var(--dr-surface, #E5E7EB);
}

#sb-table input,
#sb-table select {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: var(--sb-ctrl);
  padding: 4px 6px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: var(--panel);
}

#sb-table input[type="checkbox"] {
  width: auto;
}

#sb-table .sb-num {
  width: 7rem;
}

@media (max-width: 767px) {
  #sb-panel .insp-close {
    display: none;
  }
}

@media (min-width: 768px) {
  #sb-header {
    padding: 12px 0 14px;
    gap: 12px;
  }
  #sb-header h1 {
    font-size: var(--dr-text-title, 24px);
    letter-spacing: -0.02em;
  }
  .sb-id {
    flex-direction: row;
    align-items: baseline;
    gap: 12px;
  }
  .sb-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .sb-toolbar .sb-actions {
    flex: none;
  }
  .sb-toolbar .sb-views {
    flex: none;
  }
  #sb-post-url {
    flex: 0 1 16rem;
  }
  #sb[data-editor="on"] #sb-stage {
    grid-template-columns: minmax(0, 1fr) minmax(16rem, 21rem);
  }
  #sb[data-editor="off"] #sb-stage {
    grid-template-columns: minmax(0, 1fr);
  }
  #sb-canvas {
    border-right: 0;
    border-radius: 0;
  }
  #sb-panel {
    border-left: 1px solid #d1d5db;
    overflow: hidden;
  }
  #sb-panel.dr-sheet__body,
  #sb-panel {
    overflow-y: auto;
    padding: 12px 14px 20px;
  }
}
