/* =============================================================================
   CodeBridge — Main Stylesheet
   Base styles, CSS custom properties, layout, and components.
   All themes override variables declared here.
   ============================================================================= */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700;800;900&family=Exo+2:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400&family=Source+Sans+3:ital,wght@0,300;0,400;0,600;0,700;1,400&display=swap');

/* =============================================================================
   CSS Custom Properties — "Future Clean" defaults
   ============================================================================= */
:root {
  /* Backgrounds */
  --bg-primary:   #050d1a;
  --bg-secondary: #0a1628;
  --bg-card:      #0d1f38;

  /* Borders */
  --border-color: rgba(0, 212, 255, 0.15);

  /* Brand colours */
  --color-primary:   #00d4ff;
  --color-secondary: #00ff9d;
  --color-accent:    #ff6b35;

  /* Text */
  --text-primary:   #e8edf5;
  --text-secondary: #8899aa;
  --text-muted:     #556677;

  /* Typography */
  --font-heading: 'Orbitron', monospace;
  --font-body:    'Exo 2', sans-serif;

  /* Misc */
  --radius:     8px;
  --shadow:     0 4px 24px rgba(0, 0, 0, 0.3);
  --transition: 200ms ease;

  /* Layout */
  --sidebar-width: 240px;

  /* Effects */
  --glow-primary: 0 0 20px rgba(0, 212, 255, 0.3);
}

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

/* =============================================================================
   Base
   ============================================================================= */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img,
video {
  display: block;
  max-width: 100%;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  opacity: 0.85;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.3;
}

/* =============================================================================
   Layout
   ============================================================================= */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  top: 0;
  left: 0;
}

/* Scrollbar styling for sidebar */
.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  padding: 0;
}

/* Page header */
.page-header {
  padding: 24px 32px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header h2 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--text-primary);
  letter-spacing: 1px;
}

/* Content area */
.content-area {
  padding: 32px;
}

/* =============================================================================
   Sidebar Components
   ============================================================================= */
.sidebar-logo {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-logo h1 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  color: var(--color-primary);
  letter-spacing: 2px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-logo .logo-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
}

.nav-section-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-muted);
  padding: 16px 20px 8px;
  display: block;
  user-select: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition), background var(--transition), border-left-color var(--transition);
  border-left: 3px solid transparent;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.nav-item:hover,
.nav-item.active {
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  background: rgba(0, 212, 255, 0.05);
}

.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

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

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  background: rgba(0, 212, 255, 0.15);
  color: var(--color-primary);
  border: 1px solid var(--border-color);
}

.user-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

/* Hamburger (mobile only) */
.hamburger {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background var(--transition), color var(--transition);
}

.hamburger:hover {
  background: var(--bg-card);
  color: var(--color-primary);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

/* =============================================================================
   Buttons
   ============================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity var(--transition), transform var(--transition), background var(--transition), color var(--transition), box-shadow var(--transition);
  text-decoration: none;
  white-space: nowrap;
  font-family: var(--font-body);
  line-height: 1;
  user-select: none;
}

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

/* Primary */
.btn-primary {
  background: var(--color-primary);
  color: #000;
  box-shadow: var(--glow-primary);
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Secondary (outlined) */
.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

.btn-secondary:hover {
  background: rgba(0, 212, 255, 0.1);
}

/* Danger */
.btn-danger {
  background: #ff3b5c;
  color: #fff;
}

.btn-danger:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Small */
.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
}

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

/* Icon only */
.btn-icon {
  padding: 8px;
  border-radius: var(--radius);
}

/* =============================================================================
   Cards
   ============================================================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.card-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--color-primary);
  letter-spacing: 1px;
}

/* =============================================================================
   Forms
   ============================================================================= */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-control {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font-body);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  line-height: 1.5;
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.form-control::placeholder {
  color: var(--text-muted);
}

select.form-control {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238899aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

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

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.form-error {
  font-size: 0.8rem;
  color: #ff3b5c;
  margin-top: 6px;
}

/* =============================================================================
   Alerts
   ============================================================================= */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  border-left: 4px solid;
  margin-bottom: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-success {
  background: rgba(0, 255, 157, 0.1);
  border-color: var(--color-secondary);
  color: var(--color-secondary);
}

.alert-error {
  background: rgba(255, 59, 92, 0.1);
  border-color: #ff3b5c;
  color: #ff3b5c;
}

.alert-warning {
  background: rgba(255, 107, 53, 0.15);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.alert-info {
  background: rgba(0, 212, 255, 0.1);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* =============================================================================
   Badges
   ============================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-primary {
  background: rgba(0, 212, 255, 0.15);
  color: var(--color-primary);
}

.badge-success {
  background: rgba(0, 255, 157, 0.15);
  color: var(--color-secondary);
}

.badge-warning {
  background: rgba(255, 107, 53, 0.15);
  color: var(--color-accent);
}

.badge-danger {
  background: rgba(255, 59, 92, 0.15);
  color: #ff3b5c;
}

.badge-neutral {
  background: var(--bg-secondary);
  color: var(--text-muted);
}

/* =============================================================================
   Tables
   ============================================================================= */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  white-space: nowrap;
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-size: 0.9rem;
  vertical-align: middle;
}

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

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

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
  font-family: var(--font-heading);
  line-height: 1;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat-change {
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-change.positive { color: var(--color-secondary); }
.stat-change.negative { color: #ff3b5c; }

/* Projects grid */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.project-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}

.project-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-primary); /* overridden inline per project */
}

.project-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--color-primary);
}

