/* ==========================================================================
   BATE SOCIÉTÉ S.A — Design System Mobile-First & Desktop
   Palette : Vert forêt (#143D2B / #1D5A3F), Fond clair (#F4F7F4), Blanc (#FFF)
   Typographie : Plus Jakarta Sans (titres) + Inter (corps) · tabular-nums
   ========================================================================== */

:root {
  --c-brand-900: #0F2E20;
  --c-brand-800: #143D2B;
  --c-brand-700: #1D5A3F;
  --c-brand-600: #256F4E;
  --c-brand-100: #E6F0EA;
  --c-brand-50: #F4F7F4;

  --c-surface: #FFFFFF;
  --c-surface-alt: #F8FAF8;
  --c-border: #DCE5DF;
  --c-border-strong: #C3D3C9;

  --c-text-900: #102018;
  --c-text-700: #2E4237;
  --c-text-500: #5B7065;
  --c-text-400: #7B8E84;

  --c-success: #15803D;
  --c-success-bg: #DCFCE7;
  --c-warning: #B45309;
  --c-warning-bg: #FEF3C7;
  --c-danger: #B91C1C;
  --c-danger-bg: #FEE2E2;
  --c-info: #1D4ED8;
  --c-info-bg: #DBEAFE;

  --font-display: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  --sh-sm: 0 1px 2px rgba(16, 32, 24, 0.05);
  --sh-md: 0 4px 12px rgba(16, 32, 24, 0.08);
  --sh-lg: 0 14px 36px rgba(16, 32, 24, 0.16);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-brand-50);
  color: var(--c-text-900);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  margin: 0;
  color: var(--c-text-900);
  letter-spacing: -0.015em;
}

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

.num, .kpi-value, td.num, th.num {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* ---------- Shell ---------- */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--c-brand-800);
  color: #FFFFFF;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #86EFAC;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 16px;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.brand-subtitle {
  font-size: 11px;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.78);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #86EFAC;
}

.sync-pill.is-offline .sync-dot {
  background: #FBBF24;
}

.profile-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #FFFFFF;
  color: var(--c-text-900);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.profile-chip:hover {
  background: var(--c-brand-50);
}

/* ---------- Navigation ---------- */
.app-nav {
  position: sticky;
  top: 64px;
  z-index: 30;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--sh-sm);
}

.nav-track {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 1280px;
  margin: 0 auto;
}

.nav-track::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  padding: 9px 14px;
  min-height: 40px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--c-text-700);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-tab:hover {
  background: var(--c-brand-50);
  color: var(--c-brand-800);
}

.nav-tab.is-active {
  background: var(--c-brand-100);
  color: var(--c-brand-800);
  border-color: var(--c-border-strong);
}

.nav-badge {
  background: var(--c-danger);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  line-height: 1.4;
}

/* ---------- Main ---------- */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-title {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--c-text-500);
  font-size: 14px;
}

.page-date {
  font-size: 13px;
  color: var(--c-text-500);
  font-weight: 500;
  text-transform: capitalize;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* ---------- Cards & Grids ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

@media (min-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .kpi-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.kpi-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 16px;
  box-shadow: var(--sh-sm);
}

.kpi-label {
  font-size: 13px;
  color: var(--c-text-500);
  font-weight: 500;
  margin-bottom: 6px;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  color: var(--c-text-900);
  line-height: 1.2;
  word-break: break-word;
}

.kpi-value.is-positive { color: var(--c-success); }
.kpi-value.is-negative { color: var(--c-danger); }
.kpi-value.is-warning { color: var(--c-warning); }

.kpi-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--c-text-400);
}

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 18px;
  box-shadow: var(--sh-sm);
  margin-bottom: 16px;
}

.card-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
}

.card-desc {
  margin: 0 0 14px;
  color: var(--c-text-500);
  font-size: 14px;
}

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

@media (min-width: 900px) {
  .grid-2 {
    grid-template-columns: 1.2fr 1fr;
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--c-brand-700);
  color: #FFFFFF;
}

.btn-primary:hover {
  background: var(--c-brand-800);
}

.btn-secondary {
  background: var(--c-brand-100);
  color: var(--c-brand-800);
  border-color: var(--c-border);
}

.btn-secondary:hover {
  background: #D7E7DD;
}

.btn-ghost {
  background: var(--c-surface);
  color: var(--c-text-700);
  border-color: var(--c-border);
}

.btn-ghost:hover {
  background: var(--c-brand-50);
}

