/* ============================================
   MockDataGen - Main Stylesheet
   ============================================ */

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* ============================================
   Navbar
   ============================================ */
.navbar {
  background: var(--bg-navbar);
  border-bottom: 1px solid var(--border-primary);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.navbar-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  color: var(--accent-primary);
}

.navbar-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.navbar-badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--accent-primary);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

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

.btn-primary {
  background: var(--accent-primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
}

.btn-success {
  background: var(--accent-success);
  color: white;
}
.btn-success:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-danger {
  background: var(--accent-danger);
  color: white;
}
.btn-danger:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon {
  padding: 8px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
}

/* ============================================
   Inputs
   ============================================ */
.input {
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  width: 100%;
}
.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-primary-subtle);
}
.input::placeholder {
  color: var(--text-muted);
}

select.input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3b4' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

textarea.input {
  resize: vertical;
  min-height: 60px;
}

.input-with-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.input-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ============================================
   Cards
   ============================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title svg {
  color: var(--accent-primary);
}

.card-body {
  padding: 20px;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Dataset Settings */
.settings-row {
  display: flex;
  gap: 24px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.setting-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.setting-group .input {
  width: 160px;
}

/* ============================================
   Field Builder
   ============================================ */
.field-builder-header {
  display: grid;
  grid-template-columns: 32px 1fr 180px 100px 1fr 40px;
  gap: 10px;
  padding: 0 12px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.field-builder {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 40px;
}

.field-row {
  display: grid;
  grid-template-columns: 32px 1fr 180px 100px 1fr 40px;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.field-row:hover {
  border-color: var(--border-primary);
}
.field-row.dragging {
  opacity: 0.4;
}
.field-row.drop-above {
  border-top: 2px solid var(--accent-primary);
}
.field-row.drop-below {
  border-bottom: 2px solid var(--accent-primary);
}

.field-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 6px;
  user-select: none;
}
.field-drag-handle:active {
  cursor: grabbing;
}

.field-name-input {
  width: 100%;
}

.field-type-select {
  width: 100%;
}

.field-missing-input {
  width: 100%;
}

.field-settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-settings .setting-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.field-settings .setting-inline label {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 40px;
}

.field-settings .setting-inline .input {
  width: 100%;
}

.field-settings textarea.input {
  min-height: 48px;
  font-size: 0.8rem;
}

.field-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.field-delete-btn:hover {
  background: var(--accent-danger-subtle);
  color: var(--accent-danger);
}

/* ============================================
   Action Bar
   ============================================ */
.action-bar {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ============================================
   Preview Table
   ============================================ */
.preview-body {
  padding: 0;
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.table-wrapper {
  overflow-x: auto;
  max-height: 520px;
  overflow-y: auto;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
}

.preview-table th {
  background: var(--bg-table-header);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--border-primary);
  white-space: nowrap;
}

.preview-table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-subtle);
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-table tr:nth-child(even) td {
  background: var(--bg-table-row-alt);
}
.preview-table tr:hover td {
  background: var(--bg-table-row-hover);
}

.null-badge {
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--null-bg);
  color: var(--null-text);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.04em;
}

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
}

.modal-desc {
  font-size: 0.85rem;
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  min-width: 280px;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  animation: toastIn 300ms ease;
}

.toast.toast-out {
  animation: toastOut 300ms ease forwards;
}

.toast-success { border-left: 3px solid var(--accent-success); }
.toast-error { border-left: 3px solid var(--accent-danger); }
.toast-info { border-left: 3px solid var(--accent-info); }
.toast-warning { border-left: 3px solid var(--accent-warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ============================================
   Loading Overlay
   ============================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-primary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-bar-container {
  width: 200px;
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent-primary);
  border-radius: 2px;
  width: 0%;
  transition: width 200ms ease;
}

/* ============================================
   Footer
   ============================================ */
.site-footer {
  text-align: center;
  padding: 24px;
  margin-top: 12px;
  border-top: 1px solid var(--border-primary);
  color: var(--text-muted);
  font-size: 0.825rem;
}

.site-footer a {
  color: var(--accent-primary);
  text-decoration: none;
  font-weight: 500;
}

.site-footer a:hover {
  color: var(--accent-primary-hover);
  text-decoration: underline;
}

/* ============================================
   Utility
   ============================================ */
.text-muted {
  color: var(--text-muted);
  font-size: 0.825rem;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
  .field-builder-header {
    display: none;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .field-drag-handle {
    display: none;
  }

  .field-row .field-delete-btn {
    justify-self: end;
  }

  .navbar-content {
    padding: 0 16px;
  }

  .main-content {
    padding: 16px;
  }

  .btn span {
    display: none;
  }

  .btn svg + span {
    display: none;
  }
}

@media (max-width: 600px) {
  .action-bar {
    flex-direction: column;
  }

  .action-bar .btn {
    width: 100%;
    justify-content: center;
  }

  .action-bar .btn span {
    display: inline;
  }
}
