/* Castly — Mockup studio (extension page) */

:root {
  --ms-bg: #f8fafc;
  --ms-surface: #ffffff;
  --ms-border: #e2e8f0;
  --ms-ink: #0f172a;
  --ms-muted: #64748b;
  --ms-orange: #f1641e;
  --ms-orange-deep: #ea580c;
  --ms-box: rgba(241, 100, 30, 0.95);
  --ms-box-fill: rgba(255, 255, 255, 0.12);
}

[data-theme='dark'] {
  --ms-bg: #0f1115;
  --ms-surface: #171a20;
  --ms-border: #2a3040;
  --ms-ink: #f1f5f9;
  --ms-muted: #94a3b8;
  --ms-box: #fb923c;
  --ms-box-fill: rgba(15, 23, 42, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

.tools-app {
  --ms-bg: var(--surface-subtle, #faf9f6);
  --ms-surface: var(--surface, #ffffff);
  --ms-border: var(--border, #e2e8f0);
  --ms-ink: var(--ink, #0f172a);
  --ms-muted: var(--ink-muted, #64748b);
}

[data-theme='dark'].tools-app,
.tools-app[data-theme='dark'],
html[data-theme='dark'] .tools-app {
  --ms-bg: #0f1115;
  --ms-surface: #171a20;
  --ms-border: #2a3040;
  --ms-ink: #f1f5f9;
  --ms-muted: #94a3b8;
}

.ms-root {
  max-width: none;
  margin: 0;
  padding: 0;
}

.ms-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 900px) {
  .ms-layout {
    grid-template-columns: 1fr;
  }
}

.ms-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ms-card {
  background: var(--ms-surface);
  border: 1px solid var(--ms-border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.ms-card h2 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ms-muted);
}

.ms-hint {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ms-muted);
}

.ms-file-btn {
  display: inline-block;
  background: linear-gradient(135deg, #ea580c, var(--ms-orange));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  border: none;
  text-align: center;
}

.ms-file-btn:hover {
  filter: brightness(1.05);
}

.ms-file-name {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ms-muted);
  word-break: break-all;
}

.ms-tool-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.ms-tool-btns .ms-btn {
  width: 100%;
  justify-content: center;
}

.ms-design-slots {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}

.ms-design-slot {
  padding: 12px;
  border: 1px solid var(--ms-border);
  border-radius: 10px;
  background: var(--ms-bg);
  cursor: pointer;
}

.ms-design-slot.is-active {
  border-color: var(--ms-orange);
  box-shadow: 0 0 0 2px rgba(241, 100, 30, 0.15);
}

.ms-design-slot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.ms-design-slot-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 8px;
  background: rgba(241, 100, 30, 0.15);
  color: var(--ms-orange-deep);
  font-size: 13px;
  font-weight: 800;
}

.ms-design-slot-remove {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.08);
  color: var(--ms-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.ms-design-slot-remove:hover {
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
}

.ms-file-btn--slot {
  display: block;
  width: 100%;
  text-align: center;
  margin-bottom: 6px;
  position: relative;
  border: none;
  font-family: inherit;
}

.ms-slot-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ms-slot-file-name {
  font-size: 11px;
  color: var(--ms-muted);
  word-break: break-all;
}

.ms-add-box-btn {
  width: 100%;
}

.ms-mockup-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ms-mockup-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--ms-border);
  cursor: pointer;
  background: var(--ms-bg);
}

.ms-mockup-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ms-mockup-item.is-active {
  border-color: var(--ms-orange);
  box-shadow: 0 0 0 2px rgba(241, 100, 30, 0.25);
}

.ms-mockup-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.ms-mockup-remove:hover {
  background: #b91c1c;
}

.ms-save-studio-btn {
  margin-top: 14px;
}

.ms-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ms-muted);
  margin-bottom: 10px;
  cursor: pointer;
}

.ms-check:last-child {
  margin-bottom: 0;
}

.ms-check input {
  margin-top: 3px;
}

.ms-card--actions .ms-btn {
  width: 100%;
  margin-bottom: 10px;
}

.ms-card--actions .ms-btn:last-of-type {
  margin-bottom: 0;
}

.ms-btn {
  display: block;
  width: 100%;
  padding: 11px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--ms-border);
  background: var(--ms-surface);
  color: var(--ms-ink);
}