.project-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.project-description {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* =============================================================================
   Chat Layout
   ============================================================================= */
.chat-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: calc(100vh - 73px);
  overflow: hidden;
}

/* Conversations panel */
.conversations-panel {
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-secondary);
}

.conversations-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversations-list::-webkit-scrollbar { width: 4px; }
.conversations-list::-webkit-scrollbar-track { background: transparent; }
.conversations-list::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.conversation-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 4px;
}

.conversation-item:hover,
.conversation-item.active {
  background: rgba(0, 212, 255, 0.08);
  color: var(--color-primary);
}

.conversation-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.conversation-item:hover .conversation-title,
.conversation-item.active .conversation-title {
  color: var(--color-primary);
}

.conversation-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Chat area */
.chat-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* Messages */
.message {
  display: flex;
  gap: 12px;
  max-width: 85%;
}

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

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

.message-bubble {
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.6;
}

.message-user .message-bubble {
  background: var(--color-primary);
  color: #000;
  border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

.message-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.message-user .message-time {
  text-align: right;
}

.message-assistant .message-time {
  text-align: left;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(0, 212, 255, 0.15);
  color: var(--color-primary);
  border: 1px solid var(--border-color);
}

/* Chat input */
.chat-input-area {
  padding: 20px 24px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  resize: none;
  max-height: 200px;
  min-height: 52px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  line-height: 1.5;
  overflow-y: auto;
}

.chat-textarea:focus {
  border-color: var(--color-primary);
}

.chat-textarea::placeholder {
  color: var(--text-muted);
}

/* =============================================================================
   Code Blocks in Chat
   ============================================================================= */
.message-bubble pre {
  background: #000;
  border-radius: 8px;
  padding: 16px;
  margin: 12px 0;
  overflow-x: auto;
  position: relative;
  border: 1px solid var(--border-color);
}

/* Pre with header has top border-radius removed */
.message-bubble .code-block-header + pre {
  border-top: none;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.message-bubble code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
}

.message-bubble p code {
  background: rgba(0, 212, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--color-primary);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  border-radius: 8px 8px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.copy-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  transition: color var(--transition), background var(--transition);
  font-family: var(--font-body);
}

.copy-btn:hover {
  color: var(--color-primary);
  background: rgba(0, 212, 255, 0.08);
}

/* =============================================================================
   Tabs
   ============================================================================= */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  padding: 0 32px;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: 14px 20px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  user-select: none;
  flex-shrink: 0;
}

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

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-content {
  display: none;
}

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

/* =============================================================================
   Context Editor
   ============================================================================= */
.context-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.context-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
}

