:root {
  --bg-color: #0b0f19;
  --panel-bg: rgba(20, 26, 45, 0.6);
  --panel-border: rgba(255, 255, 255, 0.08);
  --primary-color: #7c4dff;
  --primary-hover: #9e75ff;
  --secondary-color: #2c3550;
  --secondary-hover: #3d496e;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  font-family: var(--font-sans);
  background: radial-gradient(circle at 50% 50%, #1e1b4b 0%, #09090b 100%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  padding: 20px;
}

/* Glassmorphism container */
.glass-container {
  display: flex;
  width: 100%;
  max-width: 1400px;
  height: 90vh;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 24px;
  border: 1px border var(--panel-border);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

/* Sidebar navigation */
.sidebar {
  width: 280px;
  background: rgba(10, 12, 22, 0.85);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  padding: 30px 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
}

.brain-icon {
  font-size: 28px;
  background: linear-gradient(135deg, #7c4dff, #00e5ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: pulse 2s infinite alternate;
}

.logo h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item i {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

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

.nav-item.active {
  background: var(--primary-color);
  color: #fff;
  box-shadow: 0 0 16px rgba(124, 77, 255, 0.4);
}

.sidebar-footer {
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot.active {
  background-color: var(--success-color);
  box-shadow: 0 0 8px var(--success-color);
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-header {
  padding: 30px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.top-header h1 {
  font-size: 24px;
  font-weight: 600;
}

.api-status {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success-color);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

/* Tab contents */
.tab-content {
  padding: 30px;
  overflow-y: auto;
  flex-grow: 1;
  display: none;
}

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

/* Dashboard Overview Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  transition: transform 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-4px);
}

.stat-icon {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 22px;
}

.stat-icon.purple {
  background: rgba(124, 77, 255, 0.15);
  color: #a885ff;
}

.stat-icon.blue {
  background: rgba(0, 229, 255, 0.15);
  color: #33ecff;
}

.stat-icon.green {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.stat-info .stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-info h3 {
  font-size: 28px;
  font-weight: 700;
  margin-top: 4px;
}

.welcome-box {
  background: linear-gradient(135deg, rgba(124, 77, 255, 0.1) 0%, rgba(0, 229, 255, 0.05) 100%);
  border: 1px solid rgba(124, 77, 255, 0.15);
  border-radius: 16px;
  padding: 30px;
}

.welcome-box h2 {
  font-size: 20px;
  margin-bottom: 12px;
}

.welcome-box p {
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Card components */
.card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  overflow: hidden;
}

.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.flex-header {
  justify-content: space-between;
}

.card-body {
  padding: 24px;
}

.mt-20 {
  margin-top: 20px;
}

/* Forms */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input, .form-group textarea {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 16px;
  color: #fff;
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.3s;
}

.form-group input:focus, .form-group textarea:focus {
  border-color: var(--primary-color);
}

.form-group small {
  font-size: 11px;
  color: var(--text-secondary);
}

.btn {
  background: var(--secondary-color);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

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

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

.btn-danger {
  background-color: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background-color: rgba(239, 68, 68, 0.3);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
}

.w-100 {
  width: 100%;
  justify-content: center;
}

/* Tables */
.table-container {
  overflow-x: auto;
}

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

table th {
  padding: 14px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--panel-border);
}

table td {
  padding: 14px;
  font-size: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

code {
  background: rgba(124, 77, 255, 0.15);
  color: #a885ff;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
}

/* Simulator Layout */
.simulator-layout {
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: 20px;
  height: calc(90vh - 150px);
}

.chat-wrapper {
  background: rgba(10, 12, 22, 0.5);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(10, 12, 22, 0.8);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0084ff, #00c6ff);
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  font-size: 14px;
  color: white;
}

.chat-user-info h4 {
  font-size: 15px;
  font-weight: 600;
}

.chat-user-info .status {
  font-size: 11px;
  color: var(--success-color);
}

.chat-messages {
  flex-grow: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  display: flex;
  max-width: 75%;
}

.message.user {
  align-self: flex-end;
}

.message.bot {
  align-self: flex-start;
}

.message.system {
  align-self: center;
  max-width: 90%;
  font-size: 12px;
  color: var(--text-secondary);
}

.message .bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
}

.message.user .bubble {
  background-color: #0084ff;
  color: white;
  border-bottom-right-radius: 4px;
}

.message.bot .bubble {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message.system .bubble {
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  text-align: center;
}

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--panel-border);
  background: rgba(10, 12, 22, 0.8);
}

.chat-input-area form {
  display: flex;
  gap: 10px;
}

.chat-input-area input {
  flex-grow: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 12px 20px;
  color: white;
  outline: none;
  font-family: var(--font-sans);
}

.chat-input-area input:focus {
  border-color: #0084ff;
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background-color: #0084ff;
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.2s;
}

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

/* Diagnostics trace logs */
.diagnostics-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.trace-logs {
  background: #05070c;
  border-radius: 10px;
  padding: 14px;
  height: 250px;
  overflow-y: auto;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-entry {
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  line-height: 1.4;
}

.log-entry.system { color: #888; }
.log-entry.script { color: #10b981; }
.log-entry.openai { color: #818cf8; }
.log-entry.tool { color: #f59e0b; }

/* Animations */
@keyframes pulse {
  0% { transform: scale(1); filter: drop-shadow(0 0 2px rgba(0,229,255,0.4)); }
  100% { transform: scale(1.05); filter: drop-shadow(0 0 10px rgba(124,77,255,0.8)); }
}

/* Responsive Mobile Styles */
@media (max-width: 992px) {
  body {
    padding: 0;
  }

  .glass-container {
    height: 100vh;
    border-radius: 0;
    border: none;
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    height: 100vh;
    z-index: 1000;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.8);
    background: #0a0c16;
  }

  .sidebar.show-sidebar {
    left: 0;
  }

  #mobile-menu-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  .top-header {
    padding: 15px 20px;
  }

  .tab-content {
    padding: 20px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .form-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
  }

  .form-group {
    grid-column: span 1 !important;
  }

  .form-actions {
    grid-column: span 1 !important;
  }

  .simulator-layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow-y: visible;
  }

  .chat-wrapper {
    height: 500px;
  }

  .diagnostics-panel {
    margin-top: 20px;
    height: 400px;
  }
  
  .table-container table {
    width: 100%;
    min-width: 600px;
  }
}

@media (max-width: 480px) {
  .top-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .top-header .header-actions {
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }

  .welcome-box {
    padding: 20px;
  }

  .welcome-box h2 {
    font-size: 18px;
  }
}

/* Period filter button active styling */
.filter-period.active {
  background: var(--primary-color) !important;
  color: #fff !important;
  box-shadow: 0 0 12px rgba(124, 77, 255, 0.4);
  border-color: var(--primary-color) !important;
}
