/* ==================== STUDIO SHELL (TEXPAGE-INSPIRED) ==================== */
.studio-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top Toolbar */
.topbar {
  height: 50px;
  background: var(--ui-topbar-bg);
  color: var(--ui-topbar-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid #1e293b;
  z-index: 20;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.brand-badge {
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.doc-stats {
  font-size: 12px;
  color: var(--ui-topbar-muted);
  background: #1e293b;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.zoom-control {
  display: flex;
  align-items: center;
  background: #1e293b;
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.zoom-btn {
  background: transparent;
  color: #e2e8f0;
  border: none;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.zoom-btn:hover {
  background: #334155;
}

.zoom-label {
  min-width: 44px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #f8fafc;
}

/* Main Workspace */
.workspace {
  display: grid;
  grid-template-columns: 400px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns 0.2s ease;
}

.workspace.sidebar-collapsed {
  grid-template-columns: 0px 1fr;
}

/* ==================== LEFT INSPECTOR SIDEBAR ==================== */
.sidebar {
  background: var(--ui-sidebar-bg);
  border-right: 1px solid var(--ui-border-strong);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #f1f5f9;
  border-bottom: 1px solid var(--ui-border-strong);
  padding: 6px 8px 0;
  gap: 4px;
  flex-shrink: 0;
}

.tab-btn {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--ui-text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  transition: 0.15s;
}

.tab-btn:hover {
  color: var(--ui-text);
  background: rgba(255, 255, 255, 0.6);
}

.tab-btn.active {
  background: #ffffff;
  color: var(--ui-primary);
  border-color: var(--ui-border-strong);
  position: relative;
  top: 1px;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.tab-pane.active {
  display: flex;
}

.panel {
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  padding: 12px;
  background: var(--ui-panel-bg);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ui-text-muted);
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: #1e293b;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 6px;
  font-size: 12.5px;
  background: #ffffff;
  color: var(--ui-text);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--ui-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

input[type="range"] {
  width: 100%;
  cursor: pointer;
  accent-color: var(--ui-primary);
}

/* Dropzone & JSON Editor */
.dropzone {
  border: 1.5px dashed #94a3b8;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  background: #ffffff;
  cursor: pointer;
  transition: 0.15s;
  font-size: 12px;
  color: var(--ui-text-muted);
}

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

.dropzone input[type="file"] {
  display: none;
}

.dirty-badge {
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #f59e0b;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  text-transform: none;
  letter-spacing: 0;
}

.json-editor-wrap {
  display: flex;
  border: 1px solid var(--ui-border-strong);
  border-radius: 6px;
  background: #ffffff;
  overflow: hidden;
  height: 290px;
  min-height: 180px;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.json-editor-wrap:focus-within {
  border-color: var(--ui-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.json-editor-wrap.has-error {
  border-color: #dc2626;
}

.json-gutter {
  width: 40px;
  flex-shrink: 0;
  background: #f1f5f9;
  border-right: 1px solid var(--ui-border);
  color: #64748b;
  font-family: "Cascadia Code", Consolas, "Fira Code", monospace;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 8px 6px 8px 4px;
  text-align: right;
  user-select: none;
  overflow: hidden;
  white-space: pre;
}

textarea#jsonInput {
  flex: 1;
  height: 100%;
  border: none;
  border-radius: 0;
  padding: 8px 9px;
  font-family: "Cascadia Code", Consolas, "Fira Code", monospace;
  font-size: 11.5px;
  line-height: 1.5;
  resize: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

textarea#jsonInput:focus {
  box-shadow: none;
}

.btn-save {
  background: #0f766e;
  color: #ffffff;
  flex: 1.3;
}

.btn-save:hover {
  background: #115e59;
}

.btn-save.is-dirty {
  background: #d97706;
  color: #ffffff;
}

.btn-save.is-dirty:hover {
  background: #b45309;
}

.status-msg.warn {
  display: block;
  background: #fef3c7;
  color: #92400e;
}

.validation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 170px;
  overflow-y: auto;
}

.validation-item {
  font-size: 11.5px;
  line-height: 1.4;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  gap: 6px;
  align-items: flex-start;
  border: 1px solid transparent;
}

.validation-item.err {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

.validation-item.warn {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

.validation-item:hover {
  filter: brightness(0.97);
}

.validation-line {
  font-family: Consolas, monospace;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}

.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

button {
  padding: 7px 11px;
  border: none;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn-primary {
  background: var(--ui-primary);
  color: #ffffff;
  flex: 1;
}

.btn-primary:hover {
  background: var(--ui-primary-hover);
}

.btn-outline {
  background: #ffffff;
  color: #334155;
  border: 1px solid var(--ui-border-strong);
  flex: 1;
}

.btn-outline:hover {
  background: #f1f5f9;
}

.btn-topbar {
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #334155;
  padding: 6px 10px;
  font-size: 12px;
}

.btn-topbar:hover {
  background: #334155;
}

.topbar-author {
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--ui-border);
  background: #ffffff;
  flex-shrink: 0;
}

.btn-success {
  background: var(--ui-success);
  color: #ffffff;
  width: 100%;
  padding: 10px;
  font-size: 13.5px;
}

.btn-success:hover {
  background: var(--ui-success-hover);
}

/* Theme Cards */
.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.theme-card {
  border: 2px solid var(--ui-border-strong);
  border-radius: 7px;
  padding: 8px 9px;
  background: #ffffff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: 0.15s;
}

.theme-card:hover {
  border-color: #94a3b8;
}

.theme-card.active {
  border-color: var(--ui-primary);
  background: var(--ui-primary-soft);
  color: var(--ui-primary);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.custom-style-box {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--ui-border-strong);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

input[type="color"] {
  width: 36px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
}

.color-presets {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.color-dot {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.25);
  cursor: pointer;
}

.color-dot:hover {
  transform: scale(1.12);
}

.status-msg {
  font-size: 12px;
  padding: 6px 9px;
  border-radius: 6px;
  display: none;
  line-height: 1.4;
}

.status-msg.ok {
  display: block;
  background: #dcfce7;
  color: #166534;
}

.status-msg.err {
  display: block;
  background: #fee2e2;
  color: #991b1b;
}

/* ==================== PREVIEW DESK (PDF CANVAS) ==================== */
.preview-area {
  padding: 28px 24px 48px;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background:
    radial-gradient(circle at 1px 1px, rgba(15, 23, 42, 0.08) 1px, transparent 0) 0 0 / 20px 20px,
    var(--ui-desk-bg);
}

.preview-stage {
  transform: scale(var(--preview-zoom));
  transform-origin: top center;
  transition: transform 0.15s ease;
}

/* ==================== BATCH SHUFFLE MODAL ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-dialog {
  width: 100%;
  max-width: 520px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.32);
  border: 1px solid var(--ui-border-strong);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 92vh;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: #f8fafc;
  border-bottom: 1px solid var(--ui-border);
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  color: #0f172a;
}

.modal-subtitle {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--ui-text-muted);
}

.modal-close {
  background: transparent;
  color: #64748b;
  padding: 4px 8px;
  font-size: 15px;
  border-radius: 6px;
  flex: none;
}

.modal-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.batch-codes-preview {
  font-size: 12.5px;
  color: #1e3a8a;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 7px;
  padding: 8px 10px;
  line-height: 1.45;
}

.batch-options-box,
.batch-files-info {
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.batch-files-info ul {
  margin: 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: #334155;
  line-height: 1.4;
}

.batch-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
}

.batch-progress-wrap[hidden] {
  display: none !important;
}

.batch-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: #166534;
  gap: 8px;
}

.batch-progress-bar {
  width: 100%;
  height: 8px;
  background: #dcfce7;
  border-radius: 999px;
  overflow: hidden;
}

.batch-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #16a34a, #059669);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  background: #f8fafc;
  border-top: 1px solid var(--ui-border);
}

.modal-footer .btn-outline {
  flex: 0 0 auto;
}

.modal-footer .btn-success {
  flex: 1;
  padding: 9px 14px;
  font-size: 13px;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ==================== PDF PREVIEW MODAL ==================== */
.modal-dialog.modal-pdf-preview {
  max-width: 1080px;
  width: 94vw;
  height: 92vh;
  max-height: 92vh;
}

.pdf-preview-header {
  align-items: center;
  flex-wrap: wrap;
}

.pdf-preview-title-wrap {
  min-width: 0;
}

.pdf-preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pdf-preview-actions .btn-outline,
.pdf-preview-actions .btn-success {
  width: auto;
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 12.5px;
}

.pdf-preview-body {
  flex: 1;
  min-height: 0;
  background: #334155;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.pdf-preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #525659;
  display: block;
}

.pdf-preview-frame[hidden] {
  display: none !important;
}

.pdf-preview-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 36px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.28);
  min-width: 280px;
  max-width: 90%;
}

.pdf-preview-loading[hidden] {
  display: none !important;
}

.pdf-spinner {
  width: 34px;
  height: 34px;
  border: 3.5px solid #e2e8f0;
  border-top-color: var(--ui-primary);
  border-radius: 50%;
  animation: pdfSpin 0.8s linear infinite;
}

@keyframes pdfSpin {
  to { transform: rotate(360deg); }
}

.pdf-loading-title {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
  text-align: center;
}

.pdf-loading-bar {
  width: 240px;
}

.pdf-preview-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 16px 20px;
  border-radius: 10px;
  max-width: 480px;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.pdf-preview-error[hidden] {
  display: none !important;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    max-height: 48vh;
    border-right: none;
    border-bottom: 1px solid var(--ui-border-strong);
  }
  .topbar-center {
    display: none;
  }
}
