/**
 * Landing Page Builder — Sidebar UI Stylesheet
 * CertifID EMD Tools
 *
 * Sections:
 *   1. Sidebar Tokens
 *   2. Fixed Left Panel
 *   3. Panel Header & Scrollable
 *   4. Custom Scrollbar
 *   5. Sections & Form Fields
 *   6. Color Picker
 *   7. Preview Strip
 *   8. Advanced Overrides
 *   9. Toggle Switches (iOS-style)
 *  10. File Upload & Thumbnail Preview
 *  11. Rich Text Editor (Disclosures)
 *  12. Conditional Field Visibility
 *  13. Action Footer & Buttons
 *  14. Toast Notification
 *  15. Responsive — Tablet (≤1024px)
 *  16. Responsive — Mobile (≤480px)
 */


/* ──────────────────────────────────────────────
   1. Sidebar Tokens
   ────────────────────────────────────────────── */

.control-panel {
  --cp-w: 360px;
  --cp-pad: 32px;
  --cp-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --cp-font-h: 'Thicccboi', system-ui, sans-serif;
  --cp-border: hsl(216, 10%, 91%);
  --cp-bg: #fff;
  --cp-t-dark: hsl(216, 28%, 16%);
  --cp-t-med: hsl(216, 7%, 34%);
  --cp-t-light: hsl(216, 7%, 46%);
  --cp-primary: hsl(216, 79%, 48%);
  --cp-primary-hover: hsl(216, 79%, 40%);
  --cp-focus-border: hsl(216, 50%, 82%);
  --cp-focus-ring: hsl(216, 79%, 92%);
  --cp-bg-light: hsl(216, 12%, 97%);
  --cp-r: 8px;
  --cp-ease: 0.2s ease;
  --cp-shadow: 8px 0 25px rgba(0, 0, 0, 0.05);

  /* Toast (success) */
  --toast-bg: hsl(145, 55%, 93%);
  --toast-text: hsl(145, 50%, 30%);
  --toast-border: hsl(145, 40%, 82%);
  --toast-icon: hsl(145, 50%, 36%);

  /* Toast (error) */
  --toast-err-bg: hsl(0, 55%, 95%);
  --toast-err-text: hsl(0, 50%, 35%);
  --toast-err-border: hsl(0, 40%, 85%);
}


/* ──────────────────────────────────────────────
   2. Fixed Left Panel
   ────────────────────────────────────────────── */

.control-panel,
.control-panel * {
  box-sizing: border-box;
}

.control-panel {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--cp-w);
  height: 100vh;
  background: var(--cp-bg);
  border-right: 1px solid var(--cp-border);
  display: flex;
  flex-direction: column;
  z-index: 9999;
  font-family: var(--cp-font);
  font-size: 13px;
  color: var(--cp-t-dark);
  box-shadow: var(--cp-shadow);
}

body {
  padding-left: 360px;
}


/* ──────────────────────────────────────────────
   3. Panel Header & Scrollable
   ────────────────────────────────────────────── */

.panel-header {
  padding: 36px var(--cp-pad) var(--cp-pad);
  border-bottom: 1px solid var(--cp-border);
  flex-shrink: 0;
  animation: builderSlideDown 0.12s ease-out;
  animation-fill-mode: backwards;
}

.panel-back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  color: var(--cp-primary);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.panel-back-link:hover {
  color: var(--cp-primary-hover);
}

