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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-ui);
  background: var(--studio-bg);
  color: var(--studio-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

/* Top Studio Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  background: var(--studio-panel);
  border-bottom: 1px solid var(--studio-border);
  z-index: 20;
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--studio-text);
  color: var(--studio-bg);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--studio-text);
}

.brand-sub {
  font-size: 12px;
  color: var(--studio-text-subtle);
  padding-left: 8px;
  border-left: 1px solid var(--studio-border);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--studio-border);
  background: var(--studio-surface);
  color: var(--studio-text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, transform 90ms ease;
}

.btn:hover {
  background: var(--studio-surface-hover);
  border-color: var(--studio-border-strong);
}

.btn:active {
  transform: scale(0.985);
}

.btn-primary {
  background: var(--studio-text);
  color: var(--studio-bg);
  border-color: var(--studio-text);
  font-weight: 600;
}

.btn-primary:hover {
  background: hsl(210 20% 88%);
  border-color: hsl(210 20% 88%);
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--studio-text-muted);
}

.btn-ghost:hover {
  background: var(--studio-surface);
  color: var(--studio-text);
  border-color: transparent;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: var(--radius-xs);
}

.btn-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

/* Segmented Controls */
.segmented {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  background: var(--studio-bg);
  border: 1px solid var(--studio-border);
  border-radius: var(--radius-sm);
  gap: 2px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--studio-text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  transition: background 140ms ease, color 140ms ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.segmented button:hover {
  color: var(--studio-text);
}

.segmented button[aria-pressed="true"],
.segmented button.is-active {
  background: var(--studio-surface-active);
  color: var(--studio-text);
  box-shadow: var(--shadow-sm);
}

/* Workspace Body */
.workspace {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

/* Left Composer Sidebar */
.composer-pane {
  background: var(--studio-panel);
  border-right: 1px solid var(--studio-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--studio-border-strong) transparent;
}

.composer-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--studio-border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.section-label {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--studio-text-muted);
}

/* Thread Post Pills */
.thread-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.thread-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--studio-border);
  background: var(--studio-surface);
  color: var(--studio-text-muted);
  font-size: 12px;
  font-weight: 500;
}

.thread-pill.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #ffffff;
}

.thread-pill-del {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  opacity: 0.7;
}

.thread-pill-del:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.16);
}

/* Caption Input using modern field-sizing: content + fallback */
.caption-box-wrap {
  background: var(--studio-bg);
  border: 1px solid var(--studio-border);
  border-radius: var(--radius-md);
  padding: 12px;
  transition: border-color 140ms ease;
}

.caption-box-wrap:focus-within {
  border-color: var(--accent);
}

.growable-textarea {
  display: grid;
}

.growable-textarea[data-replicated-value]::after {
  content: attr(data-replicated-value) " ";
  white-space: pre-wrap;
  visibility: hidden;
  grid-area: 1 / 1 / 2 / 2;
  font-size: 14px;
  line-height: 1.45;
  padding: 0;
}

.caption-textarea {
  grid-area: 1 / 1 / 2 / 2;
  width: 100%;
  height: auto;
  field-sizing: content;
  min-block-size: 4lh;
  max-block-size: 14lh;
  background: transparent;
  border: 0;
  outline: none;
  resize: vertical;
  font-size: 14px;
  line-height: 1.45;
  color: var(--studio-text);
  padding: 0;
}

.caption-textarea::placeholder {
  color: var(--studio-text-subtle);
}

.caption-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--studio-border);
}

.caption-quick-tags {
  display: flex;
  align-items: center;
  gap: 4px;
}

.char-meter {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--studio-text-muted);
}

.char-meter.is-warn {
  color: hsl(38 92% 58%);
}

.char-meter.is-over {
  color: var(--accent);
}

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--studio-border-strong);
  border-radius: var(--radius-md);
  background: hsl(220 14% 9% / 0.65);
  padding: 16px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-title {
  margin: 4px 0 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--studio-text);
}

