/*
 * FacturaProRD · Theme Studio v5
 * Capa visual aislada. Se carga después de los estilos históricos para que el
 * editor conserve una apariencia estable mientras previsualiza otros temas.
 */

.theme-studio,
.theme-studio *,
.theme-studio *::before,
.theme-studio *::after {
  box-sizing: border-box;
}

.theme-studio {
  --studio-accent: #2563eb;
  --studio-accent-hover: #1d4ed8;
  --studio-accent-active: #1e40af;
  --studio-accent-soft: #eff6ff;
  --studio-purple: #7c3aed;
  --studio-success: #10b981;
  --studio-warning: #f59e0b;
  --studio-danger: #ef4444;
  --studio-canvas: #f6f8fb;
  --studio-surface: #ffffff;
  --studio-section: #f8faff;
  --studio-border: #dce5f1;
  --studio-border-strong: #cbd8e8;
  --studio-text: #0f172a;
  --studio-muted: #52627a;
  --studio-soft-text: #78879d;
  --studio-radius: 10px;
  --studio-shadow: 0 10px 34px rgb(39 68 108 / 9%);

  display: block !important;
  width: 100%;
  min-width: 0;
  min-height: 0 !important;
  overflow: hidden;
  border: 1px solid var(--studio-border) !important;
  border-radius: var(--studio-radius) !important;
  background: var(--studio-surface) !important;
  color: var(--studio-text) !important;
  box-shadow: var(--studio-shadow) !important;
  font-family: "Manrope", Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.45;
  isolation: isolate;
  container-name: theme-studio;
  container-type: inline-size;
}

/* The application rendered inside the iframe already has its own read-only
   shield; suppress the legacy floating watermark so the miniature stays clean. */
html[data-theme-preview="true"] body::after {
  display: none !important;
}

.settings-admin-tab-panel[data-tab-panel="themes"] {
  min-width: 0;
}

.settings-admin-tab-panel[data-tab-panel="themes"].is-active {
  display: block;
}

/* Focus mode supplied by settingsView: Theme Studio uses the whole work area. */
.view-root.view-root--theme-studio {
  width: 100%;
  max-width: 1880px;
  padding: 12px 16px 18px;
}

.settings-admin-page--theme-studio {
  display: block !important;
  width: 100%;
  min-width: 0;
  gap: 0 !important;
}

.settings-admin-page--theme-studio > .page__header,
.settings-admin-page--theme-studio > .stats-grid,
.settings-admin-page--theme-studio > .settings-admin-tabs {
  display: none !important;
}

.settings-admin-page--theme-studio > .settings-admin-panels {
  display: block !important;
  width: 100%;
  min-width: 0;
}

.theme-studio button,
.theme-studio input,
.theme-studio select {
  font-family: inherit;
}

/* Header */
.theme-studio__header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 24px !important;
  width: 100%;
  min-height: 78px !important;
  padding: 16px 18px !important;
  border: 0 !important;
  border-bottom: 1px solid var(--studio-border) !important;
  background: var(--studio-surface) !important;
}

.theme-studio__title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 13px;
}

.theme-studio__title > span {
  display: grid !important;
  place-items: center;
  width: 34px !important;
  height: 34px !important;
  flex: 0 0 34px !important;
  border-radius: 10px !important;
  background: linear-gradient(135deg, #7546ed 0%, #8b5cf6 100%) !important;
  color: #ffffff !important;
  box-shadow: 0 7px 17px rgb(124 58 237 / 22%) !important;
}

.theme-studio__title > span svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-studio__title > span svg circle {
  fill: currentColor;
  stroke: none;
}

.theme-studio__title h2 {
  margin: 0 !important;
  color: var(--studio-text) !important;
  font-size: 20px !important;
  font-weight: 800 !important;
  line-height: 1.2;
  letter-spacing: -.025em;
}

.theme-studio__title p {
  margin: 3px 0 0 !important;
  color: var(--studio-muted) !important;
  font-size: 10.5px !important;
  font-weight: 500;
  line-height: 1.35;
}

.theme-preview-master-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 38px;
  margin: 0;
  padding: 5px 7px 5px 12px;
  border: 1px solid var(--studio-border);
  border-radius: 7px;
  background: #fbfdff;
  color: var(--studio-accent);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.theme-preview-master-toggle:hover {
  border-color: #a9c4f4;
  background: #f7faff;
}

.theme-preview-master-toggle:focus-within {
  border-color: var(--studio-accent);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 12%);
}

.theme-preview-master-toggle > span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.theme-preview-master-toggle svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-preview-master-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.theme-preview-master-toggle > i {
  position: relative;
  display: block;
  width: 36px;
  height: 21px;
  flex: 0 0 36px;
  border: 1px solid #c7d5e6;
  border-radius: 999px;
  background: #dbe4ef;
  box-shadow: inset 0 1px 2px rgb(15 23 42 / 8%);
  transition: background .18s ease, border-color .18s ease;
}

