:root {
  --emerald: #0f766e;
  --emerald-2: #14b8a6;
  --indigo: #3740a4;
  --blue: #2563eb;
  --rose: #c2415b;
  --amber: #b7791f;
  --slate-950: #0f172a;
  --slate-800: #1e293b;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;
  --white: #ffffff;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  background: linear-gradient(180deg, #f8fafc 0%, #eef3f7 100%);
  color: var(--slate-950);
  font-family: "Tajawal", sans-serif;
  margin: 0;
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.shell-header {
  align-items: center;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--slate-200);
  backdrop-filter: blur(16px);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  min-height: 86px;
  padding: 18px clamp(16px, 3vw, 36px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.title-block {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  align-items: center;
  background: var(--emerald);
  border-radius: var(--radius);
  color: #fff;
  display: inline-flex;
  font-weight: 800;
  height: 46px;
  justify-content: center;
  letter-spacing: 0;
  width: 64px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 36px);
  font-weight: 800;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  font-weight: 800;
}

.title-block p,
.panel-head p {
  color: var(--slate-500);
  font-size: 13px;
  margin-top: 3px;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.primary-button,
.icon-button,
.nav-item,
.chip,
.pager-button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 38px;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.primary-button {
  background: var(--emerald);
  color: #fff;
  font-weight: 700;
  padding: 8px 14px;
}

.icon-button {
  background: var(--slate-100);
  border-color: var(--slate-200);
  color: var(--slate-800);
  font-size: 20px;
  width: 40px;
}

.primary-button:hover,
.icon-button:hover,
.pager-button:hover {
  transform: translateY(-1px);
}

.app-shell {
  display: grid;
  gap: 18px;
  grid-template-columns: 220px minmax(0, 1fr);
  padding: 18px clamp(16px, 3vw, 36px) 36px;
}

.sidebar {
  align-content: start;
  display: grid;
  gap: 8px;
  position: sticky;
  top: 104px;
}

.nav-item {
  background: transparent;
  color: var(--slate-600);
  font-weight: 700;
  padding: 11px 14px;
  text-align: right;
}

.nav-item:hover,
.nav-item.active {
  background: #e7f5f2;
  color: var(--emerald);
}

.content {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.filter-bar,
.panel,
.kpi-card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-bar {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(150px, 210px)) minmax(220px, 1fr);
  padding: 14px;
}

label {
  color: var(--slate-500);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

input,
select {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  color: var(--slate-950);
  min-height: 40px;
  outline: none;
  padding: 8px 11px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus,
select:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.active-filters {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
}

.chip {
  align-items: center;
  background: var(--slate-100);
  border-color: var(--slate-200);
  color: var(--slate-700);
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  gap: 8px;
  padding: 7px 10px;
}

.chip button {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-weight: 800;
  padding: 0;
}

.kpi-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(6, minmax(138px, 1fr));
}

.kpi-card {
  display: grid;
  gap: 10px;
  min-height: 126px;
  overflow: hidden;
  padding: 14px;
  position: relative;
}

.kpi-card::after {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.14), transparent 65%);
  content: "";
  height: 90px;
  left: -35px;
  position: absolute;
  top: -35px;
  width: 120px;
}

.kpi-label {
  color: var(--slate-500);
  font-size: 13px;
  font-weight: 700;
}

.kpi-value {
  direction: ltr;
  font-size: clamp(21px, 2vw, 30px);
  font-weight: 800;
  text-align: right;
}

.kpi-sub {
  color: var(--slate-500);
  font-size: 12px;
}

.sparkline {
  height: 22px;
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.panel-head {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head > div {
  min-width: 0;
}

.chart-wrap {
  height: 330px;
  min-width: 0;
  position: relative;
}

.chart-wrap canvas {
  height: 100% !important;
  width: 100% !important;
}

.chart-tooltip {
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.22);
  color: #fff;
  opacity: 0;
  padding: 10px 12px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, -110%);
  transition: opacity 0.12s ease;
  z-index: 1000;
}

.tooltip-title {
  font-weight: 800;
  margin-bottom: 5px;
}

.tooltip-line {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-width: 170px;
}

.table-search {
  min-width: min(280px, 100%);
}

.table-shell {
  display: grid;
  gap: 12px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 900px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--slate-200);
  padding: 11px 10px;
  text-align: right;
  vertical-align: middle;
}

th {
  color: var(--slate-500);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
  white-space: nowrap;
}

td {
  color: var(--slate-800);
  font-size: 14px;
}

tr.highlight td {
  background: #ecfdf5;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 8px;
}

.badge.good {
  background: #dcfce7;
  color: #166534;
}

.badge.warn {
  background: #fef3c7;
  color: #92400e;
}

.badge.bad {
  background: #fee2e2;
  color: #991b1b;
}

.pagination {
  align-items: center;
  color: var(--slate-500);
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.pager-button {
  background: var(--slate-100);
  border-color: var(--slate-200);
  color: var(--slate-800);
  font-weight: 700;
  padding: 7px 10px;
}

.empty-state {
  align-items: center;
  background: var(--slate-50);
  border: 1px dashed var(--slate-300);
  border-radius: var(--radius);
  color: var(--slate-500);
  display: grid;
  min-height: 180px;
  place-items: center;
  text-align: center;
}

.ranking-list {
  display: grid;
  gap: 11px;
}

.rank-row {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(120px, 0.38fr) minmax(150px, 1fr) 110px;
  padding: 4px;
  text-align: right;
}

.rank-row:hover {
  background: var(--slate-50);
}

.rank-row strong {
  color: var(--slate-800);
}

.rank-bar {
  background: var(--slate-100);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.rank-bar span {
  background: linear-gradient(90deg, var(--emerald), var(--blue));
  display: block;
  height: 100%;
}

.rank-value {
  color: var(--slate-500);
  direction: ltr;
  font-weight: 700;
  text-align: left;
}

@media (max-width: 1220px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: flex;
    overflow-x: auto;
    position: static;
  }

  .nav-item {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .shell-header,
  .panel-head {
    align-items: stretch;
    display: grid;
  }

  .header-actions {
    justify-content: stretch;
  }

  .primary-button {
    flex: 1;
  }

  .filter-bar,
  .grid.two,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 300px;
  }

  .rank-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .app-shell,
  .shell-header {
    padding-inline: 12px;
  }

  .title-block {
    align-items: flex-start;
  }

  .brand-mark {
    height: 42px;
    width: 58px;
  }
}
