/* Modern UI-Widget Generator Styles */
:root {
  --color-bg: #f6f8fa;
  --color-text: #1f2328;
  --color-border: #d0d7de;
  --color-surface: #ffffff;
  --color-shadow: rgba(31, 35, 40, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  margin: 0;
  padding: 2rem;
  color: var(--color-text);
  line-height: 1.5;
}

h1 {
  margin: 0 0 2rem 0;
  font-size: 2rem;
  font-weight: 600;
  color: var(--color-text);
  text-align: center;
}

.site-header {
  max-width: 1400px;
  margin: 0 auto 1.5rem auto;
  padding: 0 1rem;
}

.main-container {
  /* Reworked: flex instead of grid to prevent overflow */
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
}

.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.controls-container {
  width: 320px;
  flex-shrink: 0;
  position: sticky;
  top: 1rem;
  align-self: flex-start;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  scrollbar-width: thin;
}

.controls-container::-webkit-scrollbar {
  width: 8px;
}
.controls-container::-webkit-scrollbar-track { background: transparent; }
.controls-container::-webkit-scrollbar-thumb { background: #c2c8d0; border-radius: 4px; }
.controls-container::-webkit-scrollbar-thumb:hover { background: #9aa2ab; }

.code-output.collapsed { display: none; }

.header-actions { display: flex; gap: .5rem; }

.btn-secondary {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.45rem .9rem;
  font-size: .8rem;
  cursor: pointer;
  line-height: 1.2;
  color: var(--color-text);
  transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: var(--color-bg); }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: .25rem .5rem;
  font-size: .85rem;
  line-height: 1;
  color: var(--color-text);
}
.icon-btn:hover { background: var(--color-bg); border-color: var(--color-border); }

.floating-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--color-text);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: .75rem 1.1rem;
  font-size: .85rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  display: none;
  z-index: 600;
}
.floating-toggle:hover { background: #2d3136; }

/* Mobile / narrow layout */
@media (max-width: 900px) {
  .main-container {
    flex-direction: column;
    gap: 1.5rem;
  }

  .workspace {
    gap: 1.5rem;
  }

  /* Controls should be visible and stacked below on mobile */
  .controls-container {
    position: static !important;
    width: 100% !important;
    max-width: none !important;
    flex-shrink: 0 !important;
    top: auto !important;
    align-self: auto !important;
    max-height: none !important;
    transform: none !important;
    order: 2; /* Place after workspace */
  }

  /* Hide the floating toggle button on mobile since controls are always visible */
  .floating-toggle {
    display: none !important;
  }

  /* Hide the close button on mobile since it's not a modal */
  #close-controls {
    display: none !important;
  }

  /* Remove any mobile panel styling */
  #controls-panel {
    position: static !important;
    transform: none !important;
    background: var(--color-surface) !important;
    border-radius: 6px !important;
    border: 1px solid var(--color-border) !important;
    box-shadow: 0 1px 3px var(--color-shadow) !important;
    z-index: auto !important;
    height: auto !important;
    overflow-y: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Remove overlay */
  #controls-panel::before {
    display: none !important;
  }

  /* Reset section header */
  #controls-panel .section-header {
    position: static;
    background: var(--color-surface);
    z-index: auto;
    border-bottom: 1px solid var(--color-border);
  }
}

@media (min-width: 901px) { #close-controls { display: none; } }

/* Prevent body horizontal scroll */
html, body { overflow-x: hidden; }

.section {
  background: var(--color-surface);
  border-radius: 6px;
  box-shadow: 0 1px 3px var(--color-shadow);
  border: 1px solid var(--color-border);
}

.section-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-content {
  padding: 1.5rem;
}

.widget-preview {
  grid-area: preview;
  min-height: 400px;
}

.widget-preview .section-content {
  padding: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

.code-output {
  grid-area: code;
  position: relative;
}

.code-content {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background: #f6f8fa;
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  white-space: pre;
  color: #1f2328;
  border: 1px solid #d0d7de;
  max-height: 400px;
  overflow-y: auto;
}

.copy-button {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.copy-button:hover {
  background: var(--color-bg);
}

.copy-button.copied {
  background: #1a7f37;
  color: white;
  border-color: #1a7f37;
}

/* Controls - always visible on the right */
.controls-container {
  grid-area: controls;
  min-width: 320px;
  position: sticky;
  top: 2rem;
  align-self: start;
}

.controls-container .section-content {
  padding: 0;
}

/* Tweakpane container styling */
.controls-container {
  min-width: 320px;
}

/* Override some Tweakpane styles for better integration */
.tp-dfwv {
  min-width: 100% !important;
}

/* Ensure tweakpane doesn't have padding conflicts */
#tweakpane-container {
  width: 100%;
}

.pane-actions {
  padding: .75rem 1rem 1rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap:.5rem;
  background: var(--color-surface);
}
