/* D GATE brand identity — from دليل الهوية البصرية (Nov 2025).
   Primary (60%): #2DA2F4 blue, #00FFD2 turquoise, #FF7A00 orange.
   Secondary (25%): #004C91 deep blue, #3FA9F5, #FFA94D, #F2F2F2, #999999.
   Neutral (15%): #FFFFFF, #333333.
   Fonts per guide: Al-Mohanad (AR) / Gill Sans MT (EN) — both commercial,
   not available as web fonts; using Cairo / Poppins as close modern-
   geometric substitutes until real font files are supplied. */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&family=Poppins:wght@400;600;700&display=swap');

:root {
  --brand-blue: #2DA2F4;
  --brand-turquoise: #00FFD2;
  --brand-orange: #FF7A00;
  --brand-deep-blue: #004C91;
  --brand-blue-soft: #3FA9F5;
  --brand-orange-soft: #FFA94D;
  --brand-bg-soft: #F2F2F2;
  --brand-gray: #999999;

  --bg: #F7F9FB;
  --card: #ffffff;
  --text: #333333;
  --muted: #6b7280;
  --border: #e6e9ec;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --good: #16a34a;
  --sidebar-w: 236px;
  --shadow-sm: 0 1px 3px rgba(0, 40, 80, .06);
  --shadow-md: 0 8px 24px rgba(0, 40, 80, .10);
  --font-ar: 'Cairo', Tahoma, Arial, sans-serif;
  --font-en: 'Poppins', 'Cairo', Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ar);
  background: var(--bg);
  color: var(--text);
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-deep-blue) 0%, var(--brand-blue) 55%, var(--brand-turquoise) 130%);
}
.login-card {
  background: var(--card);
  padding: 40px 40px 34px;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,.28);
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo-img { width: 96px; height: auto; margin-bottom: 10px; }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.login-card button {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-deep-blue));
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 700;
  font-family: inherit;
}
.login-card button:hover { opacity: .92; }
.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 10px;
}

/* ---------- App shell: sidebar + main ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--brand-deep-blue), #06345e);
  color: #eaf6ff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.14);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo-img { width: 38px; height: auto; flex-shrink: 0; background: #fff; border-radius: 8px; padding: 4px; }
.sidebar-brand-text { font-weight: 800; font-size: 16px; font-family: var(--font-en); letter-spacing: 1px; }
.sidebar-brand-text span {
  display: block; font-family: var(--font-ar); font-weight: 400;
  font-size: 11px; letter-spacing: 0; color: #bfe0f7; margin-top: 2px;
}
.sidebar-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; color: #d9edfb;
  padding: 11px 14px; border-radius: 9px; text-align: right;
  font-size: 14px; cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.nav-item .ic { font-size: 16px; }
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active { background: #fff; color: var(--brand-deep-blue); font-weight: 700; box-shadow: var(--shadow-sm); }
.nav-badge {
  margin-inline-start: auto;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 9px;
  align-items: center; justify-content: center; padding: 0 4px;
}
.nav-badge:not([hidden]) { display: flex; }
.sidebar-footer { padding: 14px 20px 20px; border-top: 1px solid rgba(255,255,255,.14); }
.sidebar-footer a { color: #d9edfb; font-size: 13px; text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }

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

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 14px 26px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.page-title { font-size: 17px; font-weight: 700; color: var(--brand-deep-blue); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.btn-secondary {
  background: #fff;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.btn-secondary:hover { background: var(--bg); }

.content { padding: 24px 26px; max-width: 1280px; width: 100%; margin: 0 auto; }

.page { display: none; }
.page.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Quick date filters ---------- */
.range-filters { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.range-btn {
  background: #fff; border: 1px solid var(--border); border-radius: 20px;
  padding: 7px 16px; font-size: 13px; cursor: pointer; color: var(--text); font-family: inherit;
}
.range-btn:hover { background: var(--brand-bg-soft); }
.range-btn.active { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; font-weight: 600; }

/* ---------- KPI + panels ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--brand-blue);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.kpi-card.wide { margin-bottom: 14px; }
.kpi-card.accent-orange { border-top-color: var(--brand-orange); }
.kpi-card.accent-danger { border-top-color: var(--danger); }
.kpi-label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.kpi-value { font-size: 27px; font-weight: 800; color: var(--brand-deep-blue); font-family: var(--font-en); }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.panel h2 { margin: 0 0 16px; font-size: 16px; color: var(--brand-deep-blue); }
.sub-h { font-size: 14px; color: var(--muted); margin: 0 0 10px; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .sidebar { width: 72px; }
  .sidebar-brand-text, .nav-item span.label { display: none; }
  .sidebar-brand { justify-content: center; }
  .content { padding: 16px; }
}

.chart-wrap { position: relative; height: 280px; margin-bottom: 16px; }
.chart-wrap-sm { height: 220px; }
.chart-wrap-xs { height: 180px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
tr:hover td { background: #fafcfe; }

.badge-missing { color: var(--danger); font-weight: 600; }
.badge-good { color: var(--good); font-weight: 600; }
.warn-color { color: var(--brand-orange) !important; }
.danger-color { color: var(--danger) !important; }
.good-color { color: var(--good) !important; }

.check-yes { color: var(--good); font-weight: 700; }
.check-no { color: var(--danger); font-weight: 700; }

/* ---------- Search ---------- */
.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.search-form input[type="text"],
.search-form select,
.search-form input[type="date"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
.search-form input[type="text"] { min-width: 180px; }
.date-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.btn-primary {
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-deep-blue));
  color: #fff;
  border: none;
  padding: 9px 22px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
}
.btn-primary:hover { opacity: .92; }
.btn-link {
  background: none;
  border: none;
  color: var(--brand-deep-blue);
  cursor: pointer;
  font-size: 13px;
  text-decoration: underline;
  padding: 0;
  font-family: inherit;
}

