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

:root {
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --danger-color: #ef4444;
  --danger-hover: #dc2626;
  --success-color: #10b981;
  --bg-light: #f9fafb;
  --bg-white: #ffffff;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border-color: #e5e7eb;
  --sidebar-bg: #ffffff;
  --sidebar-width: 280px;
  --topbar-height: 64px;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  background-color: var(--bg-light);
  color: var(--text-primary);
  line-height: 1.6;
}

/* App Container - Bubble-like layout */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar - Like Bubble */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text-primary);
}

.logo-icon {
  font-size: 1.5rem;
}

.sidebar-section {
  padding: 1rem 0;
}

.section-title {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.tables-list {
  display: flex;
  flex-direction: column;
}

.table-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
  font-size: 0.875rem;
}

.table-item:hover {
  background: var(--bg-light);
  color: var(--text-primary);
}

.table-item.active {
  background: var(--bg-light);
  color: var(--primary-color);
  font-weight: 500;
  border-right: 2px solid var(--primary-color);
}

.table-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.table-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Topbar - Like Bubble's header */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-color);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left {
  flex: 1;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Content Area */
.content-area {
  flex: 1;
  overflow: auto;
  padding: 2rem;
}

/* Buttons */
.btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  transition: all 0.15s;
}

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

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

.btn-secondary {
  background: var(--bg-white);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-light);
}

.btn-icon {
  padding: 0.5rem 0.75rem;
  border: none;
  cursor: pointer;
  border-radius: 0.375rem;
  font-size: 1.125rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  font-weight: 500;
}

.btn-icon:hover {
  transform: scale(1.1);
}

.btn-edit {
  background: rgba(59, 130, 246, 0.15);
  color: var(--primary-color);
}

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

.btn-delete {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger-color);
}

.btn-delete:hover {
  background: var(--danger-color);
  color: white;
}

/* Table Stats */
.table-stats {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
}

.stat-icon {
  font-size: 1rem;
}

.stat-text {
  color: var(--text-secondary);
}

/* Data Table - Like Bubble's data view */
.data-table-container {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  overflow-x: auto;
  overflow-y: visible;
  position: relative;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: max-content;
}

.data-table thead {
  background: var(--bg-light);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  background: var(--bg-light);
}

.data-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
  white-space: nowrap;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: var(--bg-light);
}

/* Sticky Actions Column */
.actions-col {
  width: 130px;
  text-align: center;
  white-space: nowrap;
  position: sticky;
  right: 0;
  background: var(--bg-white);
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.05);
}

.data-table thead .actions-col {
  background: var(--bg-light);
  z-index: 11;
}

.data-table tbody tr:hover .actions-col {
  background: var(--bg-light);
}

.action-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
}

.action-buttons form {
  margin: 0;
}

.null-value {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.8125rem;
}

