/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   WebForge Builder — Dark Premium UI
   Colors: #0D0D0D bg, #6366F1 accent, indigo theme
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

:root {
  --accent:      #6366F1;
  --accent-h:    #4F46E5;
  --bg:          #0D0D0D;
  --bg-light:    #1A1A1A;
  --bg-lighter:  #242424;
  --border:      #2E2E2E;
  --text:        #FFFFFF;
  --text-muted:  #9CA3AF;
  --text-dim:    #6B7280;
  --success:     #10B981;
  --warn:        #F59E0B;
  --danger:      #EF4444;
  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   14px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ─── Builder Layout ──────────────────────────────────────────────────────── */

.builder-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Mobile tabs (hidden on desktop) */
.mobile-tabs {
  display: none;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* 3-panel container */
.panels-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ─── Panel base ─────────────────────────────────────────────────────────── */

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.panel-left  { width: 280px; flex-shrink: 0; }
.panel-center { flex: 1; min-width: 0; border-right: 1px solid var(--border); }
.panel-right  { width: 320px; flex-shrink: 0; }

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  padding: 2px 8px;
  border-radius: 20px;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.panel-footer {
  flex-shrink: 0;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ─── Left Panel: Form Elements ─────────────────────────────────────────── */

.form-section {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.url-input {
  width: 100%;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  resize: none;
}

.url-input::placeholder { color: var(--text-dim); }

.url-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

textarea.url-input {
  border-radius: var(--radius);
  line-height: 1.5;
}

.toggle-manual {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 6px 0;
  transition: color 0.2s;
}

.toggle-manual:hover { color: var(--text-muted); }

.manual-desc {
  width: 100%;
  margin-top: 8px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  resize: vertical;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.manual-desc::placeholder { color: var(--text-dim); }
.manual-desc:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Style presets grid */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.preset-btn:hover {
  border-color: rgba(99, 102, 241, 0.4);
  background: rgba(99, 102, 241, 0.06);
}

.preset-btn.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.12);
}

.preset-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.preset-desc {
  font-size: 11px;
  color: var(--text-dim);
}

/* Color palette grid */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.palette-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.palette-swatch:hover { border-color: rgba(99, 102, 241, 0.4); }

.palette-swatch.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.swatch-preview {
  width: 100%;
  height: 28px;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
}

.swatch-accent {
  flex: 1;
  height: 100%;
}

.palette-name {
  font-size: 10px;
  color: var(--text-dim);
}

/* Error message */
.error-msg {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 12px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

/* Generate button */
.btn-generate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}

.btn-generate:hover:not(:disabled) { background: var(--accent-h); }
.btn-generate:active:not(:disabled) { transform: scale(0.98); }
.btn-generate:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-generate.loading { background: var(--accent-h); }

/* Export button */
.btn-export {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: var(--bg-lighter);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-export:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

/* Logo */
.logo-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* Progress bar */
.progress-container {
  margin-bottom: 10px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-light);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

@keyframes progressAnim {
  0%   { transform: translateX(-100%); }
  50%  { transform: translateX(0%); }
  100% { transform: translateX(100%); }
}

.progress-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, var(--accent) 0%, #818CF8 100%);
  border-radius: 2px;
  animation: progressAnim 1.5s ease-in-out infinite;
}

.progress-message {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  animation: fadeIn 0.3s ease;
}

/* Sections list */
.sections-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
}

.section-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-eye {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 2px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}

.section-eye:hover { color: var(--text-muted); }
.section-eye.hidden { color: rgba(107, 114, 128, 0.4); }

/* Footer actions */
.footer-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.btn-footer {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 12px;
  background: var(--bg-lighter);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-footer:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-footer.disabled, .btn-footer:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-footer.success {
  border-color: var(--success);
  color: var(--success);
}

/* Publish to Web */
.btn-publish {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: var(--bg-light);
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: not-allowed;
  transition: all 0.2s;
}

.coming-soon {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
  background: rgba(107, 114, 128, 0.15);
  border: 1px solid rgba(107, 114, 128, 0.2);
  border-radius: 20px;
  padding: 1px 6px;
}

/* Toolbar actions */
.preview-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
}

.toolbar-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.toolbar-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* Chat header row */
.chat-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.btn-export.disabled, .btn-export:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Spinner animation */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-sm {
  width: 12px;
  height: 12px;
  border: 1.5px solid rgba(99,102,241,0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Preview Panel ───────────────────────────────────────────────────────── */

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.device-switcher {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}

.device-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
}

.device-btn:hover { color: var(--text-muted); }
.device-btn.active {
  background: var(--bg-lighter);
  color: var(--accent);
}

.preview-label {
  font-size: 12px;
  color: var(--text-dim);
}

.preview-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  font-size: 11px;
  color: var(--success);
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); animation: pulse 2s ease-in-out infinite; }
.success-dot { background: var(--success); }

/* Preview frame area */
.preview-frame-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  background: var(--bg-light);
}

