/* ===========================
   dashboard.css
   Single Source of Truth (Dashboard layout/content ONLY)
   - No Sidebar styles
   - No Topbar styles
   =========================== */

/* ========== TOKENS ========== */
:root {
  /* Mauritania palette, per the approved design canvas */
  --primary: #006233;
  --primary-hover: #004A26;
  --dark: #013B22;
  --accent: #FFC400;
  --danger: #CD2A3E;

  --bg: #F5F4EE;
  --surface: #ffffff;
  --surface-alt: #FAF9F4;
  --text: #12211B;
  --muted: #3D4A43;

  /* Dark green sidebar rail */
  --sidebar: #013B22;
  --sidebar-fg: #EAF3ED;
  --sidebar-muted: #9FBCAC;
  --sidebar-active: #006233;

  --radius-card: 16px;
  --shadow-card: 0 10px 25px rgba(0, 0, 0, 0.06);
  --border-light: #DAD8CC;

  /* Status tones — bg / fg / dot per tone. Never used alone: every badge
     also carries an icon and a text label. */
  --tone-wait-bg: #FFF6DC;   --tone-wait-fg: #8A5B00;   --tone-wait-dot: #E0A400;
  --tone-active-bg: #E7F0EA; --tone-active-fg: #006233; --tone-active-dot: #006233;
  --tone-done-bg: #E4EFE7;   --tone-done-fg: #02502B;   --tone-done-dot: #02502B;
  --tone-bad-bg: #FCEBED;    --tone-bad-fg: #A81F30;    --tone-bad-dot: #CD2A3E;
  --tone-off-bg: #F0EFE8;    --tone-off-fg: #5D6C63;    --tone-off-dot: #8B968E;
}

/* Dark mode keeps the same hues, lifted for contrast on a dark ground. */
html.dark {
  --bg: #0E1713;
  --surface: #16221C;
  --surface-alt: #1B2922;
  --text: #EAF3ED;
  --muted: #9FBCAC;
  --border-light: #24352C;
  --primary: #2FBE72;
  --primary-hover: #4BD189;

  --tone-wait-bg: #3A2E12;   --tone-wait-fg: #FFD98A;   --tone-wait-dot: #E0A400;
  --tone-active-bg: #12301F; --tone-active-fg: #6BD79B; --tone-active-dot: #2FBE72;
  --tone-done-bg: #12301F;   --tone-done-fg: #7FE0AA;   --tone-done-dot: #2FBE72;
  --tone-bad-bg: #3A1B20;    --tone-bad-fg: #FF9AA8;    --tone-bad-dot: #FF6376;
  --tone-off-bg: #212B26;    --tone-off-fg: #A9B6AE;    --tone-off-dot: #8B968E;
}

/* ========== RESET ========== */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--dark);
}

a {
  text-decoration: none;
  color: inherit;
}

/* ========== LAYOUT ========== */
.app {
  min-height: 100vh;
  display: flex;
}

/* IMPORTANT:
   .sidebar direction/layout rules MUST be in sidebar.css only
   .topbar styles MUST be in topbar.css only
*/

.main {
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Content padding (below topbar) */
.content {
  padding: 18px 22px 30px;
}

/* ========== KPI GRID ========== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  position: relative;
  background: var(--surface);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: default;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid transparent;
  background: linear-gradient(120deg,
      rgba(0, 132, 61, 0.08),
      rgba(255, 196, 0, 0.10));
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.kpi-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.1);
}

.kpi-card:hover::before {
  opacity: 1;
}

.kpi-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.kpi-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--dark);
}

.kpi-trend {
  font-size: 0.75rem;
  color: #18a36a;
}

.kpi-warning {
  color: var(--accent);
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--bg);
  display: grid;
  place-items: center;
  font-size: 1.3rem;
}

/* clickable KPI (optional) */
#kpi-public-site {
  cursor: pointer;
}

.kpi-delta {
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 10px;
}

/* ========== HERO ROW ========== */
.hero-row {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
  margin-bottom: 22px;
}

@media (max-width: 900px) {
  .hero-row {
    grid-template-columns: 1fr;
  }
}

.hero-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  border-radius: 20px;
  padding: 26px;
  box-shadow: var(--shadow-card);
  color: #fff;
}

.hero-eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
}

.hero-value {
  font-size: 42px;
  font-weight: 900;
  color: #fff;
  margin-top: 6px;
}

.hero-sub {
  font-size: 13.5px;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 6px;
}

.hero-stats {
  display: flex;
  gap: 22px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.hero-stat-value {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}

.hero-stat-label {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 2px;
}

.quick-links-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quick-links-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--dark);
}