/* =============================================================================
   Modal
   ============================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  display: none;
  padding: 20px;
}

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

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 32px;
  max-width: 500px;
  width: 90%;
  box-shadow: var(--shadow);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-title {
  font-family: var(--font-heading);
  color: var(--color-primary);
  font-size: 1rem;
  letter-spacing: 1px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color var(--transition);
  line-height: 1;
}

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

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

/* =============================================================================
   Loading / Spinners
   ============================================================================= */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
  animation: pulse-dot 1.4s ease infinite;
  display: inline-block;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes pulse-dot {
  0%, 80%, 100% {
    opacity: 0.25;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* =============================================================================
   Admin Layout
   ============================================================================= */
.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.admin-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
}

.admin-section h3 {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  color: var(--color-primary);
  letter-spacing: 1px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

/* =============================================================================
   FTP / File Manager UI
   ============================================================================= */
.ftp-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  height: 500px;
}

.ftp-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ftp-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.ftp-file-list {
  flex: 1;
  overflow-y: auto;
}

.ftp-file-list::-webkit-scrollbar { width: 4px; }
.ftp-file-list::-webkit-scrollbar-track { background: transparent; }
.ftp-file-list::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.ftp-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-primary);
  transition: background var(--transition);
  user-select: none;
}

.ftp-file-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.ftp-file-item.selected {
  background: rgba(0, 212, 255, 0.08);
  color: var(--color-primary);
}

/* =============================================================================
   Utility Classes
   ============================================================================= */

/* Text colour */
.text-primary   { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted     { color: var(--text-muted) !important; }
.text-accent    { color: var(--color-accent) !important; }
.text-success   { color: var(--color-secondary) !important; }
.text-danger    { color: #ff3b5c !important; }
.text-brand     { color: var(--color-primary) !important; }

/* Spacing — margin-top */
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }

/* Spacing — margin-bottom */
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }

/* Spacing — padding */
.p-1 { padding: 4px; }
.p-2 { padding: 8px; }
.p-3 { padding: 16px; }
.p-4 { padding: 24px; }

/* Flexbox helpers */
.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.items-end      { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.flex-1         { flex: 1; }
.flex-wrap      { flex-wrap: wrap; }

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.gap-4 { gap: 24px; }

/* Display */
.hidden { display: none !important; }
.block  { display: block; }
.inline-flex { display: inline-flex; }

/* Sizing */
.w-full { width: 100%; }

/* Typography */
.text-sm    { font-size: 0.85rem; }
.text-xs    { font-size: 0.75rem; }
.font-bold  { font-weight: 700; }
.font-mono  { font-family: 'JetBrains Mono', monospace; }
.uppercase  { text-transform: uppercase; }
.truncate   {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Misc */
.rounded { border-radius: var(--radius); }
.border   { border: 1px solid var(--border-color); }
.shadow   { box-shadow: var(--shadow); }

/* Divider */
.divider {
  height: 1px;
  background: var(--border-color);
  margin: 20px 0;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.85rem;
}

/* Progress bar */
.progress {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 100px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: 100px;
  transition: width 300ms ease;
}

/* Tooltip */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.75rem;
  padding: 5px 10px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition);
  z-index: 500;
}

[data-tooltip]:hover::after {
  opacity: 1;
}

/* =============================================================================
   Responsive — Mobile (< 768px)
   ============================================================================= */
@media (max-width: 768px) {
  /* Sidebar off-canvas */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 300ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Overlay visible when sidebar open */
  .sidebar.open ~ .sidebar-overlay,
  .sidebar-overlay.visible {
    display: block;
  }

  /* Reset main margin */
  .main-content {
    margin-left: 0;
  }

  /* Show hamburger */
  .hamburger {
    display: flex;
  }

  /* Page header left padding for hamburger */
  .page-header {
    padding-left: 64px;
  }

  /* Content area padding */
  .content-area {
    padding: 20px 16px;
  }

  /* Chat layout: hide conversations panel, full width */
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .conversations-panel {
    display: none;
  }

  /* Single column forms */
  .form-row {
    grid-template-columns: 1fr;
  }

  /* Single column projects */
  .projects-grid {
    grid-template-columns: 1fr;
  }

  /* Single column context */
  .context-grid {
    grid-template-columns: 1fr;
  }

  /* Single column admin */
  .admin-grid {
    grid-template-columns: 1fr;
  }

  /* FTP layout stacked */
  .ftp-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .ftp-panel {
    height: 280px;
  }

  /* Stats grid */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Messages wider */
  .message {
    max-width: 95%;
  }

  /* Tabs padding */
  .tabs {
    padding: 0 16px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-number {
    font-size: 1.6rem;
  }

  .modal {
    padding: 20px;
  }
}
