/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-card: #222222;
  --bg-hover: #2a2a2a;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent-primary: #6366f1;
  --accent-secondary: #818cf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --mostaql: #10b981;
  --khamsat: #f59e0b;
  --freelancer: #3b82f6;
  --border: #333333;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

body {
  font-family: 'Inter', 'Noto Sans Arabic', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.header {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.5rem;
  font-weight: 700;
}

.logo i {
  color: var(--accent-primary);
  font-size: 1.8rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-refresh:hover {
  background: var(--accent-secondary);
  transform: translateY(-1px);
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.75rem;
}

/* Filters */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  padding: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-group select,
.filter-group input {
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.filter-group select:focus,
.filter-group input:focus {
  border-color: var(--accent-primary);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
}

.stat-icon.mostaql { background: rgba(16, 185, 129, 0.15); color: var(--mostaql); }
.stat-icon.khamsat { background: rgba(245, 158, 11, 0.15); color: var(--khamsat); }
.stat-icon.freelancer { background: rgba(59, 130, 246, 0.15); color: var(--freelancer); }
.stat-icon.total { background: rgba(99, 102, 241, 0.15); color: var(--accent-primary); }

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Table */
.table-container {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

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

.gigs-table th {
  text-align: left;
  padding: 16px 20px;
  background: var(--bg-card);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.gigs-table td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.gigs-table tbody tr {
  transition: background 0.15s;
}

.gigs-table tbody tr:hover {
  background: var(--bg-hover);
}

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

/* Source Badge */
.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: capitalize;
}

.source-badge.mostaql { background: rgba(16, 185, 129, 0.15); color: var(--mostaql); }
.source-badge.khamsat { background: rgba(245, 158, 11, 0.15); color: var(--khamsat); }
.source-badge.freelancer { background: rgba(59, 130, 246, 0.15); color: var(--freelancer); }

/* Status Badge */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: capitalize;
}

.status-badge.matched { background: rgba(99, 102, 241, 0.15); color: var(--accent-primary); }
.status-badge.applied { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.status-badge.won { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-badge.lost { background: rgba(239, 68, 68, 0.15); color: var(--error); }

/* Lang Badge */
.lang-badge {
  display: inline-block;
  padding: 4px 8px;
  background: var(--bg-card);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
}

/* Title Cell */
.title-cell {
  max-width: 300px;
}

.title-cell a {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-cell a:hover {
  color: var(--accent-secondary);
}

/* Budget */
.budget {
  font-weight: 500;
  color: var(--success);
}

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

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-icon.btn-delete:hover {
  background: var(--error);
  border-color: var(--error);
  color: white;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-top: 16px;
}

.btn-page {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-page:hover:not(:disabled) {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
}

.btn-page:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  color: var(--text-secondary);
  font-size: 14px;
}

.page-info span {
  color: var(--text-primary);
  font-weight: 500;
}

/* Loading */
.loading-row td {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 1s linear infinite;
}

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

/* Empty State */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 4rem;
  margin-bottom: 20px;
  color: var(--text-muted);
}

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

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

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h3 {
  font-size: 1.125rem;
}

.btn-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
}

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

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-body textarea {
  width: 100%;
  height: 100%;
  min-height: 350px;
  max-height: 60vh;
  background: transparent;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text-secondary);
  resize: none;
  caret-color: var(--accent-primary);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.modal-body textarea:focus {
  outline: none;
}

/* Settings Modal Styles */
.settings-modal-content {
  max-width: 480px;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

.settings-group input {
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.settings-group input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.settings-group input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

.settings-group small {
  font-size: 0.75rem;
  color: var(--text-secondary);
  opacity: 0.8;
}

.settings-row {
  display: flex;
  gap: 12px;
}

.settings-group.half {
  flex: 1;
}

.settings-info {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.settings-info i {
  color: var(--accent-primary);
  margin-top: 2px;
}

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

/* Responsive */
@media (max-width: 768px) {
  .app {
    padding: 12px;
  }
  
  .header {
    padding: 16px;
    margin-bottom: 16px;
  }
  
  .header-content {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }
  
  .header-actions {
    width: 100%;
    justify-content: center;
  }
  
  .filters {
    grid-template-columns: 1fr;
    padding: 16px;
    margin-bottom: 16px;
    gap: 12px;
  }
  
  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
  }
  
  .stat-card {
    padding: 16px;
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }
  
  .table-container {
    border-radius: var(--radius-sm);
  }
  
  .gigs-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .gigs-table th,
  .gigs-table td {
    padding: 12px;
    white-space: nowrap;
  }
  
  .title-cell {
    min-width: 200px;
    max-width: 200px;
  }
  
  .modal-content {
    margin: 10px;
    max-height: 90vh;
  }
  
  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 16px;
  }
  
  .empty-state {
    padding: 40px 20px;
  }
  
  .empty-state i {
    font-size: 3rem;
  }
}

@media (max-width: 480px) {
  .stats {
    grid-template-columns: 1fr;
  }
  
  .header-actions {
    flex-direction: column;
    gap: 12px;
  }
  
  .btn-refresh {
    width: 100%;
    justify-content: center;
  }
  
  .status-indicator {
    width: 100%;
    justify-content: center;
  }
}

/* RTL Support */
body.rtl {
  direction: rtl;
  text-align: right;
}

body.rtl .header-content {
  flex-direction: row-reverse;
}

body.rtl .header-actions {
  flex-direction: row-reverse;
}

body.rtl .logo {
  flex-direction: row-reverse;
}

body.rtl .filters {
  flex-direction: row-reverse;
}

body.rtl .filter-group {
  text-align: right;
}

body.rtl .stats {
  direction: rtl;
}

body.rtl .stat-card {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

body.rtl .stat-info {
  text-align: right;
  align-items: flex-end;
}

body.rtl .gigs-table th,
body.rtl .gigs-table td {
  text-align: right;
}

body.rtl .action-btns {
  flex-direction: row-reverse;
}

body.rtl .pagination {
  flex-direction: row-reverse;
}

body.rtl .modal-header {
  flex-direction: row-reverse;
}

body.rtl .modal-footer {
  flex-direction: row-reverse;
}

/* Mobile RTL - reset to match English mobile layout */
@media (max-width: 768px) {
  body.rtl .header-content {
    flex-direction: column !important;
    text-align: center !important;
  }
  
  body.rtl .header-actions {
    flex-direction: column !important;
    width: 100%;
  }
  
  body.rtl .logo {
    flex-direction: row !important;
    justify-content: center;
  }
  
  body.rtl .filters {
    flex-direction: column !important;
  }
  
  body.rtl .stats {
    direction: ltr !important;
  }
  
  body.rtl .stat-card {
    flex-direction: column !important;
    text-align: center !important;
    justify-content: center !important;
  }
  
  body.rtl .stat-info {
    text-align: center !important;
    align-items: center !important;
  }
}

/* PWA Safe Area */
@supports (padding: env(safe-area-inset-top)) {
  .app {
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
  }
}

/* Standalone PWA Mode */
@media (display-mode: standalone) {
  .header {
    padding-top: 24px;
  }
}

/* Pull to Refresh Indicator */
#pull-indicator {
  position: fixed;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  background: var(--accent-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  opacity: 0;
  z-index: 9999;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

#pull-indicator.ready {
  background: var(--success);
}

/* Bottom Navigation Bar - WhatsApp Style */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 4px 0;
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  z-index: 1000;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 28px;
  color: rgba(255, 255, 255, 0.5);
  text-decoration: none;
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: all 0.2s ease;
  border-radius: 8px;
}

.nav-item i {
  font-size: 1.25rem;
  transition: transform 0.2s ease;
}

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

.nav-item:hover i {
  transform: scale(1.1);
}

.nav-item.active {
  color: var(--accent-primary);
}

.nav-item.active i {
  transform: scale(1.05);
}

/* Onboarding Tutorial */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.tutorial-overlay.active {
  opacity: 1;
  visibility: visible;
}

.tutorial-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}

.tutorial-highlight {
  position: absolute;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.85);
  background: rgba(59, 130, 246, 0.08);
  border: 2px solid var(--accent-primary);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.tutorial-pointer {
  position: absolute;
  font-size: 2.4rem;
  animation: point-bounce 1s ease-in-out infinite;
  z-index: 10001;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
  transform-origin: center;
  color: #ffc107;
}

@keyframes point-bounce {
  0%, 100% { transform: translateY(0) rotate(90deg) scaleX(-1); }
  50% { transform: translateY(-8px) rotate(90deg) scaleX(-1); }
}

.tutorial-tooltip {
  position: absolute;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--bg-secondary);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: Inter, "Noto Sans Arabic", system-ui, -apple-system, "Segoe UI", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif;
}

.tutorial-progress {
  height: 3px;
  background: linear-gradient(90deg, var(--accent-primary), #25D366);
  transition: width 0.3s ease;
}

.tutorial-title {
  padding: 20px 20px 8px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.tutorial-content {
  padding: 0 20px 20px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.tutorial-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border);
}

.tutorial-nav {
  display: flex;
  gap: 8px;
}

.tutorial-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  background: transparent;
  color: var(--text-secondary);
}

.tutorial-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.tutorial-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.tutorial-btn.primary:hover {
  background: #2563eb;
}

.tutorial-skip {
  color: var(--text-secondary);
  opacity: 0.7;
}

.tutorial-skip:hover {
  opacity: 1;
}

/* Add bottom padding to app for nav bar */
.app {
  padding-bottom: 80px;
}

/* Hide bottom nav on desktop */
@media (min-width: 769px) {
  .bottom-nav {
    display: none;
  }
  
  .app {
    padding-bottom: 20px;
  }
}
