/* ── La Manufacture - Gestion d'Affaires ─────────────── */

:root {
  --primary: #1a5c2a;
  --primary-light: #2d8a42;
  --primary-dark: #0f3d1a;
  --accent: #4CAF50;
  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #333333;
  --text-light: #666666;
  --border: #e0e0e0;
  --danger: #e53935;
  --danger-light: #ffebee;
  --warning: #ff9800;
  --success: #4CAF50;
  --success-light: #e8f5e9;
  --info: #2196F3;
  --sidebar-w: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Sidebar ───────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary-dark), var(--primary));
  color: white;
  padding: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 24px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar-header .logo {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  margin-bottom: 10px;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.sidebar-header .subtitle {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
}

.nav-section {
  padding: 16px 0 8px;
}

.nav-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.5;
  padding: 0 20px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
}

.nav-item.active {
  background: rgba(255,255,255,0.15);
  border-left-color: #81C784;
}

.nav-item .icon {
  width: 20px;
  margin-right: 12px;
  text-align: center;
  font-size: 16px;
}

/* ── Main Content ──────────────────────────────────────── */

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 30px;
  max-width: 1200px;
  min-width: 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--primary-dark);
}

/* ── Cards ─────────────────────────────────────────────── */

.card {
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Stats cards (dashboard) ───────────────────────────── */

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

.stat-card {
  background: var(--card);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  text-align: center;
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Tables ────────────────────────────────────────────── */

.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background: var(--primary);
  color: white;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

th:first-child { border-radius: 6px 0 0 0; }
th:last-child { border-radius: 0 6px 0 0; }

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

tr:hover td {
  background: #f8f9fa;
}

.text-right { text-align: right; }
.text-center { text-align: center; }

/* ── Buttons ───────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { opacity: 0.9; }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { opacity: 0.9; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: #f0f0f0; }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-size: 14px;
}

.btn-icon:hover { background: #f0f0f0; }
.btn-icon.danger:hover { background: var(--danger-light); color: var(--danger); }

/* ── Forms ─────────────────────────────────────────────── */

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

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(26,92,42,0.1);
}

/* ── Badges ────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: #fff3e0; color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: #e3f2fd; color: var(--info); }

/* ── Modal ─────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: white;
  border-radius: 12px;
  padding: 28px;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 18px;
  color: var(--primary-dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Config list items ─────────────────────────────────── */

.config-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  background: #fafafa;
}

.config-item input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}

.config-item input:focus {
  outline: none;
  border-color: var(--primary);
}

.config-item .code-input { width: 70px; font-weight: 600; }
.config-item .name-input { flex: 1; min-width: 150px; }
.config-item .num-input { width: 80px; text-align: right; }

/* ── Progress bars ─────────────────────────────────────── */

.progress-bar {
  height: 8px;
  background: #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.progress-bar .fill.green { background: var(--success); }
.progress-bar .fill.orange { background: var(--warning); }
.progress-bar .fill.red { background: var(--danger); }

/* ── Mobile menu toggle ───────────────────────────────── */

.menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-size: 22px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
}

.sidebar-overlay.active {
  display: block;
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    padding: 16px;
    padding-top: 60px;
    width: 100%;
    overflow-x: hidden;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .page-header h2 {
    font-size: 20px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 14px 10px;
  }

  .stat-card .stat-value {
    font-size: 18px;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .stat-card .stat-label {
    font-size: 9px;
  }

  .card {
    padding: 16px;
    border-radius: 8px;
  }

  .modal {
    width: 95%;
    padding: 20px;
    max-height: 90vh;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .renta-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  td, th {
    padding: 8px 10px;
    font-size: 12px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat-card {
    padding: 10px 8px;
  }

  .stat-card .stat-value {
    font-size: 16px;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .stat-card .stat-label {
    font-size: 8px;
  }

  .renta-grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal {
    width: 100%;
    border-radius: 12px 12px 0 0;
    max-height: 95vh;
  }

  .page-header h2 {
    font-size: 18px;
  }

  .card {
    padding: 12px;
  }

  .card-title {
    font-size: 14px;
  }

  td, th {
    padding: 6px 8px;
    font-size: 11px;
  }
}

/* ── Responsive helpers ───────────────────────────────── */

.hidden { display: none !important; }

.page { display: none; }
.page.active { display: block; }

.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-10 { gap: 10px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ── Amounts ───────────────────────────────────────────── */

.amount { font-variant-numeric: tabular-nums; }
.amount.positive { color: var(--success); }
.amount.negative { color: var(--danger); }

/* ── Empty state ───────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-light);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Toast notification ────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 2000;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

/* ── Rentabilité panels ────────────────────────────────── */

.renta-panel {
  background: #f8faf8;
  border: 1px solid #e0e8e0;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 16px;
  border-left: 4px solid var(--primary);
}

.renta-panel.renta-ok {
  background: #f1f8f1;
  border-left-color: var(--success);
}

.renta-panel.renta-warn {
  background: #fffaf0;
  border-left-color: var(--warning);
}

.renta-panel.renta-danger {
  background: #fef5f5;
  border-left-color: var(--danger);
}

.renta-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.renta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.renta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.renta-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.renta-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
