:root {
  --brand-main: #c87d65;
  --brand-dark: #7a4635;
  --brand-light: #f4eae4;
  --brand-lighter: #fcf8f5;
  --accent-main: #a35841;
  --accent-light: #fbebe6;
  --ok-text: #2e7d32;

  --ink: #2d2926;
  --muted: #78716c;
  --bg: #f9f6f0;
  --panel: #ffffff;
  --line: #e6dfd5;
  --line2: #f0eae1;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100vw;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.5;
  padding-bottom: 40px;
  transition: background 0.3s ease;
}

header.app {
  background: var(--panel);
  border-bottom: 2px solid var(--line);
  padding: 10px 28px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
  max-width: 100vw;
  overflow-x: hidden;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-img {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.logo-text {
  font-weight: 800;
  font-size: 17px;
  color: var(--brand-dark);
}

nav.tabs {
  display: flex;
  gap: 6px;
}

nav.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

nav.tabs button:hover {
  background: var(--brand-lighter);
  color: var(--brand-main);
}

nav.tabs button.active {
  background: var(--brand-main);
  color: #fff;
}

.spacer {
  flex: 1;
}

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
}

.btn:hover {
  border-color: var(--brand-main);
  background: var(--brand-lighter);
}

.btn.primary {
  background: var(--brand-main);
  border-color: var(--brand-main);
  color: #fff;
}

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

.btn.danger {
  color: #c62828;
  border-color: #ffcdd2;
  background: #ffebee;
}

.btn.danger:hover {
  background: #ef9a9a;
  color: #b71c1c;
}

.btn.sm {
  padding: 4px 10px;
  font-size: 11.5px;
  border-radius: 6px;
  min-height: 32px;
}

main {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

.page {
  display: none;
  width: 100%;
  min-width: 0;
}

.page.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.grid-2,
.grid-3,
.grid-4,
.grid-5,
.grid-head {
  min-width: 0;
  width: 100%;
}

.grid-2>*,
.grid-3>*,
.grid-4>*,
.grid-5>*,
.grid-head>* {
  min-width: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* GRILLE 5 COLONNES OPTIMISÉE (Empêche la superposition à la verticale sur Mac) */
.grid-5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.grid-head {
  display: grid;
  grid-template-columns: 2.5fr 1.5fr 1fr 1fr;
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  min-width: 0;
  max-width: 100%;
}

.card-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--brand-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--brand-lighter);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 10px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--brand-main);
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.kpi.accent {
  border-left-color: var(--accent-main);
}

.kpi.success {
  border-left-color: var(--brand-dark);
}

.kpi.input-kpi {
  border-left-color: #2e7d32;
  background: #f4fdf5;
}

.kpi .v {
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi .l {
  font-size: 9.5px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.input-wrapper {
  display: flex;
  align-items: center;
  position: relative;
}

.kpi-input {
  width: 100%;
  font-size: 18px;
  font-weight: 800;
  color: #1b5e20;
  background: #ffffff;
  border: 1.5px solid #a5d6a7;
  border-radius: 6px;
  padding: 2px 20px 2px 6px;
  font-family: inherit;
}

.kpi-input:focus {
  outline: none;
  border-color: #2e7d32;
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.currency-symbol {
  position: absolute;
  right: 8px;
  font-size: 18px;
  font-weight: 800;
  color: #2e7d32;
  pointer-events: none;
}

.tablewrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  -webkit-overflow-scrolling: touch;
  margin-top: 6px;
}

.tablewrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: nowrap;
  table-layout: fixed;
}

#tab-calculator .tablewrap table {
  min-width: 100%;
}

#tab-inventory .tablewrap table {
  min-width: 100%;
}

#tab-catalog .tablewrap table {
  min-width: 720px;
}

/* --- ALIGNEMENT DES TABLEAUX --- */
/* Par défaut, toutes les colonnes sont centrées... */
th,
td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--line2);
  text-align: center !important;
  vertical-align: middle;
}

th {
  background: var(--brand-lighter);
  color: var(--brand-dark);
  font-weight: 700;
  font-size: 10.5px;
  text-transform: uppercase;
  position: relative;
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ...Sauf la TOUTE PREMIÈRE COLONNE (titre et données) qui est alignée À GAUCHE */
th:first-child,
td:first-child {
  text-align: left !important;
}

tr:last-child td {
  border-bottom: 0;
}

/* Centrage des éléments éditables dans les tableaux */
.tablewrap input.form-input,
.tablewrap select.form-select {
  text-align: center;
  text-align-last: center;
}

/* Alignement à gauche pour la première colonne éditable */
.tablewrap td:first-child input.form-input,
.tablewrap td:first-child select.form-select {
  text-align: left;
  text-align-last: left;
}

input.form-input,
select.form-select {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--ink);
  min-height: 34px;
}

