/* LePupitre — design system. Thème clair professionnel, mobile-first. */

@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/ibm-plex-sans-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/ibm-plex-sans-500.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/ibm-plex-sans-600.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/ibm-plex-sans-700.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/ibm-plex-mono-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/ibm-plex-mono-600.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #475467;
  --muted: #667085;
  --faint: #98a2b3;
  --primary: #1d5fd6;
  --primary-strong: #174eb2;
  --primary-soft: #eaf1fd;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font-ui: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
  --tabbar-h: calc(60px + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
svg { display: block; }
[hidden] { display: none !important; }

#screen {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + 20px);
}
#screen.no-tabbar { padding-bottom: 24px; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ── Barre d'application ─────────────────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 4px;
  height: calc(56px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 8px 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.appbar-title {
  flex: 1; font-size: 17px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 8px;
}
.appbar-back, .appbar-action {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  color: var(--text-2); flex: none;
}
.appbar-action { color: var(--primary); font-weight: 600; width: auto; padding: 0 12px; }
.appbar-back:active, .appbar-action:active { background: var(--bg); }
.appbar-sub { font-size: 12px; color: var(--muted); font-weight: 400; }

.page { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

/* ── Boutons ─────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-danger-outline {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 48px;
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600;
  transition: background .15s ease, border-color .15s ease;
  user-select: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-strong); }
.btn-primary:disabled { background: var(--border-strong); cursor: default; }
.btn-secondary {
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border-strong); font-weight: 500;
}
.btn-secondary:active { background: var(--bg); }
.btn-danger-outline {
  background: var(--surface); color: var(--danger);
  border: 1px solid #fca5a5; font-weight: 500;
}
.btn-danger-outline:active { background: var(--danger-soft); }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 10px;
  color: var(--primary); font-weight: 600; font-size: 14px;
  border-radius: var(--radius-sm);
}
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

/* ── Chips & segmented ──────────────────────────────────────────── */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 16px; flex: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; font-size: 14px; font-weight: 500; color: var(--text-2);
  transition: all .15s ease; user-select: none;
}
.chip.on {
  background: var(--primary-soft); border-color: var(--primary);
  color: var(--primary); font-weight: 600;
}
.seg {
  display: flex; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 3px; gap: 2px;
}
.seg > button {
  flex: 1; height: 38px; border-radius: 6px;
  font-size: 14px; font-weight: 500; color: var(--text-2);
  transition: all .15s ease;
}
.seg > button.on { background: var(--primary); color: #fff; font-weight: 600; }

/* ── Champs ─────────────────────────────────────────────────────── */
.field-label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.field {
  width: 100%; height: 48px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field::placeholder { color: var(--faint); }
textarea.field { height: auto; min-height: 110px; padding: 12px 14px; resize: vertical; }
.field.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
select.field { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.search-wrap { position: relative; }
.search-wrap .field { padding-left: 42px; }
.search-wrap > svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); }

/* ── Cartes, listes, sections ───────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-card);
  padding: 16px;
}
.card.tight { padding: 0; overflow: hidden; }
.section-title { font-size: 15px; font-weight: 600; }
.section-row { display: flex; align-items: center; justify-content: space-between; }

.kv-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.kv-row:last-child { border-bottom: 0; }
.kv-row .k { font-size: 13px; color: var(--text-2); flex: none; }
.kv-row .v {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 14px; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kv-row .v .unit { font-family: var(--font-ui); font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 4px; }

.list-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .15s ease;
}
.list-row:active { background: var(--bg); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .sub { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .chev { color: var(--faint); flex: none; }
.list-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-card); }
.list-group .list-row:last-child { border-bottom: 0; }

.badge-danger {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--danger-soft); color: var(--danger);
  font-size: 13px; font-weight: 600;
}
.badge-soft {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
  font-size: 13px; font-weight: 600;
}

.gauge { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; flex: 1; }
.gauge > div { height: 100%; background: var(--primary); border-radius: 4px; }
.gauge.warn > div { background: var(--warn); }
.gauge.danger > div { background: var(--danger); }

/* ── FAB & tabbar ───────────────────────────────────────────────── */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + 18px); z-index: 25;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(29, 95, 214, .4);
  transition: transform .15s ease;
}
.fab:active { transform: scale(.94); background: var(--primary-strong); }

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#tabbar .tabs { display: flex; width: 100%; max-width: 760px; }
#tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; height: 60px; color: var(--muted); font-size: 11px; font-weight: 500;
}
#tabbar button.on { color: var(--primary); font-weight: 600; }

/* ── Toast, overlay, dialogues ──────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px);
  transform: translateX(-50%) translateY(8px);
  z-index: 60; max-width: min(92vw, 480px);
  background: #101828; color: #fff;
  padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  opacity: 0; transition: all .2s ease;
  pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.dialog {
  background: var(--surface); border-radius: var(--radius);
  padding: 22px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 18px;
  box-shadow: 0 20px 50px rgba(16, 24, 40, .25);
}
.dialog p { font-size: 15px; color: var(--text); }

.overlay.photo-viewer { padding: 0; background: rgba(0, 0, 0, .92); }
.overlay.photo-viewer img { max-width: 100vw; max-height: 100vh; object-fit: contain; }

.empty-state {
  text-align: center; color: var(--muted); font-size: 14px;
  padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-state svg { color: var(--faint); }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .7s linear infinite; flex: none;
}
.spinner.dark { border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen { display: flex; align-items: center; justify-content: center; padding: 80px 0; }

/* ── Photos (vignettes communes) ────────────────────────────────── */
.photo-strip { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-thumb {
  position: relative; width: 96px; height: 72px;
  border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--border); background: var(--bg); flex: none;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .rm {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(16, 24, 40, .65); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.photo-add {
  width: 96px; height: 72px; border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border-strong); color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 500; flex: none;
}

/* ── Connexion ──────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-brand { text-align: center; margin-bottom: 18px; }
.login-brand .mark {
  width: 64px; height: 64px; border-radius: 16px; margin: 0 auto 14px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 26px; letter-spacing: .5px;
}
.login-brand h1 { font-size: 26px; font-weight: 700; }
.login-brand p { color: var(--muted); font-size: 14px; margin-top: 4px; }
.login-error {
  background: var(--danger-soft); color: var(--danger);
  border-radius: var(--radius-sm); padding: 11px 14px; font-size: 14px; font-weight: 500;
}

/* ── Accueil ────────────────────────────────────────────────────── */
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.home-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-card);
  padding: 16px; min-height: 110px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  cursor: pointer; transition: border-color .15s ease;
  text-align: left;
}
.home-card:active { border-color: var(--primary); }
.home-card .hc-top { display: flex; align-items: center; gap: 10px; }
.home-card .hc-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.home-card .hc-label { font-weight: 600; font-size: 15px; }
.home-card .hc-value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; }
.home-card .hc-value .u { font-family: var(--font-ui); font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.home-card .hc-hint { color: var(--primary); font-size: 14px; font-weight: 600; }

@media (min-width: 560px) {
  .home-grid { grid-template-columns: repeat(4, 1fr); }
}
