:root{
  --purple: #95389E;
  --purple-dark: #6e2f74;
  --purple-deep: #4a2050;
  --green: #1E9E5A;
  --green-bg: #e8f8ef;
  --amber: #C98A00;
  --amber-bg: #fdf3de;
  --red: #C63B3B;
  --red-bg: #fbe9e9;
  --blue: #2C7BE5;
  --gray: #8b8b93;
  --bg: #f3f1f7;
  --card: #ffffff;
  --text: #221c26;
  --border: #e6dfe8;
  --line: #d8c9dc;
}
*{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
html,body{margin:0; padding:0;}
body{
  font-family:'Tajawal','Cairo',Arial,sans-serif;
  background:var(--bg);
  color:var(--text);
  direction:rtl;
}

/* ===================== Login page ===================== */
.login-body{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  background:linear-gradient(160deg, var(--purple-deep), var(--purple) 55%, var(--purple-dark));
  padding:20px;
}
.login-card{
  background:#fff;
  border-radius:20px;
  padding:32px 28px;
  width:100%;
  max-width:380px;
  box-shadow:0 20px 50px rgba(0,0,0,0.25);
}
.login-logo{ text-align:center; margin-bottom:20px; }
.login-logo h1{ font-size:20px; margin:8px 0 2px; color:var(--purple-dark); }
.login-logo p{ font-size:12.5px; color:var(--gray); margin:0; }
.login-error{
  background:var(--red-bg); color:var(--red); border:1px solid #eac2c2;
  border-radius:10px; padding:10px 12px; font-size:13px; margin-bottom:14px; text-align:center;
}
.login-form label{ display:block; font-size:13px; font-weight:700; margin:12px 0 6px; color:var(--text); }
.login-form input{
  width:100%; padding:11px 14px; border:1px solid var(--border); border-radius:10px;
  font-size:14px; font-family:inherit; outline:none;
}
.login-form input:focus{ border-color:var(--purple); }
.login-form button{
  width:100%; margin-top:20px; background:var(--purple); color:#fff; border:none;
  border-radius:12px; padding:13px; font-size:15px; font-weight:800; cursor:pointer;
}

/* ===================== Admin layout ===================== */
.admin-body{ padding-bottom:40px; }
.admin-header{
  background:linear-gradient(135deg, var(--purple-deep), var(--purple-dark));
  color:#fff; padding:14px 20px; display:flex; align-items:center; justify-content:space-between;
  flex-wrap:wrap; gap:10px; box-shadow:0 4px 14px rgba(74,32,80,0.25);
}
.admin-brand{ font-weight:800; font-size:16px; }
.admin-nav{ display:flex; gap:6px; }
.admin-nav a{
  color:#fff; text-decoration:none; font-size:13.5px; font-weight:700; padding:8px 14px;
  border-radius:10px; background:rgba(255,255,255,0.1);
}
.admin-nav a.active{ background:#fff; color:var(--purple-dark); }
.admin-user{ display:flex; align-items:center; gap:10px; font-size:13px; }
.logout-link{ color:#fff; background:rgba(255,255,255,0.15); padding:6px 12px; border-radius:8px; text-decoration:none; font-weight:700; }

.admin-wrap{ max-width:1100px; margin:24px auto; padding:0 18px; }
.admin-header-row{ display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; flex-wrap:wrap; gap:10px; }
.admin-header-row h2{ margin:0; font-size:19px; color:var(--purple-dark); }

.btn-primary{
  background:var(--purple); color:#fff; border:none; border-radius:10px;
  padding:10px 18px; font-weight:800; font-size:13.5px; cursor:pointer;
}

.kpi-row{ display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin-bottom:20px; }
.kpi-card{ background:#fff; border:1px solid var(--border); border-radius:14px; padding:16px; text-align:center; }
.kpi-num{ font-size:26px; font-weight:900; color:var(--purple-dark); }
.kpi-label{ font-size:12.5px; color:var(--gray); font-weight:700; margin-top:4px; }
.kpi-card.kpi-green .kpi-num{ color:var(--green); }
.kpi-card.kpi-red .kpi-num{ color:var(--red); }

.filters-row{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; margin-bottom:14px; }
.filters-row select{
  padding:9px 12px; border:1px solid var(--border); border-radius:10px; font-family:inherit; font-size:13px; background:#fff;
}
.only-problems-toggle{ font-size:13px; color:var(--text); display:flex; align-items:center; gap:6px; }
.live-indicator{ font-size:12.5px; font-weight:700; color:var(--green); margin-inline-start:auto; }

.table-wrap{ background:#fff; border:1px solid var(--border); border-radius:14px; overflow:auto; }
.admin-table{ width:100%; border-collapse:collapse; font-size:13.5px; }
.admin-table th{
  background:#faf7fb; color:var(--purple-dark); text-align:right; padding:12px 14px;
  font-size:12.5px; border-bottom:1px solid var(--border); white-space:nowrap;
}
.admin-table td{ padding:11px 14px; border-bottom:1px solid var(--border); vertical-align:middle; }
.admin-table tr:last-child td{ border-bottom:none; }
.admin-table tr.row-problem{ background:var(--red-bg); }
.empty-row{ text-align:center; color:var(--gray); padding:30px !important; }

.pill{ font-size:11px; font-weight:800; padding:4px 10px; border-radius:20px; white-space:nowrap; }
.pill-purple{ background:#f1e3f3; color:var(--purple-dark); }
.pill-blue{ background:#e3edfc; color:var(--blue); }
.pill-amber{ background:var(--amber-bg); color:var(--amber); }
.pill-green{ background:var(--green); color:#fff; }
.pill-red{ background:var(--red); color:#fff; }
.pill-gray{ background:#eee7f0; color:var(--purple-dark); }

.status-dot{ display:inline-block; width:8px; height:8px; border-radius:50%; margin-inline-end:4px; }
.status-dot.active{ background:var(--green); }
.status-dot.inactive{ background:var(--gray); }

.actions-cell{ white-space:nowrap; }
.link-btn{
  background:none; border:none; color:var(--purple-dark); font-weight:700; font-size:12.5px;
  cursor:pointer; text-decoration:none; margin-inline-end:8px; font-family:inherit; padding:0;
}
.link-btn.danger{ color:var(--red); }

/* ===== Feed report cards (لوحة المتابعة) ===== */
.feed-list{ display:flex; flex-direction:column; gap:12px; }
.feed-card{
  display:flex; gap:12px; background:#fff; border:1px solid var(--border); border-radius:16px;
  padding:14px 16px; box-shadow:0 3px 10px rgba(60,30,70,0.05); transition:.2s;
}
.feed-card-problem{ border-color:#eac2c2; background:var(--red-bg); }
.feed-card-avatar{
  flex:none; width:40px; height:40px; border-radius:50%; background:linear-gradient(135deg, var(--purple), var(--purple-dark));
  color:#fff; display:flex; align-items:center; justify-content:center; font-weight:900; font-size:16px;
  box-shadow:0 3px 8px rgba(74,32,80,0.25);
}
.feed-card-body{ flex:1; min-width:0; }
.feed-card-top{ display:flex; justify-content:space-between; align-items:flex-start; gap:8px; flex-wrap:wrap; }
.feed-card-title{ display:flex; flex-direction:column; gap:2px; }
.feed-emp-name{ font-weight:800; font-size:14px; color:var(--text); }
.feed-branch-name{ font-size:12.5px; color:var(--purple-dark); font-weight:700; }
.feed-card-meta{ display:flex; align-items:center; gap:8px; margin-top:8px; flex-wrap:wrap; }
.feed-time{ font-size:11.5px; color:var(--gray); font-weight:700; }
.feed-note{
  margin-top:8px; font-size:12.5px; color:var(--red); background:#fff; border:1px dashed var(--red);
  border-radius:8px; padding:6px 10px;
}
.feed-photo-wrap{ margin-top:10px; display:flex; align-items:center; gap:10px; }
.feed-photo-thumb{
  width:56px; height:56px; object-fit:cover; border-radius:10px; cursor:zoom-in;
  border:1.5px solid var(--border); box-shadow:0 2px 6px rgba(0,0,0,0.1); transition:.15s;
}
.feed-photo-thumb:hover{ transform:scale(1.05); border-color:var(--purple); }
.feed-photo-label{ font-size:11.5px; color:var(--blue); font-weight:700; }

/* ===================== Modal (shared) ===================== */
.modal-overlay{
  position:fixed; inset:0; background:rgba(34,28,38,0.55); display:none;
  align-items:center; justify-content:center; z-index:50; padding:20px; overflow-y:auto;
}
.modal-overlay.show{ display:flex; }
.modal-box{ background:#fff; border-radius:16px; padding:22px; width:100%; max-width:380px; margin:auto; }
.modal-box.wide{ max-width:520px; }
.modal-box h3{ margin:0 0 14px; font-size:16px; color:var(--purple-dark); }
.modal-box label{ display:block; font-size:13px; font-weight:700; margin:12px 0 6px; }
.modal-box input[type="text"], .modal-box input[type="password"], .modal-box select{
  width:100%; padding:10px 12px; border:1px solid var(--border); border-radius:10px;
  font-size:14px; font-family:inherit; outline:none;
}
.scope-options{ display:flex; flex-direction:column; gap:8px; margin-top:6px; }
.radio-row{ display:flex; align-items:center; gap:8px; font-size:13.5px; font-weight:600; }
.branch-checklist{
  max-height:220px; overflow-y:auto; border:1px solid var(--border); border-radius:10px;
  padding:10px; margin-top:6px;
}
.branch-group-title{ font-size:12px; font-weight:800; color:var(--purple-dark); margin:10px 0 4px; }
.branch-group-title:first-child{ margin-top:0; }
.check-row{ display:flex; align-items:center; gap:8px; font-size:13px; padding:4px 0; }
.modal-box .modal-actions{ display:flex; gap:8px; margin-top:18px; }
.modal-box button{ flex:1; border:none; border-radius:10px; padding:11px; font-weight:800; font-size:13.5px; cursor:pointer; font-family:inherit; }
.modal-box .save-btn{ background:var(--purple); color:#fff; }
.modal-box .cancel-btn{ background:#f1eef2; color:var(--gray); }

/* ===================== Driver app (shared with previous design) ===================== */
body:not(.admin-body):not(.login-body){ padding-bottom:92px; }

header{
  background:
    radial-gradient(circle at 15% 0%, rgba(255,255,255,0.10), transparent 45%),
    linear-gradient(160deg, var(--purple-deep), var(--purple) 55%, var(--purple-dark));
  color:#fff; padding:18px 16px 16px; position:sticky; top:0; z-index:30;
  box-shadow:0 6px 18px rgba(74,32,80,0.28);
}
.brand-row{ display:flex; align-items:center; justify-content:space-between; gap:10px; }
.brand-title{ display:flex; align-items:center; gap:8px; }
.brand-title .pin{ width:30px;height:30px; flex:none; }
.brand-title h1{ margin:0; font-size:17px; font-weight:800; letter-spacing:.2px; }
.brand-title .sub{ font-size:11.5px; opacity:.82; margin-top:1px; }
.driver-chip{
  background:rgba(255,255,255,0.14); border:1px solid rgba(255,255,255,0.3); border-radius:20px;
  padding:6px 12px; font-size:12px; font-weight:700; color:#fff; display:flex; align-items:center;
  gap:6px; cursor:pointer; white-space:nowrap; text-decoration:none;
}

.region-bar{ display:flex; gap:8px; overflow-x:auto; padding:14px 2px 2px; margin-top:12px; -webkit-overflow-scrolling:touch; }
.region-bar::-webkit-scrollbar{display:none;}
.region-btn{
  flex:0 0 auto; background:rgba(255,255,255,0.12); border:1.5px solid rgba(255,255,255,0.32);
  color:#fff; padding:9px 16px; border-radius:24px; font-size:13.5px; font-weight:700; cursor:pointer;
  white-space:nowrap; transition:.2s;
}
.region-btn .count{ opacity:0.85; font-weight:500; font-size:11.5px; margin-inline-start:4px; }
.region-btn.active{ background:#fff; color:var(--purple-dark); border-color:#fff; }

.locate-bar{ max-width:720px; margin:14px auto 0; padding:0 14px; }
.locate-btn{
  width:100%; background:var(--card); border:1.5px dashed var(--purple); color:var(--purple-dark);
  border-radius:14px; padding:12px 14px; font-size:13.5px; font-weight:800; cursor:pointer;
  display:flex; align-items:center; justify-content:center; gap:8px;
}
.locate-btn.on{ background:linear-gradient(90deg, var(--purple), var(--purple-dark)); color:#fff; border-style:solid; }
.locate-status{ text-align:center; font-size:11.5px; color:var(--gray); margin-top:6px; }

.map-wrap{ max-width:720px; margin:12px auto 0; padding:0 14px; }
#liveMap{ width:100%; height:260px; border-radius:16px; border:1px solid var(--border); box-shadow:0 8px 22px rgba(74,32,80,0.10); z-index:1; }
.leaflet-popup-content{ font-family:'Tajawal',sans-serif; direction:rtl; text-align:right; font-size:13px; }
.leaflet-popup-content b{ color:var(--purple-dark); }

.marker-pin{
  width:26px; height:26px; border-radius:50% 50% 50% 0; transform:rotate(-45deg);
  display:flex; align-items:center; justify-content:center; box-shadow:0 2px 6px rgba(0,0,0,0.35); border:2px solid #fff;
}
.marker-pin span{ transform:rotate(45deg); font-size:12px; font-weight:900; color:#fff; }
.marker-pin.pending{ background:var(--purple); }
.marker-pin.done{ background:var(--green); }
.marker-pin.problem{ background:var(--red); }
.marker-pin.nearest{ box-shadow:0 0 0 5px rgba(44,123,229,0.35), 0 2px 6px rgba(0,0,0,0.35); }
.user-dot{ width:18px; height:18px; border-radius:50%; background:var(--blue); border:3px solid #fff; box-shadow:0 0 0 6px rgba(44,123,229,0.25); }

.route-summary{ max-width:720px; margin:14px auto 0; padding:0 14px; }
.route-card{ background:var(--card); border-radius:18px; padding:16px 16px 14px; box-shadow:0 8px 22px rgba(74,32,80,0.10); border:1px solid var(--border); }
.route-card-top{ display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; }
.route-name{ font-size:15px; font-weight:800; color:var(--purple-dark); display:flex; align-items:center; gap:6px; }
.route-pct{ font-size:22px; font-weight:900; color:var(--green); }
.stat-row{ display:flex; gap:8px; }
.stat-pill{ flex:1; text-align:center; border-radius:12px; padding:8px 4px; font-size:11.5px; font-weight:800; }
.stat-pill .num{ display:block; font-size:16px; margin-bottom:1px; }
.stat-pill.total{ background:#f1eef3; color:var(--purple-dark); }
.stat-pill.done{ background:var(--green-bg); color:var(--green); }
.stat-pill.pending{ background:#f1eef2; color:var(--gray); }
.stat-pill.problem{ background:var(--red-bg); color:var(--red); }
.progress-track{ height:8px; background:#e5dee7; border-radius:5px; overflow:hidden; margin-top:12px; }
.progress-fill{ height:100%; background:linear-gradient(90deg, var(--green), #33c481); border-radius:5px; transition:width .35s; }

.toolbar{ max-width:720px; margin:14px auto 0; padding:0 14px; display:flex; flex-direction:column; gap:10px; }
.search-box{ display:flex; align-items:center; background:#fff; border:1px solid var(--border); border-radius:12px; padding:9px 12px; gap:8px; }
.search-box input{ border:none; outline:none; flex:1; font-size:14px; background:transparent; font-family:inherit; color:var(--text); }
.status-filters{ display:flex; gap:6px; background:#fff; border:1px solid var(--border); border-radius:14px; padding:4px; }
.status-filters button{
  flex:1; border:none; background:transparent; border-radius:11px; padding:9px 4px; font-size:12.5px;
  font-weight:800; color:var(--gray); cursor:pointer; font-family:inherit; transition:.15s; white-space:nowrap;
}
.status-filters button.active.all{ background:var(--purple); color:#fff; }
.status-filters button.active.pending{ background:var(--gray); color:#fff; }
.status-filters button.active.done{ background:var(--green); color:#fff; }
.status-filters button.active.problem{ background:var(--red); color:#fff; }
.sort-row{ display:flex; align-items:center; justify-content:space-between; padding:0 2px; font-size:12px; color:var(--gray); font-weight:700; }
.sort-row .badge-nearest{ background:var(--blue); color:#fff; border-radius:10px; padding:2px 9px; font-size:11px; }

.route-list{ max-width:720px; margin:16px auto; padding:0 14px; position:relative; }
.stop{ display:flex; gap:12px; position:relative; }
.stop:not(:last-child)::before{
  content:""; position:absolute; top:34px; right:16px; width:2px; bottom:-14px;
  background:repeating-linear-gradient(to bottom, var(--line) 0 6px, transparent 6px 11px);
}
.stop-marker{
  flex:none; width:34px; height:34px; border-radius:50%; display:flex; align-items:center; justify-content:center;
  font-size:13px; font-weight:900; color:#fff; background:var(--gray); box-shadow:0 3px 8px rgba(0,0,0,0.15);
  position:relative; z-index:2;
}
.stop-marker.done{ background:var(--green); }
.stop-marker.problem{ background:var(--red); }
.stop-marker.pending{ background:var(--purple); }
.stop-marker.is-nearest{ box-shadow:0 0 0 5px rgba(44,123,229,0.25); }

.stop-body{
  flex:1; background:var(--card); border:1px solid var(--border); border-radius:16px; padding:12px 14px;
  margin-bottom:14px; box-shadow:0 3px 10px rgba(60,30,70,0.05); transition:.2s;
}
.stop-body.status-done{ border-color:#bfe6cf; background:var(--green-bg); }
.stop-body.status-problem{ border-color:#eac2c2; background:var(--red-bg); }
.stop-body.is-nearest{ border-color:var(--blue); box-shadow:0 0 0 2px rgba(44,123,229,0.18); }

.stop-top{ display:flex; justify-content:space-between; align-items:flex-start; gap:8px; }
.stop-name-wrap{ display:flex; flex-direction:column; gap:2px; }
.stop-name{ font-size:15px; font-weight:800; margin:0; line-height:1.35; }
.stop-dist{ font-size:11.5px; font-weight:700; color:var(--blue); }
.badge{ font-size:10.5px; font-weight:800; padding:4px 9px; border-radius:20px; white-space:nowrap; flex:none; }
.badge.pending{ background:#eee7f0; color:var(--purple-dark); }
.badge.done{ background:var(--green); color:#fff; }
.badge.problem{ background:var(--red); color:#fff; }
.badge.nearest{ background:var(--blue); color:#fff; margin-inline-start:6px; }
.badge.photo{ background:#e3edfc; color:var(--blue); margin-inline-start:6px; }

.problem-note{ margin:8px 0 0; font-size:12.5px; color:var(--red); background:#fff; border:1px dashed var(--red); border-radius:8px; padding:6px 10px; }

.stop-actions{ display:flex; gap:7px; margin-top:11px; flex-wrap:wrap; }
.btn{
  flex:1; min-width:76px; border:none; border-radius:10px; padding:9px 6px; font-size:12.5px; font-weight:800;
  cursor:pointer; transition:.15s; font-family:inherit; text-align:center; text-decoration:none;
  display:inline-flex; align-items:center; justify-content:center; gap:4px;
}
.btn:active{ transform:scale(0.96); }
.btn-map{ background:var(--purple); color:#fff; }
.btn-map.disabled{ background:#e5dee7; color:var(--gray); cursor:not-allowed; pointer-events:none; }
.btn-done{ background:var(--green-bg); color:var(--green); border:1.5px solid var(--green); }
.btn-done.active{ background:var(--green); color:#fff; }
.btn-pending{ background:#f1eef2; color:var(--gray); border:1.5px solid var(--border); }
.btn-pending.active{ background:var(--gray); color:#fff; }
.btn-problem{ background:var(--red-bg); color:var(--red); border:1.5px solid var(--red); }
.btn-problem.active{ background:var(--red); color:#fff; }

.empty{ text-align:center; color:var(--gray); padding:60px 20px; font-size:14px; }
.empty .big{ font-size:34px; display:block; margin-bottom:8px; }

.bottom-bar{
  position:fixed; bottom:0; right:0; left:0; background:#fff; border-top:1px solid var(--border);
  padding:10px 14px; display:flex; gap:10px; max-width:720px; margin:0 auto; box-shadow:0 -6px 18px rgba(0,0,0,0.07); z-index:20;
}
.bottom-btn{ flex:1; border:none; border-radius:12px; padding:12px 10px; font-size:14px; font-weight:800; cursor:pointer; font-family:inherit; }
.bottom-btn.report{ background:var(--purple); color:#fff; }
.bottom-btn.reset{ background:#f1eef2; color:var(--red); }

.toast{
  position:fixed; bottom:80px; right:50%; transform:translateX(50%); background:#221c26; color:#fff;
  padding:10px 18px; border-radius:10px; font-size:13px; z-index:40; opacity:0; pointer-events:none;
  transition:opacity .25s, bottom .25s; white-space:nowrap;
}
.toast.show{ opacity:1; bottom:96px; }

@media (min-width:720px){ .route-list{ max-width:900px; } }
@media (min-width:900px){ .kpi-row{ grid-template-columns:repeat(4,1fr); } }
@media (max-width:700px){ .kpi-row{ grid-template-columns:repeat(2,1fr); } }
