/* ═══════════════════════════════════════════════════════════
   ROKHAS — Main Stylesheet
   Arabic RTL Municipal Application — Light & Simple Theme
   ═══════════════════════════════════════════════════════════ */

:root {
  --primary: #1e7040;
  /* Deep rich green */
  --primary-light: #2da15f;
  /* Vibrant accent green */
  --primary-dark: #124d2b;
  /* Very dark green for titles/borders */
  --bg-light: #f8fafc;
  /* Light slate gray/white page background */
  --bg-card: #ffffff;
  /* Pure white card background */
  --bg-card-hover: #f1f5f9;
  /* Subtle hover gray */
  --border: #e2e8f0;
  /* Soft border gray */
  --text-primary: #1e293b;
  /* Slate-900 for high readability */
  --text-secondary: #475569;
  /* Slate-700 for secondary text */
  --text-muted: #94a3b8;
  /* Slate-400 for help text/muted elements */
  --sidebar-width: 280px;
  --topbar-height: 64px;
  --radius: 12px;
  --transition: all 0.2s ease-in-out;
}

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

body,
html {
  font-family: 'Cairo', sans-serif;
  background: var(--bg-light);
  color: var(--text-primary);
  direction: rtl;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
}

body::before {
  display: none;
}

/* ─── Sidebar ──────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: var(--transition);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) transparent;
}

.sidebar-header {
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.commune-logo-wrap {
  flex-shrink: 0;
}

.commune-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 50%;
  background: var(--bg-light);
  border: 1px solid var(--border);
  padding: 2px;
}

.commune-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
}

.app-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.sidebar-user {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.user-avatar {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  flex-shrink: 0;
}

.user-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-role {
  font-size: 0.82rem;
  color: var(--primary);
  font-weight: 600;
}

.sidebar-nav {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}

.nav-section-title {
  padding: 12px 20px 4px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.nav-item {
  margin: 2px 8px;
}

.nav-item .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 12px;
  transition: var(--transition);
  font-size: 1.1rem;
  font-weight: 500;
}

.nav-item .nav-link i {
  font-size: 1.3rem;
  width: 24px;
  text-align: center;
}

.nav-item .nav-link:hover {
  background: rgba(30, 112, 64, 0.05);
  color: var(--primary);
}

.nav-item.active .nav-link {
  background: rgba(30, 112, 64, 0.08);
  border-right: 4px solid var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-link-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  padding: 8px;
  border-radius: 8px;
  transition: var(--transition);
}

.nav-link-footer:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.nav-link-footer.text-danger:hover {
  color: #dc3545 !important;
  background: #fee2e2;
}

/* ─── Main Wrapper ─────────────────────────────────────── */
.main-wrapper {
  margin-right: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: var(--transition);
}

/* ─── Topbar ───────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 900;
}

.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-toggle:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.topbar-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.topbar-date {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Page Content ─────────────────────────────────────── */
.page-content {
  padding: 0;
  flex: 1;
}

.flash-container {
  padding: 12px 24px 0;
}

/* ─── Cards ────────────────────────────────────────────── */
.card-glass {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.02);
  overflow: hidden;
}

.card-header-green {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary);
}

/* ─── KPI Cards ────────────────────────────────────────── */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: var(--transition);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
}

.kpi-primary::before {
  background: #0d6efd;
}

.kpi-success::before {
  background: #198754;
}

.kpi-warning::before {
  background: #ffc107;
}

.kpi-info::before {
  background: #17a2b8;
}

.kpi-danger::before {
  background: #dc3545;
}

.kpi-icon {
  font-size: 2rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}

.kpi-value small {
  font-size: 0.9rem;
  font-weight: 400;
}

.kpi-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Tables ───────────────────────────────────────────── */
.table-dark-custom {
  color: var(--text-primary) !important;
  background: var(--bg-card) !important;
}

