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

:root {
  --primary: #3052FF;
  --primary-light: #4a6aff;
  --navy: #1a2e4a;
  --navy-dark: #0f1c2e;
  --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;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
}

/* Login Page */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
}

.login-box {
  background: var(--white);
  padding: 40px;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

.login-logo {
  text-align: center;
  margin-bottom: 30px;
}

.login-logo h1 {
  font-size: 1.5rem;
  color: var(--navy);
}

.login-logo span {
  color: var(--primary);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--gray-700);
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
  width: 100%;
}

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

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-700);
}

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

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

.btn-small {
  padding: 8px 16px;
  font-size: 0.875rem;
}

.error-message {
  background: #fee2e2;
  color: var(--red);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

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

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--navy-dark);
  color: var(--white);
  position: fixed;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-logo {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.sidebar-logo .nautilus-brand {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 6px;
  color: #fff;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: block;
}

.sidebar-logo h1 {
  font-size: 1.25rem;
}

.sidebar-logo span {
  color: var(--primary);
}

.sidebar-nav {
  padding: 20px 0;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: all 0.2s;
}

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

.sidebar-nav a svg {
  width: 20px;
  height: 20px;
}

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

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

.user-avatar {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.user-name {
  font-weight: 500;
}

.user-email {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 30px;
  max-width: calc(100vw - 260px);
  overflow-x: hidden;
}

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

.page-header h1 {
  font-size: 1.75rem;
  color: var(--gray-900);
}

/* Cards */
.card {
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 24px;
  margin-bottom: 24px;
}

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

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-900);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.2s;
}

.stat-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 2px;
  line-height: 1.2;
}

.stat-label {
  color: var(--gray-500);
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}

.stat-sub {
  color: var(--gray-400);
  font-size: 0.75rem;
  margin-top: 6px;
}

.stat-card.primary {
  background: var(--primary);
  color: var(--white);
}

.stat-card.primary .stat-value,
.stat-card.primary .stat-label {
  color: var(--white);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--gray-600);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: relative;
  user-select: none;
}

th .col-resize {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  background: transparent;
}

th .col-resize:hover,
th .col-resize.active {
  background: var(--primary);
  opacity: 0.4;
}

td {
  color: var(--gray-800);
}

tr:hover {
  background: var(--gray-50);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-green {
  background: #d1fae5;
  color: #065f46;
}

.badge-red {
  background: #fee2e2;
  color: #991b1b;
}

.badge-blue {
  background: #dbeafe;
  color: #1e40af;
}

.badge-yellow {
  background: #fef3c7;
  color: #92400e;
}

.badge-gray {
  background: var(--gray-200);
  color: var(--gray-700);
}

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filters input,
.filters select {
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 0.9rem;
  height: 42px;
}

.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--primary);
}

.filters .btn {
  height: 42px;
  padding: 0 24px;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

/* Page size selector */
.page-size-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--gray-500);
}
.page-size-selector button {
  padding: 3px 10px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  background: var(--white);
  color: var(--gray-600);
  font-size: 0.8rem;
  cursor: pointer;
}
.page-size-selector button.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  display: none;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--white);
  border-radius: 16px;
  padding: 30px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h2 {
  font-size: 1.25rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

/* Form */
.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  font-family: monospace;
  resize: vertical;
  min-height: 150px;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Toggle Switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--gray-300);
  border-radius: 26px;
  cursor: pointer;
  transition: 0.2s;
}

.toggle-slider:before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  bottom: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

/* Responsive */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

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

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

  .form-row {
    grid-template-columns: 1fr;
  }
}

/* Actions */
.actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.action-btn-edit {
  background: var(--gray-200);
  color: var(--gray-700);
}

.action-btn-edit:hover {
  background: var(--gray-300);
}

.action-btn-delete {
  background: #fee2e2;
  color: var(--red);
}

.action-btn-delete:hover {
  background: #fecaca;
}

.action-btn-view {
  background: #dbeafe;
  color: #1e40af;
}

.action-btn-view:hover {
  background: #bfdbfe;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-500);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  color: var(--gray-300);
}

/* Time Range Buttons */
.time-range-btns {
  display: inline-flex;
  gap: 0;
  flex-wrap: wrap;
  background: var(--gray-100);
  border-radius: 10px;
  padding: 3px;
}

