@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,600;9..144,700&display=swap');

:root {
  --ink: #17372c;
  --muted: #71817a;
  --line: #e3ebe6;
  --paper: #fbfcfa;
  --white: #fff;
  --mint: #f1ebfd;
  --green: #7c3aed;
  --green-dark: #5b21b6;
  --lime: #d8ed61;
  --amber: #f0b253;
  --amber-bg: #fff2dc;
  --amber-ink: #b67b27;
  --red: #dd765e;
  --red-bg: #fae6e2;
  --red-ink: #c46655;
  --shadow: 0 14px 40px rgba(29, 71, 48, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-size: 18px;
  letter-spacing: -.01em;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  width: 100%;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, .label-font { font-family: 'Fraunces', serif; font-weight: 700; letter-spacing: -0.03em; }

/* ---------- App shell / sidebar ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 245px;
  background: #f0f6f1;
  border-right: 1px solid #dfeae3;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 20px;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  transition: .25s;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 13px 30px;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 11px 11px 11px 3px;
  background: var(--green);
  color: white;
  display: grid; place-items: center;
  font-size: 17px;
  transform: rotate(-8deg);
  flex-shrink: 0;
}
.brand span { font-family: 'Fraunces', serif; font-size: 23px; font-weight: 700; letter-spacing: -.04em; }
.brand em { font-style: normal; color: var(--green); }

.nav { display: grid; gap: 5px; }
.nav a {
  height: 43px;
  border-radius: 10px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  gap: 13px;
  color: #6b7e74;
  font-weight: 600;
  font-size: 1.02rem;
  transition: .15s;
}
.nav a i { width: 18px; text-align: center; font-size: 16px; }
.nav a:hover, .nav a.active { background: var(--white); color: var(--green-dark); box-shadow: 0 5px 14px rgba(34,85,58,.06); }
.nav a.active { position: relative; }
.nav a.active:before {
  content: ''; position: absolute; left: -16px; height: 25px; width: 3px;
  border-radius: 0 5px 5px 0; background: var(--green);
}
.nav-badge {
  margin-left: auto; background: var(--red-bg); color: var(--red-ink);
  font-size: 12px; font-weight: 700; padding: 3px 7px; border-radius: 20px;
}

.sidebar-bottom { margin-top: auto; }
.sync-card {
  background: var(--green-dark); color: white; border-radius: 14px;
  padding: 16px; margin: 13px 7px 15px; position: relative; overflow: hidden;
}
.sync-card:after {
  content: ''; position: absolute; width: 90px; height: 90px;
  border: 1px solid rgba(255,255,255,.2); border-radius: 50%; right: -34px; top: -34px;
}
.sync-card strong { display: flex; align-items: center; gap: 7px; font-size: 15px; margin-bottom: 5px; }
.sync-card .sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); display: inline-block; }
.sync-card .sync-dot.offline { background: var(--amber); }
.sync-card .sync-dot.syncing { background: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.sync-card small { color: #bdd6c7; display: block; line-height: 1.4; }

.logout-link {
  display: block; text-align: center; font-size: 14px; font-weight: 700;
  color: #6b7e74; padding: 10px 14px; margin: 0 7px;
}
.legal { font-size: 12px; color: #98aaa0; padding: 10px 14px 0; line-height: 1.6; }

/* ---------- Main / topbar ---------- */
main { margin-left: 245px; flex: 1; padding: 26px 3.5vw 30px; max-width: 1400px; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; gap: 12px; flex-wrap: wrap;
}
.mobile-toggle { display: none; font-size: 20px; color: var(--ink); margin-right: 11px; }
.crumb { color: #91a098; font-size: 13px; margin-bottom: 4px; }
.page-title { font-size: 28px; margin: 0; letter-spacing: -.04em; }
.right-tools { display: flex; align-items: center; gap: 10px; }

.outline-btn, .primary-btn {
  height: 40px; padding: 0 14px; border-radius: 9px; font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.outline-btn { background: white; color: #557066; border: 1px solid var(--line); }
.primary-btn { background: var(--green); color: #fff; box-shadow: 0 5px 12px rgba(58,128,93,.2); }
.primary-btn:active { background: var(--green-dark); }

.profile { display: flex; align-items: center; gap: 9px; padding-left: 6px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg,#d4a17d,#4c1d95);
  display: grid; place-items: center; color: white; font-size: 15px; font-weight: 700;
  flex-shrink: 0;
}
.profile-email { font-size: 13px; color: var(--muted); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Welcome + stats ---------- */
.welcome { margin-bottom: 20px; }
.welcome .subtitle { color: var(--muted); font-size: 14.5px; }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 26px; }
.stat {
  background: var(--white); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 19px; box-shadow: var(--shadow); min-height: 112px; position: relative; overflow: hidden;
}
.stat:after {
  content: ''; position: absolute; right: -22px; bottom: -29px; width: 90px; height: 90px;
  border-radius: 50%; background: var(--mint);
}
.stat-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13.5px; font-weight: 600; }
.stat-icon { width: 28px; height: 28px; border-radius: 8px; background: var(--mint); color: var(--green); display: grid; place-items: center; font-size: 15px; z-index: 1; }
.stat strong { display: block; font-family: 'Fraunces', serif; font-size: 29px; margin-top: 13px; letter-spacing: -.04em; }
.stat strong span { font-family: 'DM Sans'; font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.stat.alert .stat-icon { background: var(--amber-bg); color: var(--amber-ink); }
.stat.alert strong { color: var(--amber-ink); }
.stat.expiry .stat-icon { background: var(--red-bg); color: var(--red-ink); }
.stat.expiry strong { color: var(--red-ink); }
.stat.value .stat-icon { background: #e5ecfb; color: #6182bd; }

/* ---------- Section / filters / table ---------- */
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.section-head h2 { font-size: 19px; margin: 0; }
.section-head .count-badge { color: #9aaa9f; font: 600 11px 'DM Sans'; margin-left: 4px; }

.filters-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters-row .search {
  flex: 1; min-width: 160px; height: 40px; background: white; border: 1px solid var(--line);
  border-radius: 10px; display: flex; align-items: center; gap: 8px; padding: 0 12px; color: #9aaba1;
}
.filters-row .search input { border: 0; outline: 0; width: 100%; color: var(--ink); background: transparent; font-size: 14.5px; }
.filters-row select {
  height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line);
  background: white; color: #557066; font-size: 14px; font-weight: 600;
}

.table-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); margin-bottom: 26px; }
.table-scroll { overflow: auto; }
.products { width: 100%; border-collapse: collapse; min-width: 680px; }
.products th {
  background: #f8faf8; color: #90a097; font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
  text-align: left; padding: 12px 16px; font-weight: 700; white-space: nowrap;
}
.products td { padding: 13px 16px; border-top: 1px solid #edf2ee; color: #4b6357; font-size: 14.5px; white-space: nowrap; }
.products tr.clickable-row:hover { background: #fafcfa; cursor: pointer; }
.product-name { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); }
.product-thumb {
  width: 30px; height: 30px; border-radius: 8px; background: var(--mint);
  display: grid; place-items: center; color: var(--green); font-size: 15px; flex-shrink: 0; overflow: hidden;
}
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-meta-tip { font-size: 12.5px; color: var(--green-dark); font-weight: 600; margin-top: 1px; }

.qty-cell { display: flex; align-items: center; gap: 6px; }
.qty-cell button {
  width: 22px; height: 22px; border-radius: 50%; background: var(--mint); color: var(--green-dark);
  font-size: 1.05rem; font-weight: 700; line-height: 1; flex-shrink: 0;
}
.qty-cell span { min-width: 1.3rem; text-align: center; font-weight: 700; color: var(--ink); }

.status { display: inline-flex; padding: 5px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status.good { background: #ede4fb; color: #6d28d9; }
.status.warn { background: var(--amber-bg); color: var(--amber-ink); }
.status.danger { background: var(--red-bg); color: var(--red-ink); }

.actions { display: flex; gap: 6px; }
.icon-btn { background: transparent; color: #a0aea7; padding: 4px; font-size: 15px; }
.icon-btn:hover { color: var(--green); }

.empty-row td { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-row .label-font { font-size: 1.3rem; color: var(--ink); display: block; margin-bottom: 0.3rem; }

.bulk-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--mint); border: 1px solid #ddc9f7; border-radius: 12px;
  padding: 12px 16px; margin-bottom: 12px;
}
.bulk-bar span { font-weight: 700; font-size: 13px; color: var(--green-dark); margin-right: 4px; }
.bulk-bar select {
  height: 36px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line);
  background: white; font-size: 12.5px; color: #557066;
}
.bulk-bar .btn-primary, .bulk-bar .btn-ghost { height: 36px; padding: 0 14px; border-radius: 8px; font-weight: 700; font-size: 12.5px; }
.row-check { width: 17px; height: 17px; cursor: pointer; accent-color: var(--green); }

/* ---------- Alerts ---------- */
.alerts { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-bottom: 10px; }
.alert-item {
  background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--amber);
  border-radius: 12px; padding: 15px 17px; box-shadow: var(--shadow); text-align: left;
}
.alert-item.danger { border-left-color: var(--red); }
.alert-item.green { border-left-color: var(--green); }
.alert-item header { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 14px; }
.alert-item header i { font-size: 15px; color: var(--amber); }
.alert-item.danger header i { color: var(--red); }
.alert-item.green header i { color: var(--green); }
.alert-item p { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 10px 0 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,48,36,.42); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-overlay.open, .modal-overlay:not(.hidden) { display: flex; }
.modal-overlay.hidden { display: none; }
.modal-sheet {
  width: min(560px,100%); max-height: 90vh; overflow-y: auto;
  background: white; border-radius: 17px; box-shadow: 0 30px 80px rgba(17,53,35,.25); padding: 25px;
}
.modal-sheet h2 { font-size: 24px; margin: 0 0 4px; }
.modal-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.field { display: grid; gap: 6px; margin-bottom: 0.85rem; }
.field label { font-size: 13px; font-weight: 700; color: #547065; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; height: 38px;
  padding: 0 10px; outline: none; color: var(--ink); background: #fcfdfc;
}
.field textarea { height: 65px; padding-top: 9px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--mint); }
.field-row { display: flex; gap: 0.7rem; }
.field-row .field { flex: 1; }

.field-hint {
  font-size: 0.9rem; color: var(--green-dark); margin: -0.3rem 0 0.85rem;
  padding: 0.55rem 0.75rem; background: var(--mint); border-radius: 9px; display: none; font-weight: 500;
}
.field-hint.visible { display: block; }

.scan-btn {
  width: 100%; padding: 0.7rem; border-radius: 9px; background: var(--green); color: #fff;
  font-weight: 700; margin-bottom: 1rem; display: flex; align-items: center; justify-content: center;
  gap: 0.5rem; box-shadow: 0 5px 12px rgba(58,128,93,.2);
}
#scanner-view { width: 100%; border-radius: 9px; overflow: hidden; margin-bottom: 1rem; }

#quickscan-view { width: 100%; border-radius: 9px; overflow: hidden; margin-bottom: 4px; }

.qs-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: #fcfdfc; position: relative;
}
.qs-row .product-thumb { width: 32px; height: 32px; flex-shrink: 0; }
.qs-row .qs-nom { flex: 1 1 140px; min-width: 100px; border: 1px solid var(--line); border-radius: 7px; height: 34px; padding: 0 8px; font-weight: 600; }
.qs-row .qs-cat, .qs-row .qs-empl { border: 1px solid var(--line); border-radius: 7px; height: 34px; padding: 0 6px; font-size: 12px; color: #557066; flex: 1 1 110px; }
.qs-row .qty-cell { flex-shrink: 0; }
.qs-loading { width: 100%; font-size: 11px; color: var(--amber-ink); margin-top: 2px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 21px; }
.modal-actions button { padding: 0 16px; height: 40px; border-radius: 9px; font-weight: 700; font-size: 14.5px; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-danger { background: var(--red-bg); color: var(--red-ink); }
.btn-ghost { background: white; color: #557066; border: 1px solid var(--line); }

/* ---------- Auth screen ---------- */
.auth-screen {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 2rem 1.5rem; max-width: 380px; margin: 0 auto; width: 100%; min-height: 100vh;
}
.auth-screen h1 { font-size: 2.2rem; margin-bottom: 0.3rem; display: flex; align-items: center; gap: 0.6rem; }
.auth-screen h1::before {
  content: ''; display: inline-block; width: 34px; height: 34px; border-radius: 11px 11px 11px 3px;
  background: var(--green); transform: rotate(-8deg); flex-shrink: 0;
}
.auth-screen p.tagline { color: var(--muted); margin-bottom: 2rem; font-size: 1.05rem; }
.auth-screen input {
  width: 100%; padding: 0.75rem 0.9rem; border-radius: 9px; border: 1px solid var(--line);
  background: var(--white); color: var(--ink); margin-bottom: 0.7rem;
}
.auth-screen input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--mint); }
.auth-screen button.btn-primary {
  width: 100%; padding: 0.8rem; border-radius: 9px; background: var(--green); color: #fff;
  font-weight: 700; margin-top: 0.4rem; box-shadow: 0 8px 20px rgba(58,128,93,.25);
}
.auth-toggle { text-align: center; margin-top: 1rem; font-size: 0.95rem; color: var(--muted); }
.auth-toggle button { text-decoration: underline; color: var(--green-dark); font-weight: 600; }
.auth-error { color: var(--red-ink); font-size: 0.95rem; margin-bottom: 0.6rem; min-height: 1.1em; }

.hidden { display: none !important; }

/* ---------- Entrées / Sorties ---------- */
.mv-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.mv-tab {
  padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: 14.5px;
  color: var(--muted); border: 1px solid var(--line); background: white;
}
.mv-tab.active { background: var(--green); color: #fff; border-color: var(--green); }

.mv-grid { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 18px; align-items: start; }
.mv-form-card, .mv-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; box-shadow: var(--shadow);
}
.mv-form-card h3 { font-size: 20px; margin: 0 0 16px; }
.mv-side { display: grid; gap: 18px; }
.mv-card { padding: 16px 18px; }

.mv-recent-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #f0f4f1; }
.mv-recent-item:last-child { border-bottom: none; }
.mv-recent-icon {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; flex-shrink: 0;
}
.mv-recent-icon.entree { background: #ede4fb; color: #7c3aed; }
.mv-recent-icon.sortie { background: var(--red-bg); color: var(--red-ink); }
.mv-recent-info { flex: 1; min-width: 0; }
.mv-recent-nom { font-weight: 700; font-size: 14.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-recent-meta { font-size: 13px; color: var(--muted); }
.mv-recent-date { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .summary { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .alerts { grid-template-columns: minmax(0,1fr); }
  .mv-grid { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 780px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .mobile-toggle { display: block; }
  main { margin-left: 0; padding: 18px 16px 90px; }
  .profile-email { display: none; }
  .page-title { font-size: 24px; }
  .primary-btn span { display: none; }
}
@media (max-width: 480px) {
  .summary { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  .stat { padding: 14px; min-height: 100px; }
  .stat strong { font-size: 24px; }
  .form-grid, .field-row { flex-direction: column; }
}
