:root {
  --color-bg: #f7f5f2;
  --color-surface: #ffffff;
  --color-border: #e2ddd6;
  --color-text: #2b2620;
  --color-text-muted: #756d63;
  --color-primary: #8a5a3b;
  --color-primary-dark: #6e4630;
  --color-danger: #b3452f;
  --color-success: #4d7c4a;
  --radius: 6px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
}

a {
  color: var(--color-primary-dark);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--color-text);
}

.nav-links {
  display: flex;
  gap: 1rem;
  flex: 1;
  flex-wrap: wrap;
}

.nav-links a {
  text-decoration: none;
  color: var(--color-text-muted);
  padding: 0.25rem 0;
}

.nav-links a.active {
  color: var(--color-primary-dark);
  font-weight: 600;
  border-bottom: 2px solid var(--color-primary);
}

.quick-actions {
  display: flex;
  gap: 0.5rem;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  margin-left: auto;
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  width: 1.1rem;
  height: 2px;
  margin: 0 auto;
  background: var(--color-text);
}

@media (max-width: 720px) {
  .nav-toggle {
    display: inline-flex;
  }

  .nav-links,
  .quick-actions {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .topbar.nav-open .nav-links,
  .topbar.nav-open .quick-actions {
    display: flex;
  }

  .quick-actions .button {
    text-align: center;
  }
}

main#app {
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1.5rem 3rem;
}

h1 {
  font-size: 1.4rem;
  margin-top: 0;
}

h2 {
  font-size: 1.1rem;
}

.button, button {
  display: inline-block;
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.95rem;
  cursor: pointer;
}

.button:hover, button:hover {
  background: var(--color-primary-dark);
}

.button.secondary, button.secondary {
  background: transparent;
  color: var(--color-primary-dark);
  border: 1px solid var(--color-border);
}

.button.secondary:hover, button.secondary:hover {
  background: var(--color-border);
}

.button.danger, button.danger {
  background: var(--color-danger);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
}

table th, table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.92rem;
}

table th {
  color: var(--color-text-muted);
  font-weight: 600;
  background: #f1ede7;
}

table tbody tr:hover {
  background: #faf7f3;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.table-wrap table {
  border: none;
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.toolbar input, .toolbar select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.9rem;
}

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

.field input, .field select, .field textarea {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.field-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.field-row .field {
  flex: 1;
  min-width: 180px;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #e5e0d8;
  color: var(--color-text);
}

.badge.en_stock { background: #e0ecdd; color: var(--color-success); }
.badge.vendu { background: #e4dcf3; color: #5a3c9e; }
.badge.donne { background: #dcebf3; color: #2c6f92; }
.badge.retire { background: #f3dcdc; color: var(--color-danger); }

.ligne-achat, .ligne-vente {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  background: #fbfaf8;
}

.ligne-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.article-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: center;
}

.article-row input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.muted {
  color: var(--color-text-muted);
  font-size: 0.88rem;
}

.error-banner {
  background: #fbe4de;
  color: var(--color-danger);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
}

.stat-tile .value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-tile .label {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.tabs button {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.tabs button.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.autocomplete {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  z-index: 10;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.autocomplete-list div {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
}

.autocomplete-list div:hover {
  background: var(--color-bg);
}

#toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}

.toast {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  color: white;
  background: var(--color-text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast.error {
  background: var(--color-danger);
}

.toast.success {
  background: var(--color-success);
}

.list-actions {
  display: flex;
  gap: 0.4rem;
}

.icon-button {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}
