:root {
  --bg: #0f1412;
  --bg-elev: #171e1b;
  --bg-soft: #1e2823;
  --line: rgba(214, 232, 220, 0.12);
  --text: #e8f2ec;
  --muted: #9bb0a4;
  --faint: #6d8176;
  --accent: #d4a24c;
  --accent-2: #3d9b7a;
  --danger: #d67a67;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --header-h: 78px;
  --font: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 12px);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 500px at 100% -10%, rgba(61, 155, 122, 0.18), transparent 55%),
    radial-gradient(800px 400px at 0% 0%, rgba(212, 162, 76, 0.12), transparent 50%),
    var(--bg);
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(232, 242, 236, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 242, 236, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
  z-index: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--header-h);
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: #0f1412;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.shell,
.footer {
  position: relative;
  z-index: 1;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: calc(var(--header-h) + 24px) 0 64px;
  display: grid;
  gap: 20px;
}

.shell > * {
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.footer {
  padding: 18px 28px 28px;
  color: var(--faint);
  font-size: 0.85rem;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), #b8842f);
  color: #1a1408;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand strong {
  display: block;
  font-size: 1.05rem;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.file-btn,
.primary-btn,
.ghost-btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.file-btn,
.primary-btn {
  background: var(--accent);
  color: #1a1408;
}

.file-btn:hover,
.primary-btn:hover {
  transform: translateY(-1px);
  background: #e2b560;
}

.ghost-btn {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.ghost-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.file-btn:disabled,
.primary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

#searchInput {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

#searchInput:focus {
  outline: 2px solid rgba(212, 162, 76, 0.35);
  border-color: var(--accent);
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px dashed rgba(212, 162, 76, 0.35);
  color: var(--muted);
  font-size: 0.92rem;
  background: rgba(212, 162, 76, 0.06);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elev);
}

.filter-field {
  display: grid;
  gap: 6px;
}

.filter-field label {
  color: var(--muted);
  font-size: 0.82rem;
}

.filter-field input[type="date"] {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  min-width: 160px;
  color-scheme: dark;
}

.filter-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-inline-start: auto;
}

.chip-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip-btn:hover,
.chip-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.filter-note {
  flex-basis: 100%;
  margin: 0;
  color: #f0c27a;
  font-size: 0.85rem;
}

.export-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elev);
}

.export-label {
  color: var(--muted);
  font-weight: 600;
  margin-inline-end: 4px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.brands {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.brand-card {
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elev);
}

.brand-card.itqaan {
  border-color: rgba(61, 155, 122, 0.4);
  background: linear-gradient(180deg, rgba(61, 155, 122, 0.14), var(--bg-elev));
}

.brand-card.el3rab {
  border-color: rgba(212, 162, 76, 0.4);
  background: linear-gradient(180deg, rgba(212, 162, 76, 0.12), var(--bg-elev));
}

.brand-card header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.brand-card header h2 span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  margin-inline-start: 6px;
}

.brand-card header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.brand-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.brand-metrics span {
  display: block;
  color: var(--faint);
  font-size: 0.82rem;
  margin-bottom: 6px;
}

.brand-metrics strong {
  font-family: var(--mono);
  font-size: 1.2rem;
}

.kpi {
  padding: 18px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--line);
}

.kpi.accent {
  border-color: rgba(61, 155, 122, 0.45);
  background: linear-gradient(180deg, rgba(61, 155, 122, 0.16), var(--bg-elev));
}

.kpi p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.kpi strong {
  display: block;
  margin-top: 10px;
  font-size: 1.55rem;
  font-family: var(--mono);
  letter-spacing: -0.02em;
}

.kpi em {
  display: block;
  margin-top: 6px;
  color: var(--faint);
  font-style: normal;
  font-size: 0.82rem;
}

.charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  padding: 18px;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel header h2,
.table-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.panel header p,
.table-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.chart-wrap {
  position: relative;
  height: 280px;
  margin-top: 14px;
}

.chart-wrap.tall {
  height: 320px;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.table-head #searchInput {
  max-width: 240px;
}

.table-scroll {
  overflow: auto;
  max-height: 520px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--bg-soft);
  color: var(--muted);
  font-weight: 600;
  z-index: 1;
}

tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--bg-soft);
  border-top: 1px solid rgba(212, 162, 76, 0.35);
  border-bottom: none;
  font-weight: 700;
  color: var(--text);
  z-index: 1;
}

tfoot td:first-child {
  color: var(--accent);
}

tbody tr {
  cursor: pointer;
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: rgba(61, 155, 122, 0.08);
}

tbody tr.unmatched {
  color: #f0c27a;
}

td.num {
  font-family: var(--mono);
  font-size: 0.86rem;
}

.empty {
  text-align: center;
  padding: 48px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
}

.empty h2 {
  margin: 0 0 8px;
}

.empty p {
  color: var(--muted);
  line-height: 1.7;
}

.empty code {
  font-family: var(--mono);
  color: var(--accent);
}

.dropzone {
  margin: 22px auto 0;
  width: min(420px, 100%);
  padding: 34px 20px;
  border: 1.5px dashed rgba(212, 162, 76, 0.45);
  border-radius: 16px;
  color: var(--muted);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(212, 162, 76, 0.08);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

@media (max-width: 960px) {
  :root {
    --header-h: 128px;
  }

  .charts,
  .kpis,
  .brands {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .table-head {
    flex-direction: column;
    align-items: stretch;
  }

  .table-head #searchInput {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 20px);
  }

  .kpi strong {
    font-size: 1.25rem;
  }
}
