/* ===== Design System ===== */
:root {
  --primary: #4a90d9;
  --primary-dark: #357abd;
  --primary-light: #e8f0fe;
  --secondary: #6c757d;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #17a2b8;
  --dark: #1a1a2e;
  --light: #f8f9fa;
  --white: #ffffff;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 6px;
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --ai-panel-width: 360px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--light);
  line-height: 1.5;
}

/* ===== Layout ===== */
.app-layout {
  display: flex;
  height: 100vh;
}
.sidebar {
  width: var(--sidebar-width);
  background: var(--dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s;
}
.sidebar-header {
  padding: 16px 20px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-header .logo { color: var(--primary); }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 13px;
  transition: all 0.2s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: var(--white); }
.sidebar-nav a.active { background: rgba(74,144,217,0.2); color: var(--primary); border-right: 3px solid var(--primary); }
.sidebar-nav .nav-section {
  padding: 8px 20px 4px;
  font-size: 11px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.5px;
}
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12px;
  color: rgba(255,255,255,0.4);
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar .breadcrumb { font-size: 13px; color: var(--text-muted); }

.content-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.ai-panel {
  width: var(--ai-panel-width);
  background: var(--white);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.3s;
}
.ai-panel.collapsed { width: 0; overflow: hidden; }
.ai-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 13px;
}
.ai-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}
.ai-panel-input {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.ai-panel-input input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.ai-msg { margin-bottom: 12px; font-size: 13px; line-height: 1.5; }
.ai-msg.user { text-align: right; }
.ai-msg .bubble {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 12px;
  max-width: 90%;
  text-align: left;
}
.ai-msg.user .bubble { background: var(--primary); color: var(--white); }
.ai-msg.assistant .bubble { background: var(--light); color: var(--text); }

/* ===== Login ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--dark) 0%, #16213e 100%);
}
.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--dark);
}
.login-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 13px;
}

/* ===== Cards ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 20px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color 0.2s;
  background: var(--white);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,144,217,0.15); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: var(--white); }
.btn-secondary:hover:not(:disabled) { background: #5a6268; }
.btn-success { background: var(--success); color: var(--white); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--light); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }
.btn-group { display: flex; gap: 8px; }

/* ===== Tables ===== */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.data-table th {
  background: var(--light);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
}
.data-table th:hover { background: #e9ecef; }
.data-table th.sorted-asc::after { content: ' ▲'; font-size: 10px; }
.data-table th.sorted-desc::after { content: ' ▼'; font-size: 10px; }
.data-table tbody tr:hover { background: var(--primary-light); }

/* ===== Wizard ===== */
.wizard-steps {
  display: flex;
  align-items: center;
  padding: 0 20px;
  margin-bottom: 24px;
  gap: 0;
}
.wizard-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.wizard-step .step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  border: 2px solid var(--border);
  background: var(--white);
  flex-shrink: 0;
}
.wizard-step.active .step-num {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}
.wizard-step.active { color: var(--primary); font-weight: 600; }
.wizard-step.completed .step-num {
  background: var(--success);
  border-color: var(--success);
  color: var(--white);
}
.wizard-step.completed { color: var(--success); }
.wizard-connector {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 8px;
  min-width: 20px;
}
.wizard-connector.active { background: var(--primary); }
.wizard-connector.completed { background: var(--success); }
.wizard-body { min-height: 400px; }
.wizard-footer {
  display: flex;
  justify-content: space-between;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--white);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== Badges & Tags ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-success { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-secondary { background: #e2e3e5; color: #383d41; }

/* ===== Alerts ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  color: var(--white);
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease;
  max-width: 360px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== Spinner ===== */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
.spinner-lg { width: 40px; height: 40px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 40px; }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { margin-bottom: 8px; color: var(--text); }

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  margin-top: 16px;
}
.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.pagination button.active { background: var(--primary); color: var(--white); border-color: var(--primary); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-bar input, .filter-bar select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.search-input {
  position: relative;
}
.search-input input { padding-left: 32px; width: 260px; }

/* ===== Drag & Drop zones ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  transition: all 0.2s;
  min-height: 80px;
}
.drop-zone.dragover { border-color: var(--primary); background: var(--primary-light); }
.draggable {
  cursor: grab;
  padding: 6px 12px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 2px;
}
.draggable:active { cursor: grabbing; }

/* ===== Utilities ===== */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }
.p-md { padding: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 600; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 20px; font-weight: 600; }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== Code/Script Viewer ===== */
.code-viewer {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px;
  border-radius: var(--radius);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { position: fixed; z-index: 100; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .ai-panel { display: none; }
  :root { --sidebar-width: 220px; }
}
