/* ============================================
   LeadClaw Responsive Design System
   Breakpoints:
   - Mobile: <768px (bottom nav)
   - Tablet: 768px-1023px (bottom nav)
   - Desktop: >=1024px (sidebar)
   ============================================ */

/* CSS Custom Properties for Design System */
:root {
  --color-primary: #667eea;
  --color-primary-dark: #764ba2;
  --color-sidebar: #1a1a2e;
  --color-bg: #f5f7fa;
  --color-white: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #666666;
  --color-border: #eeeeee;
  --color-border-light: #dddddd;

  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 20px;
  --spacing-2xl: 24px;
  --spacing-3xl: 32px;

  --font-size-xs: 11px;
  --font-size-sm: 12px;
  --font-size-base: 14px;
  --font-size-md: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 24px;
  --font-size-2xl: 28px;

  --border-radius-sm: 6px;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);

  --sidebar-width: 240px;
  --bottom-nav-height: 56px;
  --header-height: 60px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
}

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

/* Base Styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--color-bg);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout Container - Mobile First */
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Main Content Area - Mobile First */
.main {
  flex: 1;
  padding: var(--spacing-lg);
  padding-bottom: calc(var(--bottom-nav-height) + var(--spacing-lg));
}

/* Page Header */
.header {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-xl);
}

.header h1 {
  font-size: var(--font-size-xl);
  color: var(--color-text);
}

.header-subtitle {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  margin-top: var(--spacing-xs);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-sm);
}

/* User Menu */
.user-menu {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.user-email {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  display: none;
}

/* Cards */
.card {
  background: var(--color-white);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--spacing-xl);
}

.card-header {
  padding: var(--spacing-lg) var(--spacing-xl);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.card-title {
  font-size: var(--font-size-md);
  font-weight: 600;
}

.card-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.card-body {
  padding: var(--spacing-xl);
}

/* Stats Grid - Mobile First */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-xl);
}

.stat-card {
  background: var(--color-white);
  border-radius: var(--border-radius-lg);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--spacing-xs);
}

.stat-value {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-text);
}

.stat-change {
  font-size: var(--font-size-xs);
  color: #4CAF50;
  margin-top: var(--spacing-xs);
}

.stat-change.negative {
  color: #f44336;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-lg);
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  border: none;
  border-radius: var(--border-radius-md);
  color: var(--color-white);
  font-size: var(--font-size-base);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity var(--transition-normal);
  min-height: 44px;
}

.btn:hover {
  opacity: 0.9;
}

.btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.btn-danger {
  background: #dc3545;
}

.btn-small {
  padding: 6px var(--spacing-md);
  font-size: var(--font-size-sm);
  min-height: 36px;
}

/* Tables - Mobile First */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

th,
td {
  padding: var(--spacing-md) var(--spacing-lg);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

th {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  color: #888;
  font-weight: 600;
  white-space: nowrap;
}

td {
  font-size: var(--font-size-base);
}

/* Status Badges */
.status-badge {
  display: inline-block;
  padding: var(--spacing-xs) 10px;
  border-radius: 12px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  white-space: nowrap;
}

.status-active {
  background: #e3f2fd;
  color: #1565c0;
}

.status-won {
  background: #e8f5e9;
  color: #2e7d32;
}

.status-lost {
  background: #ffebee;
  color: #c62828;
}

.status-nurturing {
  background: #fff3e0;
  color: #e65100;
}

.status-opted_out {
  background: #fafafa;
  color: #666;
}

.status-escalated {
  background: #fce4ec;
  color: #c2185b;
}

.status-connected {
  background: #e8f5e9;
  color: #2e7d32;
}

.status-disconnected {
  background: #fff3e0;
  color: #e65100;
}

.status-error,
.status-failed {
  background: #ffebee;
  color: #c62828;
}

/* Role Badges */
.role-badge {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.role-owner {
  background: #f3e5f5;
  color: #7b1fa2;
}

.role-admin {
  background: #e3f2fd;
  color: #1565c0;
}

.role-member {
  background: #f0f0f0;
  color: #666;
}

/* Plan Badges */
.plan-badge {
  display: inline-block;
  padding: 2px var(--spacing-sm);
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 600;
  background: #e3f2fd;
  color: #1565c0;
}

.plan-pro {
  background: #f3e5f5;
  color: #7b1fa2;
}

.plan-enterprise {
  background: #fff8e1;
  color: #f57f17;
}

/* Forms */
.form-group {
  margin-bottom: var(--spacing-lg);
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: var(--spacing-sm);
  color: #333;
  font-size: var(--font-size-base);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px var(--spacing-md);
  border: 1px solid var(--color-border-light);
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-base);
  font-family: inherit;
  min-height: 44px;
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

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

.form-hint {
  font-size: var(--font-size-xs);
  color: #888;
  margin-top: var(--spacing-xs);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-lg);
}

/* Alerts */
.alert {
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--border-radius-md);
  margin-bottom: var(--spacing-lg);
  font-size: var(--font-size-base);
}