.table-dark-custom thead tr {
  background: #edf7f2 !important;
  color: var(--primary) !important;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table-dark-custom tbody tr {
  border-bottom: 1px solid var(--border) !important;
  transition: var(--transition);
  background: transparent !important;
}

.table-dark-custom tbody tr:hover {
  background: var(--bg-card-hover) !important;
}

.table-dark-custom td,
.table-dark-custom th {
  padding: 12px 16px !important;
  vertical-align: middle;
  border: none !important;
  color: var(--text-primary) !important;
}

.table-dark-custom th {
  font-weight: 700;
}

/* ─── Badges ───────────────────────────────────────────── */
.badge {
  font-family: 'Cairo', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
}

/* ─── Forms ────────────────────────────────────────────── */
.form-control,
.form-select {
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  color: var(--text-primary) !important;
  border-radius: 8px !important;
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  transition: var(--transition);
}

.form-control:focus,
.form-select:focus {
  background: #ffffff !important;
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(30, 112, 64, 0.15) !important;
  color: var(--text-primary) !important;
}

.form-control::placeholder {
  color: var(--text-muted) !important;
}

.form-label {
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-label-sm {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
  display: block;
}

.form-text {
  color: var(--text-muted) !important;
  font-size: 0.75rem;
}

.arabic-input {
  font-family: 'Cairo', sans-serif;
  text-align: right;
}

/* ─── Form Sections ────────────────────────────────────── */
.form-section {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.form-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ─── Buttons ──────────────────────────────────────────── */
.btn {
  font-family: 'Cairo', sans-serif;
  font-weight: 600;
  border-radius: 8px;
  transition: var(--transition);
}

.btn-success {
  background: var(--primary) !important;
  border: none !important;
  color: white !important;
}

.btn-success:hover {
  background: var(--primary-dark) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(30, 112, 64, 0.15);
}

.btn-xs {
  padding: 3px 8px;
  font-size: 0.75rem;
  border-radius: 6px;
}

/* ─── Modals ───────────────────────────────────────────── */
.modal {
  z-index: 1060 !important;
}

.modal-backdrop {
  z-index: 1050 !important;
}

.modal-dark {
  background: #ffffff !important;
  border: 1px solid var(--border);
  color: var(--text-primary) !important;
}

.modal-dark .modal-header {
  border-bottom: 1px solid var(--border);
}

.modal-dark .modal-footer {
  border-top: 1px solid var(--border);
}

.modal-dark .btn-close {
  filter: none !important;
}

/* ─── Status Banner ────────────────────────────────────── */
.status-banner {
  border-radius: 12px;
  padding: 16px 20px;
  border: 1px solid;
}

.status-banner-primary {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.status-banner-info {
  background: #ecfeff;
  border-color: #a5f3fc;
  color: #0369a1;
}

.status-banner-success {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.status-banner-warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.status-banner-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.status-banner-secondary {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #475569;
}

.status-banner-dark {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #1e293b;
}

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

.status-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.status-icon {
  font-size: 1.5rem;
}

/* ─── Info Items ───────────────────────────────────────── */
.info-item {
  padding: 6px 0;
}

.info-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.info-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ─── Timeline ─────────────────────────────────────────── */
.timeline {
  padding-right: 20px;
}

.timeline-item {
  position: relative;
  padding-right: 28px;
  padding-bottom: 20px;
  border-right: 2px solid var(--border);
}

.timeline-item:last-child {
  border-right: none;
  padding-bottom: 0;
}

.timeline-dot {
  position: absolute;
  right: -9px;
  top: 4px;
  width: 16px;
  height: 16px;
  background: var(--primary);
  border: 3px solid var(--bg-light);
  border-radius: 50%;
}

.timeline-action {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.timeline-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.timeline-details {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ─── Document Items ───────────────────────────────────── */
.doc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: var(--transition);
  background: #ffffff;
}

.doc-item:hover {
  background: var(--bg-card-hover);
}

.doc-icon {
  font-size: 1.5rem;
  color: var(--primary);
}

.doc-info {
  flex: 1;
}

.doc-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.doc-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ─── Photos Grid ──────────────────────────────────────── */
.photos-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.photo-thumb {
  width: 100px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--border);
  transition: var(--transition);
}

.photo-thumb:hover {
  transform: scale(1.05);
  border-color: var(--primary-light);
}

/* ─── Activity Feed ────────────────────────────────────── */
.activity-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-action {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.activity-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ─── Upcoming Visits ──────────────────────────────────── */
.upcoming-visit-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.upcoming-visit-item:last-child {
  border-bottom: none;
}

.visit-date {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.visit-name {
  font-size: 0.9rem;
  margin: 3px 0;
  color: var(--text-primary);
}

.visit-tech {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* ─── Autocomplete ─────────────────────────────────────── */
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 1000;
  max-height: 250px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  display: none;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
  color: var(--text-primary);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background: rgba(30, 112, 64, 0.05);
}

.autocomplete-item strong {
  color: var(--primary);
}

/* ─── Legend ───────────────────────────────────────────── */
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Nav Pills ────────────────────────────────────────── */
.nav-pills .nav-link {
  color: var(--text-secondary);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.88rem;
  padding: 8px 16px;
}

.nav-pills .nav-link.active {
  background: var(--primary) !important;
  border-color: transparent;
  color: white;
}

/* ─── List Items (Settings) ────────────────────────────── */
.list-item-sm {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-primary);
}

.list-item-sm:last-child {
  border-bottom: none;
}

/* ─── Demande Info Box ─────────────────────────────────── */
.demande-info-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 12px;
  padding: 16px;
  color: #166534;
}

/* ─── User Avatar Small ────────────────────────────────── */
.user-avatar-sm {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

/* ─── Pagination ───────────────────────────────────────── */
.pagination .page-link {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text-secondary);
  font-family: 'Cairo';
}

.pagination .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.pagination .page-link:hover {
  background: var(--bg-card-hover);
  color: var(--primary);
}

/* ─── Responsive: Sidebar Collapse ────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(100%);
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .main-wrapper {
    margin-right: 0;
  }
}

/* ─── Scrollbar ────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(30, 112, 64, 0.2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-light);
}

/* ─── Alerts ───────────────────────────────────────────── */
.alert {
  font-family: 'Cairo';
  border-radius: 8px;
}

.alert-success {
  background: #f0fdf4 !important;
  border-color: #bbf7d0 !important;
  color: #166534 !important;
}

.alert-danger {
  background: #fef2f2 !important;
  border-color: #fecaca !important;
  color: #991b1b !important;
}

.alert-warning {
  background: #fffbeb !important;
  border-color: #fde68a !important;
  color: #92400e !important;
}

.alert-info {
  background: #f0f9ff !important;
  border-color: #bae6fd !important;
  color: #075985 !important;
}

/* ─── Select2 Override ─────────────────────────────────── */
select option {
  background: #ffffff;
  color: #1e293b;
}

/* ─── Sticky sidebar handle for mobile ─────────────────── */
#sidebarOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 999;
}