@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&display=swap');

:root {
  --primary: #1e40af;
  --primary-dark: #1e3a8a;
  --primary-light: #dbeafe;
  --accent: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #0284c7;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-xl: 20px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: #0b132b;
  color: var(--text-main);
  direction: rtl;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow-x: hidden;
}

/* Mobile Frame Container */
#app-container {
  width: 100%;
  max-width: 500px;
  min-height: 100vh;
  background-color: var(--bg-main);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

/* App Header */
.app-header {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-md);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: white;
  padding: 2px;
  object-fit: contain;
}

.header-title {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.75rem;
  opacity: 0.9;
  font-weight: 600;
}

.header-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.18);
  padding: 4px 10px;
  border-radius: 20px;
  backdrop-filter: blur(6px);
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #22c55e;
  box-shadow: 0 0 6px #22c55e;
}

/* View Sections */
.view-section {
  display: none;
  padding: 14px;
  animation: fadeIn 0.22s ease-in-out;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* UI Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Smart Attendance Hero */
.attendance-hero {
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-xl);
  padding: 18px 14px;
  text-align: center;
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}

.attendance-hero.checked-out {
  background: linear-gradient(135deg, #fef2f2, #fee2e2);
  border-color: #fecaca;
}

.attendance-badge-state {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.attendance-badge-state.in-work {
  background: #dcfce7;
  color: #15803d;
}

.attendance-badge-state.out-work {
  background: #fee2e2;
  color: #b91c1c;
}

.gps-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: white;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #1e40af;
  margin: 8px 0;
  box-shadow: var(--shadow-sm);
}

.btn-attend-smart {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 1.05rem;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s;
}

.btn-attend-smart.check-in {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  box-shadow: 0 6px 14px rgba(16, 185, 129, 0.35);
}

.btn-attend-smart.check-out {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  box-shadow: 0 6px 14px rgba(239, 68, 68, 0.35);
}

.btn-attend-smart.checked-out-done {
  background: #f1f5f9;
  color: #64748b;
  border: 1.5px solid #cbd5e1;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-attend-smart:active {
  transform: scale(0.98);
}

/* Account View Action Buttons (Distinct Colors) */
.btn-action-add-store {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  color: #ffffff;
  font-weight: 800;
  font-size: 14px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
  transition: all 0.2s ease;
}

.btn-action-add-store:hover {
  filter: brightness(1.05);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.4);
}

.btn-action-add-store:active {
  transform: scale(0.98);
}

.btn-action-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #b91c1c 0%, #ef4444 100%);
  color: #ffffff;
  font-weight: 800;
  font-size: 14px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
  transition: all 0.2s ease;
}

.btn-action-logout:hover {
  filter: brightness(1.05);
  box-shadow: 0 6px 18px rgba(239, 68, 68, 0.4);
}

.btn-action-logout:active {
  transform: scale(0.98);
}

/* Daily Performance Evaluation Box (Point 8 in PDF) */
.eval-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.eval-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.eval-item {
  background: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: var(--radius-md);
  padding: 8px 4px;
  text-align: center;
}

.eval-num {
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1.2;
}

.eval-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 2px;
}

/* Net Salary Preview Box (Point 9 in PDF) */
.salary-box {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: white;
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-md);
}

.salary-main-amount {
  font-size: 1.5rem;
  font-weight: 900;
  color: #38bdf8;
}

.salary-details-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 10px;
}

.salary-stat-col {
  text-align: center;
}

.salary-stat-val {
  font-size: 0.85rem;
  font-weight: 800;
}

.salary-stat-lbl {
  font-size: 0.65rem;
  opacity: 0.75;
}

/* Data Tables (Visits Log & Customer Debt - Point 1 & 6 in PDF) */
.table-responsive-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: white;
  margin-bottom: 12px;
  scrollbar-width: thin;
}

.custom-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  text-align: right;
  white-space: nowrap;
}

.custom-data-table th {
  background: #f1f5f9;
  color: #475569;
  font-weight: 800;
  padding: 10px 8px;
  border-bottom: 2px solid #e2e8f0;
}

.custom-data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.custom-data-table tr:hover {
  background: #f8fafc;
}

/* Visit Status Dynamic Buttons (Point 1 in PDF) */
.btn-visit-action {
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.75rem;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-visit-not-started {
  background: #10b981;
  color: white;
  box-shadow: 0 2px 5px rgba(16, 185, 129, 0.3);
}

.btn-visit-in-progress {
  background: #f59e0b;
  color: white;
  box-shadow: 0 2px 5px rgba(245, 158, 11, 0.3);
  animation: pulseAmber 1.8s infinite;
}

@keyframes pulseAmber {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.btn-visit-ended {
  background: #047857;
  color: white;
  opacity: 0.9;
}

/* Quick Action Pill Buttons (Point 2 in PDF) */
.btn-history-pill {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-history-pill:hover {
  background: #bae6fd;
}

/* Target & KPI Widgets (Point 7 in PDF) */
.target-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.target-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 6px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.target-amount {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--primary);
  margin-top: 4px;
}

.target-type {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--text-muted);
}

.target-progress-bar {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.target-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #059669);
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* Bottom Navigation (5 Tabs) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 500px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 4px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.06);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 6px;
  transition: color 0.15s, transform 0.1s;
  min-width: 54px;
}