.quick-link-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-alt);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.quick-link-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.quick-link-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--dark);
  flex: 1;
}

/* ========== ACTIVITY FEED ========== */
.activity-feed {
  display: flex;
  flex-direction: column;
}

.activity-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border-light);
}

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

.activity-icon-wrap {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.activity-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--dark);
}

.activity-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ========== CHARTS ========== */
.charts-row {
  display: grid;
  gap: 16px;
  margin-bottom: 22px;
}

.charts-row-top {
  grid-template-columns: 1.5fr 1.1fr;
}

.charts-row-bottom {
  grid-template-columns: repeat(3, 1fr);
}

.chart-panel,
.chart-panel-small {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  padding: 14px 16px 10px;
}

.chart-panel-small {
  min-height: 260px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--dark);
}

.panel-header p {
  margin: 2px 0 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ApexCharts direction (keep charts LTR always) */
.apexcharts-canvas {
  direction: ltr;
}

.chart-panel .apexcharts-canvas,
.chart-panel-small .apexcharts-canvas {
  border-radius: 12px;
}

.apexcharts-tooltip {
  border-radius: 10px !important;
  border: 1px solid var(--border-light) !important;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08) !important;
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif !important;
}

/* ========== LOWER PANELS / TABLES ========== */
.section-header {
  margin: 10px 0 8px;
}

.section-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--dark);
}

.section-header p {
  margin: 2px 0 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.row-2-cols {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-top: 8px;
}

.col-stack {
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  padding: 14px 16px 12px;
}

.table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin-top: 8px;
  transition: 0.25s ease;
}

.table-wrapper:hover {
  transform: translateY(-3px);
}

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

thead tr {
  background: var(--surface-alt, var(--bg));
}

/* ✅ FIX: text-align: start ensures correct alignment in both RTL & LTR */
th,
td {
  padding: 10px 14px;
  text-align: start;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--dark);
}

td {
  color: var(--dark);
}

table tbody tr {
  transition: background-color 0.15s ease;
}

table tbody tr:hover {
  background: rgba(0, 132, 61, 0.05);
  cursor: pointer;
}

/* BADGES */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: rgba(0, 132, 61, 0.08);
  color: var(--primary);
}

.badge-danger {
  background: rgba(210, 16, 52, 0.08);
  color: var(--danger);
}

.badge-warning {
  background: rgba(255, 196, 0, 0.14);
  color: #8A6800;
}

.badge-success {
  background: rgba(0, 132, 61, 0.08);
  color: var(--primary);
}

/* Tabs */
.tab-header {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid #edf0f6;
  margin-top: 10px;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  font-size: 0.8rem;
  border-radius: 999px 999px 0 0;
  cursor: pointer;
  color: var(--muted);
}

.tab-btn.active {
  background: linear-gradient(90deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  font-weight: 600;
}

.tab-pane {
  display: none;
  margin-top: 8px;
}

.tab-pane.active {
  display: block;
}

/* Alert list */
.alert-list {
  list-style: none;
  padding: 0;
  margin: 6px 0 0;
}

.alert-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed #edf0f6;
}

.alert-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff5ea;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  color: var(--accent);
  flex-shrink: 0;
}

.alert-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--dark);
}

.alert-text {
  font-size: 0.78rem;
  color: var(--muted);
}

/* FOOTER */
.footer {
  padding: 10px 22px 18px;
  font-size: 0.75rem;
  color: #9aa4b4;
  text-align: center;
}

/* ========== SIMPLE ANIMATIONS (optional) ========== */
.fade-in {
  opacity: 0;
  transform: translateY(8px);
  animation: fadeSlideIn 0.55s ease forwards;
}

@keyframes fadeSlideIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-delay-1 {
  animation-delay: 0.15s;
}

.fade-delay-2 {
  animation-delay: 0.3s;
}

.fade-delay-3 {
  animation-delay: 0.45s;
}

.fade-delay-4 {
  animation-delay: 0.6s;
}

.fade-delay-5 {
  animation-delay: 0.75s;
}

/* ========== SCROLL-TRIGGERED REVEAL (see reveal.js) ========== */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s ease, transform 0.5s ease;
  will-change: opacity, transform;
}