.theme-preview-master-toggle > i::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 5px rgb(15 23 42 / 22%);
  transition: transform .18s ease;
}

.theme-preview-master-toggle input:checked + i {
  border-color: var(--studio-accent);
  background: var(--studio-accent);
}

.theme-preview-master-toggle input:checked + i::before {
  transform: translateX(15px);
}

/* Two-column body. The footer belongs to the right side, like the reference. */
.theme-studio__workspace {
  display: grid !important;
  grid-template-columns: minmax(390px, 31.5%) minmax(0, 1fr) !important;
  align-items: stretch !important;
  width: 100%;
  height: clamp(800px, calc(100dvh - 106px), 900px) !important;
  min-height: 0;
}

.theme-studio__library {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 18px 16px 20px !important;
  overflow-x: hidden;
  overflow-y: auto !important;
  border: 0 !important;
  border-right: 1px solid var(--studio-border) !important;
  background: var(--studio-surface) !important;
  scrollbar-width: thin;
  scrollbar-color: #b8c5d5 transparent;
  overscroll-behavior: contain;
}

.theme-studio__library::-webkit-scrollbar,
.theme-editor-section::-webkit-scrollbar,
.theme-studio__tabs::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

.theme-studio__library::-webkit-scrollbar-thumb,
.theme-editor-section::-webkit-scrollbar-thumb,
.theme-studio__tabs::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #b8c5d5;
  background-clip: padding-box;
}

.theme-studio__library-heading {
  flex: 0 0 auto;
  padding: 0 1px;
}

.theme-studio__library h3 {
  margin: 0 !important;
  color: var(--studio-text) !important;
  font-size: 13px !important;
  font-weight: 800 !important;
  line-height: 1.3;
}

.theme-studio__library p {
  margin: 4px 0 0 !important;
  color: var(--studio-muted) !important;
  font-size: 10px !important;
  font-weight: 500;
}

.theme-studio__preset-list {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 10px !important;
  width: 100%;
  margin: 14px 0 0 !important;
}

.theme-studio__preset {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 116px !important;
  padding: 10px !important;
  overflow: hidden;
  border: 1px solid var(--studio-border) !important;
  border-radius: 8px !important;
  outline: 0;
  background: var(--studio-surface) !important;
  color: var(--studio-text) !important;
  box-shadow: none !important;
  text-align: left;
  cursor: pointer;
  transform: none !important;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease !important;
}

.theme-studio__preset:hover {
  border-color: #8fb2f4 !important;
  background: #fcfdff !important;
  box-shadow: 0 5px 14px rgb(37 99 235 / 8%) !important;
}

.theme-studio__preset:focus-visible {
  border-color: var(--studio-accent) !important;
  box-shadow: 0 0 0 3px rgb(37 99 235 / 15%) !important;
}

.theme-studio__preset.is-active {
  border-color: var(--studio-accent) !important;
  background: #fbfdff !important;
  box-shadow: inset 0 0 0 1px var(--studio-accent) !important;
}

.theme-studio__preset-title {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 7px !important;
  min-width: 0;
  color: var(--studio-text) !important;
  font-size: 11.5px !important;
  font-weight: 700 !important;
  line-height: 1.25;
}

.theme-studio__preset-title > span {
  display: flex !important;
  align-items: center !important;
  min-width: 0;
  gap: 6px;
}