.time-range-btns button {
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--gray-500);
  transition: all 0.2s;
  white-space: nowrap;
}

.time-range-btns button.active {
  background: var(--white);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  font-weight: 600;
}

.time-range-btns button:hover:not(.active) {
  color: var(--gray-700);
  background: var(--gray-200);
}

/* Column Editor */
.col-editor-wrap {
  position: relative;
  display: inline-block;
}

.col-editor-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  background: var(--white);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--gray-600);
  transition: all 0.2s;
}

.col-editor-btn:hover,
.col-editor-btn.active {
  border-color: var(--primary);
  color: var(--primary);
}

.col-editor-panel {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 100;
  width: 260px;
  padding: 8px 0;
}

.col-editor-list {
  max-height: 360px;
  overflow-y: auto;
  padding: 0 4px;
}

.col-editor-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.1s;
}

.col-editor-item:hover {
  background: var(--gray-50);
}

.col-editor-item.dragging {
  opacity: 0.4;
}

.col-editor-item.drag-over {
  border-top: 2px solid var(--primary);
}

.col-editor-drag {
  cursor: grab;
  color: var(--gray-400);
  font-size: 14px;
  user-select: none;
  flex-shrink: 0;
}

.col-editor-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--gray-700);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-editor-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.col-editor-reset {
  display: block;
  width: calc(100% - 16px);
  margin: 6px 8px;
  padding: 8px;
  border: none;
  border-top: 1px solid var(--gray-200);
  background: none;
  color: var(--gray-500);
  font-size: 0.8rem;
  cursor: pointer;
  text-align: center;
  border-radius: 0 0 6px 6px;
}

.col-editor-reset:hover {
  color: var(--primary);
  background: var(--gray-50);
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Sidebar Nav Divider */
.sidebar-nav-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 8px 20px;
}

/* Sidebar Collapsible Submenu */
.sidebar-nav .nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  font-size: inherit;
  font-family: inherit;
  line-height: inherit;
}
.sidebar-nav .nav-group-toggle:hover,
.sidebar-nav .nav-group-toggle.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--white);
}
.sidebar-nav .nav-group-toggle svg {
  width: 20px;
  height: 20px;
  min-width: 20px;
  flex-shrink: 0;
}
.sidebar-nav .nav-group-toggle .nav-chevron {
  margin-left: auto;
  width: 16px;
  height: 16px;
  min-width: 16px;
  transition: transform 0.2s;
}
.sidebar-nav .nav-group-toggle.open .nav-chevron {
  transform: rotate(90deg);
}
.sidebar-nav .nav-submenu {
  display: none;
  background: rgba(0, 0, 0, 0.15);
}
.sidebar-nav .nav-submenu.open {
  display: block;
}
.sidebar-nav .nav-submenu a {
  padding-left: 52px;
  font-size: 0.9em;
}

/* Pipeline Kanban */
.pipeline-container {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 20px;
  min-height: calc(100vh - 200px);
}

.pipeline-column {
  min-width: 280px;
  max-width: 280px;
  background: var(--gray-100);
  border-radius: 12px;
  padding: 16px;
  flex-shrink: 0;
}

.pipeline-column-header {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--gray-700);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pipeline-count {
  background: var(--gray-300);
  color: var(--gray-700);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 50px;
}

.pipeline-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pipeline-card {
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: box-shadow 0.2s;
}

.pipeline-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.pipeline-card-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.pipeline-card-company {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-bottom: 6px;
}

.pipeline-card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--gray-400);
}

/* Detail Tabs */
.detail-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 16px;
}

.detail-tabs button {
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.detail-tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.detail-tabs button:hover {
  color: var(--gray-700);
}

/* Email Sub-nav */
.email-subnav {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--gray-200);
}

.email-subnav a {
  padding: 10px 20px;
  text-decoration: none;
  color: var(--gray-500);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.email-subnav a.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.email-subnav a:hover {
  color: var(--gray-700);
}

/* Campaign Stats */
.campaign-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.campaign-stat {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.campaign-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
}

.campaign-stat-label {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 4px;
}

/* Additional Badges */
.badge-orange {
  background: #ffedd5;
  color: #9a3412;
}

@media (max-width: 1200px) {
  .campaign-stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .campaign-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}
