/* Archead render panel — design-system aligned, deep UX polish */

:root {
  --cobot-panel-bg: rgba(18, 18, 24, 0.96);
  --cobot-panel-border: rgba(255, 255, 255, 0.12);
  --cobot-panel-radius: 16px;
  --cobot-panel-blur: 24px;
  --cobot-brand: #3c6cdc;
  --cobot-brand-hover: #446cdc;
  --cobot-accent: #fb7e49;
  --cobot-text: #fafaf9;
  --cobot-text-muted: rgba(255, 255, 255, 0.52);
  --cobot-surface: rgba(255, 255, 255, 0.06);
  --cobot-surface-hover: rgba(255, 255, 255, 0.1);
  --cobot-focus: rgba(60, 108, 220, 0.4);
  --cobot-focus-ring: 0 0 0 2px var(--cobot-focus);
  --cobot-section-bg: rgba(255, 255, 255, 0.05);
  --cobot-transition: 150ms cubic-bezier(0.33, 1, 0.68, 1);
}

/* Panel container — wins over viewer, no horizontal scroll */
div.render-panel,
.docking-panel.render-panel {
  width: 360px !important;
  max-width: calc(100vw - 32px) !important;
  min-width: 0 !important;
  max-height: calc(100vh - var(--nav-h, 56px) - var(--cs-height, 0px) - 48px) !important;
  transition: max-height 300ms cubic-bezier(0.33, 1, 0.68, 1) !important;
  display: flex !important;
  flex-direction: column !important;
  position: absolute !important;
  top: 24px !important;
  right: 24px !important;
  left: auto !important;
  padding: 0 !important;
  box-sizing: border-box !important;
  background: var(--cobot-panel-bg) !important;
  backdrop-filter: blur(var(--cobot-panel-blur)) !important;
  -webkit-backdrop-filter: blur(var(--cobot-panel-blur)) !important;
  border: 1px solid var(--cobot-panel-border) !important;
  border-radius: var(--cobot-panel-radius) !important;
  box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--cobot-panel-border) !important;
  z-index: 1000 !important;
  overflow-x: hidden !important;
  overflow-y: hidden !important;
}

/* Gradient accent line at top (::after to avoid border-image/border-radius conflict) */
div.render-panel::after,
.docking-panel.render-panel::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #3c6cdc 0%, #4b7cec 50%, #fb7e49 100%);
  border-radius: var(--cobot-panel-radius) var(--cobot-panel-radius) 0 0;
  z-index: 1;
  pointer-events: none;
}

/* Panel entrance animation */
div.render-panel:not(.render-panel--hidden),
.docking-panel.render-panel:not(.render-panel--hidden) {
  animation: panel-enter 300ms cubic-bezier(0.33, 1, 0.68, 1);
}
@keyframes panel-enter {
  from { opacity: 0; transform: translateX(20px) scale(0.97); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

/* Hidden state — must override base display:flex !important so close actually hides */
div.render-panel.render-panel--hidden,
.docking-panel.render-panel.render-panel--hidden {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* When dragging, use fixed position so left/top work in viewport */
div.render-panel.render-panel--dragging,
.docking-panel.render-panel.render-panel--dragging {
  position: fixed !important;
}

/* Title bar — draggable */
.cobot-panel__head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--cobot-panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  cursor: grab;
  position: relative;
  min-width: 0;
  user-select: none;
  transition: background var(--cobot-transition);
}
.cobot-panel__head:active {
  cursor: grabbing;
}
.render-panel--dragging .cobot-panel__head {
  cursor: grabbing;
  background: var(--cobot-surface);
}

.render-panel .cobot-panel__head .docking-panel-title,
.render-panel .cobot-panel__head .title,
.cobot-panel__head span {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--cobot-text);
  letter-spacing: -0.02em;
}

.cobot-panel__head-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--cobot-text);
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
}

.cobot-panel__close {
  width: 28px;
  height: 28px;
  min-width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--cobot-text-muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  position: relative;
  z-index: 10;
  pointer-events: auto;
  user-select: none;
  flex-shrink: 0;
}

.cobot-panel__close:hover {
  color: var(--cobot-text);
  background: var(--cobot-surface-hover);
}
.cobot-panel__close:focus-visible {
  outline: none;
  box-shadow: var(--cobot-focus-ring);
}