.theme-studio__preset-title strong {
  min-width: 0;
  overflow: hidden;
  font: inherit;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-studio__preset-dot {
  display: block;
  width: 7px !important;
  height: 7px !important;
  flex: 0 0 7px;
  margin: 0 !important;
  border: 0;
  border-radius: 50%;
  background: var(--swatch) !important;
}

.theme-studio__preset-check {
  display: grid;
  place-items: center;
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  border-radius: 50%;
  background: var(--studio-accent);
  color: #ffffff;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
}

.theme-studio__preset-title small {
  flex: 0 0 auto;
  padding: 3px 7px !important;
  border: 1px solid #c9dcfb;
  border-radius: 999px !important;
  background: #eaf2ff !important;
  color: #1d4ed8 !important;
  font-size: 8px !important;
  font-weight: 800;
  line-height: 1.2;
}

.theme-studio__preset-description {
  display: -webkit-box !important;
  min-height: 20px !important;
  margin: 6px 0 0 !important;
  overflow: hidden;
  color: var(--studio-muted) !important;
  font-size: 9.5px !important;
  font-weight: 500;
  line-height: 1.35 !important;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.theme-studio__preset-preview {
  position: relative;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 44% !important;
  grid-template-rows: 50px !important;
  gap: 7px !important;
  width: 100%;
  height: 50px !important;
  margin: 7px 0 0 !important;
  padding: 0 !important;
  overflow: hidden;
  border: 0 !important;
  border-radius: 5px !important;
  background: transparent !important;
}

.theme-studio__preset-preview::before {
  content: "";
  grid-column: 1;
  grid-row: 1;
  align-self: end;
  height: 27px;
  border: 1px solid var(--preset-border);
  border-radius: 4px;
  background: var(--preset-bg);
}

.theme-studio__preset-swatches {
  z-index: 1;
  grid-column: 1;
  grid-row: 1;
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-self: start;
  gap: 4px !important;
  width: 100%;
  height: 17px;
}

.theme-studio__preset-swatches i {
  display: block;
  width: auto !important;
  height: 17px !important;
  margin: 0 !important;
  border: 1px solid var(--preset-border) !important;
  border-radius: 3px !important;
}

.theme-studio__preset-swatches i:nth-child(1) { background: var(--preset-primary) !important; }
.theme-studio__preset-swatches i:nth-child(2) { background: var(--preset-secondary) !important; }
.theme-studio__preset-swatches i:nth-child(3) { background: var(--preset-card) !important; }
.theme-studio__preset-swatches i:nth-child(4) { background: var(--preset-sidebar) !important; }

.theme-studio__preset-scene {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  display: grid !important;
  grid-template-columns: 26% repeat(2, minmax(0, 1fr)) !important;
  grid-template-rows: 9px repeat(2, minmax(0, 1fr)) !important;
  gap: 3px !important;
  width: 100%;
  height: 50px !important;
  padding: 4px !important;
  overflow: hidden;
  border: 1px solid var(--preset-border) !important;
  border-radius: 4px !important;
  background: var(--preset-bg) !important;
}

.theme-studio__mini-sidebar {
  display: grid !important;
  grid-row: 1 / -1 !important;
  gap: 3px;
  padding: 4px 3px;
  border-radius: 2px !important;
  background: var(--preset-sidebar) !important;
}

.theme-studio__mini-sidebar b {
  display: block;
  height: 2px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--preset-primary) 55%, transparent);
}

.theme-studio__mini-topbar {
  grid-column: 2 / -1;
  border-radius: 2px;
  background: var(--preset-card) !important;
}

.theme-studio__mini-card {
  display: block;
  border-radius: 2px;
  background: var(--preset-card) !important;
}

.theme-studio__mini-button {
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 40%;
  height: 4px;
  border-radius: 999px;
  background: var(--preset-primary) !important;
}

.theme-studio__custom-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px !important;
}

.theme-studio__custom-heading span {
  color: var(--studio-muted) !important;
  font-size: 10px !important;
}

.theme-studio__preset-list--custom {
  grid-template-columns: 1fr !important;
}

.theme-studio__custom-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  margin-top: 7px;
}

.theme-studio__custom-tools button {
  min-height: 28px;
  padding: 5px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--studio-muted);
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
}

.theme-studio__custom-tools button:hover {
  background: var(--studio-accent-soft);
  color: var(--studio-accent);
}

.theme-studio__custom-card {
  display: grid !important;
  grid-template-columns: 30px minmax(0, 1fr) auto !important;
  align-items: center !important;
  gap: 10px !important;
  width: 100%;
  min-height: 58px !important;
  margin: auto 0 0 !important;
  padding: 9px 11px !important;
  border: 1px dashed #94b8ff !important;
  border-radius: 8px !important;
  outline: 0;
  background: #f9fbff !important;
  color: #27436e !important;
  text-align: left;
  cursor: pointer;
}

.theme-studio__custom-card:hover,
.theme-studio__custom-card:focus-visible {
  border-color: var(--studio-accent) !important;
  background: #f3f7ff !important;
  box-shadow: 0 0 0 3px rgb(37 99 235 / 10%);
}

.theme-studio__custom-card > span:first-child {
  display: grid !important;
  place-items: center;
  width: 30px;
  height: 30px;
  color: var(--studio-purple) !important;
}

.theme-studio__custom-card svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-studio__custom-card > span:nth-child(2) {
  display: grid !important;
  gap: 2px !important;
  min-width: 0;
}

.theme-studio__custom-card strong {
  color: #27436e;
  font-size: 10.5px !important;
  font-weight: 800;
}

.theme-studio__custom-card small {
  color: var(--studio-soft-text) !important;
  font-size: 9px !important;
}

.theme-studio__custom-card em {
  padding: 7px 10px !important;
  border: 1px solid #cadcf9 !important;
  border-radius: 6px !important;
  background: #eef4ff !important;
  color: var(--studio-accent) !important;
  font-size: 8.5px !important;
  font-style: normal !important;
  font-weight: 800 !important;
  white-space: nowrap;
}

/* Right column */
.theme-studio__right-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 68px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--studio-surface);
}

.theme-studio__main {
  display: grid !important;
  grid-template-rows: 43px auto minmax(250px, 1fr);
  min-width: 0 !important;
  min-height: 0 !important;
  height: auto;
  overflow: hidden !important;
  background: var(--studio-surface) !important;
}

