/* Base Styles */
:root {
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --secondary-color: #f3f4f6;
  --text-color: #1f2937;
  --border-color: #e5e7eb;
  --success-color: #10b981;
  --shadow-color: rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background-color: #f9fafb;
  font-size: 16px;
}

header {
  background-color: var(--primary-color);
  color: white;
  text-align: center;
  padding: 2rem 1rem;
  margin-bottom: 2rem;
}

header h1 {
  margin-bottom: 0.5rem;
  font-size: 2.5rem;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

footer {
  text-align: center;
  padding: 1.5rem;
  background-color: var(--secondary-color);
  margin-top: 2rem;
}

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.tab-btn {
  padding: 0.75rem 1.25rem;
  background-color: var(--secondary-color);
  border: 2px solid transparent;
  border-radius: 0.375rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  position: relative;
  z-index: 1;
}

.tab-btn:hover {
  background-color: #e5e7eb;
  transform: scale(1.05);
  border-color: var(--border-color);
}

.tab-btn.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.tab-pane {
  display: none;
}

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

/* Tool Container */
.tool-container {
  display: flex;
  flex-direction: row;
  gap: 2rem;
}

.controls {
  flex: 1;
  background-color: white;
  padding: 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px var(--shadow-color);
}

.preview {
  flex: 1;
  background-color: white;
  padding: 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px var(--shadow-color);
}

/* Control Groups */
.control-group {
  margin-bottom: 1.25rem;
}

.control-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.control-group input[type="text"],
.control-group input[type="number"],
.control-group select {
  width: 100%;
  padding: 0.625rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  font-size: 1rem;
}

.control-group input[type="range"] {
  width: 100%;
  margin-right: 0.5rem;
}

.control-group input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  padding: 2px;
}

.checkbox-group,
.radio-group {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
}

.checkbox-group input,
.radio-group input {
  margin-right: 0.5rem;
}

/* Preview Container */
.preview-container {
  overflow-x: auto; /* Changed from scroll to auto */
  width: auto; /* Changed from fixed width to auto */
  max-width: 100%; /* Added max-width */
  background-color: var(--secondary-color);
  padding: 2rem;
  border-radius: 0.375rem;
  margin-bottom: 1.5rem;
  min-height: 150px;
  display: flex;
overflow-x: scroll;
  width: 50vw;
  justify-content: center;
  align-items: center;
}

.table-preview-container {
  overflow-x: auto;
}

/* Code Container */
.code-container {
  background-color: #f8fafc;
  border-radius: 0.375rem;
  overflow: hidden;
  margin-bottom: 1rem;
}

.code-container h3 {
  padding: 0.75rem 1rem;
  background-color: #f1f5f9;
  margin: 0;
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.code-container pre {
  width: auto; /* Changed from fixed width to auto */
  max-width: 100%; /* Added max-width */
  overflow-x: auto; /* Changed from scroll to auto */
  margin: 0;
  padding: 1rem;
  background-color: #1e293b;
  color: #e2e8f0;
  width: 50vw;
  overflow-x: auto;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.875rem;
}

.copy-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.2s;
}

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

.copy-btn.small {
  padding: 0.25rem 0.5rem;
  margin: 0;
}

/* Button Preview */
#btn-preview {
  padding: 12px 24px;
  background-color: #4caf50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.3s;
  position: relative;
  z-index: 1;
  box-sizing: border-box;
}

/* Box Shadow Preview */
#shadow-preview {
  width: 150px;
  height: 150px;
  background-color: white;
  border-radius: 8px;
}

/* Hover Effect Preview */
#hover-preview {
  padding: 20px;
  background-color: #3498db;
  color: white;
  border-radius: 5px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

/* Color Preview */
#color-preview {
  width: 100%;
  height: 100px;
  border-radius: 5px;
  background-color: #3498db;
}

.color-values {
  padding: 1rem;
  background-color: #f8fafc;
  margin-bottom: 1rem;
}

.color-value {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
}

.color-value span {
  width: 60px;
  font-weight: 500;
}

.color-value code {
  flex: 1;
  padding: 0.25rem 0.5rem;
  background-color: #f1f5f9;
  border-radius: 0.25rem;
}

