.aibs-app {
  --aibs-radius: 18px;
  --aibs-border: #d9dee7;
  --aibs-text: #172033;
  --aibs-muted: #657087;
  --aibs-surface: #ffffff;
  --aibs-soft: #f5f7fb;
  --aibs-accent: #3157d5;
  --aibs-danger: #b42318;
  max-width: 980px;
  margin: 24px auto;
  padding: clamp(18px, 3vw, 32px);
  border: 1px solid var(--aibs-border);
  border-radius: 24px;
  background: var(--aibs-surface);
  color: var(--aibs-text);
  box-shadow: 0 18px 60px rgba(20, 32, 58, 0.08);
  box-sizing: border-box;
}

.aibs-app *,
.aibs-app *::before,
.aibs-app *::after { box-sizing: border-box; }

/* Native hidden must always win over component display rules and theme CSS. */
.aibs-app [hidden],
.aibs-dropzone[hidden],
.aibs-workspace[hidden] {
  display: none !important;
}
.aibs-dropzone[hidden] {
  pointer-events: none !important;
  visibility: hidden !important;
}
.aibs-app__header h2 { margin: 4px 0 8px; font-size: clamp(1.5rem, 3vw, 2.15rem); }
.aibs-app__header p { margin: 0; color: var(--aibs-muted); }
.aibs-app__eyebrow { font-size: 0.8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }

