/* Layout chrome for the editor itself. Component styling comes from Basecoat. */
* { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--foreground); font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif); }
[x-cloak] { display: none !important; }

.tb-layout { display: grid; grid-template-columns: 340px 1fr; min-height: 100vh; }

/* ── Panel: fixed neutral palette so the tool chrome never changes with the edited theme ── */
.tb-panel {
  --pc-bg: #ffffff;
  --pc-fg: #1c1c22;
  --pc-muted: #6b7280;
  --pc-border: #e7e7ec;
  --pc-subtle: #f5f5f7;
  --pc-accent: #4f46e5;
  --pc-radius: 9px;

  border-right: 1px solid var(--pc-border);
  background: var(--pc-bg); color: var(--pc-fg);
  /* Explicit neutral chrome font: the panel must not inherit (and drift with) the edited
     theme's --font-sans, and inside the inject shadow root there's no body to inherit from. */
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px; line-height: 1.4;
  padding: 1.1rem 1rem 0;
  display: flex; flex-direction: column; gap: .8rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.tb-panel-head { display: flex; flex-direction: column; gap: .1rem; }
.tb-panel-head h1 { font-size: 15px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.tb-panel-head p { font-size: 12px; color: var(--pc-muted); margin: 0; }
.tb-panel hr { border: 0; border-top: 1px solid var(--pc-border); margin: .3rem 0; }
.tb-panel label { color: var(--pc-fg); }

/* group + row labels */
.tb-glabel, .tb-section > summary {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--pc-muted);
}
.tb-row { display: flex; align-items: center; gap: .6rem; justify-content: space-between; min-height: 2.4rem; }
.tb-row > label:first-child { font-size: 12px; color: var(--pc-muted); white-space: nowrap; }
.tb-row input[type="range"] { flex: 1; }

/* form controls — scoped overrides so Basecoat's themed styles don't leak in */
.tb-panel select, .tb-panel input[type="text"], .tb-panel .input {
  appearance: none; -webkit-appearance: none;
  font-size: 12.5px; color: var(--pc-fg); background: var(--pc-bg);
  border: 1px solid var(--pc-border); border-radius: var(--pc-radius);
  padding: .4rem .6rem; height: 2rem; width: 100%; max-width: 10rem; cursor: pointer;
}
.tb-panel select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .5rem center; padding-right: 1.6rem;
}
.tb-panel select:hover, .tb-panel input:hover { border-color: #d4d4da; }
.tb-panel select:focus, .tb-panel input:focus { outline: 2px solid color-mix(in srgb, var(--pc-accent) 35%, transparent); outline-offset: 1px; border-color: var(--pc-accent); }

/* range sliders — accent-color kills the browser blue and gives a filled track */
.tb-panel input[type="range"] { accent-color: var(--pc-accent); height: 1.1rem; cursor: pointer; }

/* ── Theme preset picker ── */
.tb-theme { position: relative; display: flex; flex-direction: column; gap: .35rem; }
.tb-theme > label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--pc-muted); }
.tb-theme-btn {
  display: flex; align-items: center; gap: .55rem; width: 100%;
  padding: .45rem .6rem; border: 1px solid var(--pc-border); border-radius: var(--pc-radius);
  background: var(--pc-bg); color: var(--pc-fg); cursor: pointer; font-size: 13px;
}
.tb-theme-btn:hover { border-color: #d4d4da; }
.tb-dots { display: inline-flex; }
.tb-dots i { width: .8rem; height: .8rem; border-radius: 999px; margin-right: -.26rem; box-shadow: 0 0 0 1px rgb(0 0 0 / .08); }
.tb-theme-menu {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50; margin-top: .3rem;
  background: var(--pc-bg); border: 1px solid var(--pc-border); border-radius: 11px;
  box-shadow: 0 12px 34px rgb(0 0 0 / .14); padding: .5rem; display: flex; flex-direction: column; gap: .4rem;
}
.tb-theme-search { max-width: none !important; }
.tb-theme-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.tb-theme-item {
  display: flex; align-items: center; gap: .6rem; padding: .45rem .5rem; border: 0; background: none;
  border-radius: 7px; cursor: pointer; color: var(--pc-fg); text-align: left; font-size: 13px;
}
.tb-theme-item:hover { background: var(--pc-subtle); }
.tb-theme-item.is-active { background: var(--pc-accent); color: #fff; }
.tb-theme-item.is-active .tb-dots i { box-shadow: 0 0 0 1px rgb(255 255 255 / .4); }

/* ── Mode toggle ── */
.tb-mode-toggle {
  display: inline-flex; align-items: center; gap: .4rem; font-size: 12.5px; font-weight: 500;
  padding: .3rem .65rem; border: 1px solid var(--pc-border); border-radius: 999px;
  background: var(--pc-bg); color: var(--pc-fg); cursor: pointer;
}
.tb-mode-toggle:hover { background: var(--pc-subtle); }

/* ── Color swatches ── */
.tb-colors { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 0; }
.tb-color {
  display: flex; align-items: center; gap: .5rem; cursor: pointer;
  padding: .35rem .4rem; border-radius: 7px; font-size: 12px;
}
.tb-color:hover { background: var(--pc-subtle); }
.tb-color input[type="color"] {
  appearance: none; -webkit-appearance: none;
  inline-size: 1.35rem; block-size: 1.35rem; padding: 0; border: 0; border-radius: 6px;
  background: none; cursor: pointer; flex-shrink: 0;
  box-shadow: 0 0 0 1px rgb(0 0 0 / .1), inset 0 0 0 1px rgb(255 255 255 / .15);
}
.tb-color input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.tb-color input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
.tb-color input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }

/* ── Collapsible sections ── */
.tb-section { display: flex; flex-direction: column; gap: .9rem; }
.tb-section > summary { margin-bottom: .35rem; }
.tb-section > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .4rem; user-select: none; }
.tb-section > summary::-webkit-details-marker { display: none; }
.tb-ico { flex-shrink: 0; color: var(--pc-muted); }
.tb-section > summary::before { content: "›"; transition: transform .15s; font-size: 14px; color: var(--pc-muted); }
.tb-section[open] > summary::before { transform: rotate(90deg); }
.tb-row > span { min-width: 2.8rem; text-align: right; font-variant-numeric: tabular-nums; color: var(--pc-muted); font-size: 11.5px; }

