:root {
  --green: #55A932;
  --green-dark: #457f27;
  --ink: #3C3C3B;
  --paper: #FAFAF8;
  --line: #E4E2DC;
  --muted: #8A8A85;
  --danger: #C0392B;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, select {
  font-family: inherit;
  font-size: 16px; /* évite le zoom iOS au focus */
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--ink);
  color: white;
}

.topbar-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sync-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #cfcfcc;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}
.dot.pending { background: #E8A33D; animation: pulse 1.2s infinite; }
.dot.offline { background: var(--danger); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#app {
  padding: 12px 16px 96px;
  max-width: 640px;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: white;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
}

.tab-btn.active { color: var(--green-dark); font-weight: 600; }
.tab-icon { font-size: 20px; }

.search-box {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: white;
  margin-bottom: 12px;
}

.article-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  margin-bottom: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
}

.article-row-title {
  font-weight: 600;
  font-size: 15px;
}

.article-row-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.article-row-qty {
  font-size: 20px;
  font-weight: 700;
  color: var(--green-dark);
  white-space: nowrap;
}

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

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 5px;
}

.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: white;
}

.field-with-btn {
  display: flex;
  gap: 8px;
}
.field-with-btn input { flex: 1; }

.btn {
  padding: 11px 16px;
  border-radius: var(--radius);
  border: none;
  font-weight: 600;
  font-size: 14.5px;
}

.btn-primary { background: var(--green); color: white; }
.btn-primary:active { background: var(--green-dark); }

.btn-secondary { background: white; border: 1px solid var(--line); color: var(--ink); }

.btn-danger { background: none; color: var(--danger); border: 1px solid #eecfca; }

.btn-icon {
  background: var(--ink);
  color: white;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  font-size: 18px;
  flex-shrink: 0;
}

.btn-block { width: 100%; }

.back-btn {
  background: none;
  border: none;
  color: var(--green-dark);
  font-weight: 600;
  padding: 8px 0 14px;
  font-size: 15px;
}

.card-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.card-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
}

.location-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.location-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.location-name {
  font-weight: 700;
  font-size: 14.5px;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qty-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

.qty-value {
  min-width: 40px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}

datalist { display: none; }

.scanner-overlay {
  position: fixed;
  inset: 0;
  background: black;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#scanner-cam {
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius);
  overflow: hidden;
}

.scanner-close-btn {
  margin-top: 20px;
  width: 100%;
  max-width: 420px;
}

.zone-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
  display: flex;
  align-items: flex-end;
}

.zone-picker-panel {
  background: var(--paper);
  width: 100%;
  max-height: 80vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.zone-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
}

.zone-picker-breadcrumb {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.zone-picker-list {
  overflow-y: auto;
  padding: 8px 14px;
  flex: 1;
}

.zone-picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}

.zone-picker-row-name {
  font-size: 15px;
  flex: 1;
}

.zone-picker-row-actions {
  display: flex;
  gap: 6px;
}

.zone-picker-footer {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
}

.zone-path-display {
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.zone-tree-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.zone-tree-indent {
  display: inline-block;
}

.link-btn {
  background: none;
  border: none;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 6px;
}
.link-btn.danger { color: var(--danger); }

.section-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 16px;
  right: 16px;
  background: var(--ink);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  text-align: center;
  z-index: 50;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