/* ---------- Table toolbars (export / print) ---------- */
.table-toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 8px; }
.btn-tool {
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--text); font-family: inherit;
}
.btn-tool:hover { background: var(--bg); }

/* ---------- Notification bell ---------- */
.bell-wrap { position: relative; }
.bell-btn { position: relative; font-size: 16px; padding: 8px 12px; }
.bell-badge {
  position: absolute; top: -6px; left: -6px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  align-items: center; justify-content: center;
  padding: 0 4px;
}
.bell-badge:not([hidden]) { display: flex; }
.bell-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-md);
  width: 320px; max-height: 400px; overflow-y: auto;
  z-index: 50; padding: 8px;
}
.bell-item {
  display: block; width: 100%; text-align: right;
  background: none; border: none; border-bottom: 1px solid var(--border);
  padding: 10px 8px; cursor: pointer; font-size: 13px; color: var(--text);
  font-family: inherit;
}
.bell-item:last-child { border-bottom: none; }
.bell-item:hover { background: var(--bg); }
.bell-item .n { font-weight: 700; color: var(--danger); }
.bell-empty { padding: 16px; text-align: center; color: var(--muted); font-size: 13px; }

.kpi-card.clickable-kpi { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.kpi-card.clickable-kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

/* ---------- Skeleton loaders ---------- */
.skeleton-cell {
  display: inline-block; height: 12px; border-radius: 4px; width: 70%;
  background: linear-gradient(90deg, #eceff1 25%, #f6f8f9 37%, #eceff1 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}
.skeleton-value {
  display: inline-block; height: 24px; width: 60px; border-radius: 6px;
  background: linear-gradient(90deg, #eceff1 25%, #f6f8f9 37%, #eceff1 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}
@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------- Drawer (customer profile + timeline) ---------- */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,32,64,.45);
  z-index: 90; backdrop-filter: blur(1px);
}
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: min(480px, 92vw);
  background: var(--card);
  z-index: 91;
  box-shadow: 8px 0 40px rgba(0,0,0,.25);
  flex-direction: column;
  animation: drawerIn .22s ease;
}
.drawer:not([hidden]) { display: flex; }
@keyframes drawerIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.drawer-header {
  padding: 20px 22px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: flex-start;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-deep-blue)); color: #fff;
}
.drawer-header h3 { margin: 0 0 4px; font-size: 17px; }
.drawer-header .sub { font-size: 12px; color: #cfeaff; }
.drawer-close {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 15px;
  flex-shrink: 0;
}
.drawer-close:hover { background: rgba(255,255,255,.28); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 22px; }

.profile-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px;
  margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--border);
}
.profile-field .l { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.profile-field .v { font-size: 14px; font-weight: 600; }

.timeline-item {
  display: flex; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.timeline-item:last-child { border-bottom: none; }
.timeline-time { color: var(--muted); white-space: nowrap; min-width: 110px; font-size: 12px; font-family: var(--font-en); }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-blue); margin-top: 5px; flex-shrink: 0; }
.timeline-dot.status { background: var(--brand-orange); }
.timeline-dot.create { background: var(--good); }
.timeline-content b { color: var(--text); }