/* ── Shadow toggle ── */
.tb-shadow-head { display: flex; align-items: center; justify-content: space-between; }
.tb-switch {
  width: 34px; height: 19px; border-radius: 999px; border: 0; padding: 2px; cursor: pointer;
  background: #d4d4da; transition: background .15s; display: inline-flex; align-items: center;
}
.tb-switch.is-on { background: var(--pc-accent); }
.tb-switch-knob { width: 15px; height: 15px; border-radius: 999px; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgb(0 0 0 / .25); }
.tb-switch.is-on .tb-switch-knob { transform: translateX(15px); }
.tb-repo-link {
  display: inline-flex; align-items: center; gap: .35rem; margin-top: .4rem;
  font-size: 12px; color: var(--pc-muted); text-decoration: none;
}
.tb-repo-link:hover { color: var(--pc-fg); }
.tb-hint { font-size: 11.5px; color: var(--pc-muted); margin: .1rem 0 0; line-height: 1.45; }
.tb-code-copy {
  display: flex; align-items: center; gap: .5rem; width: 100%; margin-top: .35rem;
  padding: .45rem .55rem; cursor: pointer; text-align: left;
  background: var(--pc-subtle); border: 1px solid var(--pc-border); border-radius: var(--pc-radius);
}
.tb-code-copy:hover { border-color: var(--pc-accent); }
.tb-code-copy code {
  flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 11px; color: var(--pc-fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-copy-label { flex-shrink: 0; font-size: 11px; font-weight: 550; color: var(--pc-muted); }
.tb-code-copy:hover .tb-copy-label { color: var(--pc-accent); }
.tb-bookmarklet {
  display: inline-block; padding: .15rem .5rem; border-radius: var(--pc-radius);
  background: var(--pc-accent); color: #fff; font-weight: 600; font-size: 11.5px;
  text-decoration: none; cursor: grab; white-space: nowrap;
}

/* ── Footer actions ── */
.tb-actions {
  display: flex; gap: .5rem; margin: auto -1rem 0; padding: .8rem 1rem;
  position: sticky; bottom: 0; background: var(--pc-bg); border-top: 1px solid var(--pc-border);
}
.tb-actions button { font-size: 13px; font-weight: 550; border-radius: var(--pc-radius); padding: .5rem .8rem; cursor: pointer; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
.tb-actions .tb-primary { flex: 1; background: var(--pc-accent); color: #fff; }
.tb-actions .tb-primary:hover { background: color-mix(in srgb, var(--pc-accent) 88%, #000); }
.tb-actions .tb-ghost { background: var(--pc-bg); color: var(--pc-fg); border-color: var(--pc-border); }
.tb-actions .tb-ghost:hover { background: var(--pc-subtle); }

.tb-preview { padding: 2rem; overflow-y: auto; }

/* Basecoat cards are flat by default. Only when shadows are toggled on do we bind the preview
   surfaces to the editable --shadow-* scale — mirroring the optional project override the
   export emits, so what you see equals what you ship. */
body.shadows-on #preview .card { box-shadow: var(--shadow-sm); }
body.shadows-on #preview [class*="menu"],
body.shadows-on #preview .popover,
body.shadows-on #preview [role="dialog"] { box-shadow: var(--shadow-md); }
