:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  margin: 0;
  direction: rtl;
}

a { text-decoration: none; color: inherit; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px;
  background: #111827;
  color: #e5e7eb;
  flex-shrink: 0;
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  font-size: 18px;
  font-weight: 800;
  padding: 0 20px 20px;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 10px;
  color: #fff;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  font-size: 14.5px;
  color: #cbd5e1;
  border-right: 3px solid transparent;
}
.sidebar nav a:hover { background: #1f2937; color: #fff; }
.sidebar nav a.active {
  background: #1f2937;
  border-right-color: var(--primary);
  color: #fff;
  font-weight: 700;
}
.sidebar .section-title {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--gray-400);
  padding: 14px 20px 6px;
  letter-spacing: .5px;
}

/* Main */
.main { flex: 1; min-width: 0; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 800; }
.topbar .user-chip { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar .badge-role {
  background: var(--gray-100);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--gray-600);
}
.content { padding: 24px; max-width: 1400px; }

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border-right: 4px solid var(--primary);
}
.stat-card .label { font-size: 13px; color: var(--gray-600); margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 800; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--gray-200); color: var(--gray-800); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms */
label { font-size: 13.5px; font-weight: 600; color: var(--gray-600); display: block; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=date], input[type=datetime-local], input[type=number], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 14px;
}
textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--gray-100); }
th { background: var(--gray-50); font-weight: 700; color: var(--gray-600); font-size: 12.5px; text-transform: uppercase; }
tr:hover td { background: #fafbff; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; color: #fff; }

/* Kanban */
.kanban-board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.kanban-col { background: var(--gray-100); border-radius: var(--radius); min-width: 260px; max-width: 260px; padding: 10px; flex-shrink: 0; }
.kanban-col-header { display: flex; justify-content: space-between; align-items: center; padding: 6px 6px 10px; font-weight: 700; font-size: 13.5px; }
.kanban-count { background: #fff; border-radius: 20px; padding: 1px 9px; font-size: 12px; }
.kanban-card {
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: grab;
  font-size: 13.5px;
  border-right: 3px solid var(--primary);
}
.kanban-card.dragging { opacity: .4; }
.kanban-card .lead-phone { color: var(--gray-600); font-size: 12px; }
.kanban-card .lead-agent { font-size: 11.5px; color: var(--gray-400); margin-top: 4px; }
.kanban-col.drag-over { outline: 2px dashed var(--primary); }

/* Timeline */
.timeline-item {
  border-right: 2px solid var(--gray-200);
  padding: 4px 18px 18px 0;
  position: relative;
}
.timeline-item::before {
  content: '';
  position: absolute;
  right: -6px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
}
.timeline-meta { font-size: 12px; color: var(--gray-400); }

/* Call timer */
.call-timer-box {
  background: #111827;
  color: #fff;
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.call-timer-box .time { font-size: 34px; font-weight: 800; font-family: monospace; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error { background: #fee2e2; color: #991b1b; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--gray-200); margin-bottom: 18px; }
.tabs a { padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--gray-600); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.filters-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-end; }
.filters-bar .fld { min-width: 150px; }
.filters-bar label { margin-bottom: 4px; }
.filters-bar input, .filters-bar select { margin-bottom: 0; }

.pagination { display: flex; gap: 6px; margin-top: 14px; }
.pagination a, .pagination span {
  padding: 6px 12px; border-radius: 6px; font-size: 13px; border: 1px solid var(--gray-200);
}
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-400); }

@media (max-width: 900px) {
  .sidebar { position: fixed; right: -240px; z-index: 100; transition: right .3s ease; }
  .sidebar.open { right: 0; box-shadow: 0 0 10px rgba(0,0,0,0.5); }
  #sidebarToggle { display: block !important; }
  .form-row { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  /* Overlay */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 50;
  }
  .sidebar.open + .sidebar-overlay { display: block; }
}
