/* builder.css — visual builder + content studio chrome.
   Uses the console design tokens from styles.css. The site canvas itself is
   styled by preview.css inside the iframe. */

body.builder-active .app { grid-template-columns: 1fr; }
body.builder-active .sidebar { display: none; }
body.builder-active .app-main { padding: 0; }
body.builder-active .view { width: 100%; max-width: none; margin: 0; }

.studio { min-width: 0; }

/* --------------------------------------------------------------- builder */
.builder {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.builder-top {
  position: relative;
  z-index: 60;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .55rem .7rem;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.builder-top__brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  min-width: 0;
  margin-right: .15rem;
}
.builder-top__brand .brand-mark { width: 26px; height: 26px; }
.builder-top__site {
  display: grid;
  min-width: 0;
  line-height: 1.2;
}
.builder-top__name {
  overflow: hidden;
  max-width: 32ch;
  color: var(--ink);
  font-size: .9rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.builder-top__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem .5rem;
  color: var(--muted-2);
  font-size: .72rem;
}
.builder-top__spacer { flex: 1 1 auto; }
.builder-top__group {
  display: flex;
  align-items: center;
  gap: .35rem;
}
.builder-top .btn { min-height: 38px; padding: .5rem .72rem; font-size: .83rem; }
.builder-top .icon-btn { min-height: 38px; min-width: 38px; }

.save-state {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-height: 32px;
  padding: .2rem .55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .74rem;
  font-weight: 650;
  white-space: nowrap;
}
.save-state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.save-state[data-state="saving"] { color: var(--accent-ink); border-color: #bfe0d9; background: var(--accent-soft); }
.save-state[data-state="saving"]::before { animation: studio-pulse 1s ease-in-out infinite; }
.save-state[data-state="saved"] { color: var(--success); border-color: #bfe3cd; background: var(--success-soft); }
.save-state[data-state="dirty"] { color: var(--warning); border-color: #f2d6a2; background: var(--warning-soft); }
.save-state[data-state="error"] { color: var(--danger); border-color: #f3c6c2; background: var(--danger-soft); }
@keyframes studio-pulse { 50% { opacity: .25; } }

.device-toggle {
  display: inline-flex;
  gap: .15rem;
  padding: .18rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
}
.device-toggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.device-toggle button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.device-toggle button:hover { color: var(--ink); }
.device-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.builder-top__mobile { display: none; }

.builder-body {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr) minmax(320px, 372px);
  min-height: 0;
}

.builder-panel {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  overflow: auto;
  overscroll-behavior: contain;
}
.builder-left { border-right: 1px solid var(--line); padding: .85rem; }
.builder-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid var(--line);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .55rem;
}
.panel-head h2,
.panel-head h3 {
  margin: 0;
  color: var(--muted-2);
  font-size: .69rem;
  font-weight: 750;
  letter-spacing: .085em;
  text-transform: uppercase;
}
.panel-head .count { color: var(--muted-2); font-size: .72rem; font-weight: 600; }

.page-list { display: grid; gap: .15rem; margin-bottom: 1.15rem; }
.page-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .35rem;
  width: 100%;
  padding: .45rem .5rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
}
.page-row:hover { background: var(--surface-2); }
.page-row.is-active { border-color: #c7e4dd; background: var(--accent-soft); color: var(--accent-ink); }
.page-row__label {
  overflow: hidden;
  font-size: .84rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-row__slug {
  overflow: hidden;
  color: var(--muted-2);
  font-size: .71rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-row__count { color: var(--muted-2); font-size: .7rem; }

.block-list { display: grid; gap: .35rem; }
.block-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: .3rem;
  padding: .3rem .35rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  transition: border-color .12s ease, background-color .12s ease;
}
.block-row:hover { border-color: var(--line-strong); }
.block-row.is-active { border-color: #9fd4ca; background: #f2fbf8; box-shadow: 0 0 0 1px #9fd4ca inset; }
.block-row.is-dragging { opacity: .45; }
.block-row.is-drop-target { border-color: var(--accent); border-style: dashed; background: var(--accent-soft); }
.block-row__handle {
  display: grid;
  place-items: center;
  width: 16px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #9aa8a1;
  cursor: grab;
}
.block-row__handle:active { cursor: grabbing; }
.block-row__handle svg { width: 12px; height: 16px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; }
.block-row__main {
  display: grid;
  min-width: 0;
  padding: .15rem .1rem;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}
.block-row__main:hover .block-row__label { text-decoration: underline; }
.block-row__label {
  overflow: hidden;
  color: var(--ink);
  font-size: .8rem;
  font-weight: 650;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.block-row__kind { color: var(--muted-2); font-size: .68rem; }
.block-row__actions { display: flex; gap: .05rem; }
.block-row__actions .icon-btn { width: 26px; height: 26px; min-height: 26px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  min-height: 34px;
  min-width: 34px;
  padding: .35rem;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  line-height: 1;
}
.icon-btn:hover { border-color: var(--line); background: var(--surface-2); color: var(--ink); }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[disabled] { opacity: .38; cursor: not-allowed; }

.empty-inline {
  margin: 0;
  padding: .7rem .6rem;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: .78rem;
  text-align: center;
}

/* palette */
.palette { margin-top: 1.15rem; border-top: 1px solid var(--line); padding-top: .8rem; }
.palette-group + .palette-group { margin-top: .7rem; }
.palette-group h3 {
  margin: 0 0 .35rem;
  color: var(--muted-2);
  font-size: .66rem;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.palette-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; }
.palette-btn {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .42rem .5rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: .74rem;
  font-weight: 600;
  text-align: left;
}
.palette-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.palette-btn svg { width: 13px; height: 13px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }

/* canvas */
.canvas {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(14, 26, 23, .06) 1px, transparent 0) 0 0 / 18px 18px,
    #e9eeeb;
}
.canvas-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .42rem .75rem;
  border-bottom: 1px solid rgba(14, 26, 23, .08);
  background: rgba(255, 255, 255, .72);
  backdrop-filter: blur(8px);
}
.canvas-top__page {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-width: 0;
  color: var(--muted);
  font-size: .76rem;
}
.canvas-top__page strong {
  overflow: hidden;
  color: var(--ink-soft);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.canvas-top__actions { display: flex; align-items: center; gap: .25rem; }
.canvas-stage {
  display: flex;
  flex: 1 1 auto;
  align-items: flex-start;
  justify-content: center;
  min-height: 0;
  padding: .8rem;
  overflow: auto;
}
.frame-shell {
  width: 100%;
  height: 100%;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid rgba(14, 26, 23, .12);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 18px 44px -28px rgba(14, 26, 23, .5);
  transition: width .18s ease;
}
.frame-shell[data-device="tablet"] { width: 834px; max-width: 100%; }
.frame-shell[data-device="mobile"] { width: 390px; max-width: 100%; }
.frame-shell iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.canvas-empty {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100%;
  padding: 2rem;
  color: var(--muted);
  text-align: center;
}

/* ------------------------------------------------------------- inspector */
.inspector-tabs {
  display: flex;
  gap: .15rem;
  padding: .45rem .6rem 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.inspector-tabs button {
  flex: none;
  padding: .55rem .6rem .55rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
  white-space: nowrap;
}
.inspector-tabs button:hover { color: var(--ink); }
.inspector-tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent-ink); }
.inspector-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: .85rem;
  overflow: auto;
  overscroll-behavior: contain;
}
.inspector-body:focus { outline: none; }
.inspector-empty {
  display: grid;
  justify-items: center;
  gap: .5rem;
  padding: 2.4rem 1rem;
  color: var(--muted);
  text-align: center;
}
.inspector-empty svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.inspector-empty p { margin: 0; max-width: 28ch; font-size: .82rem; }
.inspector-empty strong { color: var(--ink-soft); }

.studio-field { display: grid; gap: .3rem; margin-bottom: .8rem; }
.studio-field > label,
.studio-label {
  color: var(--ink-soft);
  font-size: .74rem;
  font-weight: 650;
}
.studio-field > label .optional { font-weight: 450; }
.studio-field input,
.studio-field textarea,
.studio-field select {
  width: 100%;
  min-height: 36px;
  padding: .45rem .55rem;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: .82rem;
  line-height: 1.45;
}
.studio-field textarea { min-height: 88px; resize: vertical; }
.studio-field select { cursor: pointer; }
.studio-field input:focus,
.studio-field textarea:focus,
.studio-field select:focus { border-color: var(--accent); outline: 2px solid rgba(15, 118, 110, .22); outline-offset: 0; }
.studio-field__hint { margin: 0; color: var(--muted-2); font-size: .7rem; line-height: 1.4; }
.studio-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.studio-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.studio-section { margin: 1rem 0 .35rem; padding-top: .85rem; border-top: 1px solid var(--line); }
.studio-section:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.studio-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .55rem;
}
.studio-section__head h3 {
  margin: 0;
  color: var(--muted-2);
  font-size: .69rem;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.md-preview {
  margin-top: .3rem;
  padding: .55rem .65rem;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: .76rem;
  line-height: 1.5;
}
.md-preview p { margin: 0 0 .4em; }
.md-preview p:last-child { margin-bottom: 0; }
.md-preview h1, .md-preview h2, .md-preview h3 { margin: 0 0 .3em; font-size: .86rem; }
.md-preview ul, .md-preview ol { margin: 0 0 .4em; padding-inline-start: 1.2em; }
.md-preview a { color: var(--accent-ink); }

.color-field { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: .4rem; align-items: center; }
.color-field input[type="color"] {
  width: 40px;
  height: 36px;
  min-height: 36px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
}
.color-field input[type="text"] { font-family: var(--mono); font-size: .76rem; }

.items-list { display: grid; gap: .55rem; }
.item-card {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  padding: .55rem;
}
.item-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
  margin-bottom: .4rem;
}
.item-card__head strong { color: var(--ink-soft); font-size: .76rem; }
.item-card__tools { display: flex; gap: .05rem; }
.item-card .studio-field { margin-bottom: .45rem; }
.item-card .studio-field:last-child { margin-bottom: 0; }
.item-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; }
.item-grid-2 .studio-field { margin-bottom: 0; }

.media-preview {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .3rem;
  padding: .35rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}
.media-preview img {
  width: 46px;
  height: 38px;
  object-fit: cover;
  border-radius: 5px;
  background: var(--surface-3);
}
.media-preview span {
  overflow: hidden;
  color: var(--muted);
  font-size: .72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-unavailable { color: var(--muted-2); font-size: .7rem; }

.inline-error {
  margin: .5rem 0;
  padding: .5rem .6rem;
  border: 1px solid #f3c6c2;
  border-radius: 7px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: .76rem;
}

/* ------------------------------------------------------------------- AI */
.ai-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ai-log {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: .55rem;
  min-height: 140px;
  padding: .15rem .15rem .8rem;
  overflow: auto;
}
.ai-msg {
  max-width: 92%;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 11px 11px 11px 3px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: .8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ai-msg--user {
  align-self: flex-end;
  border-color: #bfe0d9;
  border-radius: 11px 11px 3px 11px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.ai-msg--status { border-style: dashed; color: var(--muted); font-style: italic; }
.ai-msg--error { border-color: #f3c6c2; background: var(--danger-soft); color: var(--danger); }
.ai-msg__label { display: block; margin-bottom: .15rem; font-size: .66rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; opacity: .72; }
.ai-quick { display: flex; flex-wrap: wrap; gap: .25rem; margin: .1rem 0 .6rem; }
.ai-quick button { min-height: 28px; padding: .25rem .5rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: .7rem; font-weight: 600; }
.ai-quick button:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.ai-form { display: grid; gap: .4rem; }
.ai-form textarea {
  width: 100%;
  min-height: 68px;
  resize: vertical;
  padding: .5rem .55rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  font-size: .81rem;
  line-height: 1.45;
}
.ai-form textarea:focus { border-color: var(--accent); outline: 2px solid rgba(15, 118, 110, .22); outline-offset: 0; }
.ai-form__row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.ai-form__hint { color: var(--muted-2); font-size: .68rem; }

/* --------------------------------------------------------- block menu */
.block-menu {
  position: fixed;
  z-index: 130;
  width: min(250px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px);
  overflow: auto;
  padding: .3rem;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.block-menu__head {
  padding: .4rem .55rem .35rem;
  color: var(--muted-2);
  font-size: .66rem;
  font-weight: 750;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.block-menu button {
  display: flex;
  align-items: center;
  gap: .45rem;
  width: 100%;
  min-height: 32px;
  padding: .35rem .55rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  font-size: .78rem;
  font-weight: 550;
  text-align: left;
}
.block-menu button:hover,
.block-menu button:focus-visible { background: var(--accent-soft); color: var(--accent-ink); }
.block-menu button[disabled] { opacity: .45; cursor: not-allowed; }
.block-menu hr { margin: .3rem .25rem; border: 0; border-top: 1px solid var(--line); }
.block-menu .danger { color: var(--danger); }
.block-menu .danger:hover { background: var(--danger-soft); color: var(--danger); }
.block-menu kbd { margin-left: auto; color: var(--muted-2); font-family: var(--mono); font-size: .64rem; }

/* -------------------------------------------------------------- dialogs */
.studio-dialog {
  width: min(94vw, 540px);
  max-height: min(86dvh, 760px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.studio-dialog--wide { width: min(94vw, 760px); }
.studio-dialog::backdrop { background: rgba(14, 26, 23, .46); backdrop-filter: blur(2px); }
.studio-dialog__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem .75rem;
  border-bottom: 1px solid var(--line);
}
.studio-dialog__head h2 { margin: 0 0 .15rem; font-size: 1.05rem; }
.studio-dialog__head p { margin: 0; color: var(--muted); font-size: .8rem; }
.studio-dialog__body { max-height: 58dvh; overflow: auto; padding: 1rem 1.1rem; }
.studio-dialog__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
  padding: .8rem 1.1rem 1rem;
  border-top: 1px solid var(--line);
}
.studio-dialog__foot .btn { min-height: 38px; }
.dialog-status { margin-right: auto; color: var(--muted); font-size: .76rem; }

.publish-progress {
  display: grid;
  gap: .55rem;
  margin-top: .9rem;
  padding: .7rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
}
.publish-progress__bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}
.publish-progress__bar span {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width .3s ease;
}
.publish-progress[data-state="done"] .publish-progress__bar span { width: 100%; background: var(--success); }
.publish-progress[data-state="failed"] .publish-progress__bar span { width: 100%; background: var(--danger); }
.publish-link {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-height: 38px;
  padding: .45rem .7rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-ink);
  font-size: .8rem;
  font-weight: 650;
  text-decoration: none;
}
.publish-link:hover { border-color: var(--accent); background: var(--accent-soft); }

.revision-list { display: grid; gap: .45rem; margin: 0; padding: 0; list-style: none; }
.revision-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .6rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.revision-row__main { min-width: 0; }
.revision-row strong { display: block; color: var(--ink-soft); font-size: .82rem; }
.revision-row span { color: var(--muted-2); font-size: .72rem; }

/* --------------------------------------------------------------- CMS */
.cms { display: grid; gap: 1rem; }
.cms-tabs {
  display: flex;
  gap: .15rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}
.cms-tabs button {
  flex: none;
  padding: .6rem .7rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 650;
}
.cms-tabs button:hover { color: var(--ink); }
.cms-tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent-ink); }
.cms-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
}
.cms-toolbar__status { color: var(--muted); font-size: .78rem; }
.cms-toolbar__actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.cms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr));
  gap: 1rem;
  align-items: start;
}
.cms-card { padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.cms-card--wide { grid-column: 1 / -1; }
.cms-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .75rem;
}
.cms-card__head h2 { margin: 0 0 .15rem; font-size: .98rem; }
.cms-card__head p { margin: 0; color: var(--muted); font-size: .76rem; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.settings-grid .span-2 { grid-column: 1 / -1; }
.settings-grid .studio-field { margin-bottom: 0; }
.settings-grid .studio-field textarea { min-height: 72px; }

.repeat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: .4rem;
  align-items: end;
  margin-bottom: .45rem;
}
.repeat-row .studio-field { margin-bottom: 0; }
.repeat-row--single { grid-template-columns: minmax(0, 1fr) auto; }
.footer-column {
  margin-bottom: .6rem;
  padding: .55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.footer-column__head { display: flex; align-items: end; gap: .4rem; margin-bottom: .4rem; }
.footer-column__head .studio-field { flex: 1; margin-bottom: 0; }
.footer-column__items { padding-left: .5rem; border-left: 2px solid var(--line); }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .75rem;
}
.media-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.media-card__thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  background: var(--surface-3);
  color: var(--muted-2);
}
.media-card__thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-card__thumb span { font-size: .72rem; }
.media-card__body { display: grid; gap: .25rem; padding: .5rem; }
.media-card__name {
  overflow: hidden;
  color: var(--ink-soft);
  font-size: .75rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-card__meta { color: var(--muted-2); font-size: .68rem; }
.media-card__actions { display: flex; flex-wrap: wrap; gap: .15rem; }
.upload-zone {
  display: grid;
  justify-items: center;
  gap: .35rem;
  padding: 1.6rem 1rem;
  border: 2px dashed var(--line-strong);
  border-radius: 11px;
  background: var(--surface-2);
  text-align: center;
}
.upload-zone strong { color: var(--ink-soft); font-size: .9rem; }
.upload-zone p { margin: 0; color: var(--muted); font-size: .76rem; }
.upload-zone input[type="file"] { width: auto; max-width: 100%; font-size: .78rem; }

.collection-layout { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 1rem; align-items: start; }
.collection-nav { display: grid; gap: .2rem; }
.collection-nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  text-align: left;
}
.collection-nav button:hover { background: var(--surface-2); color: var(--ink); }
.collection-nav button[aria-current="true"] { border-color: #c7e4dd; background: var(--accent-soft); color: var(--accent-ink); }
.collection-nav .count { font-size: .7rem; }
.collection-items { display: grid; gap: .5rem; }
.collection-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.collection-item__main { min-width: 0; }
.collection-item strong { display: block; color: var(--ink-soft); font-size: .82rem; }
.collection-item p {
  display: -webkit-box;
  margin: .1rem 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: .74rem;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.collection-item__actions { display: flex; flex: none; gap: .1rem; }
.collection-empty {
  padding: 1.4rem 1rem;
  border: 1px dashed var(--line-strong);
  border-radius: 9px;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
}

.admin-page-list { display: grid; gap: .45rem; margin: 0; padding: 0; list-style: none; }
.admin-page-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .6rem;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.admin-page-row__main { min-width: 0; }
.admin-page-row strong { display: block; color: var(--ink-soft); font-size: .84rem; }
.admin-page-row span { color: var(--muted-2); font-size: .72rem; }
.admin-page-row__actions { display: flex; flex-wrap: wrap; gap: .15rem; }

.cms-loading { display: grid; gap: .5rem; padding: 1rem; }

@media (max-width: 1180px) {
  .builder-body { grid-template-columns: 270px minmax(0, 1fr); }
  .builder-right {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    width: min(380px, 92vw);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
    transform: translateX(102%);
    transition: transform .18s ease;
  }
  .builder-right.is-open { transform: translateX(0); }
  .builder-top__mobile { display: inline-flex; }
  .builder-scrim {
    position: fixed;
    inset: 0;
    z-index: 85;
    background: rgba(14, 26, 23, .38);
  }
  .builder-scrim[hidden] { display: none; }
}

@media (max-width: 820px) {
  .builder-body { grid-template-columns: 1fr; }
  .builder-left {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 90;
    width: min(300px, 88vw);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    transition: transform .18s ease;
  }
  .builder-left.is-open { transform: translateX(0); }
  .builder-top { padding: .45rem .55rem; }
  .builder-top__name { max-width: 18ch; }
  .builder-top__site { flex: 1 1 120px; }
  .builder-top__group--history .btn span { display: none; }
  .frame-shell[data-device="tablet"] { width: 100%; }
  .canvas-stage { padding: .5rem; }
  .cms-grid { grid-template-columns: 1fr; }
  .collection-layout { grid-template-columns: 1fr; }
  .collection-nav { display: flex; flex-wrap: wrap; }
  .collection-nav button { width: auto; }
}

@media (max-width: 560px) {
  .builder-top__brand .brand-word { display: none; }
  .builder-top__meta { gap: .2rem .35rem; font-size: .66rem; }
  .builder-top__meta .chip { padding: .18rem .4rem; font-size: .66rem; }
  .save-state { padding-inline: .45rem; }
  .settings-grid { grid-template-columns: 1fr; }
  .repeat-row { grid-template-columns: 1fr; }
  .repeat-row .icon-btn { justify-self: end; }
  .item-grid-2 { grid-template-columns: 1fr; }
  .studio-dialog__body { max-height: 66dvh; }
}

@media (prefers-reduced-motion: reduce) {
  .frame-shell,
  .builder-left,
  .builder-right { transition: none; }
  .save-state[data-state="saving"]::before { animation: none; }
}

/* ---------------------------------------------------- integration fixes */
.studio-loading {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3.5rem) 1.25rem;
}
.studio-loading h1 { margin: 0 0 .5rem; font-size: clamp(1.4rem, 3vw, 1.9rem); }
.studio-loading > .muted { max-width: 62ch; margin: 0 0 1rem; }
.studio-loading .cms-toolbar__actions { margin-top: 1rem; }
.studio-loading .skeleton-group { margin-top: 1rem; }

.builder .btn svg,
.cms .btn svg,
.publish-link svg,
.media-card__thumb svg,
.upload-zone svg,
.block-menu svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.upload-zone > svg { width: 30px; height: 30px; color: var(--accent); }
.media-card__thumb > svg { width: 26px; height: 26px; }
.block-menu button svg { width: 15px; height: 15px; }

.builder-only-mobile,
.builder-only-narrow { display: none; }
@media (max-width: 1180px) {
  .builder-only-narrow { display: inline-flex; }
}
@media (max-width: 820px) {
  .builder-only-mobile { display: inline-flex; }
}

.page-row > span:first-child { display: block; min-width: 0; }
.page-row__label,
.page-row__slug { display: block; }

.block-dropzone {
  display: none;
  margin-top: .4rem;
  padding: .7rem;
  border: 2px dashed var(--line-strong);
  border-radius: 9px;
  color: var(--muted-2);
  font-size: .74rem;
  text-align: center;
}
.builder.is-dragging .block-dropzone { display: block; }
.block-dropzone.is-drop-target { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

.studio-section__head strong { color: var(--ink-soft); font-size: .85rem; }

.cms-panel { min-width: 0; }
.cms-grid--compact { grid-template-columns: 1fr; }

.inspector-body .cms-grid {
  grid-template-columns: 1fr;
  gap: .15rem;
}
.inspector-body .cms-card {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.inspector-body .cms-card__head {
  margin: 1rem 0 .6rem;
  padding-top: .9rem;
  border-top: 1px solid var(--line);
}
.inspector-body .cms-card:first-child .cms-card__head { margin-top: 0; padding-top: 0; border-top: 0; }
.inspector-body .cms-card__head h2 { font-size: .8rem; }
.inspector-body .cms-card__head p { font-size: .72rem; }
.inspector-body .settings-grid { grid-template-columns: 1fr; }
.inspector-body .settings-grid .span-2 { grid-column: auto; }
.inspector-body .cms-card__head + .settings-grid { margin-top: .1rem; }

.cms-card .cms-grid { grid-template-columns: 1fr 1fr; }
.cms-card .cms-card { padding: .75rem; background: var(--surface-2); }

.publish-status { margin: 0; color: var(--ink-soft); font-size: .82rem; }
.collection-item__actions { flex-wrap: wrap; }

.cms .page-head { align-items: center; margin-bottom: .9rem; }
.cms .page-head h1 { font-size: clamp(1.45rem, 2vw, 1.8rem); }
.cms .page-head p { max-width: 56ch; }
.cms > .breadcrumb { margin-bottom: 0; }

@media (max-width: 820px) {
  .builder-top .btn > span { display: none; }
  .builder-top .btn { min-width: 38px; padding-inline: .6rem; }
  .builder-top .device-toggle { order: 4; }
  .save-state > span { display: inline; }
}

.frame-shell { max-width: none; }
.frame-shell[data-device] { max-width: none; }
.frame-shell iframe { transform-origin: top left; }
@media (max-width: 820px) {
  .frame-shell[data-device="tablet"],
  .frame-shell[data-device="mobile"] { max-width: none; width: auto; }
}

.builder-top__name:focus,
.builder-top__name:focus-visible { outline: none; }
