:root {
  --bg: #0f172a;
  --bg-light: #f4f6fb;
  --panel: #ffffff;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --text: #1e293b;
  --text-muted: #64748b;
  --danger: #dc2626;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1d4ed8;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  background: var(--bg-light);
  color: var(--text);
}

#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--sidebar-bg);
  color: white;
  padding: 0.6rem 1.2rem;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 1.1rem; }
.brand-icon { font-size: 1.4rem; }

.projet-selector { display: flex; align-items: center; gap: 0.5rem; }

select, input[type="text"], textarea {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
}

#projet-select { min-width: 220px; }

.btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.15s ease;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: #334155; color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-icon {
  background: transparent; border: none; cursor: pointer;
  font-size: 1rem; color: var(--text-muted);
}

.layout { display: flex; flex: 1; overflow: hidden; }

.sidebar {
  width: 280px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 0.5rem 0;
}

.atelier-group { margin-bottom: 0.4rem; }
.atelier-title {
  padding: 0.7rem 1rem 0.3rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  font-weight: 700;
}
.table-link {
  display: block;
  padding: 0.5rem 1.2rem;
  cursor: pointer;
  font-size: 0.88rem;
  border-left: 3px solid transparent;
}
.table-link:hover { background: rgba(255,255,255,0.06); }
.table-link.active {
  background: rgba(29,78,216,0.25);
  border-left-color: var(--primary);
  color: white;
  font-weight: 600;
}

.content { flex: 1; overflow-y: auto; padding: 1.5rem 2rem; }

.empty-state { text-align: center; margin-top: 4rem; color: var(--text-muted); }

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  gap: 1rem;
}
.table-header h2 { margin: 0 0 0.2rem; }
.table-header p { margin: 0; color: var(--text-muted); font-size: 0.9rem; max-width: 640px; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
table.data-table th, table.data-table td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  vertical-align: top;
}
table.data-table th {
  background: #f1f5f9;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover { background: #f8fafc; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #e2e8f0;
  color: var(--text);
}
.badge-4 { background: #fee2e2; color: #991b1b; }
.badge-3 { background: #ffedd5; color: #9a3412; }
.badge-2 { background: #fef9c3; color: #854d0e; }
.badge-1 { background: #dcfce7; color: #166534; }

.row-actions { white-space: nowrap; }
.row-actions button {
  background: none; border: none; cursor: pointer; font-size: 0.95rem;
  padding: 0.15rem 0.3rem; color: var(--text-muted);
}
.row-actions button:hover { color: var(--primary); }
.row-actions .del:hover { color: var(--danger); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: white; border-radius: 10px; width: 520px; max-width: 92vw;
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1.1rem 1.2rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.9rem; }
.modal-body label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; font-weight: 600; color: var(--text); }
.modal-body input, .modal-body select, .modal-body textarea { font-weight: 400; width: 100%; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.6rem;
  padding: 0.9rem 1.2rem; border-top: 1px solid var(--border);
}

.toast {
  position: fixed; bottom: 1.2rem; right: 1.2rem;
  background: #0f172a; color: white; padding: 0.7rem 1.1rem;
  border-radius: var(--radius); font-size: 0.85rem; z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.toast.hidden { display: none; }
.toast.error { background: var(--danger); }

.add-bar { display: flex; justify-content: flex-end; margin-bottom: 0.8rem; }

input.hidden, input[type="file"].hidden { display: none; }

table.matrix-table th, table.matrix-table td { text-align: center; }
table.matrix-table thead th:first-child, table.matrix-table tbody th { text-align: left; background: #f1f5f9; }
table.matrix-table select { width: 100%; }
