* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --border: #e3e5ea;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px 24px;
  padding: 14px 28px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.topbar-brand { font-weight: 800; font-size: 16px; }
.topbar-meta { display: flex; gap: 10px; align-items: center; color: var(--text-muted); font-size: 14px; flex-wrap: wrap; }
.topbar-caissier { font-weight: 600; color: var(--text); }
.topbar-caissier::before { content: '· '; color: var(--text-muted); }
.topbar-nav { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.nav-link {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.nav-link:hover { background: #f0f1f3; color: var(--text); }
.nav-link.active { background: #eaf1ff; color: var(--primary-dark); }
.nav-link-danger { color: var(--danger); }

/* ------------------------------------------------------------ layout */
.app-main { max-width: 1100px; margin: 0 auto; padding: 28px; }

.screen { display: none; }
.screen.active { display: block; }
.screen-center {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 28px;
}
.screen-center.active { display: flex; }

/* ------------------------------------------------------------ card */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card-narrow { width: 100%; max-width: 380px; }
.card-title { margin: 0 0 4px; font-size: 22px; font-weight: 800; }
.card-subtitle { margin: 0 0 22px; color: var(--text-muted); font-size: 14px; }

/* ------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field input, .field-inline input {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfc;
}
.field input:focus, .field-inline input:focus { outline: none; border-color: var(--primary); background: #fff; }

.field-inline { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-muted); }

.form-error { color: var(--danger); font-size: 13px; font-weight: 600; min-height: 18px; margin: 0 0 8px; }
.form-success { color: var(--success); font-size: 13px; font-weight: 600; margin: 0 0 12px; }

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.form-actions-stack { flex-direction: column; }

.btn-primary {
  font-family: inherit;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-secondary {
  font-family: inherit;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-secondary:hover { background: #f4f5f7; }

/* ------------------------------------------------------------ caissiers */
.liste-caissiers { display: flex; flex-direction: column; gap: 8px; }
.btn-caissier {
  font-family: inherit;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfc;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-caissier:hover { border-color: var(--primary); background: #eaf1ff; }

/* ------------------------------------------------------------ view header */
.view-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-header h1 { margin: 0 0 4px; font-size: 22px; font-weight: 800; }
.view-header .subtitle { color: var(--text-muted); font-size: 14px; }

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

/* ------------------------------------------------------------ table */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--card-bg); }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  text-align: left;
  padding: 12px 16px;
  background: #fafafb;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
  font-weight: 700;
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbff; }

.input-montant {
  width: 130px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: right;
}
.input-montant:focus { outline: none; border-color: var(--primary); }

.input-libelle {
  width: 220px;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
}
.input-libelle:focus { outline: none; border-color: var(--primary); }

.ecart-pos { color: var(--success); font-weight: 700; }
.ecart-neg { color: var(--danger); font-weight: 700; }
.ecart-nul { color: var(--text-muted); }
.ecart-na { color: var(--text-muted); font-style: italic; }

.hint { color: var(--text-muted); font-size: 14px; padding: 20px 0; text-align: center; }

/* ------------------------------------------------------------ recap */
.recap-bar { display: flex; gap: 16px 24px; margin: 18px 0; padding: 16px 20px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); flex-wrap: wrap; }
.recap-item { display: flex; flex-direction: column; gap: 4px; }
.recap-label { font-size: 12px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.recap-value { font-size: 20px; font-weight: 800; }

/* ------------------------------------------------------------ historique */
.historique-liste { display: flex; flex-direction: column; gap: 16px; }
.historique-item { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.historique-item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.historique-item-head strong { font-size: 15px; margin-right: 10px; }
.historique-date { color: var(--text-muted); font-size: 13px; display: block; margin-top: 3px; }

.badge-ecart {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
.badge-pos { background: #e8f8ee; color: var(--success); }
.badge-neg { background: #fdeaea; color: var(--danger); }
.badge-nul { background: #eef0f3; color: var(--text-muted); }
.badge-na  { background: #eef0f3; color: var(--text-muted); font-style: italic; }

.data-table-compact th, .data-table-compact td { padding: 8px 14px; font-size: 13px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 720px) {
  .topbar { padding: 12px 16px; gap: 10px 16px; }
  .topbar-brand { font-size: 14px; }
  .topbar-nav { margin-left: 0; width: 100%; }
  .nav-link { padding: 8px 10px; font-size: 13px; }

  .app-main { padding: 16px; }
  .screen-center { padding: 16px; }

  .card { padding: 22px; }
  .card-narrow { max-width: 100%; }

  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn-primary, .form-actions .btn-secondary { width: 100%; }

  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar .field-inline { flex-direction: column; align-items: stretch; gap: 4px; }
  .toolbar .btn-primary { width: 100%; }

  .view-header { flex-direction: column; align-items: stretch; }
  .view-header-actions .btn-secondary { width: 100%; }

  .recap-bar { flex-direction: column; gap: 12px; padding: 14px 16px; }

  .historique-item { padding: 14px 16px; }
  .historique-item-head { flex-direction: column; align-items: flex-start; }
  .badge-ecart { align-self: flex-start; }

  .input-libelle { width: 100%; }

  /* Tableaux -> cartes empilées : chaque ligne devient une carte, chaque
     cellule affiche son libellé de colonne (via data-label) au-dessus de
     sa valeur, pour éviter le défilement horizontal sur mobile. */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .data-table tbody tr:last-child { border-bottom: none; }
  .data-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: none;
    text-align: right;
  }
  .data-table td[data-label]::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    text-align: left;
    margin-right: auto;
  }
  .data-table td[data-label=""]::before,
  .data-table td:not([data-label])::before { content: none; margin-right: 0; }
  .data-table td[data-label=""],
  .data-table td:not([data-label]) { justify-content: flex-end; }
  .data-table tr td:first-child {
    font-weight: 700;
    justify-content: flex-start;
  }
  .data-table tr td:first-child::before { content: none; }
  .data-table td.hint,
  .data-table td[colspan] { text-align: center; justify-content: center; font-weight: 500; }
  .data-table td[colspan]::before { content: none; }

  .input-montant { width: 140px; }
}