/* ---------- Print (used by the popup-window CSV/print table view) ---------- */
.print-header {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 14px; margin-bottom: 16px; border-bottom: 3px solid var(--brand-blue);
}
.print-header img { width: 48px; height: auto; }
.print-header .name { font-weight: 800; font-size: 16px; color: var(--brand-deep-blue); font-family: var(--font-en); }
.print-header .sub { font-size: 11px; color: var(--muted); }

@media print {
  .topbar, .sidebar, .search-form, #refreshBtn, .btn-tool, .table-toolbar, .bell-wrap, .range-filters { display: none !important; }
}

/* ---------- Phase D: General Monitoring / shared screen chrome ---------- */
.entity-tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.entity-tab {
  background: none; border: none; padding: 10px 18px; font-size: 14px; font-family: inherit;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.entity-tab:hover { color: var(--text); }
.entity-tab.active { color: var(--brand-deep-blue); font-weight: 700; border-bottom-color: var(--brand-blue); }

.filter-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px;
  margin-bottom: 12px;
}
.filter-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.filter-field select, .filter-field input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; background: #fff;
}
.filter-actions { display: flex; gap: 8px; margin-top: 4px; }

.applied-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0 16px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand-bg-soft); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 6px 5px 12px; font-size: 12px; color: var(--text);
}
.filter-chip button {
  background: rgba(0,40,80,.1); border: none; border-radius: 50%; width: 18px; height: 18px;
  cursor: pointer; color: var(--brand-deep-blue); font-size: 12px; line-height: 1; flex-shrink: 0;
}
.filter-chip button:hover { background: rgba(0,40,80,.2); }
.filter-clear-all { background: none; border: none; color: var(--danger); font-size: 12px; cursor: pointer; text-decoration: underline; font-family: inherit; }

.pagination-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; flex-wrap: wrap; gap: 8px; }
.pagination-info { font-size: 12px; color: var(--muted); }
.pagination-controls { display: flex; gap: 6px; align-items: center; }
.pagination-controls button {
  background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px;
  font-size: 12px; cursor: pointer; font-family: inherit;
}
.pagination-controls button:disabled { opacity: .4; cursor: not-allowed; }
.pagination-controls button:not(:disabled):hover { background: var(--bg); }

.state-banner { text-align: center; padding: 40px 20px; color: var(--muted); font-size: 13px; }
.state-banner.error { color: var(--danger); }
.state-banner .retry-btn {
  display: inline-block; margin-top: 10px; background: var(--brand-blue); color: #fff; border: none;
  border-radius: 8px; padding: 7px 18px; font-size: 12px; cursor: pointer; font-family: inherit;
}
tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover td { background: var(--brand-bg-soft); }

/* ---------- Phase D: Home screen compact widgets ---------- */
.mini-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.mini-bar-row .label { flex: 0 0 130px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-bar-track { flex: 1; background: var(--bg); border-radius: 6px; height: 16px; overflow: hidden; }
.mini-bar-fill { height: 100%; background: var(--brand-blue); border-radius: 6px; }
.mini-bar-row .count { flex: 0 0 auto; font-weight: 700; font-family: var(--font-en); min-width: 36px; text-align: end; }
.widget-list { list-style: none; margin: 0; padding: 0; }
.widget-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.widget-list li:last-child { border-bottom: none; }
.widget-stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.widget-stat { text-align: center; }
.widget-stat .n { font-size: 20px; font-weight: 800; color: var(--brand-deep-blue); font-family: var(--font-en); }
.widget-stat .l { font-size: 11px; color: var(--muted); }
.status-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status-pill.blocked { background: #fef2f2; color: var(--danger); }
.status-pill.unavailable { background: var(--brand-bg-soft); color: var(--muted); }

@media (max-width: 640px) {
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .entity-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .entity-tab { white-space: nowrap; }
  table.mobile-cards thead { display: none; }
  table.mobile-cards, table.mobile-cards tbody { display: block; width: 100%; }
  table.mobile-cards tbody tr {
    display: block; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 10px 12px;
  }
  table.mobile-cards tbody td {
    display: flex; justify-content: space-between; gap: 10px; border: none; padding: 5px 0; white-space: normal; text-align: start;
  }
  table.mobile-cards tbody td::before { content: attr(data-label); color: var(--muted); font-size: 11px; flex-shrink: 0; }
}