.nav-item i {
  font-size: 1.25rem;
}

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

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

/* Search Box & Floating Controls */
.search-input-wrap {
  position: relative;
  margin-bottom: 12px;
}

.search-input {
  width: 100%;
  padding: 10px 38px 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: white;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--primary);
}

.search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 120;
  align-items: flex-end;
  justify-content: center;
}

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

.modal-content {
  width: 100%;
  max-width: 500px;
  background: white;
  border-radius: 24px 24px 0 0;
  padding: 20px 16px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-title {
  font-size: 1.05rem;
  font-weight: 800;
}

.btn-close {
  background: #f1f5f9;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #475569;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 440px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: white;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

.toast.success {
  background: #065f46;
  border: 1px solid #10b981;
}

.toast.error {
  background: #7f1d1d;
  border: 1px solid #ef4444;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Product Card */
.product-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}

/* Category Tabs */
.tabs-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 12px;
  scrollbar-width: none;
}

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

.tab-pill {
  white-space: nowrap;
  padding: 7px 14px;
  border-radius: 20px;
  background: white;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.tab-pill.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(30, 64, 175, 0.3);
}

/* Primary Button */
.btn-primary {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #1e40af, #2563eb);
  color: white;
  font-weight: 800;
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-small {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  border: none;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 30px 16px;
  color: var(--text-muted);
}

.empty-state img {
  width: 90px;
  margin-bottom: 10px;
  opacity: 0.75;
}

.empty-state p {
  font-size: 0.85rem;
  font-weight: 700;
}

/* Sub-Tabs Switcher & Point Cards */
.subtab-container {
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.subtab-btn {
  cursor: pointer;
  outline: none;
}

.subtab-btn.active {
  background: white !important;
  color: #1d4ed8 !important;
  font-weight: 900 !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08) !important;
}

.point-card {
  background: white;
  border-radius: var(--radius-md);
  padding: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  margin-bottom: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.point-card:active {
  transform: scale(0.99);
}

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

.point-card-title {
  font-weight: 900;
  font-size: 0.92rem;
  color: #0f172a;
}

.point-card-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 9999px;
  background: #f1f5f9;
  color: #334155;
}

.point-card-body {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: #64748b;
  margin-bottom: 10px;
}

.point-card-actions {
  display: flex;
  gap: 6px;
}

.btn-point-action {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

.btn-point-action:hover {
  opacity: 0.9;
}

.btn-point-call {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.btn-point-map {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.btn-point-history {
  background: #fdf4ff;
  color: #86198f;
  border: 1px solid #f5d0fe;
}

/* ==================== LOGIN VIEW OVERLAY & CARD ==================== */
#login-view {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, #1e3a8a 0%, #0f172a 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  direction: rtl;
  font-family: inherit;
}

.login-card {
  background: #ffffff;
  width: 100%;
  max-width: 370px;
  border-radius: 28px;
  padding: 32px 24px 28px;
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
  animation: loginFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
}

@keyframes loginFadeIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

.login-avatar-box {
  width: 80px;
  height: 80px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: #eff6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #dbeafe;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.login-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.login-title {
  font-size: 19px;
  font-weight: 900;
  color: #0f172a;
  margin: 0;
  letter-spacing: -0.3px;
}

.login-subtitle {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  margin: 4px 0 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-field-group {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.login-field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
  color: #1e293b;
  margin-bottom: 7px;
}

.login-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.login-input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px 12px 42px;
  border: 1.5px solid #cbd5e1;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
  background-color: #f8fafc;
  outline: none;
  transition: all 0.2s ease;
  direction: rtl;
  text-align: right;
  font-family: inherit;
}

.login-input:focus {
  background-color: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 0 0 3.5px rgba(37, 99, 235, 0.15);
}

.login-input::placeholder {
  color: #94a3b8;
  font-weight: 500;
  font-size: 13px;
}

.login-input-icon {
  position: absolute;
  left: 14px;
  font-size: 14px;
  color: #94a3b8;
  pointer-events: none;
  transition: color 0.2s ease;
}

.login-input:focus ~ .login-input-icon {
  color: #2563eb;
}

.login-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px;
  margin-top: 4px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 18px -2px rgba(37, 99, 235, 0.4);
  transition: all 0.2s ease;
  font-family: inherit;
}

.login-submit-btn:hover {
  filter: brightness(1.05);
  box-shadow: 0 8px 22px -2px rgba(37, 99, 235, 0.5);
}

.login-submit-btn:active {
  transform: scale(0.98);
}

.login-submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}