.logo-mark {
  width: 32px;
  height: 32px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-mark img {
  width: 100%;
  height: 100%;
}

.panel-title {
  font-family: var(--cp-font-h);
  font-size: 15px;
  font-weight: 600;
  color: var(--cp-t-dark);
  margin-bottom: 4px;
}

.panel-subtitle {
  font-size: 13px;
  color: var(--cp-t-light);
  font-weight: 400;
  letter-spacing: -0.01em;
}

.panel-scrollable {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  position: relative;
}

.panel-scrollable::-webkit-scrollbar {
  display: none;
}

.panel-content {
  padding: 0 var(--cp-pad) var(--cp-pad);
}


/* ──────────────────────────────────────────────
   4. Custom Scrollbar
   ────────────────────────────────────────────── */

.custom-scrollbar-track {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 3px;
  width: 4px;
  z-index: 10;
  pointer-events: none;
}

.custom-scrollbar-thumb {
  position: absolute;
  right: 0;
  width: 100%;
  border-radius: 2px;
  background: hsla(216, 10%, 78%, 0.3);
  opacity: 0;
  transition: opacity 0.35s ease;
  min-height: 20px;
}

.custom-scrollbar-thumb.visible {
  opacity: 1;
}


/* ──────────────────────────────────────────────
   5. Sections & Form Fields
   ────────────────────────────────────────────── */

.cw-section {
  padding: 24px 0;
  border-bottom: 1px solid var(--cp-border);
  animation: builderSlideDown 0.22s ease-out;
  animation-fill-mode: backwards;
}

.cw-section:last-child {
  border-bottom: none;
}

.cw-section:nth-child(1) { animation-delay: 0.10s; }
.cw-section:nth-child(2) { animation-delay: 0.15s; }
.cw-section:nth-child(3) { animation-delay: 0.20s; }
.cw-section:nth-child(4) { animation-delay: 0.25s; }
.cw-section:nth-child(5) { animation-delay: 0.30s; }
.cw-section:nth-child(6) { animation-delay: 0.35s; }

.cw-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--cp-t-light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

.cw-field {
  margin-bottom: 16px;
}

.cw-field:last-child {
  margin-bottom: 0;
}

.cw-field-hint {
  font-size: 11.5px;
  color: var(--cp-t-light);
  margin-top: 5px;
}

.cw-field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--cp-t-med);
  margin-bottom: 8px;
}

.cw-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-r);
  font-size: 14px;
  font-family: inherit;
  background: var(--cp-bg);
  color: var(--cp-t-dark);
  transition: border-color var(--cp-ease), box-shadow var(--cp-ease);
}

.cw-input:hover {
  border-color: var(--cp-focus-border);
}

.cw-input:focus {
  outline: none;
  border-color: var(--cp-primary);
  box-shadow: 0 0 0 3px var(--cp-focus-ring);
}

.cw-input::placeholder {
  color: var(--cp-t-light);
}


/* ──────────────────────────────────────────────
   6. Color Picker
   ────────────────────────────────────────────── */

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

.cw-color-input {
  width: 40px;
  height: 40px;
  border-radius: var(--cp-r);
  border: 1px solid var(--cp-border);
  padding: 2px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
  transition: border-color var(--cp-ease), transform 0.15s;
}

.cw-color-input--lg {
  width: 44px;
  height: 44px;
}

.cw-color-input:hover {
  border-color: var(--cp-primary);
  transform: scale(1.05);
}

.cw-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.cw-color-input::-webkit-color-swatch { border-radius: 6px; border: none; }

.cw-input--hex {
  flex: 1;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 14px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}


/* ──────────────────────────────────────────────
   7. Preview Strip
   ────────────────────────────────────────────── */

.cw-preview-strip {
  display: flex;
  gap: 4px;
  margin: 16px 0;
  border-radius: var(--cp-r);
  overflow: hidden;
  height: 10px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.cw-preview-strip-item {
  flex: 1;
  transition: background var(--cp-ease);
  cursor: default;
  position: relative;
}

.cw-preview-strip-item:first-child {
  border-radius: var(--cp-r) 0 0 var(--cp-r);
}

.cw-preview-strip-item:last-child {
  border-radius: 0 var(--cp-r) var(--cp-r) 0;
}


/* ──────────────────────────────────────────────
   8. Advanced Overrides
   ────────────────────────────────────────────── */

.cw-advanced-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--cp-t-light);
  cursor: pointer;
  border: none;
  background: none;
  padding: 4px 0;
  font-family: inherit;
  transition: color 0.15s;
}