/* Form Fields */
.form-field {
  flex-wrap: nowrap;
  width: 100%;
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
  flex-wrap: nowrap;
  width: 100%;
}

.form-field select,
.form-field input {
  min-width: 0; /* Prevents flex items from overflowing */
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  min-width: 0; /* Prevents flex items from overflowing */
}

.field-type {
  flex-shrink: 0;
  width: 30%;
  flex-shrink: 0;
}

.field-label,
.field-placeholder {
  flex: 1;
  min-width: 0; /* Allows text to truncate if needed */
  flex: 1;
  min-width: 0; /* Allows text to truncate if needed */
}

.remove-field {
  flex-shrink: 0;
  background-color: #ef4444;
  color: white;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.action-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 0.75rem 1.25rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.2s;
}

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

.action-btn.small {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

/* Table Styles */
table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  text-align: left;
  padding: 8px;
}

/* Form Preview */
#form-preview form {
  width: 100%;
}

#form-preview input[type="text"],
#form-preview input[type="email"],
#form-preview input[type="password"],
#form-preview textarea,
#form-preview select {
  width: 100%;
  padding: 0.625rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
}

#form-preview button {
  padding: 0.75rem 1.25rem;
  background-color: #4caf50;
  color: white;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
}

/* Gradient Preview */
#gradient-preview {
  width: 100%;
  height: 150px;
  border-radius: 5px;
}

/* Animation Preview */
#animation-preview {
  width: 150px;
  height: 150px;
  background-color: #3498db;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 5px;
}

/* Filter Preview */
#filter-preview {
  max-width: 100%;
  height: auto;
  border-radius: 5px;
}

/* Transform Preview */
#transform-preview {
  width: 150px;
  height: 150px;
  background-color: #3498db;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 5px;
}

/* Flexbox Preview */
#flexbox-preview {
  width: 100%;
  min-height: 200px;
  background-color: #f1f5f9;
  padding: 10px;
  border-radius: 5px;
}

.flex-item {
  background-color: #3498db;
  color: white;
  padding: 20px;
  margin: 5px;
  text-align: center;
  border-radius: 5px;
}

/* Grid Preview */
#grid-preview {
  width: 100%;
  min-height: 200px;
  background-color: #f1f5f9;
  padding: 10px;
  border-radius: 5px;
}

.grid-item {
  background-color: #3498db;
  color: white;
  padding: 20px;
  text-align: center;
  border-radius: 5px;
}

/* Responsive Preview */
#responsive-preview {
  width: 100%;
  min-height: 200px;
}

.responsive-demo {
  background-color: #3498db;
  color: white;
  padding: 20px;
  text-align: center;
  border-radius: 5px;
}

/* SVG Preview */
#svg-preview {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ======================================
   MEDIA QUERIES - GROUPED AT THE END
   ====================================== */

/* Large screens */
@media (min-width: 1200px) {
  main {
    padding: 0 2rem 4rem;
  }

  .preview-container {
    padding: 2.5rem;
  }
}

/* Tablets and smaller desktops */
@media (max-width: 1199px) {
  header h1 {
    font-size: 2.25rem;
  }
}

/* Tablets */
@media (min-width: 481px) and (max-width: 768px) {
  .tool-container {
    gap: 1.5rem;
  }
}

/* Media query adjustments */
@media (min-width: 769px) {
  .form-field {
    flex-wrap: nowrap;
  }

  .field-type,
  .field-label,
  .field-placeholder {
    width: auto; /* Reset width for desktop */
    margin-bottom: 0; /* Remove bottom margin on desktop */
  }

  .field-type {
    flex: 0 0 30%; /* Fixed width for field type */
  }

  .field-label,
  .field-placeholder {
    flex: 1; /* Allow these to grow */
  }
}

/* Tablets and mobile */
@media (max-width: 768px) {
  header h1 {
    font-size: 2rem;
  }

  .tabs {
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 1.5rem;
  }

  .tab-btn {
    width: 100%;
    text-align: center;
    padding: 0.625rem 1rem;
  }

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

  .form-field {
    flex-wrap: wrap;
    gap: 0.375rem;
  }

  .field-type,
  .field-label,
  .field-placeholder {
    width: 100%;
    margin-bottom: 0.375rem;
  }

  .remove-field {
    margin-left: auto;
  }
}