.reveal.reveal-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .fade-in,
  .reveal {
    animation: none !important;
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1200px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .charts-row-bottom {
    grid-template-columns: repeat(2, 1fr);
  }

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

@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

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

/* =========================================
   DARK MODE (Added without changing originals)
   Activate by: <html class="dark">
   - Dashboard scope only (no sidebar/topbar)
========================================= */
html.dark {
  --primary: #2FBE72;
  --primary-hover: #26A863;
  --accent: #FFD23F;
  --danger: #F1495F;
  --bg: #0D100D;
  --surface: #161A15;
  --surface-alt: #1C221C;
  --dark: #F1F4F1;
  --muted: #8FA091;

  --border-light: rgba(255, 255, 255, .10);
  --shadow-card: 0 14px 34px rgba(0, 0, 0, 0.35);
}

/* Panels & KPI cards */
html.dark .kpi-card,
html.dark .chart-panel,
html.dark .chart-panel-small,
html.dark .panel {
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

/* KPI icon tile */
html.dark .kpi-icon {
  background: rgba(0, 132, 61, 0.12);
}

/* Hover backgrounds */
html.dark table tbody tr:hover {
  background: rgba(255, 255, 255, .05);
}

/* Tables */
html.dark thead tr {
  background: rgba(0, 132, 61, .10);
}

html.dark th,
html.dark td {
  border-bottom-color: rgba(255, 255, 255, .08);
}

/* Badges */
html.dark .badge {
  background: rgba(47, 190, 114, .16);
  color: #baf7de;
}

html.dark .badge-danger {
  background: rgba(241, 73, 95, .16);
  color: #ffb3bd;
}

html.dark .badge-warning {
  background: rgba(255, 210, 63, .16);
  color: #FFD23F;
}

html.dark .badge-success {
  background: rgba(47, 190, 114, .16);
  color: #baf7de;
}

/* Tabs */
html.dark .tab-header {
  border-bottom-color: rgba(255, 255, 255, .10);
}

html.dark .tab-btn {
  color: var(--muted);
}

html.dark .tab-btn.active {
  color: #fff;
}

/* Alerts */
html.dark .alert-list li {
  border-bottom-color: rgba(255, 255, 255, .12);
}

html.dark .alert-icon {
  background: rgba(255, 196, 0, .14);
}

/* =========================
   ApexCharts (Dark Mode)
   - Fix labels/tooltip/legend not changing
========================= */

/* Axis labels, titles, legend text */
html.dark .apexcharts-text,
html.dark .apexcharts-xaxis-label,
html.dark .apexcharts-yaxis-label,
html.dark .apexcharts-title-text,
html.dark .apexcharts-subtitle-text,
html.dark .apexcharts-legend-text {
  fill: rgba(243, 244, 246, .92) !important;
  color: rgba(243, 244, 246, .92) !important;
}

/* Muted secondary labels (if Apex adds this class) */
html.dark .apexcharts-text.apexcharts-datalabel,
html.dark .apexcharts-data-label {
  fill: rgba(156, 163, 175, .95) !important;
}

/* Grid lines */
html.dark .apexcharts-gridline,
html.dark .apexcharts-xaxis line,
html.dark .apexcharts-yaxis line,
html.dark .apexcharts-xaxis-tick,
html.dark .apexcharts-yaxis-tick {
  stroke: rgba(255, 255, 255, .12) !important;
}

/* Crosshair */
html.dark .apexcharts-xcrosshairs,
html.dark .apexcharts-ycrosshairs {
  stroke: rgba(255, 255, 255, .22) !important;
  opacity: 1 !important;
}

/* Tooltip container */
html.dark .apexcharts-tooltip {
  background: rgba(15, 23, 42, .96) !important;
  color: rgba(243, 244, 246, .95) !important;
  border-color: rgba(255, 255, 255, .14) !important;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.45) !important;
}

/* Tooltip title */
html.dark .apexcharts-tooltip-title {
  background: rgba(255, 255, 255, .06) !important;
  border-bottom-color: rgba(255, 255, 255, .10) !important;
  color: rgba(243, 244, 246, .95) !important;
}

/* X-axis tooltip (the little floating label) */
html.dark .apexcharts-xaxistooltip,
html.dark .apexcharts-yaxistooltip {
  background: rgba(15, 23, 42, .96) !important;
  border-color: rgba(255, 255, 255, .14) !important;
  color: rgba(243, 244, 246, .95) !important;
}

/* Tooltip arrow */
html.dark .apexcharts-xaxistooltip:before,
html.dark .apexcharts-xaxistooltip:after,
html.dark .apexcharts-yaxistooltip:before,
html.dark .apexcharts-yaxistooltip:after {
  border-bottom-color: rgba(15, 23, 42, .96) !important;
  border-top-color: rgba(15, 23, 42, .96) !important;
}

/* If Apex draws foregrounds (sometimes stays black) */
html.dark .apexcharts-graphical,
html.dark .apexcharts-annotations rect {
  filter: none !important;
}