.cw-advanced-toggle:hover { color: var(--cp-t-med); }

.cw-advanced-toggle i {
  font-size: 14px;
  transition: transform var(--cp-ease);
}

.cw-advanced-toggle.open i { transform: rotate(90deg); }

.cw-advanced-body {
  display: none;
  margin-top: 12px;
}

.cw-advanced-body.open { display: block; }

.cw-override-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.cw-override-swatch {
  width: 28px;
  height: 28px;
  border-radius: var(--cp-r);
  border: 1px solid var(--cp-border);
  padding: 1px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
  transition: border-color var(--cp-ease), transform 0.15s;
}

.cw-override-swatch:hover {
  border-color: var(--cp-primary);
  transform: scale(1.05);
}

.cw-override-swatch::-webkit-color-swatch-wrapper { padding: 0; }
.cw-override-swatch::-webkit-color-swatch { border-radius: 6px; border: none; }

.cw-override-name {
  flex: 1;
  font-size: 13px;
  color: var(--cp-t-med);
}

.cw-override-reset {
  font-size: 11px;
  color: var(--cp-t-light);
  cursor: pointer;
  border: none;
  background: none;
  padding: 2px 8px;
  border-radius: 6px;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
  display: none;
}

.cw-override-reset.visible { display: block; }

.cw-override-reset:hover {
  background: var(--cp-bg-light);
  color: var(--cp-t-med);
}


/* ──────────────────────────────────────────────
   9. Toggle Switches (iOS-style)
   ────────────────────────────────────────────── */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
}

.toggle-row + .toggle-row {
  border-top: 1px solid var(--cp-border);
}

.toggle-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--cp-t-med);
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--cp-border);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--cp-ease);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform var(--cp-ease);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--cp-primary);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(20px);
}


/* ──────────────────────────────────────────────
   10. File Upload & Thumbnail Preview
   ────────────────────────────────────────────── */

.upload-zone {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1.5px dashed var(--cp-border);
  border-radius: var(--cp-r);
  cursor: pointer;
  transition: border-color var(--cp-ease), background var(--cp-ease);
}

.upload-zone:hover {
  border-color: var(--cp-focus-border);
  background: hsl(216, 50%, 98%);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--cp-r);
  background: var(--cp-bg-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--cp-t-light);
  font-size: 18px;
}

.upload-text {
  flex: 1;
}

.upload-text-main {
  font-size: 13px;
  font-weight: 500;
  color: var(--cp-t-med);
}

.upload-text-hint {
  font-size: 11px;
  color: var(--cp-t-light);
  margin-top: 2px;
}

/* Thumbnail preview (replaces upload zone when file is loaded) */
.upload-preview {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-r);
  background: var(--cp-bg-light);
}

.upload-preview.active {
  display: flex;
}

.upload-preview-img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--cp-border);
}

.upload-preview-name {
  flex: 1;
  font-size: 12px;
  color: var(--cp-t-med);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-preview-remove {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--cp-t-light);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

.upload-preview-remove:hover {
  background: hsl(0, 55%, 95%);
  color: hsl(0, 50%, 45%);
}


/* ──────────────────────────────────────────────
   11. Rich Text Editor (Disclosures)
   ────────────────────────────────────────────── */

.editor-wrap {
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-r);
  overflow: hidden;
  transition: border-color var(--cp-ease), box-shadow var(--cp-ease);
}

.editor-wrap:focus-within {
  border-color: var(--cp-primary);
  box-shadow: 0 0 0 3px var(--cp-focus-ring);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: var(--cp-bg-light);
  border-bottom: 1px solid var(--cp-border);
}

.editor-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--cp-t-med);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  font-family: inherit;
}

.editor-btn:hover {
  background: var(--cp-border);
  color: var(--cp-t-dark);
}

.editor-btn.active {
  background: var(--cp-primary);
  color: #fff;
}