.long-text {
  display: block;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.page-info {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

/* Alerts */
.alert {
  padding: 0.875rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  transition: opacity 0.3s;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 0;
  margin-left: 1rem;
}

.alert-close:hover {
  opacity: 1;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h2 {
  color: var(--text-primary);
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* Form Styles */
.form-container {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 2rem;
  max-width: 800px;
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group-disabled {
  opacity: 0.6;
}

.form-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field-info {
  display: flex;
  gap: 0.75rem;
  font-size: 0.75rem;
}

.field-type {
  color: var(--text-muted);
  font-family: monospace;
}

.field-required {
  color: var(--danger-color);
}

.field-optional {
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  padding-top: 1rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-primary {
  background: var(--primary-color);
  color: white;
}

.badge-auto {
  background: var(--success-color);
  color: white;
}

/* Column Selector */
.column-selector {
  position: fixed;
  top: var(--topbar-height);
  right: 2rem;
  width: 300px;
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 100;
}

.column-selector-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.column-selector-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close:hover {
  color: var(--text-primary);
}

.column-selector-body {
  padding: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.column-checkbox {
  display: flex;
  align-items: center;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 0.25rem;
  transition: background 0.15s;
}

.column-checkbox:hover {
  background: var(--bg-light);
}

.column-checkbox input[type="checkbox"] {
  margin-right: 0.5rem;
  cursor: pointer;
}

.column-checkbox span {
  font-size: 0.875rem;
}

.column-selector-footer {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 0.5rem;
}

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

/* Manage Columns Page */
.manage-columns-page {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.columns-section,
.add-column-section {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  overflow: hidden;
}

.section-header {
  padding: 1rem 1.5rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-header h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.column-count {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  background: var(--bg-white);
  padding: 0.25rem 0.625rem;
  border-radius: 1rem;
  font-weight: 500;
}

.columns-table-wrapper {
  overflow-x: auto;
}

.columns-table {
  width: 100%;
  border-collapse: collapse;
}

.columns-table thead {
  background: var(--bg-light);
}

.columns-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border-color);
}

.columns-table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.15s;
}

.columns-table tbody tr:hover {
  background: var(--bg-light);
}

.columns-table td {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  vertical-align: middle;
}

.columns-table td strong {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9375rem;
}

.type-badge {
  display: inline-block;
  font-family: "Courier New", monospace;
  font-size: 0.75rem;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-weight: 500;
}

.constraint-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.constraint-badge.nullable {
  background: #dbeafe;
  color: #1e40af;
}

.constraint-badge.not-null {
  background: #fef3c7;
  color: #92400e;
}

.default-value {
  font-family: "Courier New", monospace;
  font-size: 0.75rem;
  background: #f9fafb;
  color: #374151;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-primary {
  background: #dbeafe;
  color: #1e40af;
  font-size: 0.75rem;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-weight: 600;
}

.text-muted {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.actions-cell {
  text-align: center;
}

.action-buttons-inline {
  display: flex;
  gap: 0.375rem;
  justify-content: center;
  align-items: center;
}

.btn-icon-small {
  padding: 0.375rem 0.5rem;
  border: none;
  cursor: pointer;
  border-radius: 0.25rem;
  font-size: 1rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
}

.btn-icon-small:hover {
  transform: scale(1.05);
}

.btn-icon-small.btn-edit {
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary-color);
}

.btn-icon-small.btn-edit:hover {
  background: var(--primary-color);
  color: white;
}

.btn-icon-small.btn-delete {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger-color);
}

.btn-icon-small.btn-delete:hover {
  background: var(--danger-color);
  color: white;
}

.column-name-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
}

.modal.modal-open {
  display: block;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 9998;
}

.modal-content {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-white);
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 10000;
}

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

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  transition: background-color 0.15s;
}

.btn-close:hover {
  background: var(--bg-light);
  color: var(--text-primary);
}

.modal-form {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding-top: 0.5rem;
}

.add-column-section form {
  padding: 1.25rem 1.5rem;
}

.add-column-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.form-hint {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.form-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  margin-top: 0.5rem;
}

.form-checkbox input[type="checkbox"] {
  width: 1.125rem;
  height: 1.125rem;
  cursor: pointer;
}

.topbar-buttons {
  display: flex;
  gap: 0.75rem;
}

/* Modules */
.module-item {
  font-weight: 500;
  font-size: 0.875rem;
}

.module-item.active {
  background: #eff6ff;
  color: var(--primary-color);
  font-weight: 600;
  border-right: 2px solid var(--primary-color);
}

/* Sous-menu tables (sous un module ouvert) */
.module-tables {
  margin-left: 2.25rem;
  padding-left: 0.625rem;
  border-left: 2px solid var(--primary-color);
  margin-bottom: 0.5rem;
  margin-top: 0.125rem;
  padding-top: 0.125rem;
  padding-bottom: 0.125rem;
}

.table-subitem {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3rem 0.625rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
  border-radius: 0.25rem;
  margin: 1px 0;
}

.table-subitem .table-icon {
  font-size: 0.75rem;
}

.table-subitem:hover {
  background: #e0e7ff;
  color: var(--primary-color);
}

.table-subitem.active {
  background: #dbeafe;
  color: var(--primary-color);
  font-weight: 600;
}

/* Responsive */
@media (max-width: 1024px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -100%;
    z-index: 100;
    transition: left 0.3s;
  }

  .sidebar.open {
    left: 0;
  }

  .topbar {
    padding: 0 1rem;
  }

  .topbar-buttons {
    flex-direction: column;
    width: 100%;
  }

  .content-area {
    padding: 1rem;
  }

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

  .form-actions {
    flex-direction: column;
  }

  .column-selector {
    right: 1rem;
    left: 1rem;
    width: auto;
  }
}