/* Override viewer default title/close styles inside our panel */
.render-panel .docking-panel-title,
.render-panel .docking-panel-close {
  color: inherit;
  background: none;
  border: none;
}

.cobot-panel__body {
  padding: 8px 10px;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Section grouping — subtle cards */
.cobot-panel__section {
  min-width: 0;
  padding: 8px 10px;
  background: var(--cobot-section-bg);
  border: 1px solid var(--cobot-panel-border);
  border-radius: 10px;
  transition: border-color var(--cobot-transition), background var(--cobot-transition);
}
.cobot-panel__section:focus-within {
  border-color: rgba(60, 108, 220, 0.25);
  background: rgba(255, 255, 255, 0.06);
}

.cobot-panel__section-title {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #93b4f5;
  margin: 0 0 6px;
  padding: 0;
}

.cobot-panel__field {
  margin-bottom: 6px;
}
.cobot-panel__field:last-child {
  margin-bottom: 0;
}

.cobot-panel__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--cobot-text);
  margin-bottom: 3px;
}

.cobot-panel__row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.cobot-panel__option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  color: var(--cobot-text);
  cursor: pointer;
  padding: 4px 0;
  border-radius: 6px;
  transition: color var(--cobot-transition), background var(--cobot-transition);
}
.cobot-panel__option:hover {
  color: var(--cobot-text);
}
.cobot-panel__option:focus-visible {
  outline: none;
  box-shadow: var(--cobot-focus-ring);
  border-radius: 6px;
}
.cobot-panel__option input[type="radio"] {
  accent-color: var(--cobot-brand);
}

.cobot-panel__select,
.cobot-panel__textarea,
.cobot-panel__location-display,
.cobot-panel__file {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 6px 10px;
  font-size: 0.8125rem;
  color: var(--cobot-text);
  background: var(--cobot-surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-family: inherit;
  transition: border-color 180ms cubic-bezier(0.33, 1, 0.68, 1), box-shadow 180ms cubic-bezier(0.33, 1, 0.68, 1), background 180ms cubic-bezier(0.33, 1, 0.68, 1);
  box-sizing: border-box;
}
.cobot-panel__select:hover,
.cobot-panel__textarea:hover,
.cobot-panel__location-display:hover {
  background: var(--cobot-surface-hover);
}
.cobot-panel__select:focus,
.cobot-panel__textarea:focus,
.cobot-panel__location-display:focus {
  outline: none;
  border-color: var(--cobot-brand);
  box-shadow: var(--cobot-focus-ring);
}
.cobot-panel__select:focus-visible,
.cobot-panel__textarea:focus-visible {
  outline: none;
}

/* Native option elements — force dark theme so text is visible when dropdown opens */
.cobot-panel__select option {
  background-color: #1c1917;
  color: #fafaf9;
}

.cobot-panel__textarea {
  min-height: 40px;
  resize: vertical;
}

.cobot-panel__textarea::placeholder {
  color: var(--cobot-text-muted);
}

.cobot-panel__location-row {
  display: flex;
  align-items: stretch;
  gap: var(--s2, 8px);
}

.cobot-panel__location-display {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cobot-panel__icon-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cobot-surface);
  border: 1px solid var(--cobot-panel-border);
  border-radius: 8px;
  color: var(--cobot-text);
  cursor: pointer;
  transition: background var(--cobot-transition), border-color var(--cobot-transition);
}
.cobot-panel__icon-btn:hover {
  background: var(--cobot-surface-hover);
  border-color: rgba(255, 255, 255, 0.12);
}
.cobot-panel__icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--cobot-focus-ring);
}
.cobot-panel__icon-btn.location-selected {
  border-color: var(--cobot-brand);
  color: var(--cobot-brand);
}

