/* ==========================================================================
   TimStore PHP — feuille de style unique
   Aucun framework : sur un hebergement mutualise, chaque fichier compte
   (quota d'inodes) et chaque requete HTTP supplementaire se paie sur des
   connexions mobiles algeriennes souvent lentes.
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #14181f;
  --muted: #667085;
  --brand: #111827;
  --accent: #2563eb;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --bad: #b42318;
  --bad-bg: #fef3f2;
  --info: #175cd3;
  --info-bg: #eff8ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
img { max-width: 100%; height: auto; display: block; }

/* --- Structure du tableau de bord ---------------------------------------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--brand);
  color: #fff;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar .brand {
  font-size: 17px; font-weight: 700; color: #fff;
  padding: 6px 10px 16px; display: block;
}
.sidebar .brand:hover { text-decoration: none; }
.sidebar a.nav {
  display: flex; align-items: center; gap: 9px;
  color: #cbd5e1; padding: 9px 11px; border-radius: 8px;
  font-size: 14.5px;
}
.sidebar a.nav:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar a.nav.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .foot { border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; font-size: 13px; color: #94a3b8; }

/* min-width: 0 est indispensable — sans lui, une table large force la colonne
   a s'elargir et casse la mise en page sur mobile. */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.topbar .title { font-size: 17px; font-weight: 650; }
.content { padding: 22px; flex: 1; }

.menu-toggle {
  display: none; background: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: 16px;
}

/* --- Cartes et grilles ---------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 18px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; }
.stat .label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.stat .value { font-size: 25px; font-weight: 700; margin-top: 5px; }
.stat .hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

/* --- Tableaux ------------------------------------------------------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: end; white-space: nowrap; }

/* --- Pastilles ------------------------------------------------------------ */

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.ok    { background: var(--ok-bg);   color: var(--ok); }
.badge.warn  { background: var(--warn-bg); color: var(--warn); }
.badge.bad   { background: var(--bad-bg);  color: var(--bad); }
.badge.info  { background: var(--info-bg); color: var(--info); }
.badge.muted { background: #f2f4f7;        color: var(--muted); }

/* --- Formulaires ---------------------------------------------------------- */

label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 15px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=tel], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { min-height: 96px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; margin-inline-end: 7px; }
.inline-check { display: flex; align-items: center; font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 16px; font-size: 14.5px; font-weight: 600; font-family: inherit;
  border: 1px solid var(--brand); border-radius: 8px;
  background: var(--brand); color: #fff; cursor: pointer; text-decoration: none;
}
.btn:hover { opacity: .9; text-decoration: none; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
.toolbar .field { margin-bottom: 0; }
.actions { display: flex; gap: 9px; flex-wrap: wrap; }

/* --- Messages ------------------------------------------------------------- */

.flash { padding: 11px 15px; border-radius: 8px; margin-bottom: 15px; font-size: 14px; border: 1px solid; }
.flash.success { background: var(--ok-bg);   border-color: #abefc6; color: var(--ok); }
.flash.error   { background: var(--bad-bg);  border-color: #fecdca; color: var(--bad); }
.flash.info    { background: var(--info-bg); border-color: #b2ddff; color: var(--info); }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty p { margin: 8px 0 16px; }

/* --- Pagination ----------------------------------------------------------- */

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 7px;
  background: #fff; color: var(--text); font-size: 14px;
}
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* --- Graphique en barres (CSS pur, aucune bibliotheque) ------------------- */

.chart { display: flex; align-items: flex-end; gap: 5px; height: 150px; padding-top: 10px; }
.chart .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; min-width: 0; }
.chart .bar .fill { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 3px; }
.chart .bar .lbl { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

/* --- Pages d'authentification --------------------------------------------- */

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 22px; }
.auth-box { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 30px; box-shadow: var(--shadow); }
.auth-box h1 { font-size: 21px; margin-bottom: 5px; }
.auth-box .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.auth-box .alt { text-align: center; margin-top: 18px; font-size: 14px; color: var(--muted); }
.divider { display: flex; align-items: center; gap: 11px; margin: 18px 0; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* --- Utilitaires ---------------------------------------------------------- */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.right { text-align: end; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.thumb { width: 42px; height: 42px; border-radius: 7px; object-fit: cover; background: #f2f4f7; }

/* --- Mobile --------------------------------------------------------------- */

@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 15px; }
  .topbar { padding: 11px 15px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  h1 { font-size: 20px; }
  /* 16px minimum sur les champs : en dessous, iOS zoome automatiquement
     a chaque focus et le formulaire devient penible a remplir. */
  input, select, textarea { font-size: 16px; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  body { background: #fff; }
  .card { border: none; box-shadow: none; padding: 0; }
}