.editor-btn--bold { font-weight: 700; font-size: 13px; }
.editor-btn--italic { font-style: italic; font-size: 13px; }

.editor-area {
  padding: 10px 12px;
  min-height: 100px;
  max-height: 200px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
  color: var(--cp-t-dark);
  outline: none;
  font-family: inherit;
}

.editor-area:empty::before {
  content: 'Enter disclosure text...';
  color: var(--cp-t-light);
}

.editor-area a {
  color: var(--cp-primary);
  text-decoration: underline;
}

.editor-counter {
  display: flex;
  justify-content: flex-end;
  padding: 4px 12px 8px;
  font-size: 11px;
  color: var(--cp-t-light);
  font-variant-numeric: tabular-nums;
}

.editor-counter.warning {
  color: hsl(0, 60%, 50%);
}


/* ──────────────────────────────────────────────
   12. Conditional Field Visibility
   ────────────────────────────────────────────── */

.cw-conditional {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}

.cw-conditional > * {
  overflow: hidden;
  padding: 4px;
  margin: -4px;
}

.cw-conditional.hidden {
  grid-template-rows: 0fr;
  opacity: 0;
  margin: 0;
  padding: 0;
}


/* ──────────────────────────────────────────────
   13. Action Footer & Buttons
   ────────────────────────────────────────────── */

.panel-footer {
  padding: 20px var(--cp-pad);
  border-top: 1px solid var(--cp-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: builderSlideDown 0.3s ease-out;
  animation-delay: 0.18s;
  animation-fill-mode: backwards;
}

.cw-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 24px;
  background: var(--cp-primary);
  color: #fff;
  border: none;
  border-radius: var(--cp-r);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--cp-ease), transform 0.15s, box-shadow var(--cp-ease);
}

.cw-download:hover {
  background: var(--cp-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px hsl(216, 79%, 70%, 0.3);
}

.cw-download i {
  font-size: 18px;
}

.cw-reset-all {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 24px;
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-r);
  background: var(--cp-bg);
  color: var(--cp-t-med);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--cp-ease), border-color var(--cp-ease);
}

.cw-reset-all:hover {
  background: var(--cp-bg-light);
  border-color: var(--cp-focus-border);
}

.cw-reset-all i {
  font-size: 16px;
}


/* ──────────────────────────────────────────────
   14. Toast Notification
   ────────────────────────────────────────────── */

.toast {
  position: fixed;
  top: 28px;
  right: 28px;
  padding: 12px 20px;
  border-radius: var(--cp-r);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--cp-font);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 99999;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast i {
  font-size: 17px;
}

.toast--success {
  background: var(--toast-bg);
  color: var(--toast-text);
  border: 1px solid var(--toast-border);
}

.toast--success i {
  color: var(--toast-icon);
}

.toast--error {
  background: var(--toast-err-bg);
  color: var(--toast-err-text);
  border: 1px solid var(--toast-err-border);
}

@keyframes builderSlideDown {
  0%   { opacity: 0; transform: translateY(-10px); }
  100% { opacity: 1; transform: translateY(0); }
}


/* ──────────────────────────────────────────────
   15. Responsive — Tablet (≤1024px)
   ────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .control-panel {
    --cp-w: 300px;
    --cp-pad: 24px;
  }

  body {
    padding-left: 300px;
  }

  .panel-header {
    padding: 28px var(--cp-pad) 24px;
  }
}


/* ──────────────────────────────────────────────
   16. Responsive — Mobile (≤480px)
   ────────────────────────────────────────────── */

@media (max-width: 480px) {
  .control-panel {
    position: relative;
    width: 100%;
    height: auto;
    max-height: none;
    box-shadow: none;
    border-right: none;
    border-bottom: 1px solid var(--cp-border);
  }

  body {
    padding-left: 0;
  }

  .panel-scrollable {
    overflow-y: visible;
  }

  .toast {
    left: 16px;
    right: 16px;
    top: 16px;
    justify-content: center;
  }
}
