/* =========================================================================
   Haloub / GBMODERNE — Nouveau système de design (Neww)
   Design commun aux deux applications (mobile & grand écran).
   ========================================================================= */

.ltr { direction: ltr; unicode-bidi: isolate; }

:root {
  --brand-teal: #036666;
  --brand-teal-dark: #024f4f;
  --brand-green: #047857;
  --brand-gradient: linear-gradient(135deg, #036666 0%, #047857 100%);

  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --info: #3b82f6;
  --info-bg: #dbeafe;
  --success: #10b981;
  --success-bg: #d1fae5;
  --purple: #8b5cf6;
  --purple-bg: #ede9fe;
  --teal: #0d9488;
  --teal-bg: #ccfbf1;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, .05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, .08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, .12);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #141b2d;
  --surface-alt: #101728;
  --border: rgba(255, 255, 255, .08);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .5);
  --danger-bg: rgba(239, 68, 68, .15);
  --warning-bg: rgba(245, 158, 11, .15);
  --info-bg: rgba(59, 130, 246, .15);
  --success-bg: rgba(16, 185, 129, .15);
  --purple-bg: rgba(139, 92, 246, .15);
  --teal-bg: rgba(13, 148, 136, .15);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Tajawal', sans-serif;
  transition: background-color .25s ease, color .25s ease;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

.ar {
  font-family: 'Tajawal', sans-serif;
  direction: rtl;
  unicode-bidi: isolate;
}

/* ---------- Layout helpers ---------- */
.scroll-x {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.scroll-x::-webkit-scrollbar { display: none; }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

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

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title i { color: var(--brand-teal); }

.section-link {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand-teal);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---------- KPI cards ---------- */
.kpi-card {
  min-width: 148px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.kpi-card .kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  margin-bottom: 4px;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.02em;
}

.kpi-value small {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
}

.kpi-trend {
  font-size: 11.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
  padding: 2px 7px;
  border-radius: 20px;
}
.kpi-trend.up { color: var(--success); background: var(--success-bg); }
.kpi-trend.down { color: var(--danger); background: var(--danger-bg); }
.kpi-trend.flat { color: var(--text-muted); background: var(--surface-alt); }

/* ---------- Alert cards (Tar, Dg, Vel...) ---------- */
.alert-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.alert-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--brand-teal);
}

.alert-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

.alert-body { flex: 1; min-width: 0; }
.alert-name { font-size: 17.5px; font-weight: 700; color: var(--text); }

.alert-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.pill {
  min-width: 32px;
  height: 27px;
  padding: 0 7px;
  border-radius: 8px;
  font-size: 15.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pill-red { background: var(--danger-bg); color: var(--danger); }
.pill-blue { background: var(--info-bg); color: var(--info); }
.pill-total { background: var(--brand-gradient); color: #fff; }

/* ---------- Stock alerts ---------- */
.stock-row {
  display: block;
  padding: 13px 10px;
  margin: 0 -10px;
  border-radius: 10px;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease;
}
.stock-row:last-child { border-bottom: none; }
.stock-row:hover { background: var(--surface-alt); }

.stock-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.stock-name {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  font-weight: 700;
}

.stock-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.stock-status {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}
.stock-status.ok { color: var(--success); background: var(--success-bg); }
.stock-status.low { color: var(--warning); background: var(--warning-bg); }
.stock-status.critical { color: var(--danger); background: var(--danger-bg); }

.stock-bar-bg {
  height: 7px;
  border-radius: 4px;
  background: var(--surface-alt);
  overflow: hidden;
}
.stock-bar-fill { height: 100%; border-radius: 4px; }

.stock-sub {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ---------- Répartition du troupeau ---------- */
.herd-row {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 10px; margin: 0 -10px; border-radius: 10px;
  color: inherit; text-decoration: none; cursor: pointer;
  transition: background .15s ease;
}
.herd-row:hover { background: var(--surface-alt); }
.herd-row-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.herd-row-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text); }
.herd-row-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.herd-row-count { font-size: 12.5px; font-weight: 800; color: var(--text-faint); flex-shrink: 0; }
.herd-bar-bg { height: 6px; border-radius: 4px; background: var(--surface-alt); overflow: hidden; }
.herd-bar-fill { height: 100%; border-radius: 4px; transition: width .3s ease; }

/* ---------- Menu grid item (used in mobile sheet + desktop sidebar) ---------- */
.menu-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 12px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.menu-tile:hover { background: var(--surface-alt); border-color: var(--border); }
.menu-tile .menu-tile-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--surface-alt);
  color: var(--brand-teal);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.menu-tile .menu-tile-label {
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
}
.menu-tile .menu-tile-label-ar {
  font-size: 10.5px;
  color: var(--text-faint);
}

.group-heading {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 18px 4px 10px;
}
.group-heading:first-child { margin-top: 0; }

/* ---------- Badges / misc ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--brand-teal); color: var(--brand-teal); }

.emoji-icon { font-size: 1.3em !important; font-style: normal !important; font-synthesis: none; line-height: 1; }

/* ---------- Chart ---------- */
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-legend {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Language switcher ---------- */
.lang-btn {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .03em;
}

.lang-switcher { position: relative; display: inline-flex; }

.lang-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 168px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 24px -8px rgba(0, 0, 0, .28);
  padding: 6px;
  z-index: 200;
}
.lang-menu.open { display: block; }
[dir="rtl"] .lang-menu { right: auto; left: 0; }

.lang-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  text-align: left;
}
.lang-menu-item:hover { background: var(--surface-alt); }
.lang-menu-item.active { background: var(--brand-teal); color: #fff; }

.lang-menu-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 20px;
  border-radius: 5px;
  background: var(--surface-alt);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .03em;
  flex-shrink: 0;
}
.lang-menu-item.active .lang-menu-code { background: rgba(255, 255, 255, .25); color: #fff; }

.lang-menu-name { font-size: 13px; font-weight: 600; }

/* ---------- RTL support (Arabic) ---------- */
[dir="rtl"] body { font-family: 'Tajawal', 'Inter', sans-serif; }
[dir="rtl"] .rtl-flip { display: inline-block; transform: scaleX(-1); }
[dir="rtl"] .events-table th,
[dir="rtl"] .events-table td { text-align: start; }

