/* ─── Design Tokens ────────────────────────────────────────────────────────── */
:root {
  --blue:       #2563eb;
  --blue-dark:  #1d4ed8;
  --blue-light: #3b82f6;
  --bg:         #f8f9fc;
  --sidebar-bg: #ffffff;
  --border:     #e5e7eb;
  --text:       #111827;
  --muted:      #6b7280;
  --danger:     #ef4444;
  --success:    #22c55e;
  --warning:    #f59e0b;
  --info:       #3b82f6;
  --dark-card:  #1e2330;
  --dark-card-text: #e2e8f0;
  --radius:     8px;
  --radius-lg:  12px;
  --font:       'Inter', sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ─── App Shell ────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  background: var(--blue);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-logo svg { width: 18px; height: 18px; }

.sidebar-brand-name {
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
}
.sidebar-brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.sidebar-nav {
  padding: 12px 8px;
  flex: 1;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}
.sidebar-nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-nav-item:hover { background: #f3f4f6; color: var(--text); }
.sidebar-nav-item.active {
  background: var(--blue);
  color: #fff;
}
.sidebar-nav-item.active:hover {
  background: var(--blue-dark);
}

.sidebar-footer {
  padding: 12px 8px 16px;
  border-top: 1px solid var(--border);
}

/* ─── Main Wrap ────────────────────────────────────────────────────────────── */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  gap: 16px;
}

.topbar-title { font-size: 16px; font-weight: 700; }

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.topbar-tabs { display: flex; gap: 4px; }
.topbar-tab {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: all 0.15s;
}
.topbar-tab:hover { background: #f3f4f6; color: var(--text); }
.topbar-tab.active { background: #f3f4f6; color: var(--text); }

.breadcrumb { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.breadcrumb a:hover { color: var(--blue); }
.breadcrumb span { color: var(--muted); }

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
}

.page-header { margin-bottom: 24px; }
.page-title { font-size: 26px; font-weight: 800; color: var(--text); }
.page-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ─── Stats ────────────────────────────────────────────────────────────────── */
.stats-row { display: flex; gap: 16px; }
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  flex: 1;
}
.stat-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; margin-bottom: 6px; }
.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.stat-icon { width: 20px; height: 20px; color: var(--blue); }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.card-body { padding: 20px; }
.card-section-title {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.card-section-title svg { width: 16px; height: 16px; }

.dark-card {
  background: var(--dark-card);
  border-color: #2d3451;
  color: var(--dark-card-text);
}
.dark-card-header {
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid #2d3451;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dark-card-header svg { width: 14px; height: 14px; }
.dark-card-body { padding: 16px 20px; }

.two-col-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ─── Table ────────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: #f9fafb;
}
.data-table td {
  padding: 13px 20px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
.data-table tbody tr:hover td { background: #f9fafb; }

.table-footer { padding: 10px 20px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.table-actions { display: flex; gap: 4px; }

.filter-tabs { display: flex; gap: 4px; }
.filter-tab {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.filter-tab:hover { background: #f3f4f6; color: var(--text); }
.filter-tab.active { background: var(--blue); color: #fff; }

.project-row { display: flex; align-items: center; gap: 12px; }
.project-avatar {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: #e0e7ff;
  color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.project-name { font-weight: 600; font-size: 13.5px; }
.project-url { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
}
.badge svg { width: 10px; height: 10px; }
.badge-success  { background: #dcfce7; color: #16a34a; }
.badge-warning  { background: #fef9c3; color: #ca8a04; }
.badge-info     { background: #dbeafe; color: #2563eb; }
.badge-secondary { background: #f3f4f6; color: #374151; }
.badge-dark     { background: #1f2937; color: #d1d5db; }

/* ─── Toggle ───────────────────────────────────────────────────────────────── */
.toggle {
  width: 40px; height: 22px;
  border-radius: 11px;
  background: #d1d5db;
  border: none; cursor: pointer;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px; left: 3px;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle.toggle-on { background: var(--blue); }
.toggle.toggle-on::after { left: 21px; }

/* ─── Scope ────────────────────────────────────────────────────────────────── */
.scope-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
.scope-header {
  font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 8px;
}
.scope-header svg { width: 12px; height: 12px; }
.scope-item {
  display: flex; align-items: center; gap: 6px;
  background: #f9fafb; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 7px 10px;
  font-size: 12px; font-family: monospace;
  margin-bottom: 6px;
}
.scope-item svg { width: 12px; height: 12px; color: var(--muted); flex-shrink: 0; }
.scope-add-form { display: flex; gap: 6px; margin-top: 6px; }
.btn-icon-danger {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 14px; margin-left: auto;
  padding: 0 2px;
}
.btn-icon-danger:hover { color: var(--danger); }

.perm-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.perm-item:last-child { border-bottom: none; padding-bottom: 0; }
.perm-title { font-weight: 600; font-size: 13.5px; }
.perm-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* GitHub integration ──────────────────────────────────────────── */
.github-icon {
  width: 40px; height: 40px;
  background: #f3f4f6; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.github-icon svg { width: 20px; height: 20px; }
.code-badge {
  display: inline-block; background: #f3f4f6;
  border: 1px solid var(--border); border-radius: 4px;
  padding: 2px 8px; font-size: 12px; font-family: monospace;
}
.arrow-badge { font-size: 13px; color: var(--muted); margin: 0 4px; }
.flex-1 { flex: 1; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* URL rows */
.url-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid #2d3451; }
.url-row:last-child { border-bottom: none; }
.url-label { font-size: 11px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: .05em; width: 36px; }
.url-link { font-size: 13px; color: var(--blue-light); }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; border: none; cursor: pointer;
  transition: all 0.15s; white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary-outline { background: transparent; border: 1.5px solid var(--blue); color: var(--blue); }
.btn-primary-outline:hover { background: var(--blue); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }
.btn-icon { background: #f3f4f6; color: var(--muted); padding: 7px 9px; }
.btn-icon:hover { background: #e5e7eb; color: var(--text); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn.disabled, .btn:disabled { opacity: .5; pointer-events: none; }
.mb-2 { margin-bottom: 8px; }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-family: var(--font); font-size: 13.5px; color: var(--text);
  background: #fff; transition: border-color 0.15s; outline: none;
}
.form-control:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-control-sm { padding: 6px 10px; font-size: 12px; }
.form-row { margin-bottom: 4px; }
.form-row.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; cursor: pointer; }
.toggle-label input[type=checkbox] { accent-color: var(--blue); width: 16px; height: 16px; }

/* ─── Auth ─────────────────────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  background: var(--bg);
}
.auth-card {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px 36px;
  width: 100%; max-width: 420px;
  box-shadow: 0 4px 20px rgba(0,0,0,.06);
  text-align: center;
}
.auth-logo {
  width: 48px; height: 48px;
  background: var(--blue); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; margin: 0 auto 16px;
}
.auth-logo svg { width: 24px; height: 24px; }
.auth-title { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.auth-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 24px; }
.auth-form { text-align: left; }

/* ─── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: var(--radius);
  margin-bottom: 12px; font-size: 13px; font-weight: 500;
}
.alert-success { background: #dcfce7; color: #16a34a; border: 1px solid #bbf7d0; }
.alert-danger   { background: #fee2e2; color: #dc2626; border: 1px solid #fecaca; }
.alert-warning  { background: #fef9c3; color: #ca8a04; border: 1px solid #fde68a; }
.alert-info     { background: #dbeafe; color: #2563eb; border: 1px solid #bfdbfe; }
.alert-close { background: none; border: none; cursor: pointer; font-size: 16px; color: inherit; opacity: .6; }

/* ─── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--muted);
}
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; color: #d1d5db; }
.empty-state a { color: var(--blue); }

/* ─── Search ───────────────────────────────────────────────────────────────── */
.search-input {
  padding: 7px 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: 13px;
  font-family: var(--font); outline: none; width: 200px;
}
.search-input:focus { border-color: var(--blue); }

/* ─── Avatar ───────────────────────────────────────────────────────────────── */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}

/* ─── Misc ─────────────────────────────────────────────────────────────────── */
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 20px; }
.mb-4 { margin-bottom: 20px; }
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.small { font-size: 12px; }

/* ─── Client Shell ──────────────────────────────────────────────────────────── */
.client-shell { display: flex; flex-direction: column; height: 100vh; background: #f1f5f9; }

.client-topbar {
  height: 52px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; flex-shrink: 0; gap: 12px;
}
.client-topbar-left { display: flex; align-items: center; gap: 10px; }
.client-topbar-right { display: flex; align-items: center; gap: 8px; }
.client-brand { font-weight: 800; font-size: 15px; color: var(--blue); }
.client-project-name { font-size: 13px; font-weight: 600; color: var(--text); }
.client-status-text { font-size: 12px; color: var(--muted); }

.client-body { display: flex; flex: 1; overflow: hidden; }

.client-chat-panel {
  width: 380px; flex-shrink: 0;
  background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}

.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.chat-avatar {
  width: 36px; height: 36px; background: var(--blue);
  border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff;
}
.chat-avatar svg { width: 18px; height: 18px; }
.chat-name { font-weight: 700; font-size: 13.5px; }
.chat-status { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-date { text-align: center; font-size: 11px; color: var(--muted); margin: 4px 0; }
.chat-bubble {
  padding: 10px 14px; border-radius: 14px;
  font-size: 13px; max-width: 90%; line-height: 1.55;
}
.chat-bubble.assistant {
  background: #f1f5f9; color: var(--text);
  border-bottom-left-radius: 4px; align-self: flex-start;
}
.chat-bubble.user {
  background: var(--blue); color: #fff;
  border-bottom-right-radius: 4px; align-self: flex-end;
}

.suggested-prompts { padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--border); }
.prompt-chip {
  background: #f1f5f9; border: 1px solid var(--border);
  border-radius: 20px; padding: 5px 12px;
  font-size: 11.5px; font-weight: 500; color: var(--text);
  cursor: pointer; transition: all 0.15s;
}
.prompt-chip:hover { background: var(--blue); color: #fff; border-color: var(--blue); }

.chat-input-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.chat-input {
  flex: 1; padding: 9px 12px; border: 1.5px solid var(--border);
  border-radius: 9999px; font-family: var(--font); font-size: 13.5px;
  outline: none; background: #f9fafb;
}
.chat-input:focus { border-color: var(--blue); background: #fff; }

.client-preview-panel { flex: 1; display: flex; flex-direction: column; }
.preview-chrome {
  height: 44px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 12px; flex-shrink: 0;
}
.traffic-lights { display: flex; gap: 5px; }
.traffic-lights span { width: 12px; height: 12px; border-radius: 50%; }
.traffic-lights span:nth-child(1) { background: #ef4444; }
.traffic-lights span:nth-child(2) { background: #f59e0b; }
.traffic-lights span:nth-child(3) { background: #22c55e; }
.preview-url {
  flex: 1; text-align: center; font-size: 12px; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.preview-controls { display: flex; gap: 4px; margin-left: auto; }
.preview-iframe { flex: 1; border: none; width: 100%; height: 100%; }
.preview-placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); gap: 8px;
}
.preview-placeholder svg { width: 48px; height: 48px; color: #d1d5db; }

/* Dots */
.dot-green  { width: 8px; height: 8px; border-radius: 50%; background: var(--success); display: inline-block; }
.dot-orange { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); display: inline-block; }
.dot-gray   { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; display: inline-block; }
.dot-sm     { width: 6px; height: 6px; }

/* ─── Status Badges ─────────────────────────────────────────────────────────── */
.badge-draft     { background: #f3f4f6; color: #374151; }
.badge-revision  { background: #ffedd5; color: #c2410c; }
.badge-approved  { background: #dcfce7; color: #16a34a; }
.badge-published { background: #dbeafe; color: #1d4ed8; }
.badge-archived  { background: #1f2937; color: #d1d5db; }
.badge-danger    { background: #fee2e2; color: #dc2626; }

/* ─── Diff Viewer ───────────────────────────────────────────────────────────── */
.diff-viewer {
  background: #0d1117;
  color: #e6edf3;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: .8125rem;
  line-height: 1.7;
  padding: 1.25rem 1.5rem;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
  white-space: pre;
}

/* ─── Chat Thread (review detail) ───────────────────────────────────────────── */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: .5rem 0;
}
.chat-thread-msg {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
}
.chat-thread-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: var(--blue); color: #fff;
}
.chat-thread-avatar.assistant { background: #f1f5f9; color: var(--text); }
.chat-thread-avatar svg { width: 16px; height: 16px; }
.chat-thread-bubble {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 8px; padding: .65rem 1rem;
  flex: 1; font-size: .875rem; line-height: 1.55;
}
.chat-thread-bubble .role { font-weight: 700; margin-bottom: .25rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.chat-thread-bubble .content { white-space: pre-wrap; }
.chat-thread-bubble .ts { font-size: .7rem; color: var(--muted); margin-top: .25rem; }

/* ─── Typing Indicator ──────────────────────────────────────────────────────── */
.typing-indicator {
  display: inline-flex; align-items: center; gap: 4px; padding: 8px 14px;
}
.typing-indicator span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); display: inline-block;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: .5; }
  40%            { transform: scale(1);   opacity: 1; }
}