/* Mode chooser — two-card grid */
.cobot-panel__mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cobot-panel__mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: var(--cobot-surface);
  border: 1px solid var(--cobot-panel-border);
  border-radius: 10px;
  color: var(--cobot-text-muted);
  font-size: 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--cobot-transition), color var(--cobot-transition), background var(--cobot-transition), box-shadow var(--cobot-transition);
}
.cobot-panel__mode-card strong {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--cobot-text);
}
.cobot-panel__mode-card svg {
  opacity: 0.6;
  transition: opacity var(--cobot-transition);
}
.cobot-panel__mode-card:hover {
  background: var(--cobot-surface-hover);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 16px rgba(60, 108, 220, 0.1);
}
.cobot-panel__mode-card:hover svg {
  opacity: 0.85;
}
.cobot-panel__mode-card:focus-visible {
  outline: none;
  box-shadow: var(--cobot-focus-ring);
}
.cobot-panel__mode-card--active {
  border-color: var(--cobot-brand);
  background: rgba(60, 108, 220, 0.1);
  color: var(--cobot-text);
  box-shadow: 0 0 0 1px rgba(60, 108, 220, 0.3);
}
.cobot-panel__mode-card--active svg {
  opacity: 1;
  color: var(--cobot-brand);
}
.cobot-panel__mode-card--active strong {
  color: #93b4f5;
}

/* Quality toggle — segmented pill */
.cobot-panel__quality {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.cobot-panel__quality-toggle {
  display: flex;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--cobot-panel-border);
  background: var(--cobot-surface);
  overflow: hidden;
}

.cobot-panel__quality-opt {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--cobot-text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--cobot-transition), color var(--cobot-transition), box-shadow var(--cobot-transition);
}

.cobot-panel__quality-opt:first-child {
  border-right: 1px solid var(--cobot-panel-border);
}

.cobot-panel__quality-opt--active {
  background: rgba(60, 108, 220, 0.15);
  color: var(--cobot-text);
  box-shadow: inset 0 0 0 1px rgba(60, 108, 220, 0.3);
}

.cobot-panel__quality-opt--premium.cobot-panel__quality-opt--active {
  background: linear-gradient(135deg, rgba(60, 108, 220, 0.15) 0%, rgba(251, 126, 73, 0.18) 100%);
  color: var(--cobot-accent);
  box-shadow: inset 0 0 0 1px rgba(251, 126, 73, 0.35);
}

.cobot-panel__quality-opt--premium.cobot-panel__quality-opt--active svg {
  filter: drop-shadow(0 0 3px rgba(251, 126, 73, 0.5));
}

.cobot-panel__quality-opt:hover:not(.cobot-panel__quality-opt--active) {
  background: var(--cobot-surface-hover);
  color: var(--cobot-text);
}

.cobot-panel__quality-opt:focus-visible {
  outline: none;
  box-shadow: var(--cobot-focus-ring);
}

.cobot-panel__quality-opt--disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.cobot-panel__coming-soon {
  font-size: 0.5625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(251, 146, 60, 0.15);
  color: #fb923c;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 3px;
}

.cobot-panel__quality-hint {
  font-size: 0.6875rem;
  color: var(--cobot-text-muted);
  letter-spacing: 0.02em;
}

/* Hint text */
.cobot-panel__hint {
  margin: 0 0 8px;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--cobot-text-muted);
}

/* Snippet preview */
.cobot-panel__snippet-preview {
  border-radius: 8px;
  overflow: hidden;
  max-height: 120px;
  background: var(--cobot-surface);
  border: 1px solid var(--cobot-panel-border);
  transition: border-color var(--cobot-transition);
}
.cobot-panel__snippet-preview:empty {
  display: none;
}
.cobot-panel__snippet-preview img {
  display: block;
  width: 100%;
  max-height: 120px;
  object-fit: contain;
}

/* Step section — shared base for wizard sections with staggered entrance */
.cobot-panel__step {
  animation: cobot-step-in 200ms var(--cobot-transition) both;
}
.cobot-panel__step:nth-child(1) { animation-delay: 0ms; }
.cobot-panel__step:nth-child(2) { animation-delay: 60ms; }
.cobot-panel__step:nth-child(3) { animation-delay: 120ms; }
.cobot-panel__step:nth-child(4) { animation-delay: 180ms; }
.cobot-panel__step:nth-child(5) { animation-delay: 240ms; }
@keyframes cobot-step-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .cobot-panel__step { animation: none; }
}

.cobot-panel__upload-wrap {
  margin-top: var(--s2, 8px);
  display: none;
}

.cobot-panel__preview {
  margin-top: var(--s2, 8px);
  max-height: 80px;
  overflow: hidden;
  border-radius: 8px;
}

.cobot-panel__preview img {
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
}