.alert-success {
  background: #e8f5e9;
  color: #2e7d32;
}

.alert-error {
  background: #ffebee;
  color: #c62828;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--spacing-3xl) var(--spacing-lg);
  color: #888;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  padding: var(--spacing-xl);
}

.pagination a,
.pagination span {
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--border-radius-md);
  text-decoration: none;
  color: #333;
  font-size: var(--font-size-sm);
  min-width: 36px;
  text-align: center;
}

.pagination a:hover {
  background: #f0f0f0;
}

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

/* Info Rows */
.info-row {
  display: flex;
  justify-content: space-between;
  padding: var(--spacing-sm) 0;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
  gap: var(--spacing-xs);
}

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

.info-label {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.info-value {
  font-weight: 500;
  font-size: var(--font-size-sm);
  text-align: right;
}

/* Messages */
.messages {
  max-height: 500px;
  overflow-y: auto;
}

.message {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--color-border);
}

.message:last-child {
  border-bottom: none;
}

.message.inbound {
  background: #f8f9ff;
}

.message.outbound {
  background: #f0f7f0;
}

.message-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--spacing-xs);
  font-size: var(--font-size-xs);
  color: #888;
}

.message-body {
  font-size: var(--font-size-base);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Stats Row */
.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-xl);
}

.stat-badge-item {
  padding: 6px var(--spacing-md);
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-sm);
  background: #f0f0f0;
}

.stat-badge-item.active {
  background: #e3f2fd;
  color: #1565c0;
}

.stat-badge-item.won {
  background: #e8f5e9;
  color: #2e7d32;
}

.stat-badge-item.lost {
  background: #ffebee;
  color: #c62828;
}

/* Grid Layout for Detail Pages */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-xl);
}

/* Filters */
.filters {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  width: 100%;
}

.filters input,
.filters select {
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--color-border-light);
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-base);
  min-height: 44px;
}

.filters input {
  width: 100%;
}

/* Actions */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

/* Code Preview */
.code-preview {
  background: #f8f9fa;
  border-radius: var(--border-radius-md);
  padding: var(--spacing-lg);
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: var(--font-size-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
  word-break: break-word;
}

/* Connection Status */
.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--spacing-xs) 10px;
  border-radius: 12px;
  font-size: var(--font-size-xs);
}

.connection-status.connected {
  background: #e8f5e9;
  color: #2e7d32;
}

.connection-status.disconnected {
  background: #fff3e0;
  color: #e65100;
}

.connection-status.error {
  background: #ffebee;
  color: #c62828;
}

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

/* Lead Link */
.lead-link {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.lead-link:hover {
  text-decoration: underline;
}

/* Progress (Onboarding) */
.progress {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.progress-step {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: 600;
  flex-shrink: 0;
}

.progress-step.active {
  background: var(--color-primary);
  color: var(--color-white);
}

.progress-step.completed {
  background: #4CAF50;
  color: var(--color-white);
}

.progress-step.inactive {
  background: #ddd;
  color: #666;
}

.progress-line {
  width: 24px;
  height: 3px;
  background: #ddd;
}

.progress-line.completed {
  background: #4CAF50;
}

/* Status Box */
.status-box {
  padding: var(--spacing-xl);
  border-radius: var(--border-radius-md);
  margin-bottom: var(--spacing-xl);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

.status-box.connected {
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
}

.status-box.disconnected {
  background: #fff3e0;
  border: 1px solid #ffe0b2;
}

.status-box.error {
  background: #ffebee;
  border: 1px solid #ffcdd2;
}

.status-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xl);
  flex-shrink: 0;
}

.status-box.connected .status-icon {
  background: #4CAF50;
  color: var(--color-white);
}

.status-box.disconnected .status-icon {
  background: #ff9800;
  color: var(--color-white);
}

.status-box.error .status-icon {
  background: #f44336;
  color: var(--color-white);
}

.status-text h3 {
  font-size: var(--font-size-md);
  margin-bottom: var(--spacing-xs);
}

.status-text p {
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
}

/* QR Placeholder */
.qr-section {
  text-align: center;
  padding: var(--spacing-xl) 0;
}

.qr-placeholder {
  width: 100%;
  max-width: 256px;
  height: 256px;
  background: #f5f5f5;
  border: 2px dashed #ccc;
  border-radius: var(--border-radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #888;
  margin: 0 auto;
}

/* Instructions */
.instructions {
  background: #f8f9fa;
  border-radius: var(--border-radius-md);
  padding: var(--spacing-lg);
  margin-top: var(--spacing-xl);
}

.instructions h4 {
  margin-bottom: var(--spacing-md);
  font-size: var(--font-size-md);
}

.instructions ol {
  margin-left: 20px;
}

.instructions li {
  margin-bottom: var(--spacing-sm);
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
}

/* Hide sidebar on mobile/tablet, show on desktop */
.sidebar {
  display: none;
}

/* Bottom navigation - Mobile First */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-sidebar);
  color: var(--color-white);
  height: var(--bottom-nav-height);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-sm) var(--spacing-md);
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  font-size: var(--font-size-xs);
  min-width: 56px;
  min-height: 44px;
  transition: color var(--transition-fast);
}