.theme-studio__tabs {
  display: flex !important;
  align-items: stretch;
  gap: 0 !important;
  min-width: 0;
  min-height: 43px !important;
  margin: 0;
  padding: 0 8px !important;
  overflow-x: auto !important;
  overflow-y: hidden;
  border: 0 !important;
  border-bottom: 1px solid var(--studio-border) !important;
  background: #fbfcff !important;
  scrollbar-width: thin;
}

.theme-studio__tabs button {
  position: relative;
  flex: 0 0 auto !important;
  min-height: 43px;
  padding: 0 15px !important;
  border: 0 !important;
  border-bottom: 2px solid transparent !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: #63718a !important;
  font-size: 10.5px !important;
  font-weight: 700 !important;
  white-space: nowrap;
  cursor: pointer;
}

.theme-studio__tabs button:hover {
  color: var(--studio-accent) !important;
}

.theme-studio__tabs button:focus-visible {
  z-index: 1;
  outline: 2px solid var(--studio-accent);
  outline-offset: -3px;
}

.theme-studio__tabs button.is-active {
  border-bottom-color: var(--studio-accent) !important;
  background: transparent !important;
  color: var(--studio-accent) !important;
  box-shadow: none !important;
}

/* Editor */
.theme-editor-section {
  min-width: 0;
  min-height: 488px !important;
  height: 488px;
  max-height: 488px;
  padding: 16px 16px 17px !important;
  overflow-x: hidden;
  overflow-y: auto;
  border: 0 !important;
  border-bottom: 1px solid var(--studio-border) !important;
  background: var(--studio-surface) !important;
  scrollbar-width: thin;
  scrollbar-color: #c0ccda transparent;
}

.theme-editor-section__heading {
  display: flex !important;
  align-items: flex-start !important;
  justify-content: space-between !important;
  gap: 16px !important;
  min-height: 34px;
  margin: 0 0 15px !important;
}

.theme-editor-section__heading h4,
.theme-gradient-section h4,
.theme-live-preview__header h4 {
  margin: 0 !important;
  color: var(--studio-text) !important;
  font-size: 12px !important;
  font-weight: 800 !important;
  line-height: 1.3;
}

.theme-editor-section__heading p,
.theme-gradient-section > div:first-child p,
.theme-live-preview__header p {
  margin: 2px 0 0 !important;
  color: var(--studio-muted) !important;
  font-size: 10px !important;
  font-weight: 500;
  line-height: 1.35;
}

.theme-studio__reset {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 29px;
  padding: 5px 10px;
  border: 1px solid var(--studio-border);
  border-radius: 6px;
  background: var(--studio-surface);
  color: #60718b;
  font-size: 9.5px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.theme-studio__reset:hover {
  border-color: #a9c4f4;
  background: #f8fbff;
  color: var(--studio-accent);
}

.theme-studio__reset:focus-visible {
  outline: 2px solid var(--studio-accent);
  outline-offset: 2px;
}

.theme-studio__reset svg,
.theme-studio__footer svg,
.theme-advanced-actions svg {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-color-grid {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 13px 14px !important;
}

.theme-color-grid--compact {
  align-content: start;
}

.theme-color-field {
  display: block;
  min-width: 0;
  margin: 0;
}

.theme-color-field > span:first-child {
  display: block !important;
  min-height: 13px;
  margin: 0 0 5px 1px !important;
  overflow: hidden;
  color: var(--studio-text) !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-color-field__control {
  position: relative;
  display: flex !important;
  align-items: center !important;
  width: 100%;
  height: 35px !important;
  min-height: 35px;
  overflow: hidden !important;
  border: 1px solid #d5e0ee !important;
  border-radius: 6px !important;
  background: var(--studio-surface) !important;
  box-shadow: none !important;
}

.theme-color-field__control:hover {
  border-color: #b8c9de !important;
}

.theme-color-field__control:focus-within {
  border-color: var(--studio-accent) !important;
  box-shadow: 0 0 0 3px rgb(37 99 235 / 11%) !important;
}

.theme-color-field__control::before {
  content: "";
  display: block;
  width: 22px !important;
  height: 22px !important;
  flex: 0 0 22px !important;
  margin: 0 0 0 6px !important;
  border: 1px solid #d5e0ee !important;
  border-radius: 3px !important;
  background: var(--theme-field-color) !important;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 28%);
}

.theme-color-field__control input[type="color"] {
  position: absolute !important;
  z-index: 2;
  top: 0;
  left: 0;
  width: 35px !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  opacity: 0;
  cursor: pointer;
}

.theme-color-field__control input[type="text"] {
  display: block !important;
  width: 100% !important;
  min-width: 0 !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 7px !important;
  border: 0 !important;
  border-radius: 0 !important;
  outline: 0 !important;
  background: transparent !important;
  color: #4a5a72 !important;
  box-shadow: none !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important;
  font-size: 10px !important;
  font-weight: 600;
  appearance: none;
}

.theme-color-field__control > i {
  display: grid !important;
  place-items: center;
  width: 29px !important;
  height: 100% !important;
  flex: 0 0 29px !important;
  margin: 0 !important;
  border-left: 1px solid #edf1f6;
  color: #53647d !important;
  font-style: normal !important;
  pointer-events: none;
}

.theme-color-field__control > i svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-gradient-section {
  margin: 14px -16px -17px !important;
  padding: 13px 16px 15px !important;
  border: 0 !important;
  border-top: 1px solid var(--studio-border) !important;
  background: #fcfdff;
}

.theme-gradient-section > div:first-child {
  margin-bottom: 10px;
}

.theme-gradient-grid {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 13px !important;
  margin: 0 !important;
}

.theme-gradient-grid > div {
  display: grid !important;
  min-width: 0;
  gap: 5px !important;
  color: var(--studio-muted) !important;
  font-size: 9.5px !important;
  font-weight: 600;
}

.theme-gradient-grid i {
  position: relative;
  display: flex !important;
  align-items: center;
  min-width: 0;
  height: 25px !important;
  padding: 0 10px;
  overflow: hidden;
  border: 1px solid #d5e0ee !important;
  border-radius: 5px !important;
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 18%);
  font-style: normal;
}

.theme-gradient-grid i::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgb(15 23 42 / 12%), transparent 45%);
  pointer-events: none;
}