.preview-device-frame {
  width: 100%;
  margin: 0 auto;
  transition: max-width 0.3s ease;
  min-height: 400px;
}

.preview-iframe {
  width: 100%;
  height: 700px;
  border: none;
  border-radius: var(--radius-lg);
  background: #fff;
  display: block;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* Skeleton loading */
.preview-skeleton {
  background: var(--bg-lighter);
  border-radius: var(--radius-lg);
  padding: 32px;
  min-height: 500px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton-bar {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--bg) 25%, var(--border) 50%, var(--bg) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.8s ease infinite;
}

.skeleton-row {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

.skeleton-box {
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--bg) 25%, var(--border) 50%, var(--bg) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.8s ease infinite;
}

.skeleton-text {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 20px;
}

/* Empty state */
.preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 400px;
  text-align: center;
  color: var(--text-dim);
  background: var(--bg-lighter);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border);
  padding: 40px;
}

.preview-empty p {
  font-size: 14px;
  line-height: 1.6;
  max-width: 280px;
}

.preview-empty strong { color: var(--text-muted); }

/* ─── Chat Panel ─────────────────────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Chat empty state */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 0;
  color: var(--text-dim);
}

.chat-empty-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chat-empty p {
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

/* Suggested prompts */
.suggested-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
}

.prompts-label {
  font-size: 11px;
  color: var(--text-dim);
}

.prompt-chip {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.prompt-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

/* Chat messages */
.chat-message {
  display: flex;
  gap: 10px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.msg-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-lighter);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  margin-top: 2px;
}

.chat-message.assistant .msg-avatar {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.3);
}

.msg-content {
  flex: 1;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  word-break: break-word;
}

.chat-message.user { flex-direction: row-reverse; }

.chat-message.user .msg-avatar {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
}

.chat-message.user .msg-content {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.2);
  color: var(--text);
}

.chat-message.assistant .msg-content {
  background: var(--bg-light);
}

/* Typing animation */
.msg-content.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

@keyframes blink { 0%, 60% { opacity: 0; } 30% { opacity: 1; } }

.dot-anim {
  width: 6px;
  height: 6px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: blink 1.4s infinite;
}
.dot-anim:nth-child(2) { animation-delay: 0.2s; }
.dot-anim:nth-child(3) { animation-delay: 0.4s; }

/* Chat error */
.chat-error {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 12px;
  padding: 8px 12px;
}

/* Chat input */
.chat-input-area {
  flex-shrink: 0;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input::placeholder { color: var(--text-dim); }

.chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.chat-input:disabled { opacity: 0.5; }

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s;
}

.btn-send:hover:not(:disabled) { background: var(--accent-h); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-hint {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 8px;
  text-align: center;
}

.chat-hint.updating {
  color: var(--success);
  animation: fadeIn 0.3s ease;
}

/* ─── Mobile Responsive ──────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .mobile-tabs { display: flex; }

  .panel-left,
  .panel-right { display: none; }

  .panel-left.visible,
  .panel-right.visible { display: flex; flex-direction: column; width: 100%; }

  .panel-left { order: 1; }
  .panel-center { order: 2; }
  .panel-right { order: 3; border-right: none; }

  .panels-container { flex-direction: column; }

  .preview-iframe { height: 500px; }
}

@media (max-width: 480px) {
  .panel-left { width: 100%; }
  .panel-right { width: 100%; }
  .panel-center { min-height: 300px; }
  .preview-frame-wrapper { padding: 12px; }
}