/* Mobile devices */
@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  header {
    padding: 1.5rem 1rem;
    margin-bottom: 1.5rem;
  }

  header h1 {
    font-size: 1.75rem;
  }

  main {
    padding: 0 0.75rem 2rem;
  }

  footer {
    padding: 1rem;
    margin-top: 1.5rem;
  }

  .tool-container {
    gap: 1.25rem;
  }

  .controls,
  .preview {
    padding: 1rem;
  }

  .control-group {
    margin-bottom: 1rem;
  }

  .control-group input[type="text"],
  .control-group input[type="number"],
  .control-group select {
    font-size: 0.875rem;
    padding: 0.5rem;
  }

  .control-group input[type="color"] {
    height: 36px;
  }

  .preview-container {
    padding: 1.25rem;
    margin-bottom: 1rem;
    min-height: 120px;
    width: 85vw;
    overflow: scroll;
  }

  .code-container h3 {
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
  }

  .code-container pre {
    padding: 0.75rem;
    font-size: 0.75rem;
        width: 85vw;
    overflow: scroll;
  }

  .copy-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
  }

  #btn-preview {
    padding: 10px 20px;
    font-size: 0.875rem;
  }

  #shadow-preview,
  #transform-preview,
  #animation-preview {
    width: 120px;
    height: 120px;
  }

  #hover-preview {
    padding: 15px;
  }

  #color-preview {
    height: 80px;
  }

  .color-values {
    padding: 0.75rem;
  }

  .color-value span {
    width: 50px;
    font-size: 0.875rem;
  }

  .color-value code {
    padding: 0.2rem 0.4rem;
    font-size: 0.75rem;
  }

  .form-field select,
  .form-field input {
    padding: 0.375rem;
    font-size: 0.875rem;
  }

  .remove-field {
    width: 26px;
    height: 26px;
  }

  .action-btn {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
  }

  .action-btn.small {
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
  }

  th,
  td {
    padding: 6px;
    font-size: 0.875rem;
  }

  #form-preview input[type="text"],
  #form-preview input[type="email"],
  #form-preview input[type="password"],
  #form-preview textarea,
  #form-preview select {
    padding: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
  }

  #form-preview button {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
  }

  #gradient-preview {
    height: 120px;
  }

  #animation-preview {
    font-size: 0.875rem;
  }

  #transform-preview {
    font-size: 0.875rem;
  }

  #flexbox-preview {
    min-height: 160px;
    padding: 8px;
  }

  .flex-item {
    padding: 15px;
    margin: 4px;
    font-size: 0.875rem;
  }

  #grid-preview {
    min-height: 160px;
    padding: 8px;
  }

  .grid-item {
    padding: 15px;
    font-size: 0.875rem;
  }

  #responsive-preview {
    min-height: 160px;
  }

  .responsive-demo {
    padding: 15px;
    font-size: 0.875rem;
  }
}

/* Small phones */
@media (max-width: 360px) {
  body {
    font-size: 13px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .controls,
  .preview {
    padding: 0.75rem;
  }

  .preview-container {
    padding: 1rem;
  }

  #shadow-preview,
  #transform-preview,
  #animation-preview {
    width: 100px;
    height: 100px;
  }
}

/* Touch device optimizations */
@media (hover: none) {

  .tab-btn,
  .action-btn,
  .copy-btn,
  .remove-field {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }

  input[type="range"] {
    height: 24px;
  }
}

/* Print styles */
@media print {
  body {
    background-color: white;
  }

  header,
  footer,
  .tabs,
  .controls {
    display: none;
  }

  main {
    padding: 0;
    max-width: 100%;
  }

  .preview {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* Fix for iOS input styling */
@supports (-webkit-touch-callout: none) {

  input,
  select,
  textarea {
    font-size: 16px;
  }
}

/* Fix for Firefox range inputs */
@-moz-document url-prefix() {
  input[type="range"] {
    height: 0.8rem;
  }
}


/* Fix for Edge and IE */
@supports (-ms-ime-align: auto) {

  .tab-btn,
  .action-btn {
    transition: none;
  }
}