.theme-gradient-grid i b {
  position: relative;
  z-index: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 8.5px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: .01em;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgb(15 23 42 / 45%);
  white-space: nowrap;
}

.theme-gradient-grid > div:nth-child(3) i {
  color: #53627a;
}

.theme-gradient-grid > div:nth-child(3) i b {
  text-shadow: none;
}

/* Secondary editor panels */
.theme-module-select {
  display: grid;
  max-width: 330px !important;
  margin: 0 0 15px !important;
  gap: 5px;
}

.theme-studio .field__label {
  color: var(--studio-text);
  font-size: 10px;
  font-weight: 700;
}

.theme-studio .field__select,
.theme-studio .field__input {
  min-height: 36px;
  border-color: #d5e0ee;
  border-radius: 7px;
  background: var(--studio-surface);
  color: var(--studio-text);
  font-size: 10.5px;
}

.theme-component-sample,
.theme-effect-samples {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  margin: 18px 0 0 !important;
  padding: 14px !important;
  border: 1px solid var(--studio-border);
  border-radius: 8px !important;
  background: var(--studio-section) !important;
  box-shadow: none !important;
}

.theme-component-sample > div {
  display: grid;
  gap: 2px;
  margin-right: auto;
}

.theme-component-sample > div span {
  color: var(--studio-text);
  font-size: 10px;
  font-weight: 800;
}

.theme-component-sample > div small {
  color: var(--studio-muted);
  font-size: 8px;
}

.theme-studio .theme-component-sample .btn,
.theme-studio .theme-effect-samples .btn,
.theme-studio .theme-advanced-actions .btn {
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 7px;
  font-size: 9px;
}

.theme-control-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 15px !important;
}

.theme-control-grid .field {
  display: grid;
  gap: 7px;
}

.theme-control-grid input[type="range"] {
  width: 100%;
  accent-color: var(--studio-accent);
}

.theme-type-sample {
  margin: 18px 0 0 !important;
  padding: 18px !important;
  border: 1px solid var(--studio-border) !important;
  border-radius: 8px !important;
  background: var(--studio-section) !important;
  box-shadow: none !important;
}

.theme-type-sample h3 { margin: 0 0 6px !important; color: var(--studio-text); }
.theme-type-sample p { margin: 0 0 12px !important; color: var(--studio-muted); }
.theme-type-sample strong { color: var(--studio-accent); font-size: 21px; }

.theme-login-sample {
  display: grid !important;
  place-items: center;
  min-height: 160px !important;
  margin: 17px 0 0 !important;
  padding: 18px !important;
  border: 1px solid var(--studio-border);
  border-radius: 8px !important;
  background: var(--login-sample-bg) !important;
}

.theme-login-sample > div {
  display: grid;
  gap: 7px;
  width: min(270px, 100%);
  padding: 16px;
  border: 1px solid var(--studio-border);
  border-radius: 8px;
  background: var(--login-sample-card);
  box-shadow: 0 8px 22px rgb(15 23 42 / 9%);
}

