:root {
  /* Palette officielle www.nosy-crafts.com */
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #273842;
  --text-muted: #647a87;
  --border: #ccd3d5;
  --primary: #496e83;
  --primary-hover: #405f72;
  --primary-soft: #e1ebf5;
  --primary-soft-text: #405f72;
  --secondary-bg: #ebe7df;
  --secondary-hover: #dfd9ce;
  --warning-bg: #f9c5b4;
  --warning-text: #7f1d0e;
  --danger: #9e3b1b;
  --shadow: 0 1px 3px rgba(64, 95, 114, 0.08);
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Roboto', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  background-color: var(--bg);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background-color: var(--surface);
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(64, 95, 114, 0.08);
  z-index: 10;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--primary);
  letter-spacing: 0.01em;
}

.sales-badge {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.product-list-container {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
}

.product-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.product-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.product-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.product-name {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  overflow-wrap: anywhere;
}

.product-stock {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background-color: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.product-stock.low-stock {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border-color: transparent;
}

.product-price {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  text-align: right;
  min-width: 36px;
  font-variant-numeric: tabular-nums;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
  padding: 10px 16px;
  transition: transform 0.08s ease, background-color 0.15s ease;
  touch-action: manipulation;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--secondary-bg);
  color: var(--text);
}

.btn-secondary:hover {
  background-color: var(--secondary-hover);
}

.btn-export {
  background-color: var(--primary-soft);
  color: var(--primary-soft-text);
  border: 1px solid rgba(73, 110, 131, 0.25);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 12px;
  min-height: 40px;
  white-space: nowrap;
}

.btn-export:hover {
  background-color: #d3e2f0;
}

.btn-buy {
  background-color: var(--primary);
  color: #ffffff;
  padding: 10px 16px;
  white-space: nowrap;
}

.btn-buy:hover {
  background-color: var(--primary-hover);
}

.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-muted);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

.empty-subtitle {
  margin: 0;
  font-size: 0.95rem;
}

/* Modal (<dialog>) */
.modal {
  width: min(92vw, 400px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background-color: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 40px rgba(39, 56, 66, 0.25);
}

.modal::backdrop {
  background-color: rgba(39, 56, 66, 0.52);
  backdrop-filter: blur(2px);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--primary);
}

.icon-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.6rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-close:hover {
  background-color: var(--bg);
  color: var(--text);
}

.modal-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background-color: var(--bg);
  border: 1px solid var(--border);
}

.meta-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.meta-value {
  font-size: 1.1rem;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.quantity-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.stepper {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 8px;
  align-items: center;
}

.stepper-btn {
  appearance: none;
  border: 1px solid var(--border);
  background-color: var(--bg);
  color: var(--primary);
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 500;
  height: 48px;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.stepper-btn:active {
  background-color: var(--primary-soft);
}

.stepper-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#quantity-input {
  width: 100%;
  height: 48px;
  text-align: center;
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background-color: var(--surface);
  appearance: textfield;
  -moz-appearance: textfield;
}

#quantity-input::-webkit-outer-spin-button,
#quantity-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#quantity-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.field-error {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--danger);
}

.modal-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 10px;
  background-color: var(--primary-soft);
  color: var(--primary-soft-text);
  font-size: 1rem;
  font-weight: 500;
}

.modal-total strong {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 10px;
  background-color: var(--primary-hover);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(39, 56, 66, 0.3);
  z-index: 100;
  text-align: center;
}