.btn-danger {
  background: var(--c-danger-bg);
  color: var(--c-danger);
  border-color: #FECACA;
}

.btn-danger:hover {
  background: #FECACA;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 11px;
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-700);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--c-brand-50);
}

/* ---------- Forms ---------- */
.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface);
  color: var(--c-text-900);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--c-brand-700);
  box-shadow: 0 0 0 3px rgba(29, 90, 63, 0.14);
}

.textarea {
  min-height: 84px;
  resize: vertical;
}

.search-input {
  max-width: 380px;
}

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

@media (min-width: 640px) {
  .form-grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-700);
}

.field-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--c-brand-50);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--c-text-700);
  cursor: pointer;
}

.field-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--c-brand-700);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--c-border);
}

/* ---------- Badges & Alerts ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--c-success-bg); color: var(--c-success); }
.badge-warning { background: var(--c-warning-bg); color: var(--c-warning); }
.badge-danger { background: var(--c-danger-bg); color: var(--c-danger); }
.badge-info { background: var(--c-info-bg); color: var(--c-info); }
.badge-neutral { background: var(--c-brand-100); color: var(--c-brand-800); }

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--r-sm);
  border-left: 4px solid var(--c-warning);
  background: var(--c-warning-bg);
  color: var(--c-text-900);
  font-size: 13.5px;
}

.alert-item.is-danger {
  border-left-color: var(--c-danger);
  background: var(--c-danger-bg);
}

.alert-item.is-info {
  border-left-color: var(--c-brand-700);
  background: var(--c-brand-100);
}

/* ---------- Responsive Tables & Mobile Cards ---------- */
.table-wrap {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--sh-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-text-500);
  background: var(--c-surface-alt);
  border-bottom: 1px solid var(--c-border);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: var(--c-brand-50);
}

.empty-state {
  padding: 36px 16px;
  text-align: center;
  color: var(--c-text-500);
  font-size: 14px;
}

/* Mobile card transformation so columns are NEVER cut off */
@media (max-width: 767px) {
  .data-table thead {
    display: none;
  }
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }
  .data-table tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--c-border);
  }
  .data-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
    border-bottom: none;
    text-align: right;
  }
  .data-table td::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 600;
    color: var(--c-text-500);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    flex-shrink: 0;
  }
}

.animal-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--r-sm);
  object-fit: cover;
  border: 1px solid var(--c-border);
  background: var(--c-brand-100);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--c-brand-700);
  font-weight: 700;
  font-size: 12px;
}

/* ---------- QR Scanner & Tag ---------- */
.qr-video-box {
  position: relative;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 4 / 3;
  background: #0B1B13;
  border-radius: var(--r-md);
  overflow: hidden;
  margin-top: 12px;
  border: 2px solid var(--c-brand-700);
}

.qr-video-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qr-result-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: var(--c-brand-50);
  border: 1px solid var(--c-border);
  font-size: 14px;
  color: var(--c-text-700);
}

.qr-tag-card {
  border: 2px dashed var(--c-brand-800);
  border-radius: var(--r-md);
  padding: 20px;
  text-align: center;
  background: #FFFFFF;
  max-width: 320px;
  margin: 0 auto;
}

.qr-tag-svg {
  width: 180px;
  height: 180px;
  margin: 12px auto;
}

/* ---------- Activity feed ---------- */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.activity-item {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--c-border);
}

.activity-item:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.activity-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--c-text-900);
}

.activity-meta {
  font-size: 12.5px;
  color: var(--c-text-500);
  margin-top: 2px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 46, 32, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--sh-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
}

.modal-title {
  font-size: 18px;
  font-weight: 800;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

/* ---------- Toast ---------- */
.toast-root {
  position: fixed;
  bottom: 20px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 32px);
}

.toast {
  background: var(--c-brand-900);
  color: #FFFFFF;
  padding: 12px 16px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--sh-md);
}

.toast.is-error {
  background: var(--c-danger);
}

/* ---------- Footer ---------- */
.app-footer {
  padding: 16px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12.5px;
  color: var(--c-text-500);
}

/* ---------- Print / PDF ---------- */
@media print {
  body { background: #FFFFFF; }
  .app-header, .app-nav, .no-print, .toolbar, .modal-backdrop, .toast-root {
    display: none !important;
  }
  .app-main {
    max-width: 100%;
    padding: 0;
  }
  .card, .kpi-card, .table-wrap {
    box-shadow: none;
    border-color: #CBD5E1;
    break-inside: avoid;
  }
}
