:root {
  --primary: #0078CA;
  --primary-dark: #0073BC;
  --primary-light: #E3F6FC;
  --teal: #008080;
  --teal-light: #E0F2F2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --sidebar-w: 240px;
  --topbar-h: 64px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Tahoma, "Cairo", Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }

/* ---------- Auth pages ---------- */
.auth-split { display: flex; min-height: 100vh; }

.auth-brand {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  padding: 40px;
}

.auth-brand-inner { text-align: center; max-width: 380px; }
.auth-logo { font-size: 52px; line-height: 1; margin-bottom: 18px; }
.auth-logo img { max-width: 260px; width: 100%; height: auto; }
.auth-welcome { font-size: 32px; font-weight: 800; color: var(--primary); margin: 0 0 10px; }
.auth-tagline { font-size: 15px; color: var(--gray-500); margin: 0; line-height: 1.6; }

.auth-form-panel {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: linear-gradient(135deg, #0073BC, #0078CA 60%, #00B2E2);
  padding: 40px 20px;
  overflow: hidden;
}

.auth-form-panel::before,
.auth-form-panel::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  pointer-events: none;
}
.auth-form-panel::before { width: 320px; height: 320px; top: -100px; inset-inline-end: -100px; }
.auth-form-panel::after { width: 240px; height: 240px; bottom: -70px; inset-inline-start: -70px; }

.auth-card {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, .25);
}

.auth-card h1 {
  font-size: 22px;
  margin: 0 0 22px;
  text-align: center;
  color: var(--primary);
}

@media (max-width: 900px) {
  .auth-brand { display: none; }
}

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

.sidebar {
  width: var(--sidebar-w);
  background: #101828;
  color: #cbd5e1;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 40;
  transform: translateX(0);
  transition: transform .2s ease;
}

/* Sidebar sits on the side the language reads from: right for Arabic, left for English */
html[dir="rtl"] .sidebar { right: 0; }
html[dir="ltr"] .sidebar { left: 0; }
html[dir="rtl"] .main { margin-right: var(--sidebar-w); transition: margin .2s ease; }
html[dir="ltr"] .main { margin-left: var(--sidebar-w); transition: margin .2s ease; }

/* Collapsed: slide the sidebar off its own side, in both directions */
html[dir="rtl"] .sidebar.collapsed { transform: translateX(100%); }
html[dir="ltr"] .sidebar.collapsed { transform: translateX(-100%); }

/* On desktop the content reclaims the freed space; on mobile the sidebar always overlays (see below) */
@media (min-width: 901px) {
  html[dir="rtl"] .sidebar.collapsed ~ .main { margin-right: 0; }
  html[dir="ltr"] .sidebar.collapsed ~ .main { margin-left: 0; }
}

.sidebar .brand {
  padding: 20px 18px;
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar nav { flex: 1; padding: 14px 10px; overflow-y: auto; }

.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 4px;
  color: #cbd5e1;
  font-size: 14.5px;
  cursor: pointer;
}

.sidebar .nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-item.active { background: var(--primary); color: #fff; }
.sidebar .nav-item .ic { font-size: 17px; width: 20px; text-align: center; }
.sidebar .nav-item img.ic { width: 19px; height: 19px; object-fit: contain; flex-shrink: 0; }
.sidebar .nav-item svg.ic { width: 19px; height: 19px; flex-shrink: 0; }

.sidebar .nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  color: #64748b;
  padding: 14px 14px 6px;
  letter-spacing: .05em;
}