input.form-input:focus,
select.form-select:focus {
  border-color: var(--brand-main);
  outline: none;
  box-shadow: 0 0 0 3px var(--brand-light);
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  background: var(--brand-light);
  color: var(--brand-dark);
}

.badge.accent-badge {
  background: var(--accent-light);
  color: var(--accent-main);
}

.channel-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  background: #fafaf8;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}

.channel-box.highlight {
  border: 2px solid var(--brand-main);
  background: var(--brand-lighter);
}

.channel-box .price {
  font-size: 22px;
  font-weight: 800;
  color: var(--brand-dark);
  margin: 6px 0 2px 0;
}

.channel-box .profit-tag {
  font-size: 12px;
  font-weight: 800;
  color: var(--ok-text);
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
  padding: 4px 8px;
  border-radius: 6px;
  margin: 6px auto;
  display: inline-block;
}

.theme-swatch {
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  background: #fff;
  text-align: center;
  transition: all 0.2s;
}

.theme-swatch:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.theme-swatch.active {
  border-color: var(--ink);
  box-shadow: var(--shadow);
  font-weight: bold;
}

@media (max-width: 768px) {
  header.app {
    padding: 8px 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .logo-container {
    justify-content: center;
  }

  .logo-img {
    height: 28px;
  }

  .logo-text {
    font-size: 15px;
  }

  nav.tabs {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    display: flex;
    gap: 4px;
    padding-bottom: 4px;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }

  nav.tabs button {
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: 11.5px;
  }

  main {
    padding: 10px 8px;
  }

  .grid-2,
  .grid-3,
  .grid-head {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .grid-4,
  .grid-5 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
  }

  .kpi {
    padding: 10px 12px;
  }

  .kpi .v {
    font-size: 17px;
  }

  .card {
    padding: 12px 10px;
    margin-bottom: 12px;
  }

  .card-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .card-title>div {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .btn {
    width: 100%;
  }

  .btn.sm {
    width: auto;
    flex: 1;
  }
}

#print-sheet {
  display: none;
}

@media print {
  @page {
    size: letter portrait;
    margin: 0.4in;
  }

  body {
    background: #fff !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  header.app,
  main,
  .no-print {
    display: none !important;
  }

  #print-sheet {
    display: block !important;
    font-family: 'Plus Jakarta Sans', sans-serif;
    color: #2d2926;
    padding: 0;
    max-width: 100%;
  }

  .pdf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--brand-main);
    padding-bottom: 10px;
    margin-bottom: 14px;
  }

  .pdf-logo {
    max-height: 50px;
  }

  .pdf-title {
    text-align: right;
  }

  .pdf-title h1 {
    margin: 0;
    font-size: 17px;
    color: var(--brand-dark);
    text-transform: uppercase;
  }

  .pdf-title p {
    margin: 2px 0 0 0;
    font-size: 10.5px;
    color: var(--muted);
  }

  .pdf-product-hero {
    background: var(--brand-lighter);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .pdf-product-hero h2 {
    margin: 0;
    font-size: 16px;
    color: var(--brand-dark);
  }

  .pdf-section-title {
    font-size: 11px;
    font-weight: 800;
    color: var(--brand-dark);
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
    padding-bottom: 3px;
    margin: 12px 0 8px 0;
  }

  .pdf-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10.5px;
    margin-bottom: 10px;
  }

  .pdf-table th {
    background: #f4f0eb;
    color: var(--brand-dark);
    text-transform: uppercase;
    font-size: 9px;
    padding: 5px 6px;
    border-bottom: 1px solid var(--line);
    text-align: center;
  }

  .pdf-table td {
    padding: 5px 6px;
    border-bottom: 1px solid var(--line2);
    text-align: center;
  }

  .pdf-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .pdf-prices-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 14px;
  }

  .pdf-price-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    background: #fafaf8;
  }

  .pdf-price-card.main {
    border: 2px solid var(--brand-main);
    background: var(--brand-lighter);
  }

  .pdf-price-card .val {
    font-size: 17px;
    font-weight: 800;
    color: var(--brand-dark);
    margin-top: 2px;
  }

  .pdf-price-card .pdf-profit {
    font-size: 10px;
    font-weight: bold;
    color: #2e7d32;
    margin-top: 4px;
  }

  .pdf-footer {
    margin-top: 20px;
    border-top: 1px dashed var(--line);
    padding-top: 8px;
    text-align: center;
    font-size: 9.5px;
    color: var(--muted);
  }
}

/* --- POIGNÉES DE REDIMENSIONNEMENT DES COLONNES --- */
.column-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 10;
}

.column-resizer:hover,
.column-resizer.resizing {
  background-color: var(--brand-main);
  opacity: 0.7;
}