.theme-login-sample span { color: var(--studio-muted); font-size: 9px; }
.theme-login-sample input { height: 34px; padding: 0 9px; border: 1px solid var(--studio-border); border-radius: 6px; }
.theme-login-sample button { height: 34px; border: 0; border-radius: 6px; background: var(--studio-accent); color: #fff; font-size: 10px; font-weight: 800; }

.theme-effect-samples article {
  min-width: 180px;
  padding: 13px;
  border: 1px solid var(--studio-border) !important;
  border-radius: 8px !important;
  background: var(--studio-surface) !important;
  box-shadow: 0 6px 16px rgb(15 23 42 / 7%) !important;
}

.theme-effect-samples article span { display: block; color: var(--studio-muted); font-size: 8px; }

.theme-advanced-actions,
.theme-advanced-switches {
  display: flex !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px !important;
}

.theme-advanced-switches {
  margin-top: 15px !important;
  gap: 18px !important;
}

.theme-accessibility {
  margin: 16px 0 0 !important;
  padding: 14px !important;
  border: 1px solid #bfe5d6 !important;
  border-radius: 8px !important;
  background: #f3fbf7 !important;
}

.theme-accessibility.has-warnings {
  border-color: #f1d6a8 !important;
  background: #fffaf0 !important;
}

.theme-accessibility > div {
  display: grid;
  gap: 2px;
}

.theme-accessibility > div span { color: var(--studio-muted); font-size: 8.5px; }

.theme-accessibility ul {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 7px !important;
  margin: 12px 0 0 !important;
  padding: 0 !important;
  list-style: none;
}

.theme-accessibility li {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto auto !important;
  align-items: center;
  gap: 7px !important;
  padding: 7px 9px !important;
  border-radius: 6px !important;
  background: var(--studio-surface) !important;
  color: var(--studio-text);
  font-size: 8.5px !important;
}

.theme-accessibility li em {
  padding: 2px 5px;
  border-radius: 999px;
  background: var(--studio-accent-soft);
  color: var(--studio-accent);
  font-size: 7.5px;
  font-style: normal;
  font-weight: 800;
}

.theme-schema-note {
  margin: 12px 0 0 !important;
  padding: 12px !important;
  border-radius: 8px !important;
  background: var(--studio-section) !important;
}

.theme-schema-note p { margin: 3px 0 0 !important; color: var(--studio-muted); font-size: 8.5px !important; }

/* Live FacturaProRD preview */
.theme-live-preview {
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  padding: 10px 16px 5px !important;
  overflow: hidden;
  border: 0 !important;
  background: var(--studio-surface) !important;
}

.theme-live-preview__header {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 14px !important;
  min-height: 30px;
  margin: 0 0 7px;
}

.theme-live-preview__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid #ccebdc;
  border-radius: 999px;
  background: #f1fbf6;
  color: #168657;
  font-size: 7.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .045em;
}

.theme-live-preview__status i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgb(34 197 94 / 12%);
}

.theme-preview-stage {
  --theme-preview-scale: .62;
  position: relative !important;
  width: 100% !important;
  min-width: 0;
  min-height: 240px !important;
  height: 100% !important;
  margin: 0 !important;
  overflow: hidden !important;
  border: 1px solid var(--studio-border) !important;
  border-radius: 7px !important;
  background: #eef3fa !important;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 65%), 0 8px 22px rgb(15 23 42 / 7%) !important;
  isolation: isolate;
  contain: layout paint;
}

.theme-preview-stage iframe {
  position: absolute !important;
  z-index: 1;
  top: 0;
  left: 0;
  display: block !important;
  width: 1440px !important;
  min-width: 1440px !important;
  max-width: none !important;
  height: 900px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #f6f8fb !important;
  opacity: 0;
  pointer-events: none !important;
  user-select: none;
  transform: scale(var(--theme-preview-scale)) !important;
  transform-origin: top left !important;
  transition: opacity .2s ease;
}

.theme-preview-stage.is-ready iframe {
  opacity: 1;
}

.theme-preview-stage__shield {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: block;
  background: transparent;
  cursor: default;
  pointer-events: auto !important;
  user-select: none;
  touch-action: none;
}

.theme-preview-stage__loading {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  background: linear-gradient(135deg, #f8fbff, #edf3fb);
  color: var(--studio-muted);
  font-size: 9px;
  font-weight: 700;
  transition: opacity .18s ease, visibility .18s ease;
}

.theme-preview-stage__loading i {
  width: 22px;
  height: 22px;
  border: 2px solid #cfdded;
  border-top-color: var(--studio-accent);
  border-radius: 50%;
  animation: theme-studio-spin .8s linear infinite;
}

.theme-preview-stage.is-ready .theme-preview-stage__loading {
  opacity: 0;
  visibility: hidden;
}

.theme-live-preview--disabled {
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--studio-surface) !important;
}

.theme-live-preview--disabled .theme-live-preview__status {
  border-color: #d8e1ec;
  background: #f4f7fa;
  color: #718096;
  font-size: 0;
}

.theme-live-preview--disabled .theme-live-preview__status::after {
  content: "Pausada · solo lectura";
  font-size: 7.5px;
}

.theme-live-preview--disabled .theme-live-preview__status i {
  background: #94a3b8;
  box-shadow: 0 0 0 3px rgb(148 163 184 / 12%);
}