.aibs-dropzone {
  margin-top: 24px;
  min-height: 300px;
  display: grid;
  place-items: center;
  padding: 28px;
  border: 2px dashed var(--aibs-border);
  border-radius: var(--aibs-radius);
  background: var(--aibs-soft);
  cursor: pointer;
  transition: border-color .18s ease, transform .18s ease, background .18s ease;
}
.aibs-dropzone:hover,
.aibs-dropzone:focus-visible,
.aibs-dropzone.is-dragging { border-color: var(--aibs-accent); background: #eef2ff; outline: none; transform: translateY(-1px); }
.aibs-dropzone__input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.aibs-dropzone__content { display: grid; justify-items: center; gap: 8px; text-align: center; }
.aibs-dropzone__content span,
.aibs-dropzone__content small { color: var(--aibs-muted); }
.aibs-dropzone__icon { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: var(--aibs-accent); color: #fff !important; font-size: 30px; line-height: 1; }

.aibs-workspace { margin-top: 24px; }
.aibs-preview-card { min-height: 320px; display: grid; place-items: center; overflow: hidden; border-radius: var(--aibs-radius); background-image: linear-gradient(45deg, #e8ebf1 25%, transparent 25%), linear-gradient(-45deg, #e8ebf1 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e8ebf1 75%), linear-gradient(-45deg, transparent 75%, #e8ebf1 75%); background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0; }
.aibs-preview-card img { display: block; max-width: 100%; max-height: 620px; object-fit: contain; }
.aibs-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; margin-top: 16px; }
.aibs-button { appearance: none; border: 0; border-radius: 999px; padding: 12px 20px; background: var(--aibs-accent); color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.aibs-button:disabled { opacity: .45; cursor: not-allowed; }
.aibs-button--secondary { background: #e9edf5; color: var(--aibs-text); }
.aibs-button:focus-visible { outline: 3px solid rgba(49, 87, 213, .28); outline-offset: 2px; }
.aibs-progress { margin-top: 16px; padding: 16px 18px; border: 1px solid rgba(49,87,213,.16); border-radius: 18px; background: linear-gradient(180deg, #f8faff 0%, #eef3ff 100%); box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 12px 30px rgba(49,87,213,.08); }
.aibs-progress[hidden] { display: none !important; }
.aibs-progress__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.aibs-progress__head strong { font-size: 1rem; }
.aibs-progress__head span { min-width: 48px; text-align: right; font-weight: 850; font-variant-numeric: tabular-nums; color: var(--aibs-accent); }
.aibs-progress__note { margin: -1px 0 12px; color: var(--aibs-muted); font-size: .88rem; line-height: 1.45; }
.aibs-progress__track { position: relative; overflow: hidden; height: 14px; border-radius: 999px; background: #dfe7fb; }
.aibs-progress__track > span { position: relative; display: block; height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, #3157d5 0%, #4f73e8 50%, #6f8eff 100%); transition: width .28s ease; }
.aibs-progress__track > span::after { content: ''; position: absolute; inset: 0; background: linear-gradient(120deg, transparent 0%, rgba(255,255,255,.18) 35%, rgba(255,255,255,.62) 50%, rgba(255,255,255,.18) 65%, transparent 100%); animation: aibs-progress-shimmer 1.6s linear infinite; }
@keyframes aibs-progress-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.aibs-status { min-height: 0; margin: 14px 0 0; color: var(--aibs-muted); }
.aibs-status:empty { display: none; }
.aibs-status[data-state="error"] { color: var(--aibs-danger); }
.aibs-status[data-state="success"] { color: #067647; }
.aibs-notice { padding: 14px 16px; border-left: 4px solid #3157d5; background: #f5f7fb; }

.aibs-editor {
  margin-top: 16px;
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--aibs-border);
  border-radius: var(--aibs-radius);
  background: var(--aibs-soft);
}
.aibs-editor__stack {
  min-width: 0;
  display: grid;
  gap: 14px;
}
.aibs-editor__group { display: grid; gap: 10px; }
.aibs-editor__group > small { color: var(--aibs-muted); }
.aibs-editor__controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.aibs-chip {
  appearance: none;
  border: 1px solid var(--aibs-border);
  border-radius: 999px;
  padding: 9px 14px;
  background: #fff;
  color: var(--aibs-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.aibs-chip:hover,
.aibs-chip:focus-visible { border-color: var(--aibs-accent); outline: none; }
.aibs-chip--file { position: relative; overflow: hidden; }
.aibs-chip--file input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.aibs-color-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border: 1px solid var(--aibs-border);
  border-radius: 999px;
  background: #fff;
  font-weight: 600;
}
.aibs-color-control__label { color: var(--aibs-muted); font-size: 0.92rem; }
.aibs-color-control__swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(23, 32, 51, .15);
  background: #ffffff;
  flex: 0 0 auto;
}
.aibs-color-control input[type="color"] {
  appearance: auto;
  -webkit-appearance: auto;
  width: 42px;
  min-width: 42px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: inline-block;
  opacity: 1;
  pointer-events: auto;
}

.aibs-detail-control {
  display: grid;
  grid-template-columns: auto minmax(180px, 260px) auto;
  gap: 12px;
  align-items: center;
}
.aibs-detail-control label { font-weight: 600; }
.aibs-detail-control input[type="range"] { width: 100%; }
.aibs-detail-control strong {
  min-width: 48px;
  text-align: right;
}

@media (max-width: 640px) {
  .aibs-app { margin: 12px 0; border-radius: 16px; }
  .aibs-dropzone { min-height: 230px; padding: 20px; }
  .aibs-actions { flex-direction: column-reverse; }
  .aibs-button { width: 100%; }
  .aibs-editor { align-items: stretch; flex-direction: column; }
  .aibs-editor > .aibs-button { width: 100%; }
  .aibs-detail-control {
    grid-template-columns: 1fr;
    align-items: start;
  }
  .aibs-detail-control strong { text-align: left; }
}

/* 0.2.0 editor improvements */
.aibs-chip.is-active {
  border-color: var(--aibs-accent);
  background: #eef2ff;
  box-shadow: inset 0 0 0 1px var(--aibs-accent);
}

.aibs-preview-card img.is-editing-mask {
  cursor: crosshair;
  user-select: none;
  -webkit-user-drag: none;
}

.aibs-select-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 14px;
  border: 1px solid var(--aibs-border);
  border-radius: 999px;
  background: #fff;
  font-weight: 600;
}

.aibs-select-control select {
  min-width: 86px;
  border: 0;
  background: transparent;
  color: var(--aibs-text);
  font: inherit;
  cursor: pointer;
}

.aibs-editor__stack {
  flex: 1 1 auto;
}

.aibs-editor__group[hidden] {
  display: none !important;
}

.aibs-color-control {
  cursor: pointer;
}

.aibs-color-control input[type="color"] {
  width: 44px !important;
  min-width: 44px !important;
  height: 34px !important;
  position: static !important;
  visibility: visible !important;
  clip: auto !important;
}

@media (max-width: 640px) {
  .aibs-select-control {
    width: 100%;
    justify-content: space-between;
  }
  .aibs-select-control select {
    flex: 1 1 auto;
  }
}

/* 0.2.1 robust background controls */
.aibs-editor__controls[data-aibs-background-buttons] {
  position: relative;
  z-index: 5;
  pointer-events: auto;
}
.aibs-editor__controls[data-aibs-background-buttons] .aibs-chip,
.aibs-editor__controls[data-aibs-background-buttons] .aibs-color-control {
  position: relative;
  z-index: 6;
  pointer-events: auto !important;
}
.aibs-editor__controls[data-aibs-background-buttons] button.aibs-chip {
  user-select: none;
  -webkit-user-select: none;
}
.aibs-editor__controls[data-aibs-background-buttons] button.aibs-chip[aria-pressed="true"] {
  border-color: var(--aibs-accent) !important;
  background: #eef2ff !important;
  box-shadow: inset 0 0 0 1px var(--aibs-accent);
}

@media (max-width: 640px) {
  .aibs-progress { padding: 14px 14px; }
  .aibs-progress__head strong { font-size: .96rem; }
  .aibs-progress__note { font-size: .83rem; }
}
