:root {
  --bg: #0B1E33;
  --bg-alt: #0F2740;
  --card-bg: #122C48;
  --card-border: #1E4064;
  --primary: #1480CA;
  --primary-dark: #0F659F;
  --text: #E8F0F7;
  --text-muted: #93A9C2;
  --danger: #F5703B;
  --danger-dark: #D8571F;
  --success: #2E9E5B;
  --success-dark: #24824A;
  --warning: #F49E39;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(11, 30, 51, 0.9), rgba(11, 30, 51, 0.93)),
    url('/images/site-background.jpg');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: var(--text);
  font-family: 'Cairo', 'Tajawal', sans-serif;
  direction: rtl;
}

a { color: inherit; }

.topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 24px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  min-height: 140px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar-brand img {
  height: 100%;
  max-height: 140px;
  width: auto;
  display: block;
}

@media (max-width: 720px) {
  .topbar { min-height: 100px; }
  .topbar-brand img { max-height: 100px; }
}

.topbar-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.topbar-center h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.25;
  text-align: center;
}

@media (max-width: 720px) {
  .topbar-center h1 { font-size: 1.1rem; }
}

.topbar-clock {
  text-align: center;
}

.topbar-clock #live-clock {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}

.topbar-clock .last-update {
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.btn-compact {
  width: auto;
  padding: 6px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .topbar { justify-content: center; }
  .topbar-brand { order: 0; width: 100%; justify-content: center; }
  .topbar-center { order: 1; width: 100%; }
  .topbar-actions { order: 2; width: 100%; justify-content: center; flex-wrap: wrap; }
}

.container {
  max-width: 1900px;
  margin: 0 auto;
  padding: 24px 3% 60px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card h2, .card h3 {
  margin-top: 0;
  color: var(--text);
  font-weight: 800;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--text-muted);
}

input, select, button, textarea {
  font-family: inherit;
  font-size: 1rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="file"],
select {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--text);
}

input:focus, select:focus {
  outline: 2px solid var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 20px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 1.05rem;
  width: 100%;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--success);
  color: #06331d;
  padding: 14px 24px;
  border-radius: 10px;
  font-weight: 700;
  transition: transform 0.25s ease;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.filters .field { flex: 1 1 200px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}

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

.kpi-card .value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
}

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

.kpi-card-wide {
  grid-column: span 2;
}

@media (max-width: 640px) {
  .kpi-card-wide { grid-column: span 1; }
}

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rank-row-active .rank-name,
.rank-row-active .rank-value {
  color: var(--primary);
  font-weight: 800;
}

.rank-position {
  flex: 0 0 18px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
}

.rank-name {
  flex: 0 0 88px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-bar-track {
  flex: 1;
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.rank-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.rank-value {
  flex: 0 0 auto;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.chart-box { position: relative; height: 320px; }

.activity-detail-block {
  margin-bottom: 36px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--card-border);
}

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

.activity-detail-heading {
  color: var(--primary);
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0 0 16px;
}

.activity-detail-block .kpi-grid {
  margin-bottom: 20px;
}

.activity-detail-block .charts-grid {
  margin-bottom: 20px;
}

.insights-list-content p {
  margin: 0 0 10px;
  line-height: 1.7;
}

.insights-list-content p:last-child { margin-bottom: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  padding: 10px 8px;
  text-align: right;
  border-bottom: 1px solid var(--card-border);
}

th { color: var(--text-muted); font-weight: 700; }

tr:hover td { background: rgba(20,128,202,0.1); }

.photo-icon {
  cursor: pointer;
  font-size: 1.1rem;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(244,158,57,0.15);
  color: var(--warning);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.show { display: flex; }

.modal-overlay img {
  max-width: 100%;
  max-height: 85vh;
  border-radius: 12px;
}

.modal-close {
  position: absolute;
  top: 20px;
  left: 20px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 1.2rem;
}

.modal-panel {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 28px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(16, 24, 40, 0.18);
}

.modal-panel.wide { max-width: 680px; }

.modal-panel .modal-close {
  top: 12px;
  left: 12px;
  width: 34px;
  height: 34px;
  font-size: 1rem;
}

.modal-panel h2 {
  margin-top: 0;
  color: var(--text);
  font-weight: 800;
}

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

.dropzone {
  border: 2px dashed var(--card-border);
  border-radius: 14px;
  padding: 50px 20px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.dragover {
  border-color: var(--primary);
  background: rgba(20,128,202,0.12);
}

@media (max-width: 640px) {
  .container { padding: 16px 12px 60px; }
}

.result-box {
  margin-top: 20px;
  padding: 16px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--card-border);
}

.error-list {
  max-height: 200px;
  overflow-y: auto;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--danger);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 30px;
}