.theme-preview-stage__paused {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: none;
  place-content: center;
  justify-items: center;
  gap: 5px;
  padding: 24px;
  background: linear-gradient(135deg, #f9fbfe, #edf3fa);
  color: var(--studio-muted);
  text-align: center;
}

.theme-preview-stage__paused strong {
  color: var(--studio-text);
  font-size: 12px;
  font-weight: 800;
}

.theme-preview-stage__paused span {
  max-width: 330px;
  font-size: 9.5px;
}

.theme-preview-stage.is-paused .theme-preview-stage__paused {
  display: grid;
}

.theme-preview-stage.is-paused iframe,
.theme-preview-stage.is-paused .theme-preview-stage__loading,
.theme-preview-stage.is-paused .theme-preview-stage__placeholder {
  opacity: 0 !important;
  visibility: hidden !important;
}

.theme-preview-stage__placeholder {
  position: absolute;
  z-index: 1;
  inset: 0;
  background:
    linear-gradient(90deg, #e8eef7 25%, #f4f7fb 50%, #e8eef7 75%) 0 0 / 200% 100%,
    #eef3fa;
  animation: theme-studio-placeholder 1.4s ease-in-out infinite;
}

@keyframes theme-studio-spin {
  to { transform: rotate(360deg); }
}

@keyframes theme-studio-placeholder {
  to { background-position: -200% 0; }
}

/* Footer */
.theme-studio__footer {
  position: static !important;
  z-index: auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 14px !important;
  width: 100%;
  min-height: 68px !important;
  margin: 0 !important;
  padding: 12px 16px !important;
  border: 0 !important;
  border-top: 1px solid var(--studio-border) !important;
  background: var(--studio-surface) !important;
  box-shadow: 0 -7px 20px rgb(15 23 42 / 3%) !important;
}

.theme-studio__footer-note {
  display: flex !important;
  align-items: center !important;
  min-width: 0;
  gap: 12px !important;
}

.theme-studio__footer-note > span {
  min-width: 0;
  overflow: hidden;
  color: var(--studio-muted) !important;
  font-size: 9.5px !important;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-studio__footer-note > span.is-dirty {
  color: #9a6200 !important;
}

.theme-studio__footer > div:last-child {
  display: flex !important;
  align-items: center;
  justify-content: flex-end;
  gap: 9px !important;
  flex: 0 0 auto;
}

.theme-studio__footer .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px !important;
  margin: 0 !important;
  padding: 7px 14px !important;
  border-radius: 7px !important;
  font-size: 10.5px !important;
  font-weight: 700 !important;
  white-space: nowrap;
}

.theme-studio__footer .btn--ghost {
  border: 1px solid var(--studio-border) !important;
  background: var(--studio-surface) !important;
  color: #4d607a !important;
  box-shadow: none !important;
}

.theme-studio__footer .btn--ghost:hover:not(:disabled) {
  border-color: #a9c4f4 !important;
  background: #f8fbff !important;
  color: var(--studio-accent) !important;
}

.theme-studio__footer .btn--primary {
  border: 1px solid var(--studio-accent) !important;
  background: var(--studio-accent) !important;
  color: #ffffff !important;
  box-shadow: 0 7px 15px rgb(37 99 235 / 18%) !important;
}

.theme-studio__footer .btn--primary:hover:not(:disabled) {
  border-color: var(--studio-accent-hover) !important;
  background: var(--studio-accent-hover) !important;
}

.theme-studio__footer .btn:disabled {
  opacity: .48 !important;
  cursor: not-allowed !important;
  box-shadow: none !important;
}

/* Medium desktop: preserve the composition and give controls enough width. */
@media (max-width: 1340px) {
  .theme-studio__workspace {
    grid-template-columns: 330px minmax(0, 1fr) !important;
  }

  .theme-color-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .theme-editor-section {
    min-height: 440px !important;
    height: 440px;
    max-height: 440px;
  }

  .theme-studio__tabs button {
    padding-inline: 12px !important;
  }

  .theme-studio__footer-note > span {
    max-width: 220px;
  }
}

@media (max-width: 1120px) {
  .theme-studio__workspace {
    grid-template-columns: 300px minmax(0, 1fr) !important;
  }

  .theme-studio__preset-list {
    grid-template-columns: 1fr !important;
  }

  .theme-studio__preset-preview {
    grid-template-columns: minmax(0, 1fr) 42% !important;
  }

  .theme-gradient-grid {
    grid-template-columns: 1fr !important;
  }

  .theme-editor-section {
    min-height: 396px !important;
    height: 396px;
    max-height: 396px;
  }

  .theme-studio__footer-note > span {
    display: none;
  }
}

/* Tablet: themes become a horizontal shelf, editor and preview remain unified. */
@media (max-width: 920px) {
  .theme-studio {
    border-radius: 9px !important;
  }

  .theme-studio__workspace {
    display: block !important;
    height: auto !important;
  }

  .theme-studio__library {
    display: block;
    height: auto;
    max-height: none !important;
    padding: 16px !important;
    overflow: hidden !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--studio-border) !important;
  }

  .theme-studio__preset-list,
  .theme-studio__preset-list--custom {
    display: flex !important;
    grid-template-columns: none !important;
    gap: 10px !important;
    padding: 0 0 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }

  .theme-studio__preset {
    width: 224px;
    min-width: 224px;
    flex: 0 0 224px;
    scroll-snap-align: start;
  }

  .theme-studio__custom-card {
    max-width: 430px;
    margin-top: 12px !important;
  }

  .theme-studio__right-column {
    display: block;
    height: auto;
    overflow: visible;
  }

  .theme-studio__main {
    display: block !important;
    height: auto;
    overflow: visible !important;
  }

  .theme-studio__tabs {
    position: sticky;
    z-index: 4;
    top: 0;
    background: rgb(251 252 255 / 96%) !important;
    backdrop-filter: blur(10px);
  }

  .theme-editor-section {
    min-height: 0 !important;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .theme-live-preview {
    min-height: 380px;
    border-top: 0 !important;
  }

  .theme-preview-stage {
    height: 300px !important;
  }

  .theme-studio__footer {
    position: sticky !important;
    z-index: 6 !important;
    bottom: 0;
  }
}

@media (max-width: 640px) {
  .view-root.view-root--theme-studio {
    padding: 8px;
  }

  .theme-studio__header {
    align-items: stretch !important;
    flex-direction: column !important;
    gap: 12px !important;
    min-height: 0 !important;
    padding: 14px !important;
  }

  .theme-studio__title {
    align-items: flex-start;
  }

  .theme-studio__title h2 {
    font-size: 17px !important;
  }

  .theme-studio__title p {
    max-width: 280px;
  }

  .theme-preview-master-toggle {
    justify-content: space-between;
    width: 100%;
  }

  .theme-studio__library {
    padding: 14px !important;
  }

  .theme-studio__preset {
    width: min(76vw, 244px);
    min-width: min(76vw, 244px);
    flex-basis: min(76vw, 244px);
  }

  .theme-studio__tabs {
    padding-inline: 4px !important;
  }

  .theme-studio__tabs button {
    padding-inline: 12px !important;
    font-size: 9px !important;
  }

  .theme-editor-section {
    padding: 15px 13px 16px !important;
  }

  .theme-editor-section__heading {
    align-items: stretch !important;
    flex-direction: column;
    gap: 9px !important;
  }

  .theme-studio__reset {
    align-self: flex-start;
  }

  .theme-color-grid,
  .theme-color-grid--compact {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px 9px !important;
  }

  .theme-gradient-section {
    margin: 14px -13px -16px !important;
    padding-inline: 13px !important;
  }

  .theme-control-grid,
  .theme-accessibility ul {
    grid-template-columns: 1fr !important;
  }

  .theme-component-sample,
  .theme-effect-samples {
    align-items: stretch !important;
    flex-direction: column;
  }

  .theme-component-sample > div {
    margin-right: 0;
  }

  .theme-live-preview {
    min-height: 340px;
    padding: 12px 13px 14px !important;
  }

  .theme-live-preview__header {
    align-items: flex-start;
  }

  .theme-live-preview__status {
    display: none;
  }

  .theme-preview-stage {
    min-height: 260px !important;
    height: 260px !important;
  }

  .theme-studio__footer {
    align-items: stretch !important;
    flex-direction: column !important;
    gap: 9px !important;
    padding: 11px 13px !important;
  }

  .theme-studio__footer-note {
    width: 100%;
  }

  .theme-studio__footer-note .btn {
    width: 100%;
  }

  .theme-studio__footer > div:last-child {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    width: 100%;
  }

  .theme-studio__footer > div:last-child .btn:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 350px) {
  .theme-color-grid,
  .theme-color-grid--compact {
    grid-template-columns: 1fr !important;
  }

  .theme-studio__custom-card {
    grid-template-columns: 28px minmax(0, 1fr) !important;
  }

  .theme-studio__custom-card em {
    display: none;
  }
}

@media (max-height: 820px) and (min-width: 921px) {
  .theme-studio__workspace {
    height: 800px !important;
  }
}

/*
 * Component-responsive intermediate layout.
 * The application sidebar and docked DevTools can make Theme Studio much
 * narrower than the viewport; these rules therefore measure the studio itself.
 */
@container theme-studio (min-width: 921px) and (max-width: 1200px) {
  .theme-studio__workspace {
    grid-template-columns: 300px minmax(0, 1fr) !important;
  }

  .theme-studio__preset-list {
    grid-template-columns: 1fr !important;
  }

  .theme-studio__preset-preview {
    grid-template-columns: minmax(0, 1fr) 42% !important;
  }

  .theme-color-grid,
  .theme-color-grid--compact {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .theme-editor-section {
    min-height: 396px !important;
    height: 396px;
    max-height: 396px;
  }

  .theme-studio__tabs button {
    padding-inline: 12px !important;
  }

  .theme-studio__footer-note > span {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-studio *,
  .theme-studio *::before,
  .theme-studio *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
