/* ==========================================================================
   Sales Hub — CRM Panel Stylesheet
   Main CSS for HubSpot CRM Extension panels and dashboard views.
   Pure CSS3, no preprocessors, no frameworks.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Custom Properties (Theming)
   -------------------------------------------------------------------------- */
:root {
  /* Brand palette */
  --primary: #FF7A00;
  --primary-light: #ff9633;
  --primary-dark: #cc6200;
  --secondary: #2c3e50;
  --secondary-light: #34495e;

  /* Semantic colors */
  --success: #27ae60;
  --success-light: #2ecc71;
  --danger: #e74c3c;
  --danger-light: #ff6b6b;
  --warning: #f39c12;
  --warning-light: #f1c40f;
  --info: #3498db;
  --info-light: #5dade2;

  /* Neutrals */
  --white: #ffffff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --black: #000000;

  /* Surfaces */
  --bg-body: var(--gray-50);
  --bg-card: var(--white);
  --bg-sidebar: var(--secondary);
  --border-color: var(--gray-200);
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted: var(--gray-400);
  --text-inverse: var(--white);

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 2rem;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 8px 10px -6px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 350ms ease;

  /* Layout */
  --sidebar-width: 240px;
  --header-height: 60px;
  --container-max: 1400px;
}

/* --------------------------------------------------------------------------
   2. Reset / Normalize
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

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

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

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

a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

ul, ol {
  list-style: none;
}

/* --------------------------------------------------------------------------
   3. Layout — Sidebar + Main Content
   -------------------------------------------------------------------------- */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-inverse);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition-base);
}

.sidebar-header {
  padding: var(--space-6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--primary);
}

.sidebar-nav {
  padding: var(--space-4) 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  color: rgba(255, 255, 255, 0.7);
  transition: all var(--transition-fast);
  font-size: var(--font-size-sm);
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  color: var(--white);
  background: rgba(255, 255, 255, 0.1);
  text-decoration: none;
}

.sidebar-nav a.active {
  border-left: 3px solid var(--primary);
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
}

