:root {
  --bg-dark: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-card-hover: rgba(51, 65, 85, 0.8);
  --border-color: rgba(255, 255, 255, 0.1);
  --primary-accent: #6366f1;
  --primary-hover: #4f46e5;
  --secondary-accent: #ec4899;
  --cyan-accent: #06b6d4;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-brand: 'Outfit', sans-serif;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-glow: 0 8px 32px 0 rgba(99, 102, 241, 0.25);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(236, 72, 153, 0.15) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
}

.app-container {
  display: flex;
  width: 100vw;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.logo-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-accent), var(--secondary-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-brand);
  font-size: 1.5rem;
  font-weight: 800;
  color: white;
  box-shadow: var(--shadow-glow);
}

.brand-text h1 {
  font-family: var(--font-brand);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.badge-accent {
  background: rgba(236, 72, 153, 0.2);
  color: #f472b6;
  border-color: rgba(236, 72, 153, 0.4);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.4);
}

.badge-success {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}

.badge-muted {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  border-color: var(--border-color);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.2), rgba(99, 102, 241, 0.05));
  color: var(--text-main);
  border-left: 3px solid var(--primary-accent);
}

.sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.system-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.header-title h2 {
  font-family: var(--font-brand);
  font-size: 1.8rem;
  font-weight: 700;
}

.header-title p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
}

/* Buttons */
.btn {
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-accent), var(--primary-hover));
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

/* Tab Contents */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* Cards */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

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

.count-pill {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

/* Data Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th, .data-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem !important;
  color: var(--text-muted);
}

.tag-list {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.75rem;
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  padding: 2px 6px;
  border-radius: 4px;
}

.chip {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
}

.chip:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

.chip.active {
  background: rgba(99, 102, 241, 0.25);
  color: #c7d2fe;
  border-color: rgba(99, 102, 241, 0.5);
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  margin-right: 6px;
  user-select: none;
}

.dragging {
  opacity: 0.4;
}

.drop-target-before {
  border-top: 2px solid var(--primary-accent) !important;
}

.drop-target-after {
  border-bottom: 2px solid var(--primary-accent) !important;
}

.field-drop-zone {
  min-height: 12px;
  border-radius: 6px;
  transition: background-color 0.1s ease;
}

.field-drop-zone.drop-zone-active {
  background: rgba(99, 102, 241, 0.08);
}

/* Dynamic Form Preview Styling */
.form-selector-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.form-preview-container {
  margin-top: 1.5rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem;
}

.form-section-block {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
}

.section-title {
  font-family: var(--font-brand);
  font-size: 1.25rem;
  color: #c7d2fe;
  margin-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary-accent);
  padding-bottom: 0.25rem;
  display: inline-block;
}

.form-field-group {
  margin-bottom: 1.25rem;
  transition: all 0.25s ease;
}

.form-field-group.hidden,
.form-section-block.hidden {
  display: none !important;
}

.form-field-group.field-disabled {
  opacity: 0.5;
}

.form-field-group.field-disabled .form-control,
.form-field-group.field-disabled input,
.form-field-group.field-disabled select,
.form-field-group.field-disabled textarea {
  cursor: not-allowed;
}

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

/* Controls */
.form-control {
  width: 100%;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-accent);
}

.inline-select {
  width: auto;
  min-width: 260px;
}

.query-toolbar {
  display: flex;
  gap: 1rem;
  flex: 1;
}

.search-input-group {
  display: flex;
  gap: 0.5rem;
  flex: 1;
}

/* Option Choices (Radio/Checkboxes) */
.options-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option-item-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 540px;
  max-height: 85vh;
  padding: 2rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-card.modal-lg {
  max-width: 800px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-shrink: 0;
}

/* The scrollable middle region between the fixed header and footer: .modal-body is
   used directly by the schema/manage-access modals, .modal-scroll-body wraps the
   field list in form-based modals (whose <form> becomes a flex column via .modal-form
   so this can be its non-footer flex:1 child). Keeps the header and Save/Cancel
   buttons pinned in view while only the field content scrolls. */
.modal-body,
.modal-scroll-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.modal-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.form-row {
  display: flex;
  gap: 1rem;
}

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

.form-group.col {
  flex: 1;
}

.textarea-mono {
  font-family: monospace;
  font-size: 0.85rem;
}

.auth-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary-accent);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  text-decoration: underline;
}

.center-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100vw;
  padding: 2rem;
}