.dropzone-hint {
  margin: 0;
  font-size: 12px;
  color: var(--studio-text-subtle);
}

/* Smart Overflow Callout (>4 photos) */
.overflow-banner {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid hsl(204 88% 53% / 0.32);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  line-height: 1.35;
}

/* Uploaded Gallery Item List */
.media-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.media-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  padding: 9px;
  background: var(--studio-surface);
  border: 1px solid var(--studio-border);
  border-radius: var(--radius-md);
  transition: border-color 140ms ease, opacity 140ms ease;
}

.media-item.is-dragging {
  opacity: 0.45;
  border-color: var(--accent);
}

.media-thumb-box {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--studio-bg);
  cursor: grab;
}

.media-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-index-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.media-item-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.media-item-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.mini-icon-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.icon-btn-mini {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid var(--studio-border);
  background: var(--studio-bg);
  color: var(--studio-text-muted);
  display: grid;
  place-items: center;
  font-size: 12px;
}

.icon-btn-mini:hover:not(:disabled) {
  color: var(--studio-text);
  border-color: var(--studio-border-strong);
}

.icon-btn-mini:disabled {
  opacity: 0.35;
  cursor: default;
}

.media-caption-input {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--studio-border);
  background: var(--studio-bg);
  font-size: 12px;
  color: var(--studio-text);
  outline: none;
}

.media-caption-input:focus {
  border-color: var(--accent);
}

.media-zoom-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--studio-text-muted);
}

.media-zoom-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
}

/* Collapsible Details Accordions */
details.composer-details {
  border-bottom: 1px solid var(--studio-border);
}

details.composer-details summary {
  list-style: none;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--studio-text);
}

details.composer-details summary::-webkit-details-marker {
  display: none;
}

details.composer-details summary::after {
  content: "+";
  font-size: 15px;
  color: var(--studio-text-muted);
}

details.composer-details[open] summary::after {
  content: "−";
}

.details-content {
  padding: 0 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Form Rows */
.field-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--studio-text-muted);
}

.field input[type="text"],
.field select {
  width: 100%;
  height: 32px;
  padding: 0 9px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--studio-border);
  background: var(--studio-bg);
  font-size: 13px;
  color: var(--studio-text);
  outline: none;
}

.field input[type="text"]:focus,
.field select:focus {
  border-color: var(--accent);
}

.avatar-editor-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-upload-btn {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  padding: 0;
  border: 1px solid var(--studio-border-strong);
  overflow: hidden;
  background: var(--studio-surface);
  flex-shrink: 0;
}

.avatar-upload-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.toggle-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--studio-text-muted);
}

.toggle-line input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* Right Preview Stage */
.stage-pane {
  position: relative;
  background: radial-gradient(circle at 50% 0%, hsl(220 14% 16%), var(--studio-stage-bg) 62%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid hsl(220 12% 18%);
  flex-wrap: wrap;
}

.stage-toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stage-canvas-scroll {
  overflow-y: auto;
  padding: 32px 24px 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Drafts Gallery Wall Mode */
.drafts-wall {
  width: 100%;
  max-width: 1240px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 24px;
  align-items: start;
}

.draft-wall-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.draft-wall-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
  font-size: 12px;
  color: var(--studio-text-muted);
}

/* Global Drop Overlay */
.global-drop-overlay {
  position: fixed;
  inset: 12px;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--accent);
  background: hsl(220 15% 8% / 0.84);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease;
}

.global-drop-overlay.is-visible {
  opacity: 1;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--studio-text);
  color: var(--studio-bg);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 200;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive */
@media (max-width: 960px) {
  .app-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }

  .composer-pane {
    border-right: 0;
    border-bottom: 1px solid var(--studio-border);
    overflow: visible;
  }

  .brand-sub {
    display: none;
  }
}