.page-header {
  background: var(--white);
  border-bottom: 1px solid var(--border-color);
  padding: var(--space-4) var(--space-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header h1 {
  font-size: var(--font-size-xl);
  font-weight: 600;
}

.page-body {
  padding: var(--space-8);
  max-width: var(--container-max);
}

/* Responsive grid system */
.grid {
  display: grid;
  gap: var(--space-6);
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* Flexbox utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

/* --------------------------------------------------------------------------
   4. Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--transition-fast);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

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

.card-header h2,
.card-header h3 {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.card-body {
  padding: var(--space-6);
}

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-color);
  background: var(--gray-50);
}

/* --------------------------------------------------------------------------
   5. KPI Cards
   -------------------------------------------------------------------------- */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card__label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-bottom: var(--space-2);
}

.kpi-card__value {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-card__trend {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-2);
  font-size: var(--font-size-sm);
  font-weight: 500;
}

.kpi-card__trend--up {
  color: var(--success);
}

.kpi-card__trend--down {
  color: var(--danger);
}

.kpi-card__trend--neutral {
  color: var(--text-muted);
}

/* Trend arrow via pseudo-element */
.kpi-card__trend--up::before { content: "\25B2 "; font-size: 0.7em; }
.kpi-card__trend--down::before { content: "\25BC "; font-size: 0.7em; }

/* --------------------------------------------------------------------------
   6. Tables
   -------------------------------------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.table {
  width: 100%;
  font-size: var(--font-size-sm);
}

.table th,
.table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.table th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: var(--font-size-xs);
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 1;
}

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

/* Striped variant */
.table-striped tbody tr:nth-child(even) {
  background: var(--gray-50);
}

/* Hover variant */
.table-hover tbody tr {
  transition: background var(--transition-fast);
}

.table-hover tbody tr:hover {
  background: rgba(255, 122, 0, 0.04);
}

/* Sortable column headers */
.table th[data-sort] {
  cursor: pointer;
  user-select: none;
}

.table th[data-sort]::after {
  content: " \2195";
  opacity: 0.3;
}

.table th[data-sort="asc"]::after {
  content: " \25B2";
  opacity: 1;
}

.table th[data-sort="desc"]::after {
  content: " \25BC";
  opacity: 1;
}

/* --------------------------------------------------------------------------
   7. Forms
   -------------------------------------------------------------------------- */
.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
}

.form-label.required::after {
  content: " *";
  color: var(--danger);
}

.form-control {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

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

.form-control:disabled,
.form-control[readonly] {
  background: var(--gray-100);
  cursor: not-allowed;
  opacity: 0.7;
}

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

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

select.form-control {
  appearance: none;
  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='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

.form-text {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.form-error {
  color: var(--danger);
  font-size: var(--font-size-xs);
  margin-top: var(--space-1);
}

.form-control.is-invalid {
  border-color: var(--danger);
}

.form-control.is-valid {
  border-color: var(--success);
}

/* Checkbox / Radio */
.form-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  margin-top: 0.2em;
  accent-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: 1.5;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

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

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

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

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

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

.btn-danger {
  background: var(--danger);
  color: var(--white);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #c0392b;
}

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

.btn-success:hover {
  background: #219a52;
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--gray-300);
}

.btn-outline:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

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

.btn-ghost:hover {
  background: rgba(255, 122, 0, 0.08);
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-xs);
}

.btn-lg {
  padding: var(--space-3) var(--space-8);
  font-size: var(--font-size-lg);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-group {
  display: inline-flex;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.btn-group .btn:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.btn-group .btn + .btn {
  margin-left: -1px;
}

/* --------------------------------------------------------------------------
   8. Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  line-height: 1.5;
  white-space: nowrap;
}

.badge-success {
  background: rgba(39, 174, 96, 0.12);
  color: var(--success);
}

.badge-warning {
  background: rgba(243, 156, 18, 0.12);
  color: var(--warning);
}

.badge-danger {
  background: rgba(231, 76, 60, 0.12);
  color: var(--danger);
}

.badge-info {
  background: rgba(52, 152, 219, 0.12);
  color: var(--info);
}

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

.badge-neutral {
  background: var(--gray-100);
  color: var(--text-secondary);
}

/* Dot indicator badges */
.badge-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: var(--space-1);
  display: inline-block;
}

.badge-dot.badge-success::before { background: var(--success); }
.badge-dot.badge-warning::before { background: var(--warning); }
.badge-dot.badge-danger::before { background: var(--danger); }

/* --------------------------------------------------------------------------
   9. Pipeline / Kanban Board
   -------------------------------------------------------------------------- */
.pipeline {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  padding-bottom: var(--space-4);
  -webkit-overflow-scrolling: touch;
}

.pipeline-stage {
  flex: 0 0 280px;
  background: var(--gray-100);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
}

.pipeline-stage__header {
  padding: var(--space-4);
  font-weight: 600;
  font-size: var(--font-size-sm);
  border-bottom: 2px solid var(--primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.pipeline-stage__count {
  background: var(--gray-300);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  padding: 0 var(--space-2);
  font-size: var(--font-size-xs);
}

.pipeline-stage__total {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.pipeline-stage__body {
  padding: var(--space-3);
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Drag-over visual feedback */
.pipeline-stage.drag-over {
  background: rgba(255, 122, 0, 0.08);
  outline: 2px dashed var(--primary);
  outline-offset: -2px;
}

.pipeline-card {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  cursor: grab;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.pipeline-card:active {
  cursor: grabbing;
}

.pipeline-card:hover {
  box-shadow: var(--shadow-md);
}

.pipeline-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}

.pipeline-card__name {
  font-weight: 600;
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-1);
}

.pipeline-card__company {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.pipeline-card__amount {
  font-weight: 700;
  color: var(--primary);
  font-size: var(--font-size-sm);
}

.pipeline-card__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-2);
  font-size: var(--font-size-xs);
}

/* Staleness indicators */
.pipeline-card--stale {
  border-left: 3px solid var(--warning);
}

.pipeline-card--critical {
  border-left: 3px solid var(--danger);
}

/* --------------------------------------------------------------------------
   10. Leaderboard
   -------------------------------------------------------------------------- */
.leaderboard {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-color);
  transition: background var(--transition-fast);
}

.leaderboard-row:last-child {
  border-bottom: none;
}

.leaderboard-row:hover {
  background: var(--gray-50);
}

.rank {
  font-size: var(--font-size-lg);
  font-weight: 700;
  min-width: 32px;
  text-align: center;
  color: var(--text-muted);
}

/* Top 3 get special treatment */
.leaderboard-row:nth-child(1) .rank { color: #FFD700; }
.leaderboard-row:nth-child(2) .rank { color: #C0C0C0; }
.leaderboard-row:nth-child(3) .rank { color: #CD7F32; }

.leaderboard-row__info {
  flex: 1;
  min-width: 0;
}

.leaderboard-row__name {
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.leaderboard-row__detail {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.leaderboard-row__value {
  font-weight: 700;
  font-size: var(--font-size-lg);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   11. Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border-color);
  gap: 0;
  overflow-x: auto;
}

.tab-item {
  padding: var(--space-3) var(--space-5);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

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

.tab-item.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.tab-content {
  display: none;
  padding: var(--space-6) 0;
}

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

/* --------------------------------------------------------------------------
   12. Modal
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(20px) scale(0.95);
  transition: transform var(--transition-base);
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: var(--font-size-xl);
  cursor: pointer;
  color: var(--text-muted);
  padding: var(--space-1);
  line-height: 1;
  transition: color var(--transition-fast);
}

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

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* --------------------------------------------------------------------------
   13. Alerts
   -------------------------------------------------------------------------- */
.alert {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.alert-success {
  background: rgba(39, 174, 96, 0.08);
  border: 1px solid rgba(39, 174, 96, 0.2);
  color: #1e8449;
}

.alert-danger {
  background: rgba(231, 76, 60, 0.08);
  border: 1px solid rgba(231, 76, 60, 0.2);
  color: #c0392b;
}

.alert-warning {
  background: rgba(243, 156, 18, 0.08);
  border: 1px solid rgba(243, 156, 18, 0.2);
  color: #d68910;
}

.alert-info {
  background: rgba(52, 152, 219, 0.08);
  border: 1px solid rgba(52, 152, 219, 0.2);
  color: #2874a6;
}

.alert-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  font-size: var(--font-size-lg);
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  line-height: 1;
}

.alert-dismiss:hover {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   14. Pagination
   -------------------------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  justify-content: center;
  padding: var(--space-4) 0;
}

.pagination button,
.pagination a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 var(--space-2);
  font-size: var(--font-size-sm);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.pagination button:hover,
.pagination a:hover {
  background: var(--gray-50);
  border-color: var(--primary);
  color: var(--primary);
}

.pagination .active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

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

.pagination-info {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin: 0 var(--space-4);
}

/* --------------------------------------------------------------------------
   15. Loading Spinner
   -------------------------------------------------------------------------- */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Full-page loader */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  z-index: 2000;
}

.loading-overlay .spinner {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

/* --------------------------------------------------------------------------
   16. Avatar / Initials
   -------------------------------------------------------------------------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--white);
  background: var(--primary);
  flex-shrink: 0;
  overflow: hidden;
  text-transform: uppercase;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: var(--font-size-xs);
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: var(--font-size-lg);
}

.avatar-xl {
  width: 64px;
  height: 64px;
  font-size: var(--font-size-2xl);
}

/* Avatar stack */
.avatar-group {
  display: flex;
}

.avatar-group .avatar {
  border: 2px solid var(--white);
  margin-left: -8px;
}

.avatar-group .avatar:first-child {
  margin-left: 0;
}

/* --------------------------------------------------------------------------
   17. Progress Bar
   -------------------------------------------------------------------------- */
.progress {
  width: 100%;
  height: 8px;
  background: var(--gray-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

.progress-bar--success { background: var(--success); }
.progress-bar--danger { background: var(--danger); }
.progress-bar--warning { background: var(--warning); }
.progress-bar--info { background: var(--info); }

.progress-lg {
  height: 16px;
}

.progress-sm {
  height: 4px;
}

/* Progress with label */
.progress-labeled {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.progress-labeled .progress {
  flex: 1;
}

.progress-labeled__value {
  font-size: var(--font-size-sm);
  font-weight: 600;
  min-width: 40px;
  text-align: right;
}

/* --------------------------------------------------------------------------
   18. Tooltip
   -------------------------------------------------------------------------- */
[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  background: var(--gray-800);
  color: var(--white);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
  z-index: 500;
}

[data-tooltip]::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--gray-800);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
  z-index: 500;
}

[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
  opacity: 1;
  visibility: visible;
}

/* --------------------------------------------------------------------------
   19. Toast Notifications
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 300px;
  max-width: 420px;
  pointer-events: auto;
  animation: slideInRight 0.3s ease;
  border-left: 4px solid var(--gray-400);
  font-size: var(--font-size-sm);
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-danger { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-info { border-left-color: var(--info); }

.toast.removing {
  animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* --------------------------------------------------------------------------
   20. Autosave Indicator
   -------------------------------------------------------------------------- */
.autosave-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  padding: var(--space-1) var(--space-2);
}

.autosave-indicator--saving { color: var(--warning); }
.autosave-indicator--saved { color: var(--success); }
.autosave-indicator--error { color: var(--danger); }

.autosave-indicator__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.autosave-indicator--saving .autosave-indicator__dot {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* --------------------------------------------------------------------------
   21. Utility Classes
   -------------------------------------------------------------------------- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.text-lg { font-size: var(--font-size-lg); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-mono { font-family: var(--font-mono); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }
.visible { visibility: visible; }
.invisible { visibility: hidden; }

/* --------------------------------------------------------------------------
   22. Responsive Breakpoints
   -------------------------------------------------------------------------- */

/* Tablet and below (< 1024px) */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }

  .page-body {
    padding: var(--space-6);
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    width: 280px;
    z-index: 200;
  }

  /* Overlay when sidebar is open on mobile */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 150;
    display: none;
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .main-content {
    margin-left: 0;
  }

  .page-header {
    padding: var(--space-3) var(--space-4);
  }

  .page-body {
    padding: var(--space-4);
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .pipeline {
    flex-direction: column;
  }

  .pipeline-stage {
    flex: none;
    width: 100%;
    max-height: none;
  }

  .modal {
    max-width: 100%;
    margin: var(--space-4);
    max-height: calc(100vh - var(--space-8));
  }

  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
  }

  .toast {
    min-width: auto;
    max-width: none;
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

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

/* --------------------------------------------------------------------------
   23. Print Styles
   -------------------------------------------------------------------------- */
@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  body {
    font-size: 12pt;
    line-height: 1.4;
  }

  .sidebar,
  .page-header,
  .toast-container,
  .modal-overlay,
  .btn,
  .pagination,
  .spinner,
  .loading-overlay,
  .tabs {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
  }

  .card {
    border: 1px solid #ccc;
    break-inside: avoid;
  }

  .table th,
  .table td {
    border: 1px solid #ccc;
    padding: 4px 8px;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666 !important;
  }

  @page {
    margin: 1.5cm;
  }
}

/* --------------------------------------------------------------------------
   24. Dark Mode
   -------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-body: #0f1419;
    --bg-card: #1a2332;
    --bg-sidebar: #0d1117;
    --border-color: #2d3748;
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --gray-50: #1a2332;
    --gray-100: #1e293b;
    --gray-200: #2d3748;
    --gray-300: #4a5568;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  }

  .form-control {
    background: var(--gray-100);
    border-color: var(--gray-300);
    color: var(--text-primary);
  }

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

  .toast {
    background: var(--bg-card);
  }

  .table th {
    background: var(--gray-100);
  }

  .btn-outline {
    color: var(--text-primary);
    border-color: var(--gray-300);
  }

  .btn-outline:hover {
    background: var(--gray-100);
  }

  .pipeline-card {
    background: var(--bg-card);
    border-color: var(--border-color);
  }

  .avatar-group .avatar {
    border-color: var(--bg-body);
  }

  select.form-control {
    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='%23a0aec0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  }
}

/* Optional manual dark mode toggle (add .dark to <html>) */
html.dark {
  --bg-body: #0f1419;
  --bg-card: #1a2332;
  --bg-sidebar: #0d1117;
  --border-color: #2d3748;
  --text-primary: #e2e8f0;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --gray-50: #1a2332;
  --gray-100: #1e293b;
  --gray-200: #2d3748;
  --gray-300: #4a5568;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

html.dark .form-control {
  background: var(--gray-100);
  border-color: var(--gray-300);
  color: var(--text-primary);
}

html.dark .toast {
  background: var(--bg-card);
}

html.dark .table th {
  background: var(--gray-100);
}

html.dark .pipeline-card {
  background: var(--bg-card);
}