.cobot-panel__actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--cobot-panel-border);
  flex-shrink: 0;
}

.cobot-panel__primary {
  flex: 1;
  padding: 9px 14px;
  background: linear-gradient(135deg, #3c6cdc 0%, #5580e8 50%, #e8885a 100%);
  background-size: 200% auto;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background-position var(--cobot-transition), transform var(--cobot-transition), box-shadow var(--cobot-transition);
  box-shadow: 0 2px 10px rgba(60, 108, 220, 0.3);
}
.cobot-panel__primary:hover:not(:disabled) {
  background-position: right center;
  box-shadow: 0 4px 16px rgba(60, 108, 220, 0.4);
}
.cobot-panel__primary:focus-visible {
  outline: none;
  box-shadow: var(--cobot-focus-ring), 0 2px 12px rgba(60, 108, 220, 0.35);
}
.cobot-panel__primary:hover:not(:disabled) {
  transform: translateY(-1px);
}
.cobot-panel__primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}
@media (prefers-reduced-motion: reduce) {
  .cobot-panel__primary,
  .cobot-panel__primary:hover {
    transform: none;
  }
}

.cobot-panel__secondary {
  padding: 10px 14px;
  background: transparent;
  color: var(--cobot-text-muted);
  border: 1px solid var(--cobot-panel-border);
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--cobot-transition), color var(--cobot-transition), border-color var(--cobot-transition);
}
.cobot-panel__secondary:hover {
  background: var(--cobot-surface);
  color: var(--cobot-text);
  border-color: rgba(255, 255, 255, 0.12);
}
.cobot-panel__secondary:focus-visible {
  outline: none;
  box-shadow: var(--cobot-focus-ring);
}

/* Status */
.cobot-panel__status {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.8125rem;
  line-height: 1.4;
  display: none;
  flex-shrink: 0;
}
.cobot-panel__status.render-status-info,
.cobot-panel__status.render-status-success,
.cobot-panel__status.render-status-error {
  display: block;
}
.cobot-panel__status.render-status-info {
  background: rgba(60, 108, 220, 0.18);
  border: 1px solid rgba(60, 108, 220, 0.4);
  color: var(--cobot-text);
}
.cobot-panel__status.render-status-success {
  background: rgba(5, 150, 105, 0.18);
  border: 1px solid rgba(5, 150, 105, 0.45);
  color: #a7f3d0;
}
.cobot-panel__status.render-status-error {
  background: rgba(220, 38, 38, 0.18);
  border: 1px solid rgba(220, 38, 38, 0.45);
  color: #fecaca;
}
#renderStatusRetry {
  margin-left: 8px;
  padding: 4px 10px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--cobot-transition);
}
#renderStatusRetry:hover {
  background: #b91c1c;
}
#renderStatusRetry:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.5);
}

.render-panel-download-link {
  margin-top: var(--s2, 8px);
  display: inline-block;
  color: #6b9aef;
  text-decoration: underline;
}

.render-panel-download-link:hover {
  color: #93b4f5;
}

/* ── Mobile bottom-sheet ──────────────────────────────────────── */

@media (max-width: 768px) {
  div.render-panel,
  .docking-panel.render-panel {
    position: fixed !important;
    top: auto !important;
    right: 0 !important;
    bottom: var(--cs-height, 0px) !important;
    left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(55vh - var(--cs-height, 0px)) !important;
    border-radius: 16px 16px 0 0 !important;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5) !important;
    z-index: 1001 !important;
  }

  div.render-panel:not(.render-panel--hidden),
  .docking-panel.render-panel:not(.render-panel--hidden) {
    animation: panel-enter-mobile 300ms cubic-bezier(0.33, 1, 0.68, 1);
  }

  div.render-panel::after,
  .docking-panel.render-panel::after {
    border-radius: 16px 16px 0 0;
  }

  .cobot-panel__head {
    cursor: default;
  }
}

@keyframes panel-enter-mobile {
  from { opacity: 0; transform: translateY(100%); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .cobot-panel__head,
  .cobot-panel__close,
  .cobot-panel__option,
  .cobot-panel__select,
  .cobot-panel__textarea,
  .cobot-panel__icon-btn,
  .cobot-panel__primary,
  .cobot-panel__secondary {
    transition-duration: 0.01ms;
  }
}