.sidebar .sidebar-user {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.sidebar .sidebar-user:hover { background: rgba(255,255,255,.06); }

.sidebar .sidebar-user img {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #334155; flex-shrink: 0;
}

.sidebar .sidebar-user .name { color: #fff; font-size: 13.5px; font-weight: 600; }
.sidebar .sidebar-user .role { font-size: 12px; color: #94a3b8; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar h1 { font-size: 18px; margin: 0; }
.topbar .menu-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; font-size: 22px; cursor: pointer; color: var(--gray-700);
  width: 34px; height: 34px; border-radius: 8px;
}
.topbar .menu-toggle:hover { background: var(--gray-100); }

.lang-switch { display: flex; gap: 4px; background: var(--gray-100); border-radius: 8px; padding: 3px; }
.lang-switch a { padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--gray-600); }
.lang-switch a.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.auth-lang-switch { display: flex; justify-content: center; gap: 4px; margin-bottom: 16px; }
.auth-lang-switch a { padding: 5px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; color: rgba(255,255,255,.8); border: 1px solid rgba(255,255,255,.3); }
.auth-lang-switch a.active { background: #fff; color: var(--primary-dark); }

.content { padding: 24px; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-outline { background: #fff; border-color: var(--gray-300); color: var(--gray-700); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--gray-700); }

input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=date], input[type=time], input[type=file], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--gray-900);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input:disabled { background: var(--gray-100); color: var(--gray-500); }
textarea { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 14px; }
.form-row > * { flex: 1; }
.field-hint { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

.checkbox-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 8px 12px;
}
.checkbox-list-item { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 400; padding: 4px 0; margin-bottom: 0; }
.checkbox-list-item input[type="checkbox"] { width: auto; }

/* ---------- Cards / tables ---------- */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  padding: 20px;
  margin-bottom: 20px;
}

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

.card-header h2 { font-size: 16px; margin: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 10px; text-align: start; border-bottom: 1px solid var(--gray-100); }
th { color: var(--gray-500); font-weight: 600; font-size: 12.5px; text-transform: uppercase; }
tbody tr:hover { background: var(--gray-50); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-visit { background: #eef2ff; color: #4338ca; }
.badge-call { background: #fef3c7; color: #b45309; }
.badge-meeting { background: var(--teal-light); color: var(--teal); }
.badge-other { background: var(--gray-100); color: var(--gray-600); }

.badge-approval-pending { background: var(--gray-200); color: var(--gray-600); }
.badge-approval-approved { background: var(--success-light); color: var(--success); }
.badge-approval-unplanned { background: var(--warning-light); color: var(--warning); }
.badge-approval-rejected { background: var(--danger-light); color: var(--danger); }

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

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.alert-success { background: var(--success-light); color: var(--success); }
.alert-danger { background: var(--danger-light); color: var(--danger); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 14px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; padding: 24px; box-shadow: 0 25px 60px rgba(0,0,0,.3);
}
.modal-box h3 { margin: 0 0 18px; font-size: 17px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 20px; }
.modal-close { float: inline-end; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--gray-500); }

/* ---------- Calendar ---------- */
.cal-toolbar {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.cal-toolbar .cal-title { font-size: 18px; font-weight: 700; min-width: 160px; text-align: center; }
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-view-switch { display: flex; background: var(--gray-100); border-radius: 8px; padding: 3px; }
.cal-view-switch button {
  border: none; background: none; padding: 7px 14px; border-radius: 6px; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--gray-600);
}
.cal-view-switch button.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

.tab-switch { display: inline-flex; background: var(--gray-100); border-radius: 8px; padding: 3px; }
.tab-switch a {
  border: none; background: none; padding: 7px 16px; border-radius: 6px; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--gray-600); text-decoration: none;
}
.tab-switch a.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--gray-200);
  gap: 1px;
}
.cal-grid .cal-dow {
  background: var(--gray-50); padding: 9px; text-align: center; font-size: 12.5px; font-weight: 700; color: var(--gray-500);
}
.cal-cell {
  background: #fff; min-height: 108px; padding: 6px; display: flex; flex-direction: column; gap: 4px; cursor: pointer;
}
.cal-cell:hover { background: var(--gray-50); }
.cal-cell.other-month { background: var(--gray-50); }
.cal-cell.other-month .cal-daynum { color: var(--gray-300); }
.cal-cell.today .cal-daynum {
  background: var(--primary); color: #fff; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
}
.cal-daynum { font-size: 13px; font-weight: 700; color: var(--gray-700); }
.cal-event {
  font-size: 11px; padding: 2px 6px; border-radius: 5px; background: var(--gray-200); color: var(--gray-600);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-event.approval-approved { background: var(--success-light); color: var(--success); }
.cal-event.approval-unplanned { background: var(--warning-light); color: var(--warning); }
.cal-event.approval-rejected { background: var(--danger-light); color: var(--danger); }
.cal-event-products { opacity: .75; font-size: 10px; }
.cal-more { font-size: 11px; color: var(--gray-500); padding: 0 6px; }

.cal-week-grid { display: flex; flex-direction: column; border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; }
.cal-week-day { border-bottom: 1px solid var(--gray-100); }
.cal-week-day:last-child { border-bottom: none; }
.cal-week-day-header {
  display: flex; justify-content: space-between; padding: 10px 16px; background: var(--gray-50); font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.cal-week-day-header.today { color: var(--primary); }
.cal-week-day-body { padding: 8px 16px 14px; display: flex; flex-direction: column; gap: 6px; }
.cal-week-event {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; background: var(--gray-50); font-size: 13px; cursor: pointer;
  border-inline-start: 3px solid var(--gray-400);
}
.cal-week-event.approval-approved { border-inline-start-color: var(--success); }
.cal-week-event.approval-unplanned { border-inline-start-color: var(--warning); }
.cal-week-event.approval-rejected { border-inline-start-color: var(--danger); }
.cal-week-event .time { font-weight: 700; color: var(--gray-700); min-width: 48px; }

/* ---------- 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: 1px solid var(--gray-200); border-radius: var(--radius); padding: 18px; }
.stat-card .num { font-size: 26px; font-weight: 800; }
.stat-card .lbl { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* ---------- Avatar upload ---------- */
.avatar-edit { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.avatar-edit img { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: var(--gray-100); border: 1px solid var(--gray-200); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  /* Sidebar always overlays on small screens, regardless of collapsed state's effect on .main */
  .main { margin: 0 !important; }
  .form-row { flex-direction: column; gap: 0; }
}