.bottom-nav-item:hover {
  color: rgba(255, 255, 255, 0.8);
}

.bottom-nav-item.active {
  color: var(--color-white);
}

.bottom-nav-icon {
  font-size: 20px;
  margin-bottom: 2px;
}

.bottom-nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bottom-nav-section {
  display: none;
}

/* Responsive Tables - Card view on mobile */
.responsive-table {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
  .responsive-table-card {
    display: block;
  }

  .responsive-table-card thead {
    display: none;
  }

  .responsive-table-card tbody {
    display: block;
  }

  .responsive-table-card tr {
    display: block;
    margin-bottom: var(--spacing-md);
    background: var(--color-white);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
  }

  .responsive-table-card td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--color-border);
    text-align: right;
  }

  .responsive-table-card td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    color: #888;
    margin-right: var(--spacing-md);
  }

  .responsive-table-card td:last-child {
    border-bottom: none;
  }
}

/* ============================================
   TABLET BREAKPOINT (768px+)
   iPad Mini, iPad Air, iPad Pro in portrait
   ============================================ */
@media (min-width: 768px) {
  .main {
    padding: var(--spacing-2xl);
    padding-bottom: calc(var(--bottom-nav-height) + var(--spacing-2xl));
  }

  .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .header-actions {
    margin-top: 0;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .stat-value {
    font-size: var(--font-size-2xl);
  }

  .card-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

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

  .filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .filters input {
    width: 200px;
  }

  .user-email {
    display: inline;
  }

  .detail-grid {
    grid-template-columns: 1fr 400px;
  }

  .progress-line {
    width: 40px;
  }
}

/* ============================================
   DESKTOP BREAKPOINT (1024px+)
   iPad Pro, Laptops, Desktops
   Sidebar appears, bottom nav hidden
   ============================================ */
@media (min-width: 1024px) {
  .layout {
    flex-direction: row;
  }

  .main {
    margin-left: var(--sidebar-width);
    padding: var(--spacing-2xl);
    padding-bottom: var(--spacing-2xl);
    max-width: calc(100% - var(--sidebar-width));
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    background: var(--color-sidebar);
    color: var(--color-white);
    padding: var(--spacing-xl) 0;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    overflow-y: auto;
  }

  .bottom-nav {
    display: none;
  }
}

/* Sidebar Navigation */
.logo {
  font-size: var(--font-size-xl);
  font-weight: 700;
  padding: 0 var(--spacing-xl) var(--spacing-xl);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: var(--spacing-xl);
  color: var(--color-white);
  text-decoration: none;
  display: block;
}

.nav-item {
  display: block;
  padding: var(--spacing-md) var(--spacing-xl);
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: all var(--transition-normal);
  font-size: var(--font-size-base);
}

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

@keyframes borderFadeIn {
  from {
    opacity: 0;
    border-left-width: 0;
  }
  to {
    opacity: 1;
    border-left-width: 3px;
  }
}

.nav-item.active {
  color: var(--color-white);
  background: rgba(102, 126, 234, 0.3);
  border-left: 3px solid var(--color-primary);
  animation: borderFadeIn 0.3s ease;
}

.nav-section {
  padding: var(--spacing-lg) var(--spacing-xl) var(--spacing-sm);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.5px;
}

/* ============================================
   LARGE DESKTOP (1440px+)
   Constrain content width for readability
   ============================================ */
@media (min-width: 1440px) {
  .main {
    max-width: 1200px;
    margin-left: var(--sidebar-width);
    margin-right: auto;
  }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   Larger touch targets for mobile/tablet
   ============================================ */
@media (pointer: coarse) {

  .nav-item,
  .bottom-nav-item,
  .btn {
    min-height: 44px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: var(--font-size-md);
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {

  .sidebar,
  .bottom-nav {
    display: none !important;
  }

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

  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}