.ms-btn:disabled {
  opacity: 1;
  cursor: not-allowed;
}

.ms-btn--primary:disabled {
  background: #e2e8f0;
  color: #94a3b8;
  border: none;
  filter: none;
}

[data-theme='dark'] .ms-btn--primary:disabled {
  background: #2a3040;
  color: #64748b;
}

.ms-btn--secondary:disabled {
  opacity: 0.55;
}

.ms-btn--primary {
  background: linear-gradient(135deg, #ea580c, var(--ms-orange));
  color: #fff;
  border: none;
}

.ms-btn--primary:not(:disabled):hover {
  filter: brightness(1.06);
}

.ms-btn--secondary:not(:disabled):hover {
  border-color: var(--ms-orange);
  color: var(--ms-orange-deep);
}

.ms-status {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--ms-muted);
  min-height: 1.25em;
}

.ms-stage-column {
  position: sticky;
  top: 16px;
}

.ms-stage-card {
  background: var(--ms-surface);
  border: 1px solid var(--ms-border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
}

.ms-stage-wrap {
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-conic-gradient(#f1f5f9 0% 25%, #e2e8f0 0% 50%) 50% / 16px 16px;
  border-radius: 12px;
  overflow: auto;
  max-height: min(72vh, 900px);
}

[data-theme='dark'] .ms-stage-wrap {
  background: repeating-conic-gradient(#1e293b 0% 25%, #0f172a 0% 50%) 50% / 16px 16px;
}

.ms-stage-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  margin: 0;
  padding: 32px;
  text-align: center;
  color: var(--ms-muted);
  font-size: 14px;
}

.ms-stage-empty p {
  margin: 0;
}

.ms-stage-empty-icon {
  width: 3rem;
  height: 3rem;
  color: rgba(241, 100, 30, 0.45);
}

#ms-stage-img:not([src]),
#ms-stage-img[src=''] {
  display: none !important;
}

.ms-stage-inner {
  position: relative;
  display: inline-block;
  max-width: 100%;
  vertical-align: top;
}

.ms-stage-stack {
  position: relative;
  display: inline-block;
  max-width: 100%;
  vertical-align: top;
}

.ms-stage-stack > img {
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none;
  vertical-align: top;
}

.ms-stage-composite {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  border-radius: 0;
}

.ms-box-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ms-box-layer .ms-box {
  pointer-events: auto;
  z-index: 2;
}

.ms-box {
  position: absolute;
  border: 2px dashed var(--ms-box);
  background: var(--ms-box-fill);
  box-sizing: border-box;
  cursor: grab;
  min-width: 8%;
  min-height: 8%;
  touch-action: none;
}

.ms-box.is-active {
  border-style: solid;
  border-color: var(--ms-orange);
  box-shadow: 0 0 0 2px rgba(241, 100, 30, 0.28);
  z-index: 3;
}

.ms-box:active {
  cursor: grabbing;
}

.ms-box-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  color: var(--ms-box);
  text-shadow: 0 0 8px #fff, 0 0 8px #fff;
  pointer-events: none;
}

[data-theme='dark'] .ms-box-label {
  text-shadow: 0 0 10px #0f172a, 0 0 10px #0f172a;
}

.ms-box-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 18px;
  height: 18px;
  background: var(--ms-orange);
  border: 2px solid #fff;
  border-radius: 4px;
  cursor: nwse-resize;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.ms-box-rotate {
  position: absolute;
  left: 50%;
  top: -22px;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  border-radius: 50%;
  background: var(--ms-orange);
  border: 2px solid #fff;
  cursor: grab;
  touch-action: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.ms-box-rotate:active {
  cursor: grabbing;
}

.ms-preview-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--ms-border);
}

.ms-preview-title {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ms-muted);
}

.ms-preview-sub {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--ms-muted);
}

.ms-preview-sub--strip {
  margin-top: 16px;
}

.ms-preview-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.ms-preview-strip canvas {
  display: block;
  height: 100px;
  width: auto;
  border-radius: 8px;
  border: 1px solid var(--ms-border);
  cursor: pointer;
  object-fit: contain;
}

.ms-preview-strip canvas.is-active {
  outline: 2px solid var(--ms-orange);
  outline-offset: 2px